001: package newprocess.diagram.edit.policies;
002:
003: import org.eclipse.emf.ecore.EClass;
004: import org.eclipse.emf.ecore.EObject;
005: import org.eclipse.emf.transaction.TransactionalEditingDomain;
006: import org.eclipse.gef.commands.Command;
007: import org.eclipse.gef.commands.UnexecutableCommand;
008: import org.eclipse.gmf.runtime.common.core.command.ICommand;
009: import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand;
010: import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
011: import org.eclipse.gmf.runtime.diagram.ui.commands.CommandProxy;
012: import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
013: import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
014: import org.eclipse.gmf.runtime.diagram.ui.editpolicies.SemanticEditPolicy;
015: import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
016: import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
017: import org.eclipse.gmf.runtime.emf.type.core.IEditHelperContext;
018: import org.eclipse.gmf.runtime.emf.type.core.IElementType;
019: import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
020: import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
021: import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
022: import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
023: import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyReferenceRequest;
024: import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyRequest;
025: import org.eclipse.gmf.runtime.emf.type.core.requests.DuplicateElementsRequest;
026: import org.eclipse.gmf.runtime.emf.type.core.requests.GetEditContextRequest;
027: import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
028: import org.eclipse.gmf.runtime.emf.type.core.requests.MoveRequest;
029: import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientReferenceRelationshipRequest;
030: import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest;
031: import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
032: import org.eclipse.gmf.runtime.notation.View;
033: import newprocess.Actor;
034: import newprocess.AsyncActivity;
035: import newprocess.Conclusion;
036: import newprocess.ConditionProxy;
037: import newprocess.ConditionTerm;
038: import newprocess.Expansion;
039: import newprocess.OperatorTerm;
040: import newprocess.Root;
041: import newprocess.Term;
042:
043: import newprocess.diagram.edit.helpers.New_processBaseEditHelper;
044:
045: /**
046: * @generated
047: */
048: public class New_processBaseItemSemanticEditPolicy extends
049: SemanticEditPolicy {
050:
051: /**
052: * @generated
053: */
054: protected Command getSemanticCommand(IEditCommandRequest request) {
055: IEditCommandRequest completedRequest = completeRequest(request);
056: Object editHelperContext = completedRequest
057: .getEditHelperContext();
058: if (editHelperContext instanceof View
059: || (editHelperContext instanceof IEditHelperContext && ((IEditHelperContext) editHelperContext)
060: .getEObject() instanceof View)) {
061: // no semantic commands are provided for pure design elements
062: return null;
063: }
064: if (editHelperContext == null) {
065: editHelperContext = ViewUtil
066: .resolveSemanticElement((View) getHost().getModel());
067: }
068: IElementType elementType = ElementTypeRegistry.getInstance()
069: .getElementType(editHelperContext);
070: if (elementType == ElementTypeRegistry.getInstance().getType(
071: "org.eclipse.gmf.runtime.emf.type.core.default")) { //$NON-NLS-1$
072: elementType = null;
073: }
074: Command epCommand = getSemanticCommandSwitch(completedRequest);
075: if (epCommand != null) {
076: ICommand command = epCommand instanceof ICommandProxy ? ((ICommandProxy) epCommand)
077: .getICommand()
078: : new CommandProxy(epCommand);
079: completedRequest.setParameter(
080: New_processBaseEditHelper.EDIT_POLICY_COMMAND,
081: command);
082: }
083: Command ehCommand = null;
084: if (elementType != null) {
085: ICommand command = elementType
086: .getEditCommand(completedRequest);
087: if (command != null) {
088: if (!(command instanceof CompositeTransactionalCommand)) {
089: TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost())
090: .getEditingDomain();
091: command = new CompositeTransactionalCommand(
092: editingDomain, null).compose(command);
093: }
094: ehCommand = new ICommandProxy(command);
095: }
096: }
097: boolean shouldProceed = true;
098: if (completedRequest instanceof DestroyRequest) {
099: shouldProceed = shouldProceed((DestroyRequest) completedRequest);
100: }
101: if (shouldProceed) {
102: if (completedRequest instanceof DestroyRequest) {
103: TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost())
104: .getEditingDomain();
105: Command deleteViewCommand = new ICommandProxy(
106: new DeleteCommand(editingDomain,
107: (View) getHost().getModel()));
108: ehCommand = ehCommand == null ? deleteViewCommand
109: : ehCommand.chain(deleteViewCommand);
110: }
111: return ehCommand;
112: }
113: return null;
114: }
115:
116: /**
117: * @generated
118: */
119: protected Command getSemanticCommandSwitch(IEditCommandRequest req) {
120: if (req instanceof CreateRelationshipRequest) {
121: return getCreateRelationshipCommand((CreateRelationshipRequest) req);
122: } else if (req instanceof CreateElementRequest) {
123: return getCreateCommand((CreateElementRequest) req);
124: } else if (req instanceof ConfigureRequest) {
125: return getConfigureCommand((ConfigureRequest) req);
126: } else if (req instanceof DestroyElementRequest) {
127: return getDestroyElementCommand((DestroyElementRequest) req);
128: } else if (req instanceof DestroyReferenceRequest) {
129: return getDestroyReferenceCommand((DestroyReferenceRequest) req);
130: } else if (req instanceof DuplicateElementsRequest) {
131: return getDuplicateCommand((DuplicateElementsRequest) req);
132: } else if (req instanceof GetEditContextRequest) {
133: return getEditContextCommand((GetEditContextRequest) req);
134: } else if (req instanceof MoveRequest) {
135: return getMoveCommand((MoveRequest) req);
136: } else if (req instanceof ReorientReferenceRelationshipRequest) {
137: return getReorientReferenceRelationshipCommand((ReorientReferenceRelationshipRequest) req);
138: } else if (req instanceof ReorientRelationshipRequest) {
139: return getReorientRelationshipCommand((ReorientRelationshipRequest) req);
140: } else if (req instanceof SetRequest) {
141: return getSetCommand((SetRequest) req);
142: }
143: return null;
144: }
145:
146: /**
147: * @generated
148: */
149: protected Command getConfigureCommand(ConfigureRequest req) {
150: return null;
151: }
152:
153: /**
154: * @generated
155: */
156: protected Command getCreateRelationshipCommand(
157: CreateRelationshipRequest req) {
158: return null;
159: }
160:
161: /**
162: * @generated
163: */
164: protected Command getCreateCommand(CreateElementRequest req) {
165: return null;
166: }
167:
168: /**
169: * @generated
170: */
171: protected Command getSetCommand(SetRequest req) {
172: return null;
173: }
174:
175: /**
176: * @generated
177: */
178: protected Command getEditContextCommand(GetEditContextRequest req) {
179: return null;
180: }
181:
182: /**
183: * @generated
184: */
185: protected Command getDestroyElementCommand(DestroyElementRequest req) {
186: return null;
187: }
188:
189: /**
190: * @generated
191: */
192: protected Command getDestroyReferenceCommand(
193: DestroyReferenceRequest req) {
194: return null;
195: }
196:
197: /**
198: * @generated
199: */
200: protected Command getDuplicateCommand(DuplicateElementsRequest req) {
201: return null;
202: }
203:
204: /**
205: * @generated
206: */
207: protected Command getMoveCommand(MoveRequest req) {
208: return null;
209: }
210:
211: /**
212: * @generated
213: */
214: protected Command getReorientReferenceRelationshipCommand(
215: ReorientReferenceRelationshipRequest req) {
216: return UnexecutableCommand.INSTANCE;
217: }
218:
219: /**
220: * @generated
221: */
222: protected Command getReorientRelationshipCommand(
223: ReorientRelationshipRequest req) {
224: return UnexecutableCommand.INSTANCE;
225: }
226:
227: /**
228: * @generated
229: */
230: protected Command getMSLWrapper(ICommand cmd) {
231: return new ICommandProxy(cmd);
232: }
233:
234: /**
235: * @generated
236: */
237: protected EObject getSemanticElement() {
238: return ViewUtil.resolveSemanticElement((View) getHost()
239: .getModel());
240: }
241:
242: /**
243: * Finds container element for the new relationship of the specified type.
244: * Default implementation goes up by containment hierarchy starting from
245: * the specified element and returns the first element that is instance of
246: * the specified container class.
247: *
248: * @generated
249: */
250: protected EObject getRelationshipContainer(EObject element,
251: EClass containerClass, IElementType relationshipType) {
252: for (; element != null; element = element.eContainer()) {
253: if (containerClass.isSuperTypeOf(element.eClass())) {
254: return element;
255: }
256: }
257: return null;
258: }
259:
260: /**
261: * @generated
262: */
263: protected static class LinkConstraints {
264:
265: /**
266: * @generated
267: */
268: private static final String OPPOSITE_END_VAR = "oppositeEnd"; //$NON-NLS-1$
269:
270: /**
271: * @generated
272: */
273: public static boolean canCreateAsyncActivityActor_4001(
274: AsyncActivity source, Actor target) {
275: if (source != null) {
276: if (source.getActor() != null) {
277: return false;
278: }
279: }
280: return true;
281: }
282:
283: /**
284: * @generated
285: */
286: public static boolean canCreateRootTerm_4002(Root source,
287: Term target) {
288: if (source != null) {
289: if (source.getTerm() != null) {
290: return false;
291: }
292: }
293: return true;
294: }
295:
296: /**
297: * @generated NOT
298: * @author sh
299: */
300: public static boolean canCreateOperatorTermSubTerm_4003(
301: OperatorTerm source, Term target) {
302: if (source != null) {
303: if (source.getSubTerm().contains(target)) {
304: return false;
305: }
306: }
307: if (source == target)
308: return false;
309:
310: if (target instanceof OperatorTerm)
311: return ((OperatorTerm) target).acceptIncomingLink();
312: return true;
313: }
314:
315: /**
316: * @generated
317: */
318: public static boolean canCreateConditionTermConditionProxy_4004(
319: ConditionTerm source, ConditionProxy target) {
320: if (source != null) {
321: if (source.getConditionProxy() != null) {
322: return false;
323: }
324: }
325: return true;
326: }
327:
328: /**
329: * @generated
330: */
331: public static boolean canCreateConclusionConclusionProxy_4005(
332: Conclusion source, ConditionProxy target) {
333: if (source != null) {
334: if (source.getConclusionProxy() != null) {
335: return false;
336: }
337: }
338: return true;
339: }
340:
341: /**
342: * @generated
343: */
344: public static boolean canCreateExpansionExpansionProxy_4006(
345: Expansion source, ConditionProxy target) {
346: if (source != null) {
347: if (source.getExpansionProxy() != null) {
348: return false;
349: }
350: }
351: return true;
352: }
353:
354: /**
355: * @author sh
356: * @param source
357: * @param target
358: * @return
359: */
360: public static boolean canCreateOperatorTermConditionProxy(
361: OperatorTerm source, ConditionProxy target) {
362: if (source == null)
363: return false;
364: if (target == null)
365: return false;
366: return true;
367: }
368:
369: /**
370: * @author sh
371: * @param source
372: * @param target
373: * @return
374: */
375: public static boolean canCreateRootConditionProxy(Root source,
376: ConditionProxy target) {
377: if (source != null) {
378: if (target != null)
379: return true;
380: }
381: return source.acceptOutgoingLink(Root.PORT);
382: }
383: }
384:
385: }
|