Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » getPictogramElementForBusinessObject returns wrong business object
icon5.gif  getPictogramElementForBusinessObject returns wrong business object [message #1405502] Thu, 07 August 2014 13:53 Go to next message
Homer S is currently offline Homer SFriend
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 #1405525 is a reply to message #1405502] Thu, 07 August 2014 14:52 Go to previous messageGo to next message
Martin Hanysz is currently offline Martin HanyszFriend
Messages: 30
Registered: November 2013
Member
Hi Homer,

The method DefaultToolBehaviorProvider#equalsBusinessObjects(...) uses EcoreUtil#equals(...) which does NOT check for object identity. Instead it compares the EClasses of the objects and the values of their properties. If these are the same, two objects are considered equal.

Best regards,
Martin

[Updated on: Thu, 07 August 2014 14:53]

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 Go to previous messageGo to next message
Homer S is currently offline Homer SFriend
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 #1411045 is a reply to message #1405546] Fri, 22 August 2014 08:52 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1912
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Hi 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 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
Re: getPictogramElementForBusinessObject returns wrong business object [message #1809686 is a reply to message #1411045] Sat, 20 July 2019 09:50 Go to previous message
reweini marteini is currently offline reweini marteiniFriend
Messages: 1
Registered: July 2019
Junior Member
Michael Wenz wrote on Fri, 22 August 2014 08:52
Hi 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
Previous Topic:SVG export tutorial example not working
Next Topic:how can get all business object from diagram
Goto Forum:
  


Current Time: Sat Dec 14 10:34:59 GMT 2019

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

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

Back to the top