Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » Missing property changes in Custom Field(handleScoutPropertyChange is not called)
Missing property changes in Custom Field [message #1053581] Mon, 06 May 2013 15:26 Go to next message
Urs Beeli is currently offline Urs BeeliFriend
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 #1053619 is a reply to message #1053581] Mon, 06 May 2013 21:21 Go to previous messageGo to next message
Claudio Guglielmo is currently offline Claudio GuglielmoFriend
Messages: 256
Registered: March 2010
Senior Member
Hi Urs

Could it be that the method attachScout is overridden without calling super? Thats the point where the listener is attached.

Regards
Claudio
Re: Missing property changes in Custom Field [message #1053681 is a reply to message #1053619] Tue, 07 May 2013 08:40 Go to previous messageGo to next message
Urs Beeli is currently offline Urs BeeliFriend
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 #1053691 is a reply to message #1053681] Tue, 07 May 2013 08:55 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1252
Registered: October 2011
Senior Member
Just some feedback:

Are you sure that creating a new copy is a good Java practice? I do not know your code, but often for cases like this you just need to write the appropriate hashCode() and equals(). Eclipse has a wizard to generate them for you (you need to check or uncheck the relevant java field of your java-bean)
Re: Missing property changes in Custom Field [message #1053709 is a reply to message #1053691] Tue, 07 May 2013 10:54 Go to previous messageGo to next message
Urs Beeli is currently offline Urs BeeliFriend
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.
Re: Missing property changes in Custom Field [message #1053775 is a reply to message #1053709] Tue, 07 May 2013 14:35 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1252
Registered: October 2011
Senior Member
You are probably right. If your "Gueltigkeitstage" is mutable and you change some of the field values, the reference is kept but the value represented by the bean is different. Without seeing the case I can not tell.


CompareUtility.equals(oldValue, newValue) => goes on oldValue.equals(newValue) not on "oldValue == newValue" (this utility function also handle some wired cases).

Re: Missing property changes in Custom Field [message #1053881 is a reply to message #1053775] Wed, 08 May 2013 06:07 Go to previous message
Urs Beeli is currently offline Urs BeeliFriend
Messages: 573
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Jeremie Bresson wrote on Tue, 07 May 2013 16:35
You are probably right. If your "Gueltigkeitstage" is mutable and you change some of the field values, the reference is kept but the value represented by the bean is different. Without seeing the case I can not tell.


Yes, that is exactly the situation I had. No worries, creating the copy in the setter works.

Jeremie Bresson wrote on Tue, 07 May 2013 16:35

CompareUtility.equals(oldValue, newValue) => goes on oldValue.equals(newValue) not on "oldValue == newValue" (this utility function also handle some wired cases).


You're right. Of course with oldValue==newValue, oldValue.equals(newValue) will always return true.
Previous Topic:SWT: Switching between SearchForm/TableForm-Pairs does not work
Next Topic:Authorization/Permissions: resource-level access
Goto Forum:
  


Current Time: Thu Mar 28 15:08:00 GMT 2024

Powered by FUDForum. Page generated in 0.02935 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top