Bug 439877

Summary: SiriusLayoutManager populated after VSM drop tool's tasks
Product: [Modeling] Sirius Reporter: Benoit Ries <benoit.ries>
Component: CoreAssignee: Project inbox <sirius.core-inbox>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P3 CC: benoit.ries, steve.monnier
Version: 1.0.0Keywords: triaged
Target Milestone: ---   
Hardware: Macintosh   
OS: Mac OS X   
Whiteboard:

Description Benoit Ries CLA 2014-07-18 05:50:23 EDT
steps to reproduce:

In a VSM drop tool's task using a java service with the code below. 

The method call "SiriusLayoutDataManager.INSTANCE.getData()" will always return null.

----
 public void execute(Collection<? extends EObject> selections, Map<String, Object> parameters) {
Object diagram = parameters.get("diagram");
Object elementToLookFor = parameters.get("element");

if (diagram instanceof DNodeContainer) {
DNodeContainer dNodeContainer = (DNodeContainer) diagram;
DDiagramElement diagElt = lookForElementInContainerByEObject(dNodeContainer, elementToLookFor);
if (diagElt instanceof AbstractDNode) {
AbstractDNode abstractDNode = (AbstractDNode) diagElt;
//retrieve mouse drop location
LayoutData layoutData = SiriusLayoutDataManager.INSTANCE.getData(abstractDNode);

//set view location
View view = SiriusGMFHelper.getGmfView(abstractDNode);
Node gmfnode = (Node) view;
Bounds bounds = (Bounds) gmfnode.getLayoutConstraint();
bounds.setX(layoutData.getLocation().x);
bounds.setY(layoutData.getLocation().y);

}
return;
}
Comment 1 Benoit Ries CLA 2014-07-18 08:19:38 EDT
I forgot to add the code for the lookForElementInContainerByEObject(), see below:

-------------------
private DDiagramElement lookForElementInContainerByEObject(DContainer dContainer, Object objectToLookFor) {
 if (dContainer instanceof DSemanticDiagram) {
  DSemanticDiagram dSemanticDiagram = (DSemanticDiagram) dContainer;
  for (DDiagramElement diagElt : dSemanticDiagram.getDiagramElements()) {
   if (diagElt instanceof DNode || diagElt instanceof DNodeList) {
     if (diagElt.getTarget().equals(objectToLookFor)) {
       return diagElt;
     }
   }
  }
 }
 return null;
}