|
@@ -22,6 +22,7 @@ import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
|
|
|
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
|
|
|
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
|
|
|
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
|
|
|
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
|
|
|
import org.eclipse.gmf.runtime.notation.Bounds;
|
|
|
import org.eclipse.gmf.runtime.notation.Node;
|
|
|
import org.eclipse.gmf.runtime.notation.NotationFactory;
|
|
@@ -36,10 +37,12 @@ import org.yakindu.sct.ui.editor.editparts.StateEditPart;
|
|
|
import org.yakindu.sct.ui.editor.providers.SemanticHints;
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
+
|
|
|
/**
|
|
|
- * Groups a set of states into one composite state. All transitions to and from this set of state are preserved, i.e.
|
|
|
- * the new composite state itself will have no incoming or outgoing transitions.
|
|
|
- * <br><br>
|
|
|
+ * Groups a set of states into one composite state. All transitions to and from
|
|
|
+ * this set of state are preserved, i.e. the new composite state itself will
|
|
|
+ * have no incoming or outgoing transitions. <br>
|
|
|
+ * <br>
|
|
|
* Context:
|
|
|
* <ul>
|
|
|
* <li>A set of states</li>
|
|
@@ -48,11 +51,11 @@ import com.google.common.collect.Lists;
|
|
|
* <ul>
|
|
|
* <li>All states are in the same region.</li>
|
|
|
* </ul>
|
|
|
+ *
|
|
|
* @author thomas kutz - Initial contribution and API
|
|
|
*
|
|
|
*/
|
|
|
-public class GroupStatesIntoCompositeRefactoring extends
|
|
|
- AbstractRefactoring<GraphicalEditPart> {
|
|
|
+public class GroupStatesIntoCompositeRefactoring extends AbstractRefactoring<GraphicalEditPart> {
|
|
|
|
|
|
private View parentRegionView;
|
|
|
private PreferencesHint preferencesHint = DiagramActivator.DIAGRAM_PREFERENCES_HINT;
|
|
@@ -60,7 +63,7 @@ public class GroupStatesIntoCompositeRefactoring extends
|
|
|
private final int PADDING = 55;
|
|
|
private State compositeState;
|
|
|
private Region innerRegion;
|
|
|
-
|
|
|
+
|
|
|
protected List<State> contextStates;
|
|
|
|
|
|
@Override
|
|
@@ -76,11 +79,11 @@ public class GroupStatesIntoCompositeRefactoring extends
|
|
|
|
|
|
protected void doSemanticalRefactoring() {
|
|
|
compositeState = createCompositeState();
|
|
|
-
|
|
|
+
|
|
|
innerRegion = SGraphFactory.eINSTANCE.createRegion();
|
|
|
innerRegion.setName("inner region"); // TODO check for uniqueness?
|
|
|
compositeState.getRegions().add(innerRegion);
|
|
|
-
|
|
|
+
|
|
|
for (State state : contextStates) {
|
|
|
innerRegion.getVertices().add(state);
|
|
|
}
|
|
@@ -88,12 +91,11 @@ public class GroupStatesIntoCompositeRefactoring extends
|
|
|
|
|
|
protected void doGraphicalRefactoring() {
|
|
|
Node compositeStateView = createNodeForCompositeState(compositeState);
|
|
|
- Node innerRegionNode = ViewService.createNode(
|
|
|
- getStateFigureCompartmentView(compositeStateView), innerRegion,
|
|
|
+ Node innerRegionNode = ViewService.createNode(getStateFigureCompartmentView(compositeStateView), innerRegion,
|
|
|
SemanticHints.REGION, preferencesHint);
|
|
|
-
|
|
|
+
|
|
|
View regionCompartment = ViewUtil.getChildBySemanticHint(innerRegionNode, SemanticHints.REGION_COMPARTMENT);
|
|
|
- moveSelectedStateNodesTo(regionCompartment, (Bounds)compositeStateView.getLayoutConstraint());
|
|
|
+ moveSelectedStateNodesTo(regionCompartment, (Bounds) compositeStateView.getLayoutConstraint());
|
|
|
}
|
|
|
|
|
|
protected State createCompositeState() {
|
|
@@ -104,8 +106,8 @@ public class GroupStatesIntoCompositeRefactoring extends
|
|
|
}
|
|
|
|
|
|
protected Node createNodeForCompositeState(State compositeState) {
|
|
|
- Node compositeStateNode = ViewService.createNode(parentRegionView,
|
|
|
- compositeState, SemanticHints.STATE, preferencesHint);
|
|
|
+ Node compositeStateNode = ViewService.createNode(parentRegionView, compositeState, SemanticHints.STATE,
|
|
|
+ preferencesHint);
|
|
|
setCompositeStateLayoutConstraint(compositeStateNode);
|
|
|
return compositeStateNode;
|
|
|
}
|
|
@@ -118,27 +120,37 @@ public class GroupStatesIntoCompositeRefactoring extends
|
|
|
contextStates.add((State) element);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public void setContextObjects(List<GraphicalEditPart> contextObject) {
|
|
|
super.setContextObjects(contextObject);
|
|
|
setContextStates();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
protected void moveSelectedStateNodesTo(View containerView, Bounds compositeBounds) {
|
|
|
|
|
|
for (GraphicalEditPart editPart : getContextObjects()) {
|
|
|
- Node stateNode = (Node)editPart.getNotationView();
|
|
|
+ Node stateNode = (Node) editPart.getNotationView();
|
|
|
ViewUtil.insertChildView(containerView, stateNode, ViewUtil.APPEND, true);
|
|
|
Bounds newBounds = NotationFactory.eINSTANCE.createBounds();
|
|
|
- Bounds oldBounds = (Bounds)stateNode.getLayoutConstraint();
|
|
|
- newBounds.setX(oldBounds.getX() - compositeBounds.getX() - 7); //FIXME use bounds of region view
|
|
|
- newBounds.setY(oldBounds.getY() - compositeBounds.getY() - 34); //FIXME use bounds of region view
|
|
|
-
|
|
|
- ((Node)editPart.getNotationView()).setLayoutConstraint(newBounds);
|
|
|
+ Bounds oldBounds = (Bounds) stateNode.getLayoutConstraint();
|
|
|
+ newBounds.setX(oldBounds.getX() - compositeBounds.getX() - 7); // FIXME
|
|
|
+ // use
|
|
|
+ // bounds
|
|
|
+ // of
|
|
|
+ // region
|
|
|
+ // view
|
|
|
+ newBounds.setY(oldBounds.getY() - compositeBounds.getY() - 34); // FIXME
|
|
|
+ // use
|
|
|
+ // bounds
|
|
|
+ // of
|
|
|
+ // region
|
|
|
+ // view
|
|
|
+
|
|
|
+ ((Node) editPart.getNotationView()).setLayoutConstraint(newBounds);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Iterates through all {@link StateEditPart}s of the current selection and
|
|
|
* computes layout constraints for the composite node.
|
|
@@ -149,12 +161,12 @@ public class GroupStatesIntoCompositeRefactoring extends
|
|
|
protected void setCompositeStateLayoutConstraint(Node compositeStateNode) {
|
|
|
|
|
|
Rectangle newbounds = null;
|
|
|
-
|
|
|
+
|
|
|
for (GraphicalEditPart editPart : getContextObjects()) {
|
|
|
Rectangle childBounds = editPart.getFigure().getBounds();
|
|
|
if (newbounds == null)
|
|
|
newbounds = childBounds.getCopy();
|
|
|
-
|
|
|
+
|
|
|
newbounds.union(childBounds);
|
|
|
}
|
|
|
newbounds.expand(new Insets(PADDING, PADDING, PADDING, PADDING));
|
|
@@ -168,8 +180,7 @@ public class GroupStatesIntoCompositeRefactoring extends
|
|
|
}
|
|
|
|
|
|
protected View getStateFigureCompartmentView(Node compositeStateView) {
|
|
|
- return ViewUtil.getChildBySemanticHint(compositeStateView,
|
|
|
- SemanticHints.STATE_FIGURE_COMPARTMENT);
|
|
|
+ return ViewUtil.getChildBySemanticHint(compositeStateView, SemanticHints.STATE_FIGURE_COMPARTMENT);
|
|
|
}
|
|
|
|
|
|
protected String getNameForCompositeState() {
|
|
@@ -178,7 +189,7 @@ public class GroupStatesIntoCompositeRefactoring extends
|
|
|
nameBuilder.append("_");
|
|
|
nameBuilder.append(state.getName());
|
|
|
}
|
|
|
- makeNameUnique(nameBuilder);
|
|
|
+ makeNameUnique(nameBuilder);
|
|
|
return nameBuilder.toString();
|
|
|
}
|
|
|
|
|
@@ -202,9 +213,9 @@ public class GroupStatesIntoCompositeRefactoring extends
|
|
|
parentRegionView = null;
|
|
|
for (IGraphicalEditPart editPart : getContextObjects()) {
|
|
|
if (parentRegionView == null) {
|
|
|
- parentRegionView = (Node) ((Node)editPart.getNotationView()).eContainer();
|
|
|
+ parentRegionView = (Node) ((Node) editPart.getNotationView()).eContainer();
|
|
|
} else {
|
|
|
- Node nextParentRegion = (Node) ((Node)editPart.getNotationView()).eContainer();
|
|
|
+ Node nextParentRegion = (Node) ((Node) editPart.getNotationView()).eContainer();
|
|
|
if (!nextParentRegion.equals(parentRegionView)) {
|
|
|
return false;
|
|
|
}
|
|
@@ -217,10 +228,15 @@ public class GroupStatesIntoCompositeRefactoring extends
|
|
|
protected String getCommandLabel() {
|
|
|
return "Group states into composite state";
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
protected Resource getResource() {
|
|
|
return getContextObject().resolveSemanticElement().eResource();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ protected void executeCommand(AbstractTransactionalCommand refactoringCommand) {
|
|
|
+ executeCommand(refactoringCommand, getResource(), false);
|
|
|
+ }
|
|
|
+
|
|
|
}
|