001: /**
002: *
003: */package diagram.commands;
004:
005: import newprocess.NewprocessFactory;
006: import newprocess.NewprocessPackage;
007: import newprocess.diagram.edit.parts.ActorEditPart;
008: import newprocess.diagram.edit.parts.AsyncActivity2EditPart;
009: import newprocess.diagram.edit.parts.AsyncActivityEditPart;
010: import newprocess.diagram.edit.parts.ConditionEditPart;
011: import newprocess.diagram.edit.parts.EventEditPart;
012: import newprocess.diagram.edit.parts.ListenerEditPart;
013: import newprocess.diagram.edit.parts.LoaderEditPart;
014: import newprocess.diagram.edit.parts.ProcessEditPart;
015: import newprocess.diagram.edit.parts.SyncActivityEditPart;
016: import newprocess.diagram.providers.New_processElementTypes;
017:
018: import org.eclipse.core.commands.ExecutionException;
019: import org.eclipse.core.runtime.IAdaptable;
020: import org.eclipse.core.runtime.IProgressMonitor;
021: import org.eclipse.emf.ecore.EClass;
022: import org.eclipse.emf.ecore.EObject;
023: import org.eclipse.emf.ecore.EReference;
024: import org.eclipse.emf.transaction.TransactionalEditingDomain;
025: import org.eclipse.gef.EditPart;
026: import org.eclipse.gmf.runtime.common.core.command.CommandResult;
027: import org.eclipse.gmf.runtime.common.core.command.ICommand;
028: import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
029: import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
030: import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
031: import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramEditDomain;
032: import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil;
033: import org.eclipse.gmf.runtime.emf.type.core.IElementType;
034: import org.eclipse.gmf.runtime.emf.type.core.commands.ConfigureElementCommand;
035: import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
036: import org.eclipse.gmf.runtime.notation.Diagram;
037: import org.eclipse.gmf.runtime.notation.Node;
038:
039: import diagram.section.EnvEntry;
040:
041: /**
042: * @author sh
043: *
044: */
045: public class ConfigureCommand {
046: private newprocess.EnvEntry modelEnvEntry = null;
047:
048: /**
049: * This method configures a Environment Entries an sets the values of
050: * the Environment Entry property.
051: *
052: * @param editPart the EditPart containing the Environment Entry to configure
053: * @param envEntryValues an info object containig the info for the new environment entry
054: * @return modelEnvEntry the created and configured Environment Entry
055: */
056: public newprocess.EnvEntry executeConfigureElementCommand(
057: EditPart editPart, EnvEntry envEntryValues) {
058: TransactionalEditingDomain writeEditingDomain = null;
059: EObject elementToConfigure = null;
060: IDiagramEditDomain diagramEditDomain = null;
061: IElementType typeToConfigure = null;
062:
063: if (editPart instanceof DiagramEditPart) {
064: writeEditingDomain = ((DiagramEditPart) editPart)
065: .getEditingDomain();
066: elementToConfigure = ((Diagram) editPart.getModel())
067: .getElement();
068: diagramEditDomain = ((DiagramEditPart) editPart)
069: .getDiagramEditDomain();
070: }
071: if (editPart instanceof ShapeNodeEditPart) {
072: writeEditingDomain = ((ShapeNodeEditPart) editPart)
073: .getEditingDomain();
074: elementToConfigure = ((Node) editPart.getModel())
075: .getElement();
076: diagramEditDomain = ((ShapeNodeEditPart) editPart)
077: .getDiagramEditDomain();
078: }
079:
080: typeToConfigure = getType(editPart);
081:
082: ConfigureRequest req = new ConfigureRequest(writeEditingDomain,
083: elementToConfigure, typeToConfigure);
084: ICommand configureCommand = getConfigureCommand(req,
085: envEntryValues);
086: ICommandProxy proxy = new ICommandProxy(configureCommand);
087: diagramEditDomain.getDiagramCommandStack().execute(proxy);
088:
089: return modelEnvEntry;
090: }
091:
092: protected ICommand getConfigureCommand(final ConfigureRequest req,
093: final EnvEntry envEntryValues) {
094: return new ConfigureElementCommand(req) {
095: protected CommandResult doExecuteWithResult(
096: IProgressMonitor monitor, IAdaptable info)
097: throws ExecutionException {
098: EObject element = req.getElementToConfigure();
099:
100: modelEnvEntry = doConfiguration(element, monitor,
101: envEntryValues);
102: return CommandResult.newOKCommandResult(element);
103: }
104: };
105: }
106:
107: /**
108: * This method configures a Environment Entries an sets the values of
109: * the Environment Entry property.
110: *
111: * @param element the Environment Entry to configure
112: * @param monitor a progress monitor
113: * @param envEntryValues a info object containing data for the environment entry
114: * @return envEntry the new created and configured Environment Entry
115: */
116: protected newprocess.EnvEntry doConfiguration(EObject element,
117: IProgressMonitor monitor, EnvEntry envEntryValues) {
118: // create the EnvEntry
119: EReference envEntryContainer = NewprocessPackage.eINSTANCE
120: .getElement_HasEnvEntries();
121: newprocess.EnvEntry entry = NewprocessFactory.eINSTANCE
122: .createEnvEntry();
123: EClass envEntryClass = entry.eClass();
124: newprocess.EnvEntry envEntry = (newprocess.EnvEntry) EMFCoreUtil
125: .create(element, envEntryContainer, envEntryClass);
126:
127: // setting the attributes
128: envEntry.setName(envEntryValues.getName());
129: envEntry.setType(envEntryValues.getType());
130: envEntry.setValue(envEntryValues.getValue());
131: return envEntry;
132: }
133:
134: /**
135: * a helper method to load meta information of the selected EditPart.
136: *
137: * @param ep the EditPart of the metat data
138: * @return the IElementType of the selected EditPart
139: */
140: private IElementType getType(EditPart ep) {
141: if (ep instanceof ActorEditPart)
142: return New_processElementTypes.Actor_2007;
143: else if (ep instanceof ProcessEditPart)
144: return New_processElementTypes.Process_1000;
145: else if (ep instanceof LoaderEditPart)
146: return New_processElementTypes.Loader_3013;
147: else if (ep instanceof ConditionEditPart)
148: return New_processElementTypes.Condition_3014;
149: else if (ep instanceof AsyncActivityEditPart
150: || ep instanceof AsyncActivity2EditPart)
151: return New_processElementTypes.AsyncActivity_2003;
152: else if (ep instanceof SyncActivityEditPart)
153: return New_processElementTypes.SyncActivity_2001;
154: else if (ep instanceof EventEditPart)
155: return New_processElementTypes.Event_2005;
156: else if (ep instanceof ListenerEditPart)
157: return New_processElementTypes.Listener_2002;
158: else
159: return null;
160: }
161: }
|