Search in sources :

Example 1 with PreferencesHint

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;
}
Also used : State(org.yakindu.sct.model.sgraph.State) Node(org.eclipse.gmf.runtime.notation.Node) Bounds(org.eclipse.gmf.runtime.notation.Bounds) Rectangle(org.eclipse.draw2d.geometry.Rectangle) View(org.eclipse.gmf.runtime.notation.View) PreferencesHint(org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint) Diagram(org.eclipse.gmf.runtime.notation.Diagram)

Aggregations

Rectangle (org.eclipse.draw2d.geometry.Rectangle)1 PreferencesHint (org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint)1 Bounds (org.eclipse.gmf.runtime.notation.Bounds)1 Diagram (org.eclipse.gmf.runtime.notation.Diagram)1 Node (org.eclipse.gmf.runtime.notation.Node)1 View (org.eclipse.gmf.runtime.notation.View)1 State (org.yakindu.sct.model.sgraph.State)1