| package org.eclipse.uml2.diagram.activity.edit.commands; |
| |
| import org.eclipse.core.commands.ExecutionException; |
| import org.eclipse.core.runtime.IAdaptable; |
| import org.eclipse.core.runtime.IProgressMonitor; |
| import org.eclipse.emf.ecore.EClass; |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.gmf.runtime.common.core.command.CommandResult; |
| import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand; |
| import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest; |
| import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest; |
| import org.eclipse.uml2.diagram.activity.edit.policies.UMLBaseItemSemanticEditPolicy; |
| import org.eclipse.uml2.uml.Activity; |
| import org.eclipse.uml2.uml.ActivityNode; |
| import org.eclipse.uml2.uml.ControlFlow; |
| import org.eclipse.uml2.uml.UMLFactory; |
| import org.eclipse.uml2.uml.UMLPackage; |
| |
| /** |
| * @generated |
| */ |
| public class ControlFlowCreateCommand extends CreateElementCommand { |
| |
| /** |
| * @generated |
| */ |
| private final EObject source; |
| |
| /** |
| * @generated |
| */ |
| private final EObject target; |
| |
| /** |
| * @generated |
| */ |
| private Activity container; |
| |
| /** |
| * @generated |
| */ |
| public ControlFlowCreateCommand(CreateRelationshipRequest request, EObject source, EObject target) { |
| super(request); |
| this.source = source; |
| this.target = target; |
| if (request.getContainmentFeature() == null) { |
| setContainmentFeature(UMLPackage.eINSTANCE.getActivity_Edge()); |
| } |
| |
| // Find container element for the new link. |
| // Climb up by containment hierarchy starting from the source |
| // and return the first element that is instance of the container class. |
| for (EObject element = source; element != null; element = element.eContainer()) { |
| if (element instanceof Activity) { |
| container = (Activity) element; |
| super.setElementToEdit(container); |
| break; |
| } |
| } |
| } |
| |
| /** |
| * @generated |
| */ |
| public boolean canExecute() { |
| if (source == null && target == null) { |
| return false; |
| } |
| if (source != null && false == source instanceof ActivityNode) { |
| return false; |
| } |
| if (target != null && false == target instanceof ActivityNode) { |
| return false; |
| } |
| if (getSource() == null) { |
| return true; // link creation is in progress; source is not defined yet |
| } |
| // target may be null here but it's possible to check constraint |
| if (getContainer() == null) { |
| return false; |
| } |
| return UMLBaseItemSemanticEditPolicy.LinkConstraints.canCreateControlFlow_4001(getContainer(), getSource(), getTarget()); |
| } |
| |
| /** |
| * @generated |
| */ |
| protected EObject doDefaultElementCreation() { |
| ControlFlow newElement = UMLFactory.eINSTANCE.createControlFlow(); |
| getContainer().getEdges().add(newElement); |
| newElement.setSource(getSource()); |
| newElement.setTarget(getTarget()); |
| return newElement; |
| } |
| |
| /** |
| * @generated |
| */ |
| protected EClass getEClassToEdit() { |
| return UMLPackage.eINSTANCE.getActivity(); |
| } |
| |
| /** |
| * @generated |
| */ |
| protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { |
| if (!canExecute()) { |
| throw new ExecutionException("Invalid arguments in create link command"); //$NON-NLS-1$ |
| } |
| return super.doExecuteWithResult(monitor, info); |
| } |
| |
| /** |
| * @generated |
| */ |
| protected ConfigureRequest createConfigureRequest() { |
| ConfigureRequest request = super.createConfigureRequest(); |
| request.setParameter(CreateRelationshipRequest.SOURCE, getSource()); |
| request.setParameter(CreateRelationshipRequest.TARGET, getTarget()); |
| return request; |
| } |
| |
| /** |
| * @generated |
| */ |
| protected void setElementToEdit(EObject element) { |
| throw new UnsupportedOperationException(); |
| } |
| |
| /** |
| * @generated |
| */ |
| protected ActivityNode getSource() { |
| return (ActivityNode) source; |
| } |
| |
| /** |
| * @generated |
| */ |
| protected ActivityNode getTarget() { |
| return (ActivityNode) target; |
| } |
| |
| /** |
| * @generated |
| */ |
| public Activity getContainer() { |
| return container; |
| } |
| } |