001: /**
002: *
003: */package newprocess.diagram.cust.annotations.commands;
004:
005: import java.util.Collection;
006:
007: import newprocess.diagram.cust.annotations.dialogs.AnnotationList;
008: import newprocess.diagram.cust.annotations.utils.FeatureUtil;
009:
010: import org.eclipse.emf.ecore.EAttribute;
011: import org.eclipse.emf.ecore.EObject;
012: import org.eclipse.emf.edit.command.RemoveCommand;
013: import org.eclipse.emf.edit.domain.EditingDomain;
014: import org.eclipse.emf.transaction.TransactionalEditingDomain;
015: import org.eclipse.gef.EditPart;
016: import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionNodeEditPart;
017: import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
018: import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
019: import org.eclipse.gmf.runtime.notation.Diagram;
020: import org.eclipse.gmf.runtime.notation.Edge;
021: import org.eclipse.gmf.runtime.notation.Node;
022:
023: /**
024: * @author sh
025: *
026: */
027: public class DeleteCommand {
028: /**
029: * Constructor
030: */
031: public DeleteCommand() {
032: }
033:
034: /**
035: * executes a RemoveCommand which removes the url
036: */
037: public void executeRemoveCommand(EditPart editPart, Object value) {
038: // do nothing if it is the default value
039: if (value.equals(AnnotationList.STANDARD_TEXT))
040: return;
041:
042: // create the RemoveCommand
043: EObject elementToEdit = null;
044: TransactionalEditingDomain diagramEditDomain = null;
045: if (editPart instanceof DiagramEditPart) {
046: diagramEditDomain = ((DiagramEditPart) editPart)
047: .getEditingDomain();
048: elementToEdit = ((Diagram) editPart.getModel())
049: .getElement();
050: }
051: if (editPart instanceof ShapeNodeEditPart) {
052: diagramEditDomain = ((ShapeNodeEditPart) editPart)
053: .getEditingDomain();
054: elementToEdit = ((Node) editPart.getModel()).getElement();
055: }
056: if (editPart instanceof ConnectionNodeEditPart) {
057: diagramEditDomain = ((ConnectionNodeEditPart) editPart)
058: .getEditingDomain();
059: elementToEdit = ((Edge) editPart.getModel()).getElement();
060: }
061: FeatureUtil featureUtil = new FeatureUtil();
062: EAttribute feature = featureUtil.getFeature(editPart);
063:
064: // execute the RemoveCommmand
065: RemoveCommand removeCommand = new RemoveCommand(
066: diagramEditDomain, elementToEdit, feature, value);
067: EditingDomain dom = removeCommand.getDomain();
068: dom.getCommandStack().execute(removeCommand);
069: }
070:
071: /**
072: * executes a RemoveCommand which removes a collection of urls
073: */
074: public void executeRemoveCommand(EditPart editPart,
075: Collection values) {
076: // create the RemoveCommand
077: EObject elementToEdit = null;
078: TransactionalEditingDomain diagramEditDomain = null;
079: if (editPart instanceof DiagramEditPart) {
080: diagramEditDomain = ((DiagramEditPart) editPart)
081: .getEditingDomain();
082: elementToEdit = ((Diagram) editPart.getModel())
083: .getElement();
084: }
085: if (editPart instanceof ShapeNodeEditPart) {
086: diagramEditDomain = ((ShapeNodeEditPart) editPart)
087: .getEditingDomain();
088: elementToEdit = ((Node) editPart.getModel()).getElement();
089: }
090: if (editPart instanceof ConnectionNodeEditPart) {
091: diagramEditDomain = ((ConnectionNodeEditPart) editPart)
092: .getEditingDomain();
093: elementToEdit = ((Edge) editPart.getModel()).getElement();
094: }
095: FeatureUtil featureUtil = new FeatureUtil();
096: EAttribute feature = featureUtil.getFeature(editPart);
097:
098: // execute the RemoveCommmand
099: RemoveCommand removeCommand = new RemoveCommand(
100: diagramEditDomain, elementToEdit, feature, values);
101: EditingDomain dom = removeCommand.getDomain();
102: dom.getCommandStack().execute(removeCommand);
103: }
104: }
|