Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Exception using a ContainerShape for grouping
Exception using a ContainerShape for grouping [message #714529] Wed, 10 August 2011 14:25 Go to next message
Hernan Gonzalez is currently offline Hernan Gonzalez
Messages: 181
Registered: October 2010
Location: Buenos Aires, Argentina
Senior Member
I have an ZZZAddShapeFeature that creates several shapes, the add() method works well when I create all the shapes with a single ContainerShape as parent (as in the tutorial). I tried to group some of the shapes by placing them inside another ContainerShape. Basically:

public PictogramElement add(IAddContext context) {
  Gnode addedNode = (Gnode) context.getNewObject();
  Diagram targetDiagram = (Diagram) context.getTargetContainer();
  IPeCreateService peCreateService = Graphiti.getPeCreateService();
  ContainerShape mainContShape = peCreateService.createContainerShape(targetDiagram, true);
  ....
  // create several shapes inside mainContShape 
  for(...) {
     ContainerShape contShape = peCreateService.createContainerShape(mainContShape , false);
     //  ContainerShape contShape = mainContShape ; // all ok if I uncomment this 
     ...
     // create several shapes with contShape as parent
  }
  ...
}


This gives me some strange NPE, deep inside Draw2D (the stack trace does not include my own classes). As I point out in the code, this works ok if I uncomment the other line, i.e. if I create the shapes with the main container as parent.
I'm using Eclipse 3.6.2, EMF 2.6.1 Graphiti 0.8.0

!ENTRY org.eclipse.graphiti 4 0 2011-08-10 15:09:20.898
!MESSAGE refresh edit part problem
!STACK 0
java.lang.NullPointerException
	at org.eclipse.draw2d.Figure.add(Figure.java:148)
	at org.eclipse.draw2d.Figure.add(Figure.java:174)
	at org.eclipse.graphiti.ui.internal.parts.PictogramElementDelegate.createFigureForPictogramElement(PictogramElementDelegate.java:827)
	at org.eclipse.graphiti.ui.internal.parts.PictogramElementDelegate.createFigure(PictogramElementDelegate.java:188)
	at org.eclipse.graphiti.ui.internal.parts.ShapeEditPart.createFigure(ShapeEditPart.java:621)
	at org.eclipse.graphiti.ui.internal.parts.ContainerShapeEditPart.createFigure(ContainerShapeEditPart.java:98)
	at org.eclipse.gef.editparts.AbstractGraphicalEditPart.getFigure(AbstractGraphicalEditPart.java:494)
	at org.eclipse.gef.editparts.AbstractGraphicalEditPart.addChildVisual(AbstractGraphicalEditPart.java:208)
	at org.eclipse.graphiti.ui.internal.parts.ContainerShapeEditPart.addChildVisual(ContainerShapeEditPart.java:161)
	at org.eclipse.gef.editparts.AbstractEditPart.addChild(AbstractEditPart.java:210)
	at org.eclipse.gef.editparts.AbstractEditPart.refreshChildren(AbstractEditPart.java:773)
	at org.eclipse.graphiti.ui.internal.parts.ShapeEditPart.refreshChildren(ShapeEditPart.java:632)
	at org.eclipse.gef.editparts.AbstractEditPart.refresh(AbstractEditPart.java:718)
	at org.eclipse.gef.editparts.AbstractGraphicalEditPart.refresh(AbstractGraphicalEditPart.java:633)
	at org.eclipse.graphiti.ui.internal.parts.ShapeEditPart.refresh(ShapeEditPart.java:552)
	at org.eclipse.graphiti.ui.internal.parts.DiagramEditPart.refresh(DiagramEditPart.java:183)
	at org.eclipse.graphiti.ui.internal.editor.DiagramEditorInternal.internalRefreshEditPart(DiagramEditorInternal.java:1246)
	at org.eclipse.graphiti.ui.internal.editor.DiagramEditorInternal.refresh(DiagramEditorInternal.java:1330)
  ...




Update: I can reproduce the NPE in the tutorial code, just by adding a dummy containerShape creation in TutorialAddEClassFeature:

  public class TutorialAddEClassFeature extends AbstractAddShapeFeature {
   ...
   @Override
   public PictogramElement add(IAddContext context) {
     ...
     // CONTAINER SHAPE WITH ROUNDED RECTANGLE
     final IPeCreateService peCreateService = Graphiti.getPeCreateService();
     final ContainerShape containerShape = peCreateService.createContainerShape(targetDiagram, true);
     // uncoment the following dummy containerShape creation => NPE
     // ContainerShape containerShape2 = peCreateService.createContainerShape(containerShape, false);
	


Any clues?

[Updated on: Wed, 10 August 2011 16:18]

Report message to a moderator

Re: Exception using a ContainerShape for grouping [message #714647 is a reply to message #714529] Thu, 11 August 2011 03:32 Go to previous messageGo to next message
Tim Kaiser is currently offline Tim Kaiser
Messages: 118
Registered: July 2009
Senior Member
Hi Hernan,

i suspect the rendering engine is looking for a GA for your containershape.
what happens if you equip the second containershape with a graphics algorithm?
Does the NPE persist?

Best, Tim
Re: Exception using a ContainerShape for grouping [message #714810 is a reply to message #714647] Thu, 11 August 2011 10:43 Go to previous messageGo to next message
Hernan Gonzalez is currently offline Hernan Gonzalez
Messages: 181
Registered: October 2010
Location: Buenos Aires, Argentina
Senior Member
Tim Kaiser wrote on Thu, 11 August 2011 04:32
Hi Hernan,

i suspect the rendering engine is looking for a GA for your containershape.
what happens if you equip the second containershape with a graphics algorithm?
Does the NPE persist?

Best, Tim


Aha, it seems to work... I'm still warping my mind over the pictogram concepts (thanks Kieler for that graph, it's very useful), it took me some time to getting used at the idea that "a Rectangle is not a Shape", for example Razz

My first idea was: a Shape (in general: a PictogramElement) can contain a Rectangle (in general: a GraphicAlgorithm=GA). And a ContainerShape can contain other Shapes - and besides (because it's a Shape) can contain a GA.

But now, it seems that a Shape not only can but MUST contain a GA; also if it's a ContainerShape, even if it's used only to group other shapes (with their own GAs) (right?).

Ok. It seemed to me a superabundance of Shapes and GA at first sight (for each Shape a GA, and viceversa?) ... but then I came to realize that a Rectangle (a GA) must not necesarily be included in its own Shape, but in a "GAContainer" (can be a Pictogram element, but also a GA!). One should create a Shape for a GA only when that's needed.

But, then, I'm thinking that the tutorial does not make this concept clear, and that in that diagram it would be much more reasonable (both didactically and practically) to NOT create a Shape for the horizontal line, it should be created with the 'roundedRectangle' as container. Do you agree?

[Updated on: Mon, 15 August 2011 11:06]

Report message to a moderator

Re: Exception using a ContainerShape for grouping [message #715705 is a reply to message #714810] Mon, 15 August 2011 05:08 Go to previous messageGo to next message
Tim Kaiser is currently offline Tim Kaiser
Messages: 118
Registered: July 2009
Senior Member
Hi Hernan,

think of PEs (Pictogram Elements) and GAs (Graphic Algorithms) as of two distinct worlds.
PEs are used for linking business objects an for defining the containment hierarchy
and also for defining the elements which are selectable and can be manipulated via mouse gestures.
GAs are just about what pixels are spit on the screen.
GAs are linked to PEs. Both, PES and GAs, have there own containment hierarchies...etc
I agree, it is really something to warp the mind....

But you are right, there should be a section in the tutorial exactly describing
the extents and relationship between the two concepts.
Please open a bugzilla to request a respective extra page in the tutorial.

Best, Tim
Re: Exception using a ContainerShape for grouping [message #723309 is a reply to message #715705] Thu, 08 September 2011 05:51 Go to previous messageGo to next message
Sébastien  Gandon is currently offline Sébastien Gandon
Messages: 169
Registered: July 2009
Senior Member
I really would be interested in seeing the object graph mentionned in Hernan latest message, by it is too small a png. Where can I get a large picture please, this PE and GA hierarchy is a bit confusing.
Re: Exception using a ContainerShape for grouping [message #723336 is a reply to message #723309] Thu, 08 September 2011 07:13 Go to previous message
Michael Wenz is currently offline Michael Wenz
Messages: 1577
Registered: July 2009
Location: Walldorf, Germany
Senior Member
There's a full-size PDF version available for download fron Graphiti site:
http://www.eclipse.org/graphiti/images/pictograms.pdf

Michael


"S" schrieb im Newsbeitrag news:j4a2i8$cfm$1@news.eclipse.org...

I really would be interested in seeing the object graph mentionned in Hernan
latest message, by it is too small a png. Where can I get a large picture
please, this PE and GA hierarchy is a bit confusing.
Previous Topic:creating nested shapes
Next Topic:Coding style of Graphiti plug-ins
Goto Forum:
  


Current Time: Sat Aug 02 04:39:41 EDT 2014

Powered by FUDForum. Page generated in 0.01606 seconds