Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 363229 - Nested GA inside Anchors are not correctly refreshed
Summary: Nested GA inside Anchors are not correctly refreshed
Status: CLOSED FIXED
Alias: None
Product: Graphiti
Classification: Modeling
Component: Core (show other bugs)
Version: 0.8.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 0.9.0   Edit
Assignee: Matthias Gorning CLA
QA Contact:
URL:
Whiteboard: Juno M4 Theme_bugs
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-08 16:41 EST by Hernan Gonzalez CLA
Modified: 2012-06-29 04:14 EDT (History)
2 users (show)

See Also:
matthias.gorning: juno+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hernan Gonzalez CLA 2011-11-08 16:41:47 EST
Build Identifier: 

When a nested GA (GraphicAlgorithm) is added to an Anchor in runtime, sometimes the GEF objects are not correctly created.

Reproducible: Always

Steps to Reproduce:
1. In the tutorial, modify the TutorialRenameEClassFeature so that, in adition of the name change a circle is added to the BoxRelativeAnchor (code below) under some condition
2. The circle is added to the Diagram (can be seen in the saved diagram), but is not displayed. The editpart is not added. The editor internal listener is notified, PictogramElementDelegate.createFigureForGraphicsAlgorithm() is not reached.
3. Instead, if the circle is added to the ContainerShape of the EClass, it works ok
Comment 1 Hernan Gonzalez CLA 2011-11-08 16:45:31 EST
Here's my code for TutorialRenameEClassFeature: in this example, we add the circle when the new name has a trailing 'X' (and the original hadn't it), and viceversa.

in execute() add the line:


this.hasDoneChanges = true;
addRemoveCircle((Shape) pes[0], newName, currentName);
eClass.setName(newName);
updatePictogramElement(pes[0]);

and the method:

private void addRemoveCircle(Shape pes, String newname, String oldname) {
if (newname == null || oldname == null)	return;
boolean useanchor = true;
GraphicsAlgorithm ga = useanchor ? pes.getAnchors().get(1).getGraphicsAlgorithm() : pes.getGraphicsAlgorithm();
int r = 2;
if (newname.endsWith("X") && !oldname.endsWith("X")) { // add
 Ellipse c = Graphiti.getGaCreateService().createEllipse(ga);
 Graphiti.getGaService().setLocationAndSize(c, ga.getWidth() / 2 - r, ga.getHeight() / 2 - r, r * 2, r * 2);
 c.setFilled(true);
}
if (oldname.endsWith("X") && !newname.endsWith("X")) { // remove
 Ellipse c = null;
 for (GraphicsAlgorithm ga2 : ga.getGraphicsAlgorithmChildren()) {
 if (ga2 instanceof Ellipse)
   c = (Ellipse) ga2;
 }
 System.err.println("removing circle " + c);
 if (c != null)
   ga.getGraphicsAlgorithmChildren().remove(c);
 }
}
Comment 2 Hernan Gonzalez CLA 2011-11-08 16:51:54 EST
I tried to debug the issue, but got tired. There are lots  of 

if(pe instanceof Shape) { }  
if(pe instanceof Anchor) { }  

and similar, see PictogramElementDelegate.refreshFigureForEditPart() for example, and I'm not sure about the correcteness of all these. For example, I'm not sure why there seems to be more intensive digging of Shapes than for Anchors (when one tries to create/recrete/update related Figures/Edit parts of the children GA). Perhaps originally the Anchor was conceived to not include nested GAs? (There was recently other related bug, this about positioning). If this is so, perhaps it would be better to disallow or discourage the use of nested GA in Anchors ?
Comment 3 Matthias Gorning CLA 2011-11-17 06:23:31 EST
Fixed. 

commit 13fec4416024403bdf457bdace7a8831fd1608f4
Author: mgorning <matthias.gorning@sap.com> 2011-11-17 12:16:38
Committer: mgorning <matthias.gorning@sap.com> 2011-11-17 12:16:38
Parent: 462a61237ec1f28dbf71817ef5a67a38950db420 (Bug 363229 - Nested GA inside Anchors are not correctly refreshed / refresh corrected for BoxRelativeAnchor's; inner ga's now have the correct location)
Child: 8936aee9e7f7924e8b7c1c67757e6df90a6c24b6 (Bug 363229 - Nested GA inside Anchors are not correctly refreshed / comments)
Branches: origin/master, master
Comment 4 Michael Wenz CLA 2011-11-22 11:00:01 EST
Looks good to me
Comment 5 Michael Wenz CLA 2012-04-11 10:46:08 EDT
Bookkeeping: Set target release
Comment 6 Michael Wenz CLA 2012-06-29 04:14:16 EDT
Part of Graphiti 0.9.0 (Eclipse Juno)