Missing property changes in Custom Field [message #1053581] |
Mon, 06 May 2013 15:26 |
Urs Beeli Messages: 573 Registered: October 2012 Location: Bern, Switzerland |
Senior Member |
|
|
I've created two custom fields (drawing some pretty complex stuff using the draw2d library). I've modelled these fields on the DrawLine custom field from the tutorial. Most things seem to work (mainly the drawing part and reporting changes in the drawing back to the client/model).
However, there is one thing I just can't get to work and that is to notify the renderer when the model has changed.
My AbstractBlablaField extends AbstractCustomField and implements IBlablaField which in turn extends IFormField.
I have setXxxx() methods that also set the corresponding property:
@Override
@FormData
public void setAnordnungsTage(Gueltigkeitstage anordnungsTage) {
m_anordnungsTage = anordnungsTage;
propertySupport.setProperty(PROP_ANORDNUNGSTAGE, anordnungsTage);
}
On the renderer side, I have a SwtScoutBlablaField extending SwtScoutFieldComposite<IBlablaField>. This class also contains the following method:
@Override
protected void handleScoutPropertyChange(String name, Object newValue) {
if ((name.equals(ITagesfilterField.PROP_FP)) || (name.equals(ITagesfilterField.PROP_ANORDNUNGSTAGE)) || (name.equals(ITagesfilterField.PROP_OPTIONSTAGE))
|| (name.equals(ITagesfilterField.PROP_UNSELEKTIERBAR))) {
System.out.println("Updating Tagesfilter because of property: " + name);
updateKalenderFromScout();
} else {
System.out.println("No need to update Tagesfilter because of property: " + name);
}
super.handleScoutPropertyChange(name, newValue);
}
However, if I call setAnordnungsTage() in the client, handleScoutPropertyChange() in the renderer is never called.
I am sure I'm missing something very small but extremely obvious, but for the life of me just can't find it...
I'd appreciate any hints you could give me on where to look!
|
|
|
|
Re: Missing property changes in Custom Field [message #1053681 is a reply to message #1053619] |
Tue, 07 May 2013 08:40 |
Urs Beeli Messages: 573 Registered: October 2012 Location: Bern, Switzerland |
Senior Member |
|
|
Claudio, thanks for that pointer, but that wasn't the issue.
I've tracked down the problem:
In my AbstractBlablaField I used a bean class of which I kept three instances. Based on user input in the drawn interface, I modified these beans from the UIFacade, so the code looked like this:
P_UIFacade.selectionChanged(Date date, boolean selection) {
Gueltigkeitstage at = getAnordnungsTage();
at.modify(date, selection);
setAnordnungsTage();
}
@Override
@FormData
public void setAnordnungsTage(Gueltigkeitstage anordnungsTage) {
m_anordnungsTage = anordnungsTage;
propertySupport.setProperty(PROP_ANORDNUNGSTAGE, anordnungsTage);
}
Stepping into propertySupport.setProperty() I found the following:
BasicPropertySupport.setProperty() gets the oldValue using m_props.get(name) and then passes both oldValue and newValue to CompareUtility.equals() which returns true, because both oldValue and newValue reference the same object. Changing my setter to create a new copy solved this problem.
@Override
@FormData
public void setAnordnungsTage(Gueltigkeitstage anordnungsTage) {
m_anordnungsTage = new Gueltigkeitstage(anordnungsTage);
propertySupport.setProperty(PROP_ANORDNUNGSTAGE, anordnungsTage);
}
|
|
|
|
Re: Missing property changes in Custom Field [message #1053709 is a reply to message #1053691] |
Tue, 07 May 2013 10:54 |
Urs Beeli Messages: 573 Registered: October 2012 Location: Bern, Switzerland |
Senior Member |
|
|
I tried that first, but unfortunately it doesn't work because of the following code:
public boolean BasicPropertySupport.setProperty(String name, Object newValue, Object defaultOldValueWhenNull) {
Object oldValue = m_props.get(name); // this will return the reference to the object stored with the last call, which is the same as the reference to the new object
if (oldValue == null) {
oldValue = defaultOldValueWhenNull;
}
m_props.put(name, newValue);
if (CompareUtility.equals(oldValue, newValue)) { // returns true if oldValue == newValue
// no change
return false;
}
else {
firePropertyChangeImpl(name, oldValue, newValue);
return true;
}
}
If I don't create a new copy in my setter, oldValue and newValue in setProperty will always be a reference to the same object.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02935 seconds