Exception using a ContainerShape for grouping [message #714529] |
Wed, 10 August 2011 18:25 |
Hernan Gonzalez Messages: 188 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 20:18] Report message to a moderator
|
|
|
|
Re: Exception using a ContainerShape for grouping [message #714810 is a reply to message #714647] |
Thu, 11 August 2011 14:43 |
Hernan Gonzalez Messages: 188 Registered: October 2010 Location: Buenos Aires, Argentina |
Senior Member |
|
|
Tim Kaiser wrote on Thu, 11 August 2011 04:32Hi 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
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 15:06] Report message to a moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03813 seconds