/** * Used by PropertyAction to mimic property sheet behavior - trying to invoke * PropertyEnv listener of the current property editor (we can't create our * own PropertyEnv instance). * * @return current value * @throws java.beans.PropertyVetoException if someone vetoes this change. */ public Object commitChanges() throws PropertyVetoException { int currentIndex = editorsCombo.getSelectedIndex(); PropertyEditor currentEditor = currentIndex > -1 ? allEditors[currentIndex] : null; if (currentEditor instanceof ExPropertyEditor) { // we can only guess - according to the typical pattern the propetry // editor itself or the custom editor usually implement the listener // registered in PropertyEnv PropertyChangeEvent evt = new PropertyChangeEvent( this, PropertyEnv.PROP_STATE, null, PropertyEnv.STATE_VALID); if (currentEditor instanceof VetoableChangeListener) { ((VetoableChangeListener)currentEditor).vetoableChange(evt); } Component currentCustEd = currentIndex > -1 ? allCustomEditors[currentIndex] : null; if (currentCustEd instanceof VetoableChangeListener) { ((VetoableChangeListener)currentCustEd).vetoableChange(evt); } if (currentEditor instanceof PropertyChangeListener) { ((PropertyChangeListener)currentEditor).propertyChange(evt); } if (currentCustEd instanceof PropertyChangeListener) { ((PropertyChangeListener)currentCustEd).propertyChange(evt); } } return commitChanges0(); }
public void testSetNodesSurviveChangeOfNodes() throws Exception { final Node a = keys.key("toRemove"); class ChangeTheSelectionInMiddleOfMethod implements VetoableChangeListener { public int cnt; public void vetoableChange(PropertyChangeEvent evt) { cnt++; keys.keys(new String[0]); } } ChangeTheSelectionInMiddleOfMethod list = new ChangeTheSelectionInMiddleOfMethod(); em.addVetoableChangeListener(list); em.setSelectedNodes(new Node[] { a }); assertEquals("Vetoable listener called", 1, list.cnt); assertEquals("Node is dead", null, a.getParentNode()); // handling of removed nodes is done asynchronously em.waitFinished(); Node[] arr = em.getSelectedNodes(); assertEquals("No nodes can be selected", 0, arr.length); }
public void testCannotVetoSetToEmptySelection() throws Exception { final Node a = keys.key("toRemove"); em.setSelectedNodes(new Node[] { a }); class NeverCalledVeto implements VetoableChangeListener { public int cnt; public void vetoableChange(PropertyChangeEvent evt) { cnt++; keys.keys(new String[0]); } } NeverCalledVeto list = new NeverCalledVeto(); em.addVetoableChangeListener(list); em.setSelectedNodes(new Node[0]); assertEquals("Veto not called", 0, list.cnt); Node[] arr = em.getSelectedNodes(); assertEquals("No nodes can be selected", 0, arr.length); }
/** * Add a PropertyChangeListener to the listener list if it is * not already present. * The listener is registered for all properties. * The operation maintains Set semantics: If the listener is already * registered, the operation has no effect. * * @param listener The PropertyChangeListener to be added * @exception NullPointerException If listener is null */ public synchronized void addVetoableChangeListenerIfAbsent(VetoableChangeListener listener) { if (listener == null) throw new NullPointerException(); // Copy while checking if already present. int len = listeners.length; VetoableChangeListener[] newArray = new VetoableChangeListener[len + 1]; for (int i = 0; i < len; ++i) { newArray[i] = listeners[i]; if (listener.equals(listeners[i])) return; // already present -- throw away copy } newArray[len] = listener; listeners = newArray; }
private void addListener(PropertiesDataObject dataObj) { PropertyChangeListener l =weakEnvPropListeners.get(dataObj); VetoableChangeListener v = weakEnvVetoListeners.get(dataObj); if (l != null) { dataObj.removePropertyChangeListener(l); } else { l = WeakListeners.propertyChange(this, dataObj); weakEnvPropListeners.put(dataObj, l); } if (v != null) { dataObj.removeVetoableChangeListener(v); } else { v = WeakListeners.vetoableChange(this, dataObj); weakEnvVetoListeners.put(dataObj, v); } dataObj.addPropertyChangeListener(l); dataObj.addVetoableChangeListener(v); }
private void addListeners() { BundleStructure structure = bundleStructure; PropertiesDataObject dataObj; weakEnvPropListeners = new HashMap<PropertiesDataObject, PropertyChangeListener>(); weakEnvVetoListeners = new HashMap<PropertiesDataObject, VetoableChangeListener>(); PropertyChangeListener l; VetoableChangeListener v; for(int i=0;i<structure.getEntryCount();i++) { dataObj = (PropertiesDataObject) structure.getNthEntry(i).getDataObject(); l = WeakListeners.propertyChange(this, dataObj); weakEnvPropListeners.put(dataObj, l); dataObj.addPropertyChangeListener(l); v = WeakListeners.vetoableChange(this, dataObj); weakEnvVetoListeners.put(dataObj, v); dataObj.addVetoableChangeListener(v); } }
private void removeListeners() { BundleStructure structure = bundleStructure; PropertiesDataObject dataObj; PropertyChangeListener l; VetoableChangeListener v; for(int i=0;i<structure.getEntryCount();i++) { dataObj = (PropertiesDataObject) structure.getNthEntry(i).getDataObject(); l = weakEnvPropListeners.remove(dataObj); v = weakEnvVetoListeners.remove(dataObj); if (l!=null) { dataObj.removePropertyChangeListener(l); } if (v!=null) { dataObj.removeVetoableChangeListener(v); } } }
final void atomicUnlockImpl (boolean notifyUnmodifyIfNoMods) { boolean noModsAndOuterUnlock = false; synchronized (this) { if (atomicDepth <= 0) { throw new IllegalStateException("atomicUnlock() without atomicLock()"); // NOI18N } if (--atomicDepth == 0) { // lock really ended fireAtomicUnlock(atomicLockEventInstance); noModsAndOuterUnlock = !checkAndFireAtomicEdits(); atomicLockListenerList = null; extWriteUnlock(); } } if (notifyUnmodifyIfNoMods && noModsAndOuterUnlock) { // Notify unmodification if there were no document modifications // inside the atomic section. // Fire VetoableChangeListener outside Document lock VetoableChangeListener l = (VetoableChangeListener) getProperty(MODIFICATION_LISTENER_PROP); if (l != null) { try { // Notify unmodification by Boolean.FALSE l.vetoableChange(new PropertyChangeEvent(this, "modified", null, Boolean.FALSE)); } catch (java.beans.PropertyVetoException ex) { // Ignored (should not be thrown) } } } }
private boolean notifyModified (Object o) { boolean canBeModified = true; if (o instanceof VetoableChangeListener) { VetoableChangeListener l = (VetoableChangeListener)o; try { l.vetoableChange (new java.beans.PropertyChangeEvent (this, "modified", null, Boolean.TRUE)); } catch (java.beans.PropertyVetoException ex) { canBeModified = false; } } return canBeModified; }
protected synchronized void removeVetoableChangeListener(String property, VetoableChangeListener listener) { if (_vcSupport != null) { _vcSupport.removeVetoableChangeListener(property, listener); } }
/** * Adds a <code>VetoableChangeListener</code> to the listener list. * The listener is registered for all properties. * * @param listener the <code>VetoableChangeListener</code> to be added */ public synchronized void addVetoableChangeListener(VetoableChangeListener listener) { if (vetoableChangeSupport == null) { vetoableChangeSupport = new java.beans.VetoableChangeSupport(this); } vetoableChangeSupport.addVetoableChangeListener(listener); }
/** * Gets the VetoableChangeListener * (if any) of the specified child * @param child the specified child * @return the VetoableChangeListener (if any) of the specified child */ protected static final VetoableChangeListener getChildVetoableChangeListener(Object child) { try { return (VetoableChangeListener)child; } catch (ClassCastException cce) { return null; } }
/** * Add a VetoableChangeListener to the listener list. * The listener is registered for all properties. * If the listener is added multiple times, it will * receive multiple change notifications upon any fireVetoableChange. * * @param listener The VetoableChangeListener to be added */ public synchronized void addVetoableChangeListener(VetoableChangeListener listener) { if (listener == null) throw new NullPointerException(); int len = listeners.length; VetoableChangeListener[] newArray = new VetoableChangeListener[len + 1]; if (len > 0) System.arraycopy(listeners, 0, newArray, 0, len); newArray[len] = listener; listeners = newArray; }
protected void openInnerPanel() { if (toolBarDesignEditor == null) { toolBarDesignEditor = sectionView.getToolBarDesignEditor(); if (toolBarDesignEditor != null) { toolBarDesignEditor.addVetoableChangeListener(new VetoableChangeListener() { public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException { if (ToolBarDesignEditor.PROPERTY_FLUSH_DATA.equals(evt.getPropertyName()) && evt.getNewValue() == null) { if (innerPanel != null && !innerPanel.canClose()) { throw new PropertyVetoException("", evt); } } } }); } } if (innerPanel != null) { return; } innerPanel = createInnerpanel(); java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 2; gridBagConstraints.gridwidth = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(2, 0, 0, 0); fillerLine.setVisible(true); fillerEnd.setVisible(true); innerPanel.addFocusListener(sectionFocusListener); add(innerPanel, gridBagConstraints); Utils.scrollToVisible(this); // issue 233048: the background color issues with dark metal L&F // innerPanel.setBackground( // active ? SectionVisualTheme.getSectionActiveBackgroundColor() : SectionVisualTheme.getDocumentBackgroundColor()); }
/** Adds listener for the veto of property change. * @param listener the listener */ public final void addVetoableChangeListener(VetoableChangeListener listener) { synchronized (internLock) { if (vetoableChangeList == null) { vetoableChangeList = new ListenerList<VetoableChangeListener>(); } vetoableChangeList.add(listener); } }
private VetoableChangeListener createVetoableChangeListener () { return new VetoableChangeListener () { public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException { abacus++; } }; }
/** Fire a property change event. * @param name the name of the property * @param oldValue the old value * @param newValue the new value * @exception PropertyVetoException if the change is vetoed */ public final void fireVetoableChange(String name, Object oldValue, Object newValue) throws PropertyVetoException { PropertyChangeEvent ev = new PropertyChangeEvent(this, name, oldValue, newValue); Iterator en; synchronized (getLock()) { en = ((HashSet) getVeto().clone()).iterator(); } while (en.hasNext()) { ((VetoableChangeListener) en.next()).vetoableChange(ev); } }
/** Tests if the object we reference to still exists and * if so, delegate to it. Otherwise remove from the source * if it has removePropertyChangeListener method. */ @Override public void vetoableChange(PropertyChangeEvent ev) throws PropertyVetoException { VetoableChangeListener l = (VetoableChangeListener) super.get(ev); if (l != null) { l.vetoableChange(ev); } }
/** Adds veto listener. */ @Override public void addVetoableChangeListener(VetoableChangeListener l) { }
/** Removes veto listener. */ @Override public void removeVetoableChangeListener(VetoableChangeListener l) { }
@Override public synchronized void addVetoableChangeListener(VetoableChangeListener l) { assertNull ("This is the first veto listener", vetoL); vetoL = l; }
@Override public void removeVetoableChangeListener(VetoableChangeListener l) { assertEquals ("Removing the right veto one", vetoL, l); vetoL = null; }
/** * Returns an array of all the objects currently registered * as <code><em>Foo</em>Listener</code>s * upon this <code>JComponent</code>. * <code><em>Foo</em>Listener</code>s are registered using the * <code>add<em>Foo</em>Listener</code> method. * * <p> * * You can specify the <code>listenerType</code> argument * with a class literal, * such as * <code><em>Foo</em>Listener.class</code>. * For example, you can query a * <code>JComponent</code> <code>c</code> * for its mouse listeners with the following code: * <pre>MouseListener[] mls = (MouseListener[])(c.getListeners(MouseListener.class));</pre> * If no such listeners exist, this method returns an empty array. * * @param listenerType the type of listeners requested; this parameter * should specify an interface that descends from * <code>java.util.EventListener</code> * @return an array of all objects registered as * <code><em>Foo</em>Listener</code>s on this component, * or an empty array if no such * listeners have been added * @exception ClassCastException if <code>listenerType</code> * doesn't specify a class or interface that implements * <code>java.util.EventListener</code> * * @since 1.3 * * @see #getVetoableChangeListeners * @see #getAncestorListeners */ public <T extends EventListener> T[] getListeners(Class<T> listenerType) { T[] result; if (listenerType == AncestorListener.class) { // AncestorListeners are handled by the AncestorNotifier result = (T[])getAncestorListeners(); } else if (listenerType == VetoableChangeListener.class) { // VetoableChangeListeners are handled by VetoableChangeSupport result = (T[])getVetoableChangeListeners(); } else if (listenerType == PropertyChangeListener.class) { // PropertyChangeListeners are handled by PropertyChangeSupport result = (T[])getPropertyChangeListeners(); } else { result = listenerList.getListeners(listenerType); } if (result.length == 0) { return super.getListeners(listenerType); } return result; }
void setRemoteEnvVetoListener(VetoableChangeListener vl) { remotevEnvListener = vl; }
/** * Vetoable change listener removal. */ public void removeVetoableChangeListener(VetoableChangeListener l) { getSupport().removeVetoableChangeListener(l); }
public synchronized void addVetoableChangeListener(VetoableChangeListener l) { assertNull ("This is the first veto listener", vetoL); vetoL = l; }
public void removeVetoableChangeListener(VetoableChangeListener l) { assertEquals ("Removing the right veto one", vetoL, l); vetoL = null; }
/** Removes veto listener. */ public void removeVetoableChangeListener(VetoableChangeListener l) { }