001: /**
002: *
003: */package newprocess.diagram.cust.annotations.commands;
004:
005: import newprocess.diagram.cust.annotations.utils.FeatureUtil;
006:
007: import org.eclipse.emf.ecore.EAttribute;
008: import org.eclipse.emf.ecore.EObject;
009: import org.eclipse.emf.transaction.TransactionalEditingDomain;
010: import org.eclipse.gef.EditPart;
011: import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
012: import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionNodeEditPart;
013: import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
014: import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
015: import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramEditDomain;
016: import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
017: import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
018: import org.eclipse.gmf.runtime.notation.Diagram;
019: import org.eclipse.gmf.runtime.notation.Edge;
020: import org.eclipse.gmf.runtime.notation.Node;
021:
022: /**
023: * @author sh
024: *
025: */
026: public class WriteCommand {
027: /**
028: * Constructor
029: */
030: public WriteCommand() {
031: }
032:
033: /**
034: * executes a SetValueCommand which writes a value to the collection
035: */
036: public void executeWriteCommand(EditPart editPart, Object value) {
037: TransactionalEditingDomain writeEditingDomain = null;
038: EObject elementToEdit = null;
039: EAttribute feature = null;
040: FeatureUtil featureUtil = null;
041: IDiagramEditDomain diagramEditDomain = null;
042:
043: if (editPart instanceof DiagramEditPart) {
044: // create the SetValueCommand
045: writeEditingDomain = ((DiagramEditPart) editPart)
046: .getEditingDomain();
047: elementToEdit = ((Diagram) editPart.getModel())
048: .getElement();
049: featureUtil = new FeatureUtil();
050: feature = featureUtil.getFeature(editPart);
051: diagramEditDomain = ((DiagramEditPart) editPart)
052: .getDiagramEditDomain();
053: }
054: if (editPart instanceof ShapeNodeEditPart) {
055: // create the SetValueCommand
056: writeEditingDomain = ((ShapeNodeEditPart) editPart)
057: .getEditingDomain();
058: elementToEdit = ((Node) editPart.getModel()).getElement();
059: featureUtil = new FeatureUtil();
060: feature = featureUtil.getFeature(editPart);
061: diagramEditDomain = ((ShapeNodeEditPart) editPart)
062: .getDiagramEditDomain();
063: }
064: if (editPart instanceof ConnectionNodeEditPart) {
065: // create the SetValueCommand
066: writeEditingDomain = ((ConnectionNodeEditPart) editPart)
067: .getEditingDomain();
068: elementToEdit = ((Edge) editPart.getModel()).getElement();
069: featureUtil = new FeatureUtil();
070: feature = featureUtil.getFeature(editPart);
071: diagramEditDomain = ((ConnectionNodeEditPart) editPart)
072: .getDiagramEditDomain();
073: }
074:
075: // execute the SetValueCommmand
076: SetRequest reqSet = new SetRequest(writeEditingDomain,
077: elementToEdit, feature, value);
078: SetValueCommand setCommand = new SetValueCommand(reqSet);
079: ICommandProxy proxy = new ICommandProxy(setCommand);
080: diagramEditDomain.getDiagramCommandStack().execute(proxy);
081: }
082:
083: /**
084: * clear the annotations collection
085: */
086: /*
087: public void clearValues(ShapeNodeEditPart editPart) {
088: if(editPart instanceof PersonEditPart) {
089: ((person)((Node)editPart.getModel()).getElement()).getUrl().clear();
090: }
091: }
092: */
093:
094: /**
095: * checks if the given Object is already stored
096: * in the model
097: * @return
098: */
099: /*
100: public boolean containsObject(ShapeNodeEditPart editPart, Object value) {
101: if(editPart instanceof PersonEditPart) {
102: EList items = ((person)((Node)editPart.getModel()).getElement()).getUrl();
103: if(items.contains(value)) return true;
104: }
105: return false;
106: }
107: */
108: }
|