Newer
Older
package org.etsi.mts.tdl.graphical.sirius.part;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.LayoutManager;
import org.eclipse.draw2d.RectangleFigure;
import org.eclipse.draw2d.RoundedRectangle;
import org.eclipse.draw2d.StackLayout;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.gmf.runtime.notation.impl.NodeImpl;
import org.eclipse.sirius.diagram.business.internal.metamodel.spec.DNodeListSpec;
import org.eclipse.sirius.diagram.business.internal.metamodel.spec.DNodeSpec;
import org.eclipse.sirius.ext.gmf.runtime.gef.ui.figures.SiriusWrapLabel;
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import org.eclipse.sirius.viewpoint.DMappingBased;
public class Util {
public static void disableOutlines(IFigure f) {
if (f instanceof RectangleFigure)
((RectangleFigure) f).setOutline(false);
if (f instanceof RoundedRectangle)
((RoundedRectangle) f).setOutline(false);
if (f instanceof SiriusWrapLabel) {
LayoutManager layout = f.getParent().getLayoutManager();
if (layout == null)
f.getParent().setLayoutManager(new StackLayout());
}
for (Object c: f.getChildren())
disableOutlines((IFigure) c);
}
@SuppressWarnings({ "unchecked", "restriction", "rawtypes" })
public static List getModelChildren(Object model) {
//this determines the order of compartments
//the current approach is not ideal and makes some unsound assumptions
//but it does the job for the time being
if(model!=null && model instanceof View){
ArrayList children = new ArrayList();
EList vc = ((View)model).getVisibleChildren();
for (Object c : vc) {
if (((NodeImpl)c).getElement() instanceof DNodeSpec ||
(((NodeImpl)c).getElement() instanceof DNodeListSpec)
&& ((DNodeListSpec)((NodeImpl)c).getElement()).getActualMapping().getName().endsWith(".name")) {
children.add(c);
}
}
for (Object c : vc) {
if (!children.contains(c)) {
children.add(c);
}
}
return children;
}
return Collections.EMPTY_LIST;
}
public static String getMappingId(IGraphicalEditPart part) {
EObject semantic = part.resolveSemanticElement();
if (semantic instanceof DMappingBased)
return ((DMappingBased)semantic).getMapping().getName();
return null;
}
}