001: package newprocess.diagram.edit.policies;
002:
003: import newprocess.Conclusion;
004: import newprocess.ConditionProxy;
005: import newprocess.ConditionTerm;
006: import newprocess.Expansion;
007: import newprocess.NewprocessPackage;
008: import newprocess.OperatorTerm;
009: import newprocess.Root;
010: import newprocess.diagram.cust.operation.ConditionProxyChainDeleteOperation;
011: import newprocess.diagram.providers.New_processElementTypes;
012:
013: import org.eclipse.emf.ecore.EAnnotation;
014: import org.eclipse.emf.ecore.EObject;
015: import org.eclipse.gef.commands.Command;
016: import org.eclipse.gef.commands.UnexecutableCommand;
017: import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
018: import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
019: import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
020: import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
021: import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
022: import org.eclipse.gmf.runtime.notation.View;
023:
024: /**
025: * @generated
026: */
027: public class ConditionProxyItemSemanticEditPolicy extends
028: New_processBaseItemSemanticEditPolicy {
029:
030: /**
031: * @generated NOT
032: * @author sh
033: */
034: protected Command getDestroyElementCommand(DestroyElementRequest req) {
035: return getMSLWrapper(new DestroyElementCommand(req) {
036:
037: protected EObject getElementToDestroy() {
038: View view = (View) getHost().getModel();
039: EAnnotation annotation = view
040: .getEAnnotation("Shortcut"); //$NON-NLS-1$
041: if (annotation != null) {
042: return view;
043: }
044:
045: // if the proxy should be deleted, also delete all linked terms
046: ConditionProxyChainDeleteOperation deleteOperation = new ConditionProxyChainDeleteOperation();
047: deleteOperation.doExecute(getHost());
048:
049: return super .getElementToDestroy();
050: }
051:
052: });
053: }
054:
055: /**
056: * @generated NOT
057: * @author sh
058: */
059: protected Command getCreateRelationshipCommand(
060: CreateRelationshipRequest req) {
061: if (New_processElementTypes.OperatorTermSubTerm_4003 == req
062: .getElementType()) {
063: if (req.getTarget() != null)
064: return getCreateCompleteIncomingOperatorTerm_ConditionProxyCommand(req);
065: }
066: if (New_processElementTypes.ConditionTermConditionProxy_4004 == req
067: .getElementType()) {
068: if (req.getTarget() == null)
069: return null; // proxy --> term
070: else
071: return getCreateCompleteIncomingConditionTerm_ConditionProxy4004Command(req);
072: }
073: if (New_processElementTypes.RootTerm_4002 == req
074: .getElementType()) {
075: if (req.getTarget() == null)
076: return null; // proxy --> root
077: else
078: return getCreateCompleteIncomingRoot_ConditionProxyCommand(req);
079: }
080: if (New_processElementTypes.ConclusionConclusionProxy_4005 == req
081: .getElementType()) {
082: return req.getTarget() == null ? null
083: : getCreateCompleteIncomingConclusion_ConclusionProxy4005Command(req);
084: }
085: if (New_processElementTypes.ExpansionExpansionProxy_4006 == req
086: .getElementType()) {
087: return req.getTarget() == null ? null
088: : getCreateCompleteIncomingExpansion_ExpansionProxy4006Command(req);
089: }
090: return super .getCreateRelationshipCommand(req);
091: }
092:
093: /**
094: * @author sh
095: * @param req
096: * @return
097: */
098: protected Command getCreateCompleteIncomingOperatorTerm_ConditionProxyCommand(
099: CreateRelationshipRequest req) {
100:
101: // check source and target objects
102: EObject sourceEObject = req.getSource();
103: EObject targetEObject = req.getTarget();
104:
105: // if source is not an operator and target is not a proxy
106: if (!(sourceEObject instanceof OperatorTerm)
107: || !(targetEObject instanceof ConditionProxy)) {
108: return UnexecutableCommand.INSTANCE;
109: }
110:
111: OperatorTerm source = (OperatorTerm) sourceEObject;
112: ConditionProxy target = (ConditionProxy) targetEObject;
113:
114: if (!New_processBaseItemSemanticEditPolicy.LinkConstraints
115: .canCreateOperatorTermConditionProxy(source, target)) {
116: return UnexecutableCommand.INSTANCE;
117: }
118:
119: return new Command() {
120: };
121: }
122:
123: /**
124: * @author sh
125: * @param req
126: * @return
127: */
128: protected Command getCreateCompleteIncomingRoot_ConditionProxyCommand(
129: CreateRelationshipRequest req) {
130:
131: // check source and target objects
132: EObject sourceEObject = req.getSource();
133: EObject targetEObject = req.getTarget();
134:
135: // if source is not an operator and target is not a proxy
136: if (!(sourceEObject instanceof Root)
137: || !(targetEObject instanceof ConditionProxy)) {
138: return UnexecutableCommand.INSTANCE;
139: }
140:
141: Root source = (Root) sourceEObject;
142: ConditionProxy target = (ConditionProxy) targetEObject;
143:
144: if (!New_processBaseItemSemanticEditPolicy.LinkConstraints
145: .canCreateRootConditionProxy(source, target)) {
146: return UnexecutableCommand.INSTANCE;
147: }
148:
149: return new Command() {
150: };
151: }
152:
153: /**
154: * @generated
155: */
156: protected Command getCreateCompleteIncomingConditionTerm_ConditionProxy4004Command(
157: CreateRelationshipRequest req) {
158: EObject sourceEObject = req.getSource();
159: EObject targetEObject = req.getTarget();
160: if (false == sourceEObject instanceof ConditionTerm
161: || false == targetEObject instanceof ConditionProxy) {
162: return UnexecutableCommand.INSTANCE;
163: }
164: ConditionTerm source = (ConditionTerm) sourceEObject;
165: ConditionProxy target = (ConditionProxy) targetEObject;
166: if (!New_processBaseItemSemanticEditPolicy.LinkConstraints
167: .canCreateConditionTermConditionProxy_4004(source,
168: target)) {
169: return UnexecutableCommand.INSTANCE;
170: }
171: SetRequest setReq = new SetRequest(req.getSource(),
172: NewprocessPackage.eINSTANCE
173: .getConditionTerm_ConditionProxy(), req
174: .getTarget());
175: return getMSLWrapper(new SetValueCommand(setReq));
176: }
177:
178: /**
179: * @generated
180: */
181: protected Command getCreateCompleteIncomingConclusion_ConclusionProxy4005Command(
182: CreateRelationshipRequest req) {
183: EObject sourceEObject = req.getSource();
184: EObject targetEObject = req.getTarget();
185: if (false == sourceEObject instanceof Conclusion
186: || false == targetEObject instanceof ConditionProxy) {
187: return UnexecutableCommand.INSTANCE;
188: }
189: Conclusion source = (Conclusion) sourceEObject;
190: ConditionProxy target = (ConditionProxy) targetEObject;
191: if (!New_processBaseItemSemanticEditPolicy.LinkConstraints
192: .canCreateConclusionConclusionProxy_4005(source, target)) {
193: return UnexecutableCommand.INSTANCE;
194: }
195: SetRequest setReq = new SetRequest(req.getSource(),
196: NewprocessPackage.eINSTANCE
197: .getConclusion_ConclusionProxy(), req
198: .getTarget());
199: return getMSLWrapper(new SetValueCommand(setReq));
200: }
201:
202: /**
203: * @generated
204: */
205: protected Command getCreateCompleteIncomingExpansion_ExpansionProxy4006Command(
206: CreateRelationshipRequest req) {
207: EObject sourceEObject = req.getSource();
208: EObject targetEObject = req.getTarget();
209: if (false == sourceEObject instanceof Expansion
210: || false == targetEObject instanceof ConditionProxy) {
211: return UnexecutableCommand.INSTANCE;
212: }
213: Expansion source = (Expansion) sourceEObject;
214: ConditionProxy target = (ConditionProxy) targetEObject;
215: if (!New_processBaseItemSemanticEditPolicy.LinkConstraints
216: .canCreateExpansionExpansionProxy_4006(source, target)) {
217: return UnexecutableCommand.INSTANCE;
218: }
219: SetRequest setReq = new SetRequest(req.getSource(),
220: NewprocessPackage.eINSTANCE
221: .getExpansion_ExpansionProxy(), req.getTarget());
222: return getMSLWrapper(new SetValueCommand(setReq));
223: }
224: }
|