Search in sources :

Example 1 with VetoableChangeListener

use of java.beans.VetoableChangeListener in project adempiere by adempiere.

the class Graph method loadData.

private void loadData() {
    list = builder.loadData();
    JFreeChart chart = builder.createChart(builder.getMGoal().getChartType());
    if (chartPanel != null)
        remove(chartPanel);
    chartPanel = new ChartPanel(chart);
    chartPanel.setSize(getSize());
    chartPanel.addChartMouseListener(this);
    add(chartPanel, BorderLayout.CENTER);
    if (m_userSelection) {
        int AD_Reference_Value_ID = DB.getSQLValue(null, "SELECT AD_Reference_ID FROM AD_Reference WHERE Name = ?", "PA_Goal ChartType");
        MLookupInfo info = MLookupFactory.getLookup_List(Env.getLanguage(Env.getCtx()), AD_Reference_Value_ID);
        MLookup mLookup = new MLookup(info, 0);
        VLookup lookup = new VLookup("ChartType", false, false, true, mLookup);
        lookup.addVetoableChangeListener(new VetoableChangeListener() {

            public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException {
                Object value = evt.getNewValue();
                if (value == null)
                    return;
                JFreeChart chart = null;
                chart = builder.createChart(value.toString());
                if (chart != null) {
                    if (chartPanel != null)
                        remove(chartPanel);
                    chartPanel = new ChartPanel(chart);
                    chartPanel.setSize(getSize());
                    chartPanel.addChartMouseListener(Graph.this);
                    add(chartPanel, BorderLayout.CENTER);
                    getParent().validate();
                }
            }
        });
        add(lookup, BorderLayout.NORTH);
    }
    this.setMinimumSize(paneldimension);
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) MLookupInfo(org.compiere.model.MLookupInfo) PropertyChangeEvent(java.beans.PropertyChangeEvent) ChartPanel(org.jfree.chart.ChartPanel) MLookup(org.compiere.model.MLookup) VLookup(org.compiere.grid.ed.VLookup) VetoableChangeListener(java.beans.VetoableChangeListener) JFreeChart(org.jfree.chart.JFreeChart) Point(java.awt.Point)

Example 2 with VetoableChangeListener

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

the class TestListeners method main.

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);
}
Also used : VetoableChangeListenerProxy(java.beans.VetoableChangeListenerProxy) VetoableChangeSupport(java.beans.VetoableChangeSupport) VetoableChangeListener(java.beans.VetoableChangeListener)

Example 3 with VetoableChangeListener

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

the class TestSynchronization method main.

public static void main(String[] args) throws PropertyVetoException {
    final VetoableChangeSupport vcs = new VetoableChangeSupport(TestSynchronization.class);
    vcs.addVetoableChangeListener("name", new VetoableChangeListener() {

        public void vetoableChange(PropertyChangeEvent event) {
            isCalled = true;
        }
    });
    vcs.addVetoableChangeListener(new VetoableChangeListener() {

        public void vetoableChange(PropertyChangeEvent event) {
            for (VetoableChangeListener listener : vcs.getVetoableChangeListeners()) vcs.removeVetoableChangeListener(listener);
        }
    });
    vcs.fireVetoableChange("name", null, null);
    if (!isCalled)
        throw new Error("test failed");
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) VetoableChangeSupport(java.beans.VetoableChangeSupport) VetoableChangeListener(java.beans.VetoableChangeListener)

Example 4 with VetoableChangeListener

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

the class Test4985020 method main.

public static void main(String[] args) {
    PropertyChangeSupport pcs = new PropertyChangeSupport(args);
    VetoableChangeSupport vcs = new VetoableChangeSupport(args);
    Test4985020 listener = new Test4985020();
    //PropertyChangeSupport.addPropertyChangeListener(null, listener)
    System.out.println("PropertyChangeSupport.addPropertyChangeListener(null, listener)");
    try {
        pcs.addPropertyChangeListener(null, listener);
        pcs.firePropertyChange(NAME, null, null);
    } catch (Throwable error) {
        print(error);
    }
    //PropertyChangeSupport.removePropertyChangeListener(null, listener)
    System.out.println("PropertyChangeSupport.removePropertyChangeListener(null, listener)");
    try {
        pcs.removePropertyChangeListener(null, listener);
        pcs.firePropertyChange(NAME, null, null);
    } catch (Throwable error) {
        print(error);
    }
    //PropertyChangeSupport.getPropertyChangeListeners(null)
    System.out.println("PropertyChangeSupport.getPropertyChangeListeners(null)");
    try {
        PropertyChangeListener[] pcls = pcs.getPropertyChangeListeners(null);
        if (pcls == null) {
            throw new Error("getPropertyChangeListener() returned null");
        }
        if (pcls.length != 0) {
            throw new Error("getPropertyChangeListener() did not return an empty array");
        }
    } catch (Throwable error) {
        print(error);
    }
    //PropertyChangeSupport.hasListeners(null)
    System.out.println("PropertyChangeSupport.hasListeners(null)");
    try {
        pcs.hasListeners(null);
    } catch (Throwable error) {
        print(error);
    }
    //PropertyChangeSupport.hasListeners(null): with a generic listener
    System.out.println("PropertyChangeSupport.hasListeners(null) with a generic listener");
    try {
        pcs.addPropertyChangeListener(listener);
        if (!pcs.hasListeners(null)) {
            throw new Error("hasListeners(null) returned false, but there was a generic listener");
        }
    } catch (Throwable error) {
        print(error);
    }
    // reset
    pcs = new PropertyChangeSupport(args);
    //PropertyChangeSupport.hasListeners(null): with a specific listener
    System.out.println("PropertyChangeSupport.hasListeners(null) with a specific listener");
    try {
        pcs.addPropertyChangeListener(NAME, listener);
        if (pcs.hasListeners(null)) {
            throw new Error("hasListeners(null) returned true, but there were no generic listeners - only a specific listener");
        }
    } catch (Throwable error) {
        print(error);
    }
    //VetoableChangeSupport.addVetoableChangeListener(null, listener)
    System.out.println("VetoableChangeSupport.addVetoableChangeListener(null, listener)");
    try {
        vcs.addVetoableChangeListener(null, listener);
        vcs.fireVetoableChange(NAME, null, null);
    } catch (Throwable error) {
        print(error);
    }
    //VetoableChangeSupport.removeVetoableChangeListener(null, listener)
    System.out.println("VetoableChangeSupport.removeVetoableChangeListener(null, listener)");
    try {
        vcs.removeVetoableChangeListener(null, listener);
        vcs.fireVetoableChange(NAME, null, null);
    } catch (Throwable error) {
        print(error);
    }
    //VetoableChangeSupport.getVetoableChangeListeners(null)
    System.out.println("VetoableChangeSupport.getVetoableChangeListeners(null)");
    try {
        VetoableChangeListener[] pcls = vcs.getVetoableChangeListeners(null);
        if (pcls == null) {
            throw new Error("getVetoableChangeListener() returned null");
        }
        if (pcls.length != 0) {
            throw new Error("getVetoableChangeListener() did not return an empty array");
        }
    } catch (Throwable error) {
        print(error);
    }
    //VetoableChangeSupport.hasListeners(null)
    System.out.println("VetoableChangeSupport.hasListeners(null)");
    try {
        boolean result = vcs.hasListeners(null);
    } catch (Throwable error) {
        print(error);
    }
    //VetoableChangeSupport.hasListeners(null): with a generic listener
    System.out.println("VetoableChangeSupport.hasListeners(null) with a generic listener");
    try {
        vcs.addVetoableChangeListener(listener);
        if (!vcs.hasListeners(null)) {
            throw new Error("hasListeners(null) returned false, but there was a generic listener");
        }
    } catch (Throwable error) {
        print(error);
    }
    // reset
    vcs = new VetoableChangeSupport(args);
    //VetoableChangeSupport.hasListeners(null): with a specific listener
    System.out.println("VetoableChangeSupport.hasListeners(null) with a specific listener");
    try {
        vcs.addVetoableChangeListener(NAME, listener);
        if (vcs.hasListeners(null)) {
            throw new Error("hasListeners(null) returned true, but there were no generic listeners - only a specific listener");
        }
    } catch (Throwable error) {
        print(error);
    }
    if (failed) {
        throw new Error("TEST FAILED");
    }
}
Also used : PropertyChangeListener(java.beans.PropertyChangeListener) VetoableChangeSupport(java.beans.VetoableChangeSupport) PropertyChangeSupport(java.beans.PropertyChangeSupport) VetoableChangeListener(java.beans.VetoableChangeListener)

Example 5 with VetoableChangeListener

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

the class EventListenerSupportTest method testSerialization.

@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);
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) ByteArrayInputStream(java.io.ByteArrayInputStream) VetoableChangeListener(java.beans.VetoableChangeListener) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) Date(java.util.Date) ObjectInputStream(java.io.ObjectInputStream) 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