Search in sources :

Example 6 with VetoableChangeSupport

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

the class Test6630275 method main.

public static void main(String[] args) {
    CheckListener first = new CheckListener(false);
    CheckListener second = new CheckListener(true);
    CheckListener third = new CheckListener(false);
    VetoableChangeSupport vcs = new VetoableChangeSupport(Test6630275.class);
    vcs.addVetoableChangeListener(first);
    vcs.addVetoableChangeListener(PROPERTY, first);
    vcs.addVetoableChangeListener(PROPERTY, second);
    vcs.addVetoableChangeListener(PROPERTY, third);
    try {
        vcs.fireVetoableChange(PROPERTY, true, false);
    } catch (PropertyVetoException exception) {
        first.validate();
        second.validate();
        third.validate();
        // expected exception
        return;
    }
    throw new Error("exception should be thrown");
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) VetoableChangeSupport(java.beans.VetoableChangeSupport)

Example 7 with VetoableChangeSupport

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

the class Test4092906 method main.

public static void main(String[] args) {
    VetoableChangeSupport pcs = new VetoableChangeSupport(args);
    pcs.addVetoableChangeListener(PUBLIC, new PublicListener());
    pcs.addVetoableChangeListener(PRIVATE, new PrivateListener());
    if (!pcs.hasListeners(PUBLIC)) {
        throw new Error("no public listener");
    }
    if (!pcs.hasListeners(PRIVATE)) {
        throw new Error("no private listener");
    }
    try {
        // serialize into byte array
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream output = new ObjectOutputStream(baos);
        output.writeObject(pcs);
        output.flush();
        // deserialize from byte array
        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
        ObjectInputStream input = new ObjectInputStream(bais);
        pcs = (VetoableChangeSupport) input.readObject();
    } catch (Exception exception) {
        throw new Error("unexpected exception", exception);
    }
    if (!pcs.hasListeners(PUBLIC)) {
        throw new Error("no public listener");
    }
    if (pcs.hasListeners(PRIVATE)) {
        throw new Error("unexpected private listener");
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) VetoableChangeSupport(java.beans.VetoableChangeSupport) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) PropertyVetoException(java.beans.PropertyVetoException) ObjectInputStream(java.io.ObjectInputStream)

Example 8 with VetoableChangeSupport

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

the class TestEquals method main.

public static void main(String[] args) throws PropertyVetoException {
    TestEquals one = new TestEquals(1);
    TestEquals two = new TestEquals(2);
    Object source = TestEquals.class;
    VetoableChangeSupport vcs = new VetoableChangeSupport(source);
    vcs.addVetoableChangeListener(PROPERTY, one);
    vcs.addVetoableChangeListener(PROPERTY, two);
    PropertyChangeEvent event = new PropertyChangeEvent(source, PROPERTY, one, two);
    vcs.fireVetoableChange(event);
    // only one check
    test(one, two, 1);
    vcs.fireVetoableChange(PROPERTY, one, two);
    // because it invokes fireVetoableChange(PropertyChangeEvent)
    test(one, two, 2);
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) VetoableChangeSupport(java.beans.VetoableChangeSupport)

Example 9 with VetoableChangeSupport

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

the class Test4425885 method main.

public static void main(String[] args) {
    CheckListener first = new CheckListener();
    VetoListener second = new VetoListener();
    CheckListener third = new CheckListener();
    VetoableChangeSupport vcs = new VetoableChangeSupport(Test4425885.class);
    vcs.addVetoableChangeListener(PROPERTY, first);
    vcs.addVetoableChangeListener(PROPERTY, second);
    vcs.addVetoableChangeListener(PROPERTY, third);
    try {
        vcs.fireVetoableChange(PROPERTY, 0, 1);
    } catch (PropertyVetoException exception) {
        if (first.odd)
            throw new Error("no undo for the first listener", exception);
        if (third.odd)
            throw new Error("no undo for the third listener", exception);
        // expected exception
        return;
    }
    throw new Error("exception should be thrown");
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) VetoableChangeSupport(java.beans.VetoableChangeSupport)

Example 10 with VetoableChangeSupport

use of java.beans.VetoableChangeSupport 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)

Aggregations

VetoableChangeSupport (java.beans.VetoableChangeSupport)10 VetoableChangeListener (java.beans.VetoableChangeListener)4 PropertyChangeEvent (java.beans.PropertyChangeEvent)3 PropertyVetoException (java.beans.PropertyVetoException)3 PropertyChangeListener (java.beans.PropertyChangeListener)1 PropertyChangeSupport (java.beans.PropertyChangeSupport)1 VetoableChangeListenerProxy (java.beans.VetoableChangeListenerProxy)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1