Explorar el Código

StatechartTextExpressionEditPart -> disallow self connection, removed connection handles.
Refactoring of connection crerating command to avoid class cast exceptions.

markus.muehlbrandt@itemis.de hace 14 años
padre
commit
69a6e1f83d

+ 6 - 0
plugins/org.yakindu.sct.ui.editor/plugin.xml

@@ -207,6 +207,12 @@
                   value="Synchronization">
             </param>
          </metamodelType>
+          <adviceBinding
+                class="org.yakindu.sct.ui.editor.edithelper.StatechartEditHelperAdvice"
+                id="org.yakindu.sct.ui.editor.StatechartAdviceBinding"
+                inheritance="none"
+                typeId="org.yakindu.sct.ui.editor.Statechart">
+          </adviceBinding>
          </metamodel>
    </extension>
    

+ 22 - 22
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/commands/CreateTransitionCommand.java

@@ -13,6 +13,7 @@ package org.yakindu.sct.ui.editor.commands;
 import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.ecore.EObject;
 import org.eclipse.gmf.runtime.common.core.command.CommandResult;
 import org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand;
 import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
@@ -25,22 +26,25 @@ import org.yakindu.sct.model.sgraph.Vertex;
  * 
  * @author muelder
  * @author terfloth
+ * @author muehlbrandt
  * 
  */
 public class CreateTransitionCommand extends EditElementCommand {
-
-	private final Vertex source;
-
-	private final Vertex target;
-
+	
 	public CreateTransitionCommand(CreateRelationshipRequest request) {
 		super(request.getLabel(), null, request);
-		this.source = (Vertex) request.getSource();
-		this.target = (Vertex) request.getTarget();
+	}
+	
+	@Override
+	protected CreateRelationshipRequest getRequest() {
+		return (CreateRelationshipRequest) super.getRequest();
 	}
 
 	@Override
 	public boolean canExecute() {
+		EObject source = getRequest().getSource();
+		EObject target = getRequest().getTarget();
+		
 		if (source == null && target == null) {
 			return false;
 		}
@@ -54,11 +58,17 @@ public class CreateTransitionCommand extends EditElementCommand {
 	@Override
 	protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
 			IAdaptable info) throws ExecutionException {
-		if (!canExecute()) {
-			throw new ExecutionException(
-					"Invalid arguments in create link command");
-		}
-		if (getSource() != null && getTarget() != null) {
+
+		// This class casts should be save because they are validated in
+		// canExecute() method which is called by the framework before
+		// execution.
+		Vertex source = (Vertex) getRequest().getSource();
+		Vertex target = (Vertex) getRequest().getTarget();
+//		if (!canExecute()) {
+//			throw new ExecutionException(
+//					"Invalid arguments in create link command");
+//		}
+		if (source != null && target != null) {
 			Transition transition = SGraphFactory.eINSTANCE.createTransition();
 			source.getOutgoingTransitions().add(transition);
 			transition.setSource(source);
@@ -68,15 +78,5 @@ public class CreateTransitionCommand extends EditElementCommand {
 			((CreateElementRequest) getRequest()).setNewElement(transition);
 		}
 		return CommandResult.newOKCommandResult();
-
-	}
-
-	public Vertex getSource() {
-		return source;
 	}
-
-	public Vertex getTarget() {
-		return target;
-	}
-
 }

+ 19 - 0
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/edithelper/StatechartEditHelperAdvice.java

@@ -0,0 +1,19 @@
+package org.yakindu.sct.ui.editor.edithelper;
+
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
+import org.yakindu.sct.model.sgraph.Statechart;
+
+public class StatechartEditHelperAdvice extends AbstractEditHelperAdvice {
+
+	@Override
+	protected ICommand getBeforeCreateRelationshipCommand(
+			CreateRelationshipRequest request) {
+		if (request.getSource() instanceof Statechart) {
+			return UnexecutableCommand.INSTANCE;
+		}
+		return super.getBeforeCreateRelationshipCommand(request);
+	}
+}

+ 2 - 0
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/editparts/StatechartTextExpressionEditPart.java

@@ -2,6 +2,7 @@ package org.yakindu.sct.ui.editor.editparts;
 
 import org.eclipse.gef.EditPolicy;
 import org.eclipse.gef.editpolicies.RootComponentEditPolicy;
+import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
 import org.eclipse.gmf.runtime.notation.View;
 import org.yakindu.sct.ui.editor.policies.ContextSensitiveHelpPolicy;
 import org.yakindu.sct.ui.editor.utils.IYakinduSctHelpContextIds;
@@ -29,6 +30,7 @@ public class StatechartTextExpressionEditPart extends
 				EditPolicy.SELECTION_FEEDBACK_ROLE,
 				new ContextSensitiveHelpPolicy(
 						IYakinduSctHelpContextIds.SC_PROPERTIES_STATECHART_EXPRESSION));
+		removeEditPolicy(EditPolicyRoles.CONNECTION_HANDLES_ROLE);
 	}
 
 }