use of org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint in project statecharts by Yakindu.
the class ExtractSubdiagramRefactoring method createSubdiagram.
/**
* Creates a new {@link Diagram} and copies child elements
*/
protected Diagram createSubdiagram() {
View contextView = getContextObject();
State contextElement = (State) contextView.getElement();
Diagram subdiagram = ViewService.createDiagram(contextElement, StatechartDiagramEditor.ID, preferencesHint);
View figureCompartment = ViewUtil.getChildBySemanticHint(contextView, SemanticHints.STATE_FIGURE_COMPARTMENT);
getResource().getContents().add(subdiagram);
boolean isHorizontal = isHorizontal(figureCompartment);
int offset = 0;
int subregions = figureCompartment.getChildren().size();
while (figureCompartment.getChildren().size() > 0) {
Node child = (Node) figureCompartment.getChildren().get(0);
if (subregions > 1) {
Rectangle actualBounds = getActualBounds(child);
if (actualBounds != Rectangle.SINGLETON) {
Bounds modelBounds = (Bounds) child.getLayoutConstraint();
modelBounds.setWidth(actualBounds.width());
modelBounds.setHeight(actualBounds.height());
if (isHorizontal) {
modelBounds.setX(offset);
offset += actualBounds.width();
} else {
modelBounds.setY(offset);
offset += actualBounds.height();
}
}
}
subdiagram.insertChild(child);
}
return subdiagram;
}
Aggregations