Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Anchor creation breaks Graphiti
Anchor creation breaks Graphiti [message #992764] Sat, 22 December 2012 14:54 Go to next message
Philipp Adolf is currently offline Philipp Adolf
Messages: 3
Registered: December 2012
Junior Member
I'm having trouble using FixPointAnchor and BoxRelativeAnchor. Whenever I call the PECreateService methods to create either of those in my AddFeature, I get a "refresh edit part problem" which is caused by a NullPointerException at org.eclipse.draw2d.Figure.add when I add an object and I can't select the object afterwards, not even using ctrl-A. Graphiti also shows me scroll bars although there is no need to scroll. The exception is not triggered while my code is running, but afterwards, during drawing, I suspect, given the name of the package the exception occurs in.

I prepared a small example, which was created using the Graphiti Plug-in wizard, and contains the code for the tutorial Add- and CreateFeatures plus four lines to create and initialize a BoxRelativeAnchor (taken from the Anchors section of the tutorial). The exception occurs every time I drag EClass from the palette onto the diagram. Using the PredefinedEClass also works.

It seems to be too simple to do something wrong, but maybe I'm missing something obvious. I'm happy for every help I can get, as I need some kind of anchor that is not a ChopBoxAnchor.
Re: Anchor creation breaks Graphiti [message #993099 is a reply to message #992764] Sun, 23 December 2012 11:33 Go to previous messageGo to next message
Andreas Graf is currently offline Andreas Graf
Messages: 154
Registered: July 2009
Senior Member
Hi Philipp,

having only briefly looked at your code, I think it is because you don't create a graphics algorithm for your anchor. IIRC, according to the tutorial, ChopBoxAnchors are the only one without a GA.

I have code similiar to yours, but with the additional fragment (onea is my relative anchor):

final Rectangle rectangle = gaService.createPlainRectangle(onea);
		  rectangle.setForeground(manageColor(IColorConstant.LIGHT_BLUE));
		  rectangle.setBackground(manageColor(IColorConstant.WHITE));
		  rectangle.setLineWidth(2);
		  rectangle.setLineVisible(true);
		  
		  Graphiti.getGaService().setLocationAndSize(rectangle, -12, -6, 12, 12);


What would be nice in Graphiti would be an earlier and more specific exception, but I haven't found where this should/could be done.

Regards,

Andreas
Re: Anchor creation breaks Graphiti [message #993164 is a reply to message #993099] Sun, 23 December 2012 16:08 Go to previous messageGo to next message
Philipp Adolf is currently offline Philipp Adolf
Messages: 3
Registered: December 2012
Junior Member
Creating a rectangle using the Anchor as the container doesn't help, it behaves just the same. The only thing missing from the example code of the Anchors section is the creation of the ChopboxAnchor (which I tried, makes no difference) and calling layoutPictogramElement() which I don't think should cause this behavior if missing.
Re: Anchor creation breaks Graphiti [message #996616 is a reply to message #993164] Wed, 02 January 2013 14:29 Go to previous messageGo to next message
Michael Wenz is currently offline Michael Wenz
Messages: 1618
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Adolf,

maybe there's a misunderstanding what graphics algorithm for a shape means.
Andreas meant that every shape needs a graphics algorithm, and an anchor
(well, all besides ChopboxAnchors) are only special shapes.

I added the following to lines to your add feature's add method (right
before the return) and the example worked for me:

Rectangle anchorRectangle = gaService.createRectangle(anchor);
gaService.setLocationAndSize(anchorRectangle, 0, 0, 20, 20);

Michael
Re: Anchor creation breaks Graphiti [message #997026 is a reply to message #996616] Thu, 03 January 2013 12:53 Go to previous message
Philipp Adolf is currently offline Philipp Adolf
Messages: 3
Registered: December 2012
Junior Member
Hi Michael,

That is strange, I did the same but I used createPlainRectangle and set a few style options, which still gave me the error when I tested it a week ago. Now I tested your code, which worked, and because I wanted to know what the problem was, I ran my code again which now works too. Maybe Eclipse didn't recompile the class or something, I have no idea. Still, thank you, it's seems to be working without problems now.

Philipp
Previous Topic:ResizeFeature: keep aspect Ratio
Next Topic:Need suggestion on programatically creating connection with diamond shape in between
Goto Forum:
  


Current Time: Sat Oct 25 17:48:01 GMT 2014

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

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