Index: openide/test/unit/src/org/openide/explorer/propertysheet/PropertyPanelTest.java =================================================================== RCS file: /cvs/openide/test/unit/src/org/openide/explorer/propertysheet/PropertyPanelTest.java,v retrieving revision 1.4.6.2 diff -u -r1.4.6.2 PropertyPanelTest.java --- openide/test/unit/src/org/openide/explorer/propertysheet/PropertyPanelTest.java 19 Nov 2003 16:18:26 -0000 1.4.6.2 +++ openide/test/unit/src/org/openide/explorer/propertysheet/PropertyPanelTest.java 5 Dec 2003 10:20:06 -0000 @@ -238,6 +238,123 @@ assertGC ("Panel should disappear even if we have reference to property editor", weak); } + public void testCompatibilityWhenUsingNodePropertyAndAskingForPropertyModel () throws Exception { + final Ed editor = new Ed (); + + class NP extends org.openide.nodes.Node.Property { + private Object value; + + public NP () { + super (Runnable.class); + } + + public Object getValue () { + return value; + } + + public void setValue (Object o) { + this.value = o; + } + + public boolean canWrite () { + return true; + } + + public boolean canRead () { + return true; + } + + public java.beans.PropertyEditor getPropertyEditor () { + return editor; + } + } + + NP property = new NP (); + PropertyPanel panel = new PropertyPanel (property); + + assertEquals ("The property is mine", property, panel.getProperty ()); + assertEquals ("Editor is delegated", editor, panel.getPropertyEditor()); + assertNotNull ("There is a model", panel.getModel ()); + assertEquals ("Type is delegated", Runnable.class, panel.getModel ().getPropertyType()); + + Listener listener = new Listener(); + PropertyModel model = panel.getModel (); + model.addPropertyChangeListener(listener); + panel.getProperty ().setValue (this); + + assertEquals("Value changed in model", this, model.getValue()); + assertEquals("Value changed in prop", this, panel.getProperty().getValue()); + listener.assertChanges ("Change has been notified", 1, -1); + } + + public void testCompatibilityWhenUsingPropertyModelAndAskingForNodeProperty () throws Exception { + class PM implements PropertyModel { + private Object value; + private PropertyChangeListener listener; + + public PM() { + } + + public void addPropertyChangeListener (PropertyChangeListener l) { + assertNull ("Support for only one listener is here now", listener); + listener = l; + } + + public void removePropertyChangeListener (PropertyChangeListener l) { + assertEquals ("Removing the one added", listener, l); + listener = null; + } + + public Class getPropertyType () { + return Runnable.class; + } + + public Object getValue() { + return value; + } + + public void setValue(Object o) { + Object old = value; + + this.value = o; + if (listener != null) { + listener.propertyChange (new PropertyChangeEvent (this, "value", old, o)); + } + } + /* + public boolean canWrite() { + return true; + } + + public boolean canRead() { + return true; + } + */ + + public Class getPropertyEditorClass () { + return Ed.class; + } + } + + PM model = new PM (); + PropertyPanel panel = new PropertyPanel(model, 0); + + assertEquals("The model is mine", model, panel.getModel()); + assertEquals("Editor is delegated", Ed.class, panel.getPropertyEditor().getClass ()); + assertNotNull("There is a property", panel.getProperty()); + assertEquals("Type is delegated", Runnable.class, panel.getProperty ().getValueType()); + + panel.getProperty ().setValue (this); + assertEquals ("Value changed in model", this, model.getValue ()); + assertEquals ("Value changed in prop", this, panel.getProperty ().getValue ()); + + + model.setValue (model); + assertEquals("Value change propagated into prop", model, panel.getProperty().getValue()); + + + } + /** Listener that counts changes. */ private static final class Listener