blob: fe761552ee8cc08315a7ddb55f40429fe5ff7886 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2016 KPIT Technologies.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Jan Mauersberger- initial API and implementation
* Sascha Baumgart- initial API and implementation
*******************************************************************************/
/*
*
*/
package org.eclipse.opencert.vocabulary.diagram.edit.policies;
import java.util.Iterator;
import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.gef.commands.Command;
import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand;
import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyReferenceCommand;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyReferenceRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientReferenceRelationshipRequest;
import org.eclipse.gmf.runtime.notation.Edge;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.opencert.vocabulary.diagram.edit.commands.CategoryTermsCreateCommand;
import org.eclipse.opencert.vocabulary.diagram.edit.commands.CategoryTermsReorientCommand;
import org.eclipse.opencert.vocabulary.diagram.edit.commands.TermDefinedByCreateCommand;
import org.eclipse.opencert.vocabulary.diagram.edit.commands.TermDefinedByReorientCommand;
import org.eclipse.opencert.vocabulary.diagram.edit.commands.TermHasACreateCommand;
import org.eclipse.opencert.vocabulary.diagram.edit.commands.TermHasAReorientCommand;
import org.eclipse.opencert.vocabulary.diagram.edit.commands.TermIsACreateCommand;
import org.eclipse.opencert.vocabulary.diagram.edit.commands.TermIsAReorientCommand;
import org.eclipse.opencert.vocabulary.diagram.edit.commands.TermRefersToCreateCommand;
import org.eclipse.opencert.vocabulary.diagram.edit.commands.TermRefersToReorientCommand;
import org.eclipse.opencert.vocabulary.diagram.edit.parts.CategoryTermsEditPart;
import org.eclipse.opencert.vocabulary.diagram.edit.parts.TermDefinedByEditPart;
import org.eclipse.opencert.vocabulary.diagram.edit.parts.TermHasAEditPart;
import org.eclipse.opencert.vocabulary.diagram.edit.parts.TermIsAEditPart;
import org.eclipse.opencert.vocabulary.diagram.edit.parts.TermRefersToEditPart;
import org.eclipse.opencert.vocabulary.diagram.part.VocabularyVisualIDRegistry;
import org.eclipse.opencert.vocabulary.diagram.providers.VocabularyElementTypes;
/**
* @generated
*/
public class TermItemSemanticEditPolicy extends
VocabularyBaseItemSemanticEditPolicy {
/**
* @generated
*/
public TermItemSemanticEditPolicy() {
super(VocabularyElementTypes.Term_2001);
}
/**
* @generated
*/
protected Command getDestroyElementCommand(DestroyElementRequest req) {
View view = (View) getHost().getModel();
CompositeTransactionalCommand cmd = new CompositeTransactionalCommand(
getEditingDomain(), null);
cmd.setTransactionNestingEnabled(false);
for (Iterator<?> it = view.getTargetEdges().iterator(); it.hasNext();) {
Edge incomingLink = (Edge) it.next();
if (VocabularyVisualIDRegistry.getVisualID(incomingLink) == CategoryTermsEditPart.VISUAL_ID) {
DestroyReferenceRequest r = new DestroyReferenceRequest(
incomingLink.getSource().getElement(), null,
incomingLink.getTarget().getElement(), false);
cmd.add(new DestroyReferenceCommand(r));
cmd.add(new DeleteCommand(getEditingDomain(), incomingLink));
continue;
}
if (VocabularyVisualIDRegistry.getVisualID(incomingLink) == TermIsAEditPart.VISUAL_ID) {
DestroyReferenceRequest r = new DestroyReferenceRequest(
incomingLink.getSource().getElement(), null,
incomingLink.getTarget().getElement(), false);
cmd.add(new DestroyReferenceCommand(r));
cmd.add(new DeleteCommand(getEditingDomain(), incomingLink));
continue;
}
if (VocabularyVisualIDRegistry.getVisualID(incomingLink) == TermHasAEditPart.VISUAL_ID) {
DestroyReferenceRequest r = new DestroyReferenceRequest(
incomingLink.getSource().getElement(), null,
incomingLink.getTarget().getElement(), false);
cmd.add(new DestroyReferenceCommand(r));
cmd.add(new DeleteCommand(getEditingDomain(), incomingLink));
continue;
}
if (VocabularyVisualIDRegistry.getVisualID(incomingLink) == TermRefersToEditPart.VISUAL_ID) {
DestroyReferenceRequest r = new DestroyReferenceRequest(
incomingLink.getSource().getElement(), null,
incomingLink.getTarget().getElement(), false);
cmd.add(new DestroyReferenceCommand(r));
cmd.add(new DeleteCommand(getEditingDomain(), incomingLink));
continue;
}
}
for (Iterator<?> it = view.getSourceEdges().iterator(); it.hasNext();) {
Edge outgoingLink = (Edge) it.next();
if (VocabularyVisualIDRegistry.getVisualID(outgoingLink) == TermDefinedByEditPart.VISUAL_ID) {
DestroyReferenceRequest r = new DestroyReferenceRequest(
outgoingLink.getSource().getElement(), null,
outgoingLink.getTarget().getElement(), false);
cmd.add(new DestroyReferenceCommand(r));
cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink));
continue;
}
if (VocabularyVisualIDRegistry.getVisualID(outgoingLink) == TermIsAEditPart.VISUAL_ID) {
DestroyReferenceRequest r = new DestroyReferenceRequest(
outgoingLink.getSource().getElement(), null,
outgoingLink.getTarget().getElement(), false);
cmd.add(new DestroyReferenceCommand(r));
cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink));
continue;
}
if (VocabularyVisualIDRegistry.getVisualID(outgoingLink) == TermHasAEditPart.VISUAL_ID) {
DestroyReferenceRequest r = new DestroyReferenceRequest(
outgoingLink.getSource().getElement(), null,
outgoingLink.getTarget().getElement(), false);
cmd.add(new DestroyReferenceCommand(r));
cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink));
continue;
}
if (VocabularyVisualIDRegistry.getVisualID(outgoingLink) == TermRefersToEditPart.VISUAL_ID) {
DestroyReferenceRequest r = new DestroyReferenceRequest(
outgoingLink.getSource().getElement(), null,
outgoingLink.getTarget().getElement(), false);
cmd.add(new DestroyReferenceCommand(r));
cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink));
continue;
}
}
EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
if (annotation == null) {
// there are indirectly referenced children, need extra commands: false
addDestroyShortcutsCommand(cmd, view);
// delete host element
cmd.add(new DestroyElementCommand(req));
} else {
cmd.add(new DeleteCommand(getEditingDomain(), view));
}
return getGEFWrapper(cmd.reduce());
}
/**
* @generated
*/
protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
Command command = req.getTarget() == null ? getStartCreateRelationshipCommand(req)
: getCompleteCreateRelationshipCommand(req);
return command != null ? command : super
.getCreateRelationshipCommand(req);
}
/**
* @generated
*/
protected Command getStartCreateRelationshipCommand(
CreateRelationshipRequest req) {
if (VocabularyElementTypes.CategoryTerms_4001 == req.getElementType()) {
return null;
}
if (VocabularyElementTypes.TermDefinedBy_4003 == req.getElementType()) {
return getGEFWrapper(new TermDefinedByCreateCommand(req,
req.getSource(), req.getTarget()));
}
if (VocabularyElementTypes.TermIsA_4004 == req.getElementType()) {
return getGEFWrapper(new TermIsACreateCommand(req, req.getSource(),
req.getTarget()));
}
if (VocabularyElementTypes.TermHasA_4005 == req.getElementType()) {
return getGEFWrapper(new TermHasACreateCommand(req,
req.getSource(), req.getTarget()));
}
if (VocabularyElementTypes.TermRefersTo_4006 == req.getElementType()) {
return getGEFWrapper(new TermRefersToCreateCommand(req,
req.getSource(), req.getTarget()));
}
return null;
}
/**
* @generated
*/
protected Command getCompleteCreateRelationshipCommand(
CreateRelationshipRequest req) {
if (VocabularyElementTypes.CategoryTerms_4001 == req.getElementType()) {
return getGEFWrapper(new CategoryTermsCreateCommand(req,
req.getSource(), req.getTarget()));
}
if (VocabularyElementTypes.TermDefinedBy_4003 == req.getElementType()) {
return null;
}
if (VocabularyElementTypes.TermIsA_4004 == req.getElementType()) {
return getGEFWrapper(new TermIsACreateCommand(req, req.getSource(),
req.getTarget()));
}
if (VocabularyElementTypes.TermHasA_4005 == req.getElementType()) {
return getGEFWrapper(new TermHasACreateCommand(req,
req.getSource(), req.getTarget()));
}
if (VocabularyElementTypes.TermRefersTo_4006 == req.getElementType()) {
return getGEFWrapper(new TermRefersToCreateCommand(req,
req.getSource(), req.getTarget()));
}
return null;
}
/**
* Returns command to reorient EReference based link. New link target or source
* should be the domain model element associated with this node.
*
* @generated
*/
protected Command getReorientReferenceRelationshipCommand(
ReorientReferenceRelationshipRequest req) {
switch (getVisualID(req)) {
case CategoryTermsEditPart.VISUAL_ID:
return getGEFWrapper(new CategoryTermsReorientCommand(req));
case TermDefinedByEditPart.VISUAL_ID:
return getGEFWrapper(new TermDefinedByReorientCommand(req));
case TermIsAEditPart.VISUAL_ID:
return getGEFWrapper(new TermIsAReorientCommand(req));
case TermHasAEditPart.VISUAL_ID:
return getGEFWrapper(new TermHasAReorientCommand(req));
case TermRefersToEditPart.VISUAL_ID:
return getGEFWrapper(new TermRefersToReorientCommand(req));
}
return super.getReorientReferenceRelationshipCommand(req);
}
}