|
@@ -1,102 +0,0 @@
|
|
|
-package org.yakindu.sct.statechart.diagram.policies;
|
|
|
-
|
|
|
-import org.eclipse.emf.common.util.EList;
|
|
|
-import org.eclipse.emf.ecore.EStructuralFeature;
|
|
|
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
|
|
|
-import org.eclipse.gef.EditPart;
|
|
|
-import org.eclipse.gef.EditPolicy;
|
|
|
-import org.eclipse.gef.Request;
|
|
|
-import org.eclipse.gef.commands.Command;
|
|
|
-import org.eclipse.gef.requests.CreateRequest;
|
|
|
-import org.eclipse.gmf.runtime.diagram.core.commands.AddCommand;
|
|
|
-import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
|
|
|
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
|
|
|
-import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableEditPolicyEx;
|
|
|
-import org.eclipse.gmf.runtime.emf.commands.core.commands.RepositionEObjectCommand;
|
|
|
-import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
|
|
|
-import org.eclipse.gmf.runtime.notation.View;
|
|
|
-import org.yakindu.sct.statechart.diagram.commands.CompartmentRepositionEObjectCommand;
|
|
|
-
|
|
|
-//TODO: Move to commons
|
|
|
-public class CompartmentEditPolicy extends
|
|
|
- org.eclipse.gef.editpolicies.FlowLayoutEditPolicy {
|
|
|
-
|
|
|
- private EStructuralFeature feature = null;
|
|
|
-
|
|
|
- protected Command createAddCommand(EditPart child, EditPart after) {
|
|
|
- int index = getHost().getChildren().indexOf(after);
|
|
|
- TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost())
|
|
|
- .getEditingDomain();
|
|
|
- AddCommand command = new AddCommand(editingDomain, new EObjectAdapter(
|
|
|
- (View) getHost().getModel()), new EObjectAdapter(
|
|
|
- (View) child.getModel()), index);
|
|
|
- return new ICommandProxy(command);
|
|
|
- }
|
|
|
-
|
|
|
- protected EditPolicy createChildEditPolicy(EditPart child) {
|
|
|
- ResizableEditPolicyEx policy = new ResizableEditPolicyEx();
|
|
|
- policy.setResizeDirections(0);
|
|
|
- return policy;
|
|
|
- }
|
|
|
-
|
|
|
- @SuppressWarnings("rawtypes")
|
|
|
- protected Command createMoveChildCommand(EditPart child, EditPart after) {
|
|
|
-
|
|
|
- int newIndex;
|
|
|
- int displacement;
|
|
|
-
|
|
|
- int childIndex = getHost().getChildren().indexOf(child);
|
|
|
- int afterIndex = getHost().getChildren().indexOf(after);
|
|
|
-
|
|
|
- if (afterIndex == -1) {
|
|
|
- newIndex = getHost().getChildren().size() - 1;
|
|
|
- displacement = newIndex - childIndex;
|
|
|
- } else {
|
|
|
- newIndex = afterIndex;
|
|
|
- displacement = afterIndex - childIndex;
|
|
|
- if (childIndex <= afterIndex) {
|
|
|
- newIndex--;
|
|
|
- displacement--;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost())
|
|
|
- .getEditingDomain();
|
|
|
-
|
|
|
- RepositionEObjectCommand command = new CompartmentRepositionEObjectCommand(
|
|
|
- child, editingDomain, "", (EList) ((View) child.getParent()
|
|
|
- .getModel()).getElement().eGet(feature),
|
|
|
- ((View) child.getModel()).getElement(), displacement, newIndex);
|
|
|
-
|
|
|
- // TODO ev. reintroduce target feedback (actual problem: line is not
|
|
|
- // deleted after dropping)
|
|
|
- eraseLayoutTargetFeedback(null);
|
|
|
-
|
|
|
- return new ICommandProxy(command);
|
|
|
- }
|
|
|
-
|
|
|
- protected Command getCreateCommand(CreateRequest request) {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- protected Command getDeleteDependantCommand(Request request) {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- protected Command getOrphanChildrenCommand(Request request) {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @param feature
|
|
|
- * has to be an EList
|
|
|
- */
|
|
|
- public CompartmentEditPolicy(EStructuralFeature feature) {
|
|
|
- super();
|
|
|
- this.feature = feature;
|
|
|
- }
|
|
|
- @Override
|
|
|
- protected boolean isHorizontal() {
|
|
|
- return true;
|
|
|
- }
|
|
|
-}
|