Lines 238-243
Link Here
|
238 |
assertGC ("Panel should disappear even if we have reference to property editor", weak); |
238 |
assertGC ("Panel should disappear even if we have reference to property editor", weak); |
239 |
} |
239 |
} |
240 |
|
240 |
|
|
|
241 |
public void testCompatibilityWhenUsingNodePropertyAndAskingForPropertyModel () throws Exception { |
242 |
final Ed editor = new Ed (); |
243 |
|
244 |
class NP extends org.openide.nodes.Node.Property { |
245 |
private Object value; |
246 |
|
247 |
public NP () { |
248 |
super (Runnable.class); |
249 |
} |
250 |
|
251 |
public Object getValue () { |
252 |
return value; |
253 |
} |
254 |
|
255 |
public void setValue (Object o) { |
256 |
this.value = o; |
257 |
} |
258 |
|
259 |
public boolean canWrite () { |
260 |
return true; |
261 |
} |
262 |
|
263 |
public boolean canRead () { |
264 |
return true; |
265 |
} |
266 |
|
267 |
public java.beans.PropertyEditor getPropertyEditor () { |
268 |
return editor; |
269 |
} |
270 |
} |
271 |
|
272 |
NP property = new NP (); |
273 |
PropertyPanel panel = new PropertyPanel (property); |
274 |
|
275 |
assertEquals ("The property is mine", property, panel.getProperty ()); |
276 |
assertEquals ("Editor is delegated", editor, panel.getPropertyEditor()); |
277 |
assertNotNull ("There is a model", panel.getModel ()); |
278 |
assertEquals ("Type is delegated", Runnable.class, panel.getModel ().getPropertyType()); |
279 |
|
280 |
Listener listener = new Listener(); |
281 |
PropertyModel model = panel.getModel (); |
282 |
model.addPropertyChangeListener(listener); |
283 |
panel.getProperty ().setValue (this); |
284 |
|
285 |
assertEquals("Value changed in model", this, model.getValue()); |
286 |
assertEquals("Value changed in prop", this, panel.getProperty().getValue()); |
287 |
listener.assertChanges ("Change has been notified", 1, -1); |
288 |
} |
289 |
|
290 |
public void testCompatibilityWhenUsingPropertyModelAndAskingForNodeProperty () throws Exception { |
291 |
class PM implements PropertyModel { |
292 |
private Object value; |
293 |
private PropertyChangeListener listener; |
294 |
|
295 |
public PM() { |
296 |
} |
297 |
|
298 |
public void addPropertyChangeListener (PropertyChangeListener l) { |
299 |
assertNull ("Support for only one listener is here now", listener); |
300 |
listener = l; |
301 |
} |
302 |
|
303 |
public void removePropertyChangeListener (PropertyChangeListener l) { |
304 |
assertEquals ("Removing the one added", listener, l); |
305 |
listener = null; |
306 |
} |
307 |
|
308 |
public Class getPropertyType () { |
309 |
return Runnable.class; |
310 |
} |
311 |
|
312 |
public Object getValue() { |
313 |
return value; |
314 |
} |
315 |
|
316 |
public void setValue(Object o) { |
317 |
Object old = value; |
318 |
|
319 |
this.value = o; |
320 |
if (listener != null) { |
321 |
listener.propertyChange (new PropertyChangeEvent (this, "value", old, o)); |
322 |
} |
323 |
} |
324 |
/* |
325 |
public boolean canWrite() { |
326 |
return true; |
327 |
} |
328 |
|
329 |
public boolean canRead() { |
330 |
return true; |
331 |
} |
332 |
*/ |
333 |
|
334 |
public Class getPropertyEditorClass () { |
335 |
return Ed.class; |
336 |
} |
337 |
} |
338 |
|
339 |
PM model = new PM (); |
340 |
PropertyPanel panel = new PropertyPanel(model, 0); |
341 |
|
342 |
assertEquals("The model is mine", model, panel.getModel()); |
343 |
assertEquals("Editor is delegated", Ed.class, panel.getPropertyEditor().getClass ()); |
344 |
assertNotNull("There is a property", panel.getProperty()); |
345 |
assertEquals("Type is delegated", Runnable.class, panel.getProperty ().getValueType()); |
346 |
|
347 |
panel.getProperty ().setValue (this); |
348 |
assertEquals ("Value changed in model", this, model.getValue ()); |
349 |
assertEquals ("Value changed in prop", this, panel.getProperty ().getValue ()); |
350 |
|
351 |
|
352 |
model.setValue (model); |
353 |
assertEquals("Value change propagated into prop", model, panel.getProperty().getValue()); |
354 |
|
355 |
|
356 |
} |
357 |
|
241 |
/** Listener that counts changes. |
358 |
/** Listener that counts changes. |
242 |
*/ |
359 |
*/ |
243 |
private static final class Listener |
360 |
private static final class Listener |