Java Code Examples for java.beans.VetoableChangeListener#vetoableChange()

The following examples show how to use java.beans.VetoableChangeListener#vetoableChange() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClosableTabbedPane.java    From darklaf with MIT License 5 votes vote down vote up
private boolean notifyVetoableChangeListeners(final TabPropertyChangeEvent e) {
    try {
        VetoableChangeListener[] listeners = getVetoableChangeListeners();
        for (VetoableChangeListener l : listeners) {
            l.vetoableChange(e);
        }
    } catch (PropertyVetoException ex) {
        return true;
    }
    return false;
}
 
Example 2
Source File: NbLikeEditorKit.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 3
Source File: WeakListenerImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** 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);
    }
}
 
Example 4
Source File: BaseDocument.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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)
            }
        }
    }
}
 
Example 5
Source File: EventListenerSupportTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testSerialization() throws IOException, ClassNotFoundException, PropertyVetoException {
    EventListenerSupport<VetoableChangeListener> listenerSupport = EventListenerSupport.create(VetoableChangeListener.class);
    listenerSupport.addListener(new VetoableChangeListener() {
        
        public void vetoableChange(PropertyChangeEvent e) {
        }
    });
    listenerSupport.addListener(EasyMock.createNiceMock(VetoableChangeListener.class));

    //serialize:
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);

    objectOutputStream.writeObject(listenerSupport);
    objectOutputStream.close();

    //deserialize:
    @SuppressWarnings("unchecked")
    EventListenerSupport<VetoableChangeListener> deserializedListenerSupport = (EventListenerSupport<VetoableChangeListener>) new ObjectInputStream(
            new ByteArrayInputStream(outputStream.toByteArray())).readObject();

    //make sure we get a listener array back, of the correct component type, and that it contains only the serializable mock
    VetoableChangeListener[] listeners = deserializedListenerSupport.getListeners();
    assertEquals(VetoableChangeListener.class, listeners.getClass().getComponentType());
    assertEquals(1, listeners.length);

    //now verify that the mock still receives events; we can infer that the proxy was correctly reconstituted
    VetoableChangeListener listener = listeners[0];
    PropertyChangeEvent evt = new PropertyChangeEvent(new Date(), "Day", 7, 9);
    listener.vetoableChange(evt);
    EasyMock.replay(listener);
    deserializedListenerSupport.fire().vetoableChange(evt);
    EasyMock.verify(listener);

    //remove listener and verify we get an empty array of listeners
    deserializedListenerSupport.removeListener(listener);
    assertEquals(0, deserializedListenerSupport.getListeners().length);
}
 
Example 6
Source File: EventListenerSupportTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testSubclassInvocationHandling() throws PropertyVetoException {

        @SuppressWarnings("serial")
        EventListenerSupport<VetoableChangeListener> eventListenerSupport = new EventListenerSupport<VetoableChangeListener>(
                VetoableChangeListener.class) {
            protected java.lang.reflect.InvocationHandler createInvocationHandler() {
                return new ProxyInvocationHandler() {
                    /**
                     * {@inheritDoc}
                     */
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args)
                            throws Throwable {
                        return "vetoableChange".equals(method.getName())
                                && "Hour".equals(((PropertyChangeEvent) args[0]).getPropertyName()) ? null
                                : super.invoke(proxy, method, args);
                    }
                };
            };
        };

        VetoableChangeListener listener = EasyMock.createNiceMock(VetoableChangeListener.class);
        eventListenerSupport.addListener(listener);
        Object source = new Date();
        PropertyChangeEvent ignore = new PropertyChangeEvent(source, "Hour", 5, 6);
        PropertyChangeEvent respond = new PropertyChangeEvent(source, "Day", 6, 7);
        listener.vetoableChange(respond);
        EasyMock.replay(listener);
        eventListenerSupport.fire().vetoableChange(ignore);
        eventListenerSupport.fire().vetoableChange(respond);
        EasyMock.verify(listener);
    }
 
Example 7
Source File: EventListenerSupportTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testSerialization() throws IOException, ClassNotFoundException, PropertyVetoException {
    EventListenerSupport<VetoableChangeListener> listenerSupport = EventListenerSupport.create(VetoableChangeListener.class);
    listenerSupport.addListener(new VetoableChangeListener() {
        
        @Override
        public void vetoableChange(PropertyChangeEvent e) {
        }
    });
    listenerSupport.addListener(EasyMock.createNiceMock(VetoableChangeListener.class));

    //serialize:
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);

    objectOutputStream.writeObject(listenerSupport);
    objectOutputStream.close();

    //deserialize:
    @SuppressWarnings("unchecked")
    EventListenerSupport<VetoableChangeListener> deserializedListenerSupport = (EventListenerSupport<VetoableChangeListener>) new ObjectInputStream(
            new ByteArrayInputStream(outputStream.toByteArray())).readObject();

    //make sure we get a listener array back, of the correct component type, and that it contains only the serializable mock
    VetoableChangeListener[] listeners = deserializedListenerSupport.getListeners();
    assertEquals(VetoableChangeListener.class, listeners.getClass().getComponentType());
    assertEquals(1, listeners.length);

    //now verify that the mock still receives events; we can infer that the proxy was correctly reconstituted
    VetoableChangeListener listener = listeners[0];
    PropertyChangeEvent evt = new PropertyChangeEvent(new Date(), "Day", 7, 9);
    listener.vetoableChange(evt);
    EasyMock.replay(listener);
    deserializedListenerSupport.fire().vetoableChange(evt);
    EasyMock.verify(listener);

    //remove listener and verify we get an empty array of listeners
    deserializedListenerSupport.removeListener(listener);
    assertEquals(0, deserializedListenerSupport.getListeners().length);
}
 
Example 8
Source File: EventListenerSupportTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testSubclassInvocationHandling() throws PropertyVetoException {

    @SuppressWarnings("serial")
    EventListenerSupport<VetoableChangeListener> eventListenerSupport = new EventListenerSupport<VetoableChangeListener>(
            VetoableChangeListener.class) {
        @Override
        protected java.lang.reflect.InvocationHandler createInvocationHandler() {
            return new ProxyInvocationHandler() {
                /**
                 * {@inheritDoc}
                 */
                @Override
                public Object invoke(Object proxy, Method method, Object[] args)
                        throws Throwable {
                    return "vetoableChange".equals(method.getName())
                            && "Hour".equals(((PropertyChangeEvent) args[0]).getPropertyName()) ? null
                            : super.invoke(proxy, method, args);
                }
            };
        }
    };

    VetoableChangeListener listener = EasyMock.createNiceMock(VetoableChangeListener.class);
    eventListenerSupport.addListener(listener);
    Object source = new Date();
    PropertyChangeEvent ignore = new PropertyChangeEvent(source, "Hour", 5, 6);
    PropertyChangeEvent respond = new PropertyChangeEvent(source, "Day", 6, 7);
    listener.vetoableChange(respond);
    EasyMock.replay(listener);
    eventListenerSupport.fire().vetoableChange(ignore);
    eventListenerSupport.fire().vetoableChange(respond);
    EasyMock.verify(listener);
}
 
Example 9
Source File: EventListenerSupportTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testSubclassInvocationHandling() throws PropertyVetoException {

    @SuppressWarnings("serial")
    final
    EventListenerSupport<VetoableChangeListener> eventListenerSupport = new EventListenerSupport<VetoableChangeListener>(
            VetoableChangeListener.class) {
        @Override
        protected java.lang.reflect.InvocationHandler createInvocationHandler() {
            return new ProxyInvocationHandler() {
                /**
                 * {@inheritDoc}
                 */
                @Override
                public Object invoke(final Object proxy, final Method method, final Object[] args)
                        throws Throwable {
                    return "vetoableChange".equals(method.getName())
                            && "Hour".equals(((PropertyChangeEvent) args[0]).getPropertyName()) ? null
                            : super.invoke(proxy, method, args);
                }
            };
        }
    };

    final VetoableChangeListener listener = EasyMock.createNiceMock(VetoableChangeListener.class);
    eventListenerSupport.addListener(listener);
    final Object source = new Date();
    final PropertyChangeEvent ignore = new PropertyChangeEvent(source, "Hour", 5, 6);
    final PropertyChangeEvent respond = new PropertyChangeEvent(source, "Day", 6, 7);
    listener.vetoableChange(respond);
    EasyMock.replay(listener);
    eventListenerSupport.fire().vetoableChange(ignore);
    eventListenerSupport.fire().vetoableChange(respond);
    EasyMock.verify(listener);
}
 
Example 10
Source File: EventListenerSupportTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testSerialization() throws IOException, ClassNotFoundException, PropertyVetoException {
    EventListenerSupport<VetoableChangeListener> listenerSupport = EventListenerSupport.create(VetoableChangeListener.class);
    listenerSupport.addListener(new VetoableChangeListener() {
        
        @Override
        public void vetoableChange(PropertyChangeEvent e) {
        }
    });
    listenerSupport.addListener(EasyMock.createNiceMock(VetoableChangeListener.class));

    //serialize:
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);

    objectOutputStream.writeObject(listenerSupport);
    objectOutputStream.close();

    //deserialize:
    @SuppressWarnings("unchecked")
    EventListenerSupport<VetoableChangeListener> deserializedListenerSupport = (EventListenerSupport<VetoableChangeListener>) new ObjectInputStream(
            new ByteArrayInputStream(outputStream.toByteArray())).readObject();

    //make sure we get a listener array back, of the correct component type, and that it contains only the serializable mock
    VetoableChangeListener[] listeners = deserializedListenerSupport.getListeners();
    assertEquals(VetoableChangeListener.class, listeners.getClass().getComponentType());
    assertEquals(1, listeners.length);

    //now verify that the mock still receives events; we can infer that the proxy was correctly reconstituted
    VetoableChangeListener listener = listeners[0];
    PropertyChangeEvent evt = new PropertyChangeEvent(new Date(), "Day", 7, 9);
    listener.vetoableChange(evt);
    EasyMock.replay(listener);
    deserializedListenerSupport.fire().vetoableChange(evt);
    EasyMock.verify(listener);

    //remove listener and verify we get an empty array of listeners
    deserializedListenerSupport.removeListener(listener);
    assertEquals(0, deserializedListenerSupport.getListeners().length);
}
 
Example 11
Source File: EventListenerSupportTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testSubclassInvocationHandling() throws PropertyVetoException {

    @SuppressWarnings("serial")
    EventListenerSupport<VetoableChangeListener> eventListenerSupport = new EventListenerSupport<VetoableChangeListener>(
            VetoableChangeListener.class) {
        @Override
        protected java.lang.reflect.InvocationHandler createInvocationHandler() {
            return new ProxyInvocationHandler() {
                /**
                 * {@inheritDoc}
                 */
                @Override
                public Object invoke(Object proxy, Method method, Object[] args)
                        throws Throwable {
                    return "vetoableChange".equals(method.getName())
                            && "Hour".equals(((PropertyChangeEvent) args[0]).getPropertyName()) ? null
                            : super.invoke(proxy, method, args);
                }
            };
        }
    };

    VetoableChangeListener listener = EasyMock.createNiceMock(VetoableChangeListener.class);
    eventListenerSupport.addListener(listener);
    Object source = new Date();
    PropertyChangeEvent ignore = new PropertyChangeEvent(source, "Hour", 5, 6);
    PropertyChangeEvent respond = new PropertyChangeEvent(source, "Day", 6, 7);
    listener.vetoableChange(respond);
    EasyMock.replay(listener);
    eventListenerSupport.fire().vetoableChange(ignore);
    eventListenerSupport.fire().vetoableChange(respond);
    EasyMock.verify(listener);
}
 
Example 12
Source File: EventListenerSupportTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void testSerialization() throws IOException, ClassNotFoundException, PropertyVetoException {
    final EventListenerSupport<VetoableChangeListener> listenerSupport = EventListenerSupport.create(VetoableChangeListener.class);
    listenerSupport.addListener(new VetoableChangeListener() {
        
        @Override
        public void vetoableChange(final PropertyChangeEvent e) {
        }
    });
    listenerSupport.addListener(EasyMock.createNiceMock(VetoableChangeListener.class));

    //serialize:
    final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    final ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);

    objectOutputStream.writeObject(listenerSupport);
    objectOutputStream.close();

    //deserialize:
    @SuppressWarnings("unchecked")
    final
    EventListenerSupport<VetoableChangeListener> deserializedListenerSupport = (EventListenerSupport<VetoableChangeListener>) new ObjectInputStream(
            new ByteArrayInputStream(outputStream.toByteArray())).readObject();

    //make sure we get a listener array back, of the correct component type, and that it contains only the serializable mock
    final VetoableChangeListener[] listeners = deserializedListenerSupport.getListeners();
    assertEquals(VetoableChangeListener.class, listeners.getClass().getComponentType());
    assertEquals(1, listeners.length);

    //now verify that the mock still receives events; we can infer that the proxy was correctly reconstituted
    final VetoableChangeListener listener = listeners[0];
    final PropertyChangeEvent evt = new PropertyChangeEvent(new Date(), "Day", 7, 9);
    listener.vetoableChange(evt);
    EasyMock.replay(listener);
    deserializedListenerSupport.fire().vetoableChange(evt);
    EasyMock.verify(listener);

    //remove listener and verify we get an empty array of listeners
    deserializedListenerSupport.removeListener(listener);
    assertEquals(0, deserializedListenerSupport.getListeners().length);
}