blob: 8473a956340cff5a1233676a9208b18efaff8f48 [file] [log] [blame]
//------------------------------------------------------------------------------
// Copyright (c) 2005, 2007 IBM Corporation and others.
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// which accompanies this distribution, and is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// Contributors:
// IBM Corporation - initial implementation
//------------------------------------------------------------------------------
/*
* Copyright (c) 2005, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial implementation
*
*/
package org.eclipse.epf.diagramming.edit.policies;
import java.util.List;
import org.eclipse.gef.commands.Command;
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.epf.diagramming.providers.UMLElementTypes;
import org.eclipse.gef.commands.UnexecutableCommand;
import org.eclipse.gmf.runtime.emf.type.core.commands.CreateRelationshipCommand;
import org.eclipse.uml2.uml.ActivityNode;
import org.eclipse.uml2.uml.ControlFlow;
import org.eclipse.uml2.uml.DecisionNode;
import org.eclipse.uml2.uml.ForkNode;
import org.eclipse.uml2.uml.StructuredActivityNode;
import org.eclipse.uml2.uml.UMLPackage;
/**
* @generated
*/
public class DecisionNodeItemSemanticEditPolicy extends
UMLBaseItemSemanticEditPolicy {
/**
* @generated
*/
protected Command getDestroyElementCommand(DestroyElementRequest req) {
return getMSLWrapper(new DestroyElementCommand(req) {
protected EObject getElementToDestroy() {
View view = (View) getHost().getModel();
EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
if (annotation != null) {
return view;
}
return super.getElementToDestroy();
}
});
}
/**
* @modified
*/
protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
// if (UMLElementTypes.ControlFlow_3001 == req.getElementType()) {
// return req.getTarget() == null ? getCreateStartOutgoingControlFlow3001Command(req)
// : getCreateCompleteIncomingControlFlow3001Command(req);
// }
return super.getCreateRelationshipCommand(req);
}
/**
* @generated
*/
protected Command getCreateStartOutgoingControlFlow3001Command(
CreateRelationshipRequest req) {
return new Command() {
};
}
/**
* @generated
*/
protected Command getCreateCompleteIncomingControlFlow3001Command(
CreateRelationshipRequest req) {
if (!(req.getSource() instanceof ActivityNode)) {
return UnexecutableCommand.INSTANCE;
}
final StructuredActivityNode element = (StructuredActivityNode) getRelationshipContainer(
req.getSource(), UMLPackage.eINSTANCE
.getStructuredActivityNode(), req.getElementType());
if (element == null) {
return UnexecutableCommand.INSTANCE;
}
if (req.getContainmentFeature() == null) {
req.setContainmentFeature(UMLPackage.eINSTANCE
.getStructuredActivityNode_Edge());
}
return getMSLWrapper(new CreateIncomingControlFlow3001Command(req) {
/**
* @generated
*/
protected EObject getElementToEdit() {
return element;
}
});
}
/**
* @generated
*/
private static class CreateIncomingControlFlow3001Command extends
CreateRelationshipCommand {
/**
* @generated
*/
public CreateIncomingControlFlow3001Command(
CreateRelationshipRequest req) {
super(req);
}
/**
* @generated
*/
protected EClass getEClassToEdit() {
return UMLPackage.eINSTANCE.getStructuredActivityNode();
};
/**
* @generated
*/
protected void setElementToEdit(EObject element) {
throw new UnsupportedOperationException();
}
/**
* @generated
*/
protected EObject doDefaultElementCreation() {
ControlFlow newElement = (ControlFlow) super
.doDefaultElementCreation();
if (newElement != null) {
newElement.setTarget((ActivityNode) getTarget());
newElement.setSource((ActivityNode) getSource());
}
return newElement;
}
}
/*
* (non-Javadoc)
* @see org.eclipse.epf.diagramming.edit.policies.UMLBaseItemSemanticEditPolicy#getCreateIncomingComplete(org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest)
* @modified
*/
protected Command getCreateIncomingComplete(CreateRelationshipRequest req) {
if (req.getTarget() instanceof DecisionNode) {
DecisionNode decision = (DecisionNode) req.getTarget();
List list = decision.getIncomings();
if (list != null && list.size() >= 1) {
return UnexecutableCommand.INSTANCE;
}
}
return super.getCreateIncomingComplete(req);
}
}