01: /**
02: *
03: */package newprocess.diagram.cust.annotations.commands;
04:
05: import newprocess.diagram.cust.annotations.utils.FeatureUtil;
06:
07: import org.eclipse.emf.ecore.EAttribute;
08: import org.eclipse.emf.ecore.EObject;
09: import org.eclipse.emf.edit.command.ReplaceCommand;
10: import org.eclipse.emf.edit.domain.EditingDomain;
11: import org.eclipse.emf.transaction.TransactionalEditingDomain;
12: import org.eclipse.gef.EditPart;
13: import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionNodeEditPart;
14: import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
15: import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
16: import org.eclipse.gmf.runtime.notation.Diagram;
17: import org.eclipse.gmf.runtime.notation.Edge;
18: import org.eclipse.gmf.runtime.notation.Node;
19:
20: /**
21: * @author sh
22: *
23: */
24: public class ChangeCommand {
25: /**
26: * Constructor
27: */
28: public ChangeCommand() {
29: }
30:
31: /**
32: * executes a ReplaceCommand
33: */
34: public void executeReplaceCommand(EditPart editPart,
35: Object oldValue, Object newValue) {
36: // create the ReplaceCommand
37: EObject elementToEdit = null;
38: FeatureUtil featureUtil = new FeatureUtil();
39: EAttribute feature = featureUtil.getFeature(editPart);
40: TransactionalEditingDomain diagramEditDomain = null;
41: if (editPart instanceof DiagramEditPart) {
42: diagramEditDomain = ((DiagramEditPart) editPart)
43: .getEditingDomain();
44: elementToEdit = ((Diagram) editPart.getModel())
45: .getElement();
46: }
47: if (editPart instanceof ShapeNodeEditPart) {
48: diagramEditDomain = ((ShapeNodeEditPart) editPart)
49: .getEditingDomain();
50: elementToEdit = ((Node) editPart.getModel()).getElement();
51: }
52: if (editPart instanceof ConnectionNodeEditPart) {
53: diagramEditDomain = ((ConnectionNodeEditPart) editPart)
54: .getEditingDomain();
55: elementToEdit = ((Edge) editPart.getModel()).getElement();
56: }
57:
58: // execute the ReplaceCommand
59: ReplaceCommand repCommand = new ReplaceCommand(
60: diagramEditDomain, elementToEdit, feature, oldValue,
61: newValue);
62: EditingDomain dom = repCommand.getDomain();
63: dom.getCommandStack().execute(repCommand);
64: }
65: }
|