| package org.eclipse.uml2.diagram.clazz.edit.commands; |
| |
| import java.util.List; |
| |
| 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.clazz.edit.policies.UMLBaseItemSemanticEditPolicy; |
| import org.eclipse.uml2.uml.Classifier; |
| import org.eclipse.uml2.uml.Generalization; |
| import org.eclipse.uml2.uml.GeneralizationSet; |
| import org.eclipse.uml2.uml.UMLFactory; |
| import org.eclipse.uml2.uml.UMLPackage; |
| |
| /** |
| * @generated |
| */ |
| public class Generalization2CreateCommand extends CreateElementCommand { |
| |
| /** |
| * @generated |
| */ |
| private final EObject source; |
| |
| /** |
| * @generated |
| */ |
| private final EObject target; |
| |
| /** |
| * @generated |
| */ |
| public Generalization2CreateCommand(CreateRelationshipRequest request, EObject source, EObject target) { |
| super(request); |
| this.source = source; |
| this.target = target; |
| if (request.getContainmentFeature() == null) { |
| setContainmentFeature(UMLPackage.eINSTANCE.getClassifier_Generalization()); |
| } |
| |
| super.setElementToEdit(source); |
| } |
| |
| /** |
| * @generated |
| */ |
| public boolean canExecute() { |
| if (source == null && target == null) { |
| return false; |
| } |
| if (source != null && false == source instanceof Classifier) { |
| return false; |
| } |
| if (target != null && false == target instanceof GeneralizationSet) { |
| 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 |
| return UMLBaseItemSemanticEditPolicy.LinkConstraints.canCreateGeneralization_4011(getSource(), getTarget()); |
| } |
| |
| /** |
| * @generated |
| */ |
| protected EObject doDefaultElementCreationGen() { |
| Generalization newElement = UMLFactory.eINSTANCE.createGeneralization(); |
| getSource().getGeneralizations().add(newElement); |
| newElement.getGeneralizationSets().add(getTarget()); |
| return newElement; |
| } |
| |
| /** |
| * @generated NOT |
| */ |
| protected EObject doDefaultElementCreation() { |
| Generalization newElement = (Generalization) doDefaultElementCreationGen(); |
| newElement.setGeneral(getGeneralClassifier()); |
| return newElement; |
| } |
| |
| /** |
| * @NOT-generated |
| */ |
| private Classifier getGeneralClassifier() { |
| List<Generalization> generalisations = getTarget().getGeneralizations(); |
| return generalisations.isEmpty() ? null : generalisations.get(0).getGeneral(); |
| |
| } |
| |
| /** |
| * @generated |
| */ |
| protected EClass getEClassToEdit() { |
| return UMLPackage.eINSTANCE.getClassifier(); |
| } |
| |
| /** |
| * @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 Classifier getSource() { |
| return (Classifier) source; |
| } |
| |
| /** |
| * @generated |
| */ |
| protected GeneralizationSet getTarget() { |
| return (GeneralizationSet) target; |
| } |
| } |