Java Code Examples for java.beans.VetoableChangeSupport#addVetoableChangeListener()

The following examples show how to use java.beans.VetoableChangeSupport#addVetoableChangeListener() . 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: Test6630275.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
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();
        return; // expected exception
    }
    throw new Error("exception should be thrown");
}
 
Example 2
Source File: Test4425885.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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);

        return; // expected exception
    }
    throw new Error("exception should be thrown");
}
 
Example 3
Source File: Test4425885.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
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);

        return; // expected exception
    }
    throw new Error("exception should be thrown");
}
 
Example 4
Source File: Test4425885.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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);

        return; // expected exception
    }
    throw new Error("exception should be thrown");
}
 
Example 5
Source File: Test6630275.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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();
        return; // expected exception
    }
    throw new Error("exception should be thrown");
}
 
Example 6
Source File: Test6630275.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
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();
        return; // expected exception
    }
    throw new Error("exception should be thrown");
}
 
Example 7
Source File: Test6630275.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
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();
        return; // expected exception
    }
    throw new Error("exception should be thrown");
}
 
Example 8
Source File: TestEquals.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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);
    test(one, two, 1); // only one check
    vcs.fireVetoableChange(PROPERTY, one, two);
    test(one, two, 2); // because it invokes fireVetoableChange(PropertyChangeEvent)
}
 
Example 9
Source File: TestEquals.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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);
    test(one, two, 1); // only one check
    vcs.fireVetoableChange(PROPERTY, one, two);
    test(one, two, 2); // because it invokes fireVetoableChange(PropertyChangeEvent)
}
 
Example 10
Source File: TestSerialization.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private static VetoableChangeSupport create() {
    VetoableChangeSupport vcs = new VetoableChangeSupport(TestSerialization.class);
    vcs.addVetoableChangeListener(new TestSerialization(0));
    vcs.addVetoableChangeListener(NAME, new TestSerialization(1));
    return vcs;
}
 
Example 11
Source File: Test7148143.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    VetoableChangeListener listener = new CustomProxy();
    VetoableChangeSupport support = new VetoableChangeSupport(listener);
    support.addVetoableChangeListener(listener);
    support.addVetoableChangeListener("foo", listener); // cast class exception
}
 
Example 12
Source File: TestSerialization.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private static VetoableChangeSupport create() {
    VetoableChangeSupport vcs = new VetoableChangeSupport(TestSerialization.class);
    vcs.addVetoableChangeListener(new TestSerialization(0));
    vcs.addVetoableChangeListener(NAME, new TestSerialization(1));
    return vcs;
}
 
Example 13
Source File: Test7148143.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    VetoableChangeListener listener = new CustomProxy();
    VetoableChangeSupport support = new VetoableChangeSupport(listener);
    support.addVetoableChangeListener(listener);
    support.addVetoableChangeListener("foo", listener); // cast class exception
}
 
Example 14
Source File: TestListeners.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws PropertyVetoException {
    VetoableChangeSupport vcs = new VetoableChangeSupport(TestListeners.class);
    vcs.addVetoableChangeListener(new TestListeners(0));
    vcs.addVetoableChangeListener(NAME, new TestListeners(2));
    vcs.addVetoableChangeListener(new TestListeners(1));
    vcs.addVetoableChangeListener(NAME, new VetoableChangeListenerProxy(NAME, new TestListeners(3)));


    current = 0;
    vcs.fireVetoableChange(NAME, 0, 1);
    if (current != 4)
        throw new Error("Expected 4 listeners, but called " + current);

    current = 0;
    vcs.fireVetoableChange(NONE, 1, 0);
    if (current != 2)
        throw new Error("Expected 2 listeners, but called " + current);


    VetoableChangeListener[] all = vcs.getVetoableChangeListeners();
    if (all.length != 4)
        throw new Error("Expected 4 listeners, but contained " + all.length);

    VetoableChangeListener[] named = vcs.getVetoableChangeListeners(NAME);
    if (named.length != 2)
        throw new Error("Expected 2 named listeners, but contained " + named.length);

    VetoableChangeListener[] other = vcs.getVetoableChangeListeners(NONE);
    if (other.length != 0)
        throw new Error("Expected 0 other listeners, but contained " + other.length);

    vcs.removeVetoableChangeListener(new TestListeners(0));
    vcs.removeVetoableChangeListener(new TestListeners(1));
    vcs.removeVetoableChangeListener(NAME, new TestListeners(2));
    vcs.removeVetoableChangeListener(NAME, new VetoableChangeListenerProxy(NAME, new TestListeners(3)));

    all = vcs.getVetoableChangeListeners();
    if (all.length != 0)
        throw new Error("Expected 4 listeners, but contained " + all.length);

    named = vcs.getVetoableChangeListeners(NAME);
    if (named.length != 0)
        throw new Error("Expected 2 named listeners, but contained " + named.length);

    other = vcs.getVetoableChangeListeners(NONE);
    if (other.length != 0)
        throw new Error("Expected 0 other listeners, but contained " + other.length);
}
 
Example 15
Source File: Test7148143.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    VetoableChangeListener listener = new CustomProxy();
    VetoableChangeSupport support = new VetoableChangeSupport(listener);
    support.addVetoableChangeListener(listener);
    support.addVetoableChangeListener("foo", listener); // cast class exception
}
 
Example 16
Source File: TestSerialization.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private static VetoableChangeSupport create() {
    VetoableChangeSupport vcs = new VetoableChangeSupport(TestSerialization.class);
    vcs.addVetoableChangeListener(new TestSerialization(0));
    vcs.addVetoableChangeListener(NAME, new TestSerialization(1));
    return vcs;
}
 
Example 17
Source File: TestSerialization.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private static VetoableChangeSupport create() {
    VetoableChangeSupport vcs = new VetoableChangeSupport(TestSerialization.class);
    vcs.addVetoableChangeListener(new TestSerialization(0));
    vcs.addVetoableChangeListener(NAME, new TestSerialization(1));
    return vcs;
}
 
Example 18
Source File: TestListeners.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws PropertyVetoException {
    VetoableChangeSupport vcs = new VetoableChangeSupport(TestListeners.class);
    vcs.addVetoableChangeListener(new TestListeners(0));
    vcs.addVetoableChangeListener(NAME, new TestListeners(2));
    vcs.addVetoableChangeListener(new TestListeners(1));
    vcs.addVetoableChangeListener(NAME, new VetoableChangeListenerProxy(NAME, new TestListeners(3)));


    current = 0;
    vcs.fireVetoableChange(NAME, 0, 1);
    if (current != 4)
        throw new Error("Expected 4 listeners, but called " + current);

    current = 0;
    vcs.fireVetoableChange(NONE, 1, 0);
    if (current != 2)
        throw new Error("Expected 2 listeners, but called " + current);


    VetoableChangeListener[] all = vcs.getVetoableChangeListeners();
    if (all.length != 4)
        throw new Error("Expected 4 listeners, but contained " + all.length);

    VetoableChangeListener[] named = vcs.getVetoableChangeListeners(NAME);
    if (named.length != 2)
        throw new Error("Expected 2 named listeners, but contained " + named.length);

    VetoableChangeListener[] other = vcs.getVetoableChangeListeners(NONE);
    if (other.length != 0)
        throw new Error("Expected 0 other listeners, but contained " + other.length);

    vcs.removeVetoableChangeListener(new TestListeners(0));
    vcs.removeVetoableChangeListener(new TestListeners(1));
    vcs.removeVetoableChangeListener(NAME, new TestListeners(2));
    vcs.removeVetoableChangeListener(NAME, new VetoableChangeListenerProxy(NAME, new TestListeners(3)));

    all = vcs.getVetoableChangeListeners();
    if (all.length != 0)
        throw new Error("Expected 4 listeners, but contained " + all.length);

    named = vcs.getVetoableChangeListeners(NAME);
    if (named.length != 0)
        throw new Error("Expected 2 named listeners, but contained " + named.length);

    other = vcs.getVetoableChangeListeners(NONE);
    if (other.length != 0)
        throw new Error("Expected 0 other listeners, but contained " + other.length);
}
 
Example 19
Source File: TestSerialization.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private static VetoableChangeSupport create() {
    VetoableChangeSupport vcs = new VetoableChangeSupport(TestSerialization.class);
    vcs.addVetoableChangeListener(new TestSerialization(0));
    vcs.addVetoableChangeListener(NAME, new TestSerialization(1));
    return vcs;
}
 
Example 20
Source File: TestListeners.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws PropertyVetoException {
    VetoableChangeSupport vcs = new VetoableChangeSupport(TestListeners.class);
    vcs.addVetoableChangeListener(new TestListeners(0));
    vcs.addVetoableChangeListener(NAME, new TestListeners(2));
    vcs.addVetoableChangeListener(new TestListeners(1));
    vcs.addVetoableChangeListener(NAME, new VetoableChangeListenerProxy(NAME, new TestListeners(3)));


    current = 0;
    vcs.fireVetoableChange(NAME, 0, 1);
    if (current != 4)
        throw new Error("Expected 4 listeners, but called " + current);

    current = 0;
    vcs.fireVetoableChange(NONE, 1, 0);
    if (current != 2)
        throw new Error("Expected 2 listeners, but called " + current);


    VetoableChangeListener[] all = vcs.getVetoableChangeListeners();
    if (all.length != 4)
        throw new Error("Expected 4 listeners, but contained " + all.length);

    VetoableChangeListener[] named = vcs.getVetoableChangeListeners(NAME);
    if (named.length != 2)
        throw new Error("Expected 2 named listeners, but contained " + named.length);

    VetoableChangeListener[] other = vcs.getVetoableChangeListeners(NONE);
    if (other.length != 0)
        throw new Error("Expected 0 other listeners, but contained " + other.length);

    vcs.removeVetoableChangeListener(new TestListeners(0));
    vcs.removeVetoableChangeListener(new TestListeners(1));
    vcs.removeVetoableChangeListener(NAME, new TestListeners(2));
    vcs.removeVetoableChangeListener(NAME, new VetoableChangeListenerProxy(NAME, new TestListeners(3)));

    all = vcs.getVetoableChangeListeners();
    if (all.length != 0)
        throw new Error("Expected 4 listeners, but contained " + all.length);

    named = vcs.getVetoableChangeListeners(NAME);
    if (named.length != 0)
        throw new Error("Expected 2 named listeners, but contained " + named.length);

    other = vcs.getVetoableChangeListeners(NONE);
    if (other.length != 0)
        throw new Error("Expected 0 other listeners, but contained " + other.length);
}