001: /**
002: *
003: */package diagram.commands;
004:
005: import newprocess.diagram.edit.parts.ActorEditPart;
006: import newprocess.diagram.edit.parts.AsyncActivity2EditPart;
007: import newprocess.diagram.edit.parts.AsyncActivityEditPart;
008: import newprocess.diagram.edit.parts.ConditionEditPart;
009: import newprocess.diagram.edit.parts.EventEditPart;
010: import newprocess.diagram.edit.parts.ListenerEditPart;
011: import newprocess.diagram.edit.parts.LoaderEditPart;
012: import newprocess.diagram.edit.parts.ProcessEditPart;
013: import newprocess.diagram.edit.parts.SyncActivityEditPart;
014: import newprocess.diagram.providers.New_processElementTypes;
015:
016: import org.eclipse.core.commands.ExecutionException;
017: import org.eclipse.core.runtime.IAdaptable;
018: import org.eclipse.core.runtime.IProgressMonitor;
019: import org.eclipse.emf.ecore.EObject;
020: import org.eclipse.emf.transaction.TransactionalEditingDomain;
021: import org.eclipse.gef.EditPart;
022: import org.eclipse.gmf.runtime.common.core.command.CommandResult;
023: import org.eclipse.gmf.runtime.common.core.command.ICommand;
024: import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
025: import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
026: import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
027: import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramEditDomain;
028: import org.eclipse.gmf.runtime.emf.type.core.IElementType;
029: import org.eclipse.gmf.runtime.emf.type.core.commands.ConfigureElementCommand;
030: import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
031: import org.eclipse.gmf.runtime.notation.Diagram;
032: import org.eclipse.gmf.runtime.notation.Node;
033:
034: import diagram.section.EnvEntry;
035:
036: /**
037: * Sets the attributes "name", "type" and "value"
038: * of an EMF EnvEntry model Object
039: *
040: * @author sh
041: */
042: public class WriteCommand {
043:
044: /**
045: * This command sets the attributes "name", "type" and "value" ob an given
046: * EMF EnvEntry model Object and values.
047: *
048: * @param editPart the EditPart which owns the EnvEntry
049: * @param elementToEdit the EMF EnvEntry model Object
050: * @param envEntryValues the values to be set
051: */
052: public void executeWriteCommand(EditPart editPart,
053: newprocess.EnvEntry elementToEdit, EnvEntry envEntryValues) {
054: TransactionalEditingDomain writeEditingDomain = null;
055: EObject elementToConfigure = null;
056: IDiagramEditDomain diagramEditDomain = null;
057: IElementType typeToConfigure = null;
058:
059: if (editPart instanceof DiagramEditPart) {
060: writeEditingDomain = ((DiagramEditPart) editPart)
061: .getEditingDomain();
062: elementToConfigure = ((Diagram) editPart.getModel())
063: .getElement();
064: diagramEditDomain = ((DiagramEditPart) editPart)
065: .getDiagramEditDomain();
066: }
067: if (editPart instanceof ShapeNodeEditPart) {
068: writeEditingDomain = ((ShapeNodeEditPart) editPart)
069: .getEditingDomain();
070: elementToConfigure = ((Node) editPart.getModel())
071: .getElement();
072: diagramEditDomain = ((ShapeNodeEditPart) editPart)
073: .getDiagramEditDomain();
074: }
075:
076: typeToConfigure = getType(editPart);
077:
078: ConfigureRequest req = new ConfigureRequest(writeEditingDomain,
079: elementToConfigure, typeToConfigure);
080: ICommand configureCommand = getConfigureCommand(req,
081: elementToEdit, envEntryValues);
082: ICommandProxy proxy = new ICommandProxy(configureCommand);
083: diagramEditDomain.getDiagramCommandStack().execute(proxy);
084: }
085:
086: /**
087: * This method returns a ConfigureElementCommand which sets the attributes by the
088: * doExecuteWithResult method.
089: *
090: * @param req the specified ConfigureRequest
091: * @param modelEntry the EMF EnvEntry model object where changes take place
092: * @param envEntryValues the values do be set
093: * @return a new ConfigureElementCommand
094: */
095: protected ICommand getConfigureCommand(final ConfigureRequest req,
096: final newprocess.EnvEntry modelEntry,
097: final EnvEntry envEntryValues) {
098:
099: return new ConfigureElementCommand(req) {
100: protected CommandResult doExecuteWithResult(
101: IProgressMonitor monitor, IAdaptable info)
102: throws ExecutionException {
103: EObject element = req.getElementToConfigure();
104:
105: // setting the attributes
106: modelEntry.setName(envEntryValues.getName());
107: modelEntry.setType(envEntryValues.getType());
108: modelEntry.setValue(envEntryValues.getValue());
109:
110: return CommandResult.newOKCommandResult(element);
111: }
112: };
113: }
114:
115: /**
116: * a helper method to load meta information of the selected EditPart.
117: *
118: * @param ep the EditPart of the metat data
119: * @return the IElementType of the selected EditPart
120: */
121: private IElementType getType(EditPart ep) {
122: if (ep instanceof ActorEditPart)
123: return New_processElementTypes.Actor_2007;
124: else if (ep instanceof ProcessEditPart)
125: return New_processElementTypes.Process_1000;
126: else if (ep instanceof LoaderEditPart)
127: return New_processElementTypes.Loader_3013;
128: else if (ep instanceof ConditionEditPart)
129: return New_processElementTypes.Condition_3014;
130: else if (ep instanceof AsyncActivityEditPart
131: || ep instanceof AsyncActivity2EditPart)
132: return New_processElementTypes.AsyncActivity_2003;
133: else if (ep instanceof SyncActivityEditPart)
134: return New_processElementTypes.SyncActivity_2001;
135: else if (ep instanceof EventEditPart)
136: return New_processElementTypes.Event_2005;
137: else if (ep instanceof ListenerEditPart)
138: return New_processElementTypes.Listener_2002;
139: else
140: return null;
141: }
142: }
|