Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Problem when writing add constraint
Problem when writing add constraint [message #897477] Tue, 24 July 2012 09:07 Go to next message
Maxime D is currently offline Maxime DFriend
Messages: 27
Registered: June 2012
Junior Member
I'm currently writing my own Graphiti editor on top of my EMF model which comes from Xtext.
I'm following the documentation founded in Eclipse Help but I have a question.

I have 2 forms from now, a rectangle and a shape.
I would like to say to Graphiti "You can create a shape in a rectangle and only in a rectangle, not in the diagram."

So I'm trying something like this in AddObjectAFeature.java :

@Override
public boolean canAdd(IAddContext context) {	
if (context.getNewObject() instanceof ObjectA) {
  if (context.getTargetContainer().getXXXXX() instanceof ObjectB) {
     return true;
  }
}
return false;
}


ObjectA is the business object represented by the shape and the ObjectB is represented by the rectangle.

My problem is, I can't access to my instance of ObjectB through "context.getTargetContainer(). etc...".

Any help would be appreciated, thanks Smile
Re: Problem when writing add constraint [message #897527 is a reply to message #897477] Tue, 24 July 2012 12:19 Go to previous messageGo to next message
Maxime D is currently offline Maxime DFriend
Messages: 27
Registered: June 2012
Junior Member
Ok I found the solution, I guess Wink

if(getBusinessObjectForPictogramElement(context.getTargetContainer()) instanceof ObjectA){
...
}


Sometimes you just need to write your problem Wink

[Updated on: Tue, 24 July 2012 12:19]

Report message to a moderator

Re: Problem when writing add constraint [message #897539 is a reply to message #897527] Tue, 24 July 2012 12:52 Go to previous messageGo to next message
Matthias Gorning is currently offline Matthias GorningFriend
Messages: 81
Registered: April 2010
Location: Germany
Member
Yes, that is the correct method to get the business object which is linked to the pictogram element.

If you don't want allow the creation of new elements directly in the diagram, you can simply add this to your canAdd() method:

if (context.getTargetContainer() instanceof Diagram){
   return false;
}

Re: Problem when writing add constraint [message #897570 is a reply to message #897539] Tue, 24 July 2012 14:25 Go to previous message
Maxime D is currently offline Maxime DFriend
Messages: 27
Registered: June 2012
Junior Member
Thank you for the int Wink
Previous Topic:Changing Palette Font + Size
Next Topic:ManhattanConnectionRouter
Goto Forum:
  


Current Time: Fri Apr 26 18:18:02 GMT 2024

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

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

Back to the top