getPictogramElementForBusinessObject returns wrong business object [message #1405502] |
Thu, 07 August 2014 13:53 |
Homer S Messages: 13 Registered: June 2014 |
Junior Member |
|
|
Hi dear Graphiti users,
a somewhat odd problem occured to me just now.
I have two separate business objects of the same class. Now I want to get the pictogram elements for each of these. But the getPictogramElementForBusinessObject(Object businessObject) method returns the same pictogram element for both business objects.
When I look at the XML code my diagram file, I can see clearly that the links of the pictogram elements point to different business objects. So my code that's setting up the links is fine.
I went into the debugger and stepped through the methods and looked around the call stack.
Attached is a screenshot of the situation where the if statement just got evaluated to true for one of the business objects. In the Variables tab on the upper right one can see that the variables businessObject and obj actually contain different objects of the same class. So why did this evaluate to true for this businessObject, when it shouldn't?
I stepped deeper into it and EcoreUtils' equals method sets up an EqualityHelper and calls it's own equals method with the two given objects. It seems to me, that it just looks at the type of the class.
Can anybody help or clear up the situation?
EDIT:
Ok, I tried to fill a property on one of the objects and they don't get evaluated as equal anymore. Great.
BUT: Why doesn't this work for empty objects?
When I call getPictogramElementForBusinessObject and give it a business object, I expect it to return the pictogram that has a link to this particular business object and not some other random one that has the same "looks"
Please correct me if I'm wrong and overlooked something essential here.
Thanks.
[Updated on: Thu, 07 August 2014 14:03] Report message to a moderator
|
|
|
|
Re: getPictogramElementForBusinessObject returns wrong business object [message #1405546 is a reply to message #1405525] |
Thu, 07 August 2014 15:36 |
Homer S Messages: 13 Registered: June 2014 |
Junior Member |
|
|
Hi Martin,
Thanks for the clarification.
I've seen the methods as stated above, but I couldn't tell from the implementation of equals in the EqualityHelper class, if it checks for identity or not.
As mentioned in my EDIT in the OP:
Isn't this a source for error?
Who would suspect to get a pictogram element that is linked to the next best business object of the same EClass instead of the pictogram element actually linked to the business object given as a parameter?
At least the latter, expected behaviour is stated in the docs:
/**
* Provides the pictogram elements which represents the given business
* object.
*
* @param businessObject
* the given business object
* @return the pictogram elements
*/
PictogramElement[] getAllPictogramElementsForBusinessObject(Object businessObject);
[...]
/**
* This method is similar to the method
* getAllPictogramElementsForBusinessObject, but only return the first
* PictogramElement.
*
* @param businessObject
* the business object
* @return linked pictogram element
* @see #getAllPictogramElementsForBusinessObject(Object)
*/
PictogramElement getPictogramElementForBusinessObject(Object businessObject);
The getAllPict... version states "all pictograms for given business object" and getPict... states "similar but only the first". From this at least I am suspecting that it actually checks for identity, since the docs don't state business object class or something along those lines.
Maybe I'll use getAll... for my purpose and then match my given business object to the business objects of the leftover pictograms.
EDIT: nvm, forget that idea. other problem, same cause.
Thanks and best regards
Homer
[Updated on: Thu, 07 August 2014 15:59] Report message to a moderator
|
|
|
|
Re: getPictogramElementForBusinessObject returns wrong business object [message #1809686 is a reply to message #1411045] |
Sat, 20 July 2019 09:50 |
reweini marteini Messages: 1 Registered: July 2019 |
Junior Member |
|
|
Michael Wenz wrote on Fri, 22 August 2014 08:52Hi Homer,
yes, this is a potential source of errors or confusion. While implementing
the default functionality in a way that it suites most usecases we decided
to go for the EcoreUtils.equals method. Using instance equality had much
more negative consequences for the usecases we targeted.
But since this might be different in other scenarios we offered the method
equalsBusinssObjects in the tool behavior provider (default implemention
using the EcoreUtils.equals) that clients can override. Maybe thats an
option in your case?
See the comment on the DefaultToolBehaviorProvider implementation liteblue of that
method:
/**
* Default Implementation. Customers requested the possibility to plug in
* equality decision based on object identity.
*/
public boolean equalsBusinessObjects(Object o1, Object o2) {
But right, the JavaDoc of getPictogramElementForBusinessObject should
mention that, I'll add it there.
Michael
I also need help with the same, help is highly appreciate.
Thanks in advance,
Regards,
Reweini Marteini
|
|
|
Powered by
FUDForum. Page generated in 0.02170 seconds