Search in sources :

Example 6 with VetoableChangeListener

use of java.beans.VetoableChangeListener in project commons-lang by apache.

the class EventListenerSupportTest method testRemoveListenerDuringEvent.

@Test
public void testRemoveListenerDuringEvent() throws PropertyVetoException {
    final EventListenerSupport<VetoableChangeListener> listenerSupport = EventListenerSupport.create(VetoableChangeListener.class);
    for (int i = 0; i < 10; ++i) {
        addDeregisterListener(listenerSupport);
    }
    assertEquals(listenerSupport.getListenerCount(), 10);
    listenerSupport.fire().vetoableChange(new PropertyChangeEvent(new Date(), "Day", 4, 5));
    assertEquals(listenerSupport.getListenerCount(), 0);
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) VetoableChangeListener(java.beans.VetoableChangeListener) Date(java.util.Date) Test(org.junit.Test)

Example 7 with VetoableChangeListener

use of java.beans.VetoableChangeListener in project jdk8u_jdk by JetBrains.

the class Test7148143 method main.

public static void main(String[] args) {
    VetoableChangeListener listener = new CustomProxy();
    VetoableChangeSupport support = new VetoableChangeSupport(listener);
    support.addVetoableChangeListener(listener);
    // cast class exception
    support.addVetoableChangeListener("foo", listener);
}
Also used : VetoableChangeSupport(java.beans.VetoableChangeSupport) VetoableChangeListener(java.beans.VetoableChangeListener)

Example 8 with VetoableChangeListener

use of java.beans.VetoableChangeListener in project jdk8u_jdk by JetBrains.

the class BeanContextSupport method initialize.

/**
     * protected method called from constructor and readObject to initialize
     * transient state of BeanContextSupport instance.
     *
     * This class uses this method to instantiate inner class listeners used
     * to monitor PropertyChange and VetoableChange events on children.
     *
     * subclasses may envelope this method to add their own initialization
     * behavior
     */
protected synchronized void initialize() {
    children = new HashMap(serializable + 1);
    bcmListeners = new ArrayList(1);
    childPCL = new PropertyChangeListener() {

        /*
             * this adaptor is used by the BeanContextSupport class to forward
             * property changes from a child to the BeanContext, avoiding
             * accidential serialization of the BeanContext by a badly
             * behaved Serializable child.
             */
        public void propertyChange(PropertyChangeEvent pce) {
            BeanContextSupport.this.propertyChange(pce);
        }
    };
    childVCL = new VetoableChangeListener() {

        /*
             * this adaptor is used by the BeanContextSupport class to forward
             * vetoable changes from a child to the BeanContext, avoiding
             * accidential serialization of the BeanContext by a badly
             * behaved Serializable child.
             */
        public void vetoableChange(PropertyChangeEvent pce) throws PropertyVetoException {
            BeanContextSupport.this.vetoableChange(pce);
        }
    };
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) VetoableChangeListener(java.beans.VetoableChangeListener)

Example 9 with VetoableChangeListener

use of java.beans.VetoableChangeListener in project commons-lang by apache.

the class EventUtilsTest method testAddEventListenerWithPrivateAddMethod.

@Test
public void testAddEventListenerWithPrivateAddMethod() {
    final PropertyChangeSource src = new PropertyChangeSource();
    final EventCountingInvociationHandler handler = new EventCountingInvociationHandler();
    final VetoableChangeListener listener = handler.createListener(VetoableChangeListener.class);
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("Class " + src.getClass().getName() + " does not have a public add" + VetoableChangeListener.class.getSimpleName() + " method which takes a parameter of type " + VetoableChangeListener.class.getName() + ".");
    EventUtils.addEventListener(src, VetoableChangeListener.class, listener);
}
Also used : VetoableChangeListener(java.beans.VetoableChangeListener) Test(org.junit.Test)

Example 10 with VetoableChangeListener

use of java.beans.VetoableChangeListener in project commons-lang by apache.

the class EventListenerSupportTest method testSubclassInvocationHandling.

@Test
public void testSubclassInvocationHandling() throws PropertyVetoException {
    final EventListenerSupport<VetoableChangeListener> eventListenerSupport = new EventListenerSupport<VetoableChangeListener>(VetoableChangeListener.class) {

        private static final long serialVersionUID = 1L;

        @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);
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) VetoableChangeListener(java.beans.VetoableChangeListener) Method(java.lang.reflect.Method) Date(java.util.Date) Test(org.junit.Test)

Aggregations

VetoableChangeListener (java.beans.VetoableChangeListener)15 PropertyChangeEvent (java.beans.PropertyChangeEvent)9 Test (org.junit.Test)8 PropertyVetoException (java.beans.PropertyVetoException)4 VetoableChangeSupport (java.beans.VetoableChangeSupport)4 Date (java.util.Date)4 PropertyChangeListener (java.beans.PropertyChangeListener)2 ArrayList (java.util.ArrayList)2 Point (java.awt.Point)1 PropertyChangeSupport (java.beans.PropertyChangeSupport)1 VetoableChangeListenerProxy (java.beans.VetoableChangeListenerProxy)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 JComponent (javax.swing.JComponent)1 JTextComponent (javax.swing.text.JTextComponent)1