|
@@ -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;
|
|
|
- }
|
|
|
-
|
|
|
}
|