01: /**
02: *
03: */package model;
04:
05: import newprocess.NewprocessPackage;
06:
07: import org.eclipse.emf.ecore.EAttribute;
08: import org.eclipse.emf.ecore.EObject;
09: import org.eclipse.emf.transaction.TransactionalEditingDomain;
10: import org.eclipse.gef.EditPart;
11: import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
12: import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
13: import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
14: import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramEditDomain;
15: import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
16: import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
17: import org.eclipse.gmf.runtime.notation.Diagram;
18: import org.eclipse.gmf.runtime.notation.Node;
19:
20: /**
21: * @author sh
22: *
23: */
24: public class ModelChangeCommand {
25:
26: /**
27: * This method checks if the implementation value could be changed
28: * by a Replace Command.
29: *
30: * @param editPart the EditPart containing the implementation
31: * @param newValue the new value to set
32: * @return true if the Change Command could be executed
33: */
34:
35: public boolean canExecuteImplChange(EditPart editPart,
36: Object newValue) {
37: TransactionalEditingDomain writeEditingDomain = null;
38: EObject elementToEdit = null;
39: EAttribute feature = NewprocessPackage.eINSTANCE
40: .getElement_Implementation();
41:
42: if (editPart instanceof DiagramEditPart) {
43: writeEditingDomain = ((DiagramEditPart) editPart)
44: .getEditingDomain();
45: elementToEdit = ((Diagram) editPart.getModel())
46: .getElement();
47: } else if (editPart instanceof ShapeNodeEditPart) {
48: writeEditingDomain = ((ShapeNodeEditPart) editPart)
49: .getEditingDomain();
50: elementToEdit = ((Node) editPart.getModel()).getElement();
51: }
52:
53: SetRequest reqSet = new SetRequest(writeEditingDomain,
54: elementToEdit, feature, newValue);
55: SetValueCommand setCommand = new SetValueCommand(reqSet);
56: ICommandProxy proxy = new ICommandProxy(setCommand);
57: return proxy.canExecute();
58: }
59:
60: /**
61: * This method performs a implementation change by
62: * a Set Value Command.
63: *
64: * @param editPart the editPart containing the value to change
65: * @param newValue the new value to set
66: */
67: public void executeImplChange(EditPart editPart, Object newValue) {
68: TransactionalEditingDomain writeEditingDomain = null;
69: EObject elementToEdit = null;
70: EAttribute feature = NewprocessPackage.eINSTANCE
71: .getElement_Implementation();
72: IDiagramEditDomain diagramEditDomain = null;
73:
74: if (editPart instanceof DiagramEditPart) {
75: writeEditingDomain = ((DiagramEditPart) editPart)
76: .getEditingDomain();
77: elementToEdit = ((Diagram) editPart.getModel())
78: .getElement();
79: diagramEditDomain = ((DiagramEditPart) editPart)
80: .getDiagramEditDomain();
81: } else if (editPart instanceof ShapeNodeEditPart) {
82: writeEditingDomain = ((ShapeNodeEditPart) editPart)
83: .getEditingDomain();
84: elementToEdit = ((Node) editPart.getModel()).getElement();
85: diagramEditDomain = ((ShapeNodeEditPart) editPart)
86: .getDiagramEditDomain();
87: }
88:
89: SetRequest reqSet = new SetRequest(writeEditingDomain,
90: elementToEdit, feature, newValue);
91: SetValueCommand setCommand = new SetValueCommand(reqSet);
92: ICommandProxy proxy = new ICommandProxy(setCommand);
93: diagramEditDomain.getDiagramCommandStack().execute(proxy);
94: }
95: }
|