001: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012: // POSSIBILITY OF SUCH DAMAGE.
013: //
014: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
015: package com.metaboss.applications.designstudio.userobjects;
016:
017: import java.awt.event.ActionEvent;
018: import java.util.ArrayList;
019:
020: import javax.swing.JTabbedPane;
021:
022: import com.metaboss.applications.designstudio.Application;
023: import com.metaboss.applications.designstudio.BaseAction;
024: import com.metaboss.applications.designstudio.BasePropertiesDialog;
025: import com.metaboss.applications.designstudio.BaseUserObject;
026: import com.metaboss.applications.designstudio.components.SeparatorAction;
027: import com.metaboss.applications.designstudio.constraintstable.ConstraintsViewPanel;
028: import com.metaboss.applications.designstudio.fieldstable.FieldsViewPanel;
029: import com.metaboss.applications.designstudio.propertiesdialogs.OperationPropertiesDialog;
030: import com.metaboss.applications.designstudio.propertiesview.PropertiesTableModel;
031: import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
032: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
033: import com.metaboss.sdlctools.models.metabossmodel.ModelElementConstraint;
034: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EnterpriseModelPackage;
035: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Operation;
036: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.OperationClass;
037: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.OperationInputField;
038: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.OperationOutputField;
039: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.OperationOutputMessage;
040: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Service;
041:
042: /* BOOperation user object class */
043:
044: public class OperationUserObject extends BaseUserObject {
045: public static final int ADD_INPUTFIELD = 1;
046: public static final int ADD_OUTPUTFIELD = 2;
047: public static final int ADD_OUTPUTMESSAGE = 3;
048: public static final int ADD_CONSTRAINT = 4;
049:
050: private Operation mOperation = null;
051: private DuplicateAction mDuplicateAction = new DuplicateAction();
052: private AddNewInputFieldAction mAddNewInputFieldAction = new AddNewInputFieldAction();
053: private AddNewOutputFieldAction mAddNewOutputFieldAction = new AddNewOutputFieldAction();
054: private AddNewMessageFieldAction mAddNewMessageFieldAction = new AddNewMessageFieldAction();
055: private AddNewConstraint mAddNewConstraint = new AddNewConstraint();
056: private StudyDependenciesAction mShowDataTypeDependenciesAction = new StudyDependenciesAction();
057:
058: public OperationUserObject(Operation pOperation) {
059: super (pOperation, Application.OPERATION_ICON);
060: mOperation = pOperation;
061: }
062:
063: public OperationUserObject(Operation pOperation, String pCaption,
064: int pMode) {
065: super (pOperation, pCaption, pMode);
066: mOperation = pOperation;
067: }
068:
069: // create new service module
070: public static void addNewOperation(Service pService)
071: throws Exception {
072: new OperationUserObject(null).addNewObject(
073: getObjectPackage(pService), pService.getOperations());
074: }
075:
076: public BaseUserObject createNewObject(MetaBossModelPackage pPackage) {
077: EnterpriseModelPackage lEnterpriseModelPackage = pPackage
078: .getEnterpriseModel();
079: OperationClass lClass = lEnterpriseModelPackage.getOperation();
080: return new OperationUserObject(lClass.createOperation());
081: }
082:
083: public Operation getOperation() {
084: return mOperation;
085: }
086:
087: // return object root node captions
088: public String getRootNodeName() {
089: return Application.getString("operations_node");
090: }
091:
092: // convert tree element to an action code
093: public int convertCaptionToAction(String pCaption) {
094: if (pCaption.equals(Application.getString("inputfields_node")))
095: return ADD_INPUTFIELD;
096: else if (pCaption.equals(Application
097: .getString("outputfields_node")))
098: return ADD_OUTPUTFIELD;
099: else if (pCaption.equals(Application
100: .getString("outputmessages_node")))
101: return ADD_OUTPUTMESSAGE;
102: else if (pCaption.equals(Application
103: .getString("inputconstraints_node")))
104: return ADD_CONSTRAINT;
105: else
106: return super .convertCaptionToAction(pCaption);
107: }
108:
109: // add extra properties tabs
110: public void addExtraPropertiesTabs(JTabbedPane pTabbedPane) {
111: super .addExtraPropertiesTabs(pTabbedPane);
112: pTabbedPane.insertTab("Input Fields", null,
113: new FieldsViewPanel(mOperation, 1), null, 1);
114: pTabbedPane.insertTab("Input Constraints", null,
115: new ConstraintsViewPanel(mOperation), null, 2);
116: pTabbedPane.insertTab("Output Fields", null,
117: new FieldsViewPanel(mOperation, 2), null, 3);
118: pTabbedPane.insertTab("Output Messages", null,
119: new FieldsViewPanel(mOperation, 3), null, 4);
120: }
121:
122: // fill actions list
123: public void fillActionsList(ArrayList pList) {
124: switch (mMode) {
125: case ALL_ACTIONS:
126: super .fillActionsList(pList);
127: pList.add(new SeparatorAction());
128: pList.add(mAddNewInputFieldAction);
129: pList.add(mAddNewConstraint);
130: pList.add(mAddNewOutputFieldAction);
131: pList.add(mAddNewMessageFieldAction);
132: pList.add(new SeparatorAction());
133: pList.add(mShowDataTypeDependenciesAction);
134: break;
135: case ADD_INPUTFIELD:
136: pList.add(mAddNewInputFieldAction);
137: break;
138: case ADD_OUTPUTFIELD:
139: pList.add(mAddNewOutputFieldAction);
140: break;
141: case ADD_OUTPUTMESSAGE:
142: pList.add(mAddNewMessageFieldAction);
143: break;
144: case ADD_CONSTRAINT:
145: pList.add(mAddNewConstraint);
146: break;
147: }
148: }
149:
150: // load object properties into grid control
151: public void loadObjectProperties(PropertiesTableModel pModel)
152: throws Exception {
153: super .loadObjectProperties(pModel);
154: if (pModel == null || mOperation == null)
155: return;
156:
157: if (mOperation.getTransactionPolicy() != null)
158: pModel.AddProperty("Transaction Policy", mOperation
159: .getTransactionPolicy().toString());
160: pModel.AddProperty("Is Query", boolToString(mOperation
161: .isQuery()));
162: }
163:
164: public BasePropertiesDialog getObjectEditor() {
165: return new OperationPropertiesDialog();
166: }
167:
168: private void addInputField() throws Exception {
169: OperationInputFieldUserObject
170: .addNewOperationInputField(mOperation);
171: }
172:
173: private void addOutputField() throws Exception {
174: OperationOutputFieldUserObject
175: .addNewOperationOutputField(mOperation);
176: }
177:
178: // add new Output Message object
179: private void addOutputMessage() throws Exception {
180: OperationOutputMessageUserObject.addNewMessage(mOperation);
181: }
182:
183: // add new Model Element Constraint
184: public void addNewConstraint() throws Exception {
185: ModelElementConstraintUserObject.addNewConstraint(mOperation);
186: }
187:
188: // can duplicate model element
189: public boolean canDuplicate() {
190: return true;
191: }
192:
193: // duplicate model element
194: public ModelElement duplicate() throws Exception {
195: Operation lTargetOperation = (Operation) Application.sModelRepository
196: .duplicateModelElement(mOperation);
197: lTargetOperation.setService(mOperation.getService());
198: return lTargetOperation;
199: }
200:
201: // returns true if drop object could be accepted
202: public boolean canAcceptDropObject(BaseUserObject pUserObject,
203: boolean pCopy) {
204: if (pUserObject != null
205: && super .canAcceptDropObject(pUserObject, pCopy)) {
206: if ((pUserObject instanceof OperationInputFieldUserObject && (mMode == BaseUserObject.ALL_ACTIONS || mMode == OperationUserObject.ADD_INPUTFIELD))
207: || (pUserObject instanceof OperationOutputFieldUserObject && (mMode == BaseUserObject.ALL_ACTIONS || mMode == OperationUserObject.ADD_OUTPUTFIELD))
208: || (pUserObject instanceof OperationOutputMessageUserObject && (mMode == BaseUserObject.ALL_ACTIONS || mMode == OperationUserObject.ADD_OUTPUTMESSAGE))
209: || (pUserObject instanceof ModelElementConstraintUserObject && (mMode == BaseUserObject.ALL_ACTIONS || mMode == OperationUserObject.ADD_CONSTRAINT))) {
210: return (pCopy) ? pUserObject.canDuplicate() : true;
211: }
212: }
213: return false;
214: }
215:
216: // acccept drop target in transaction
217: protected void transactionalAccept(BaseUserObject pUserObject,
218: boolean pCopy) throws Exception {
219: if (pUserObject != null) {
220: if (pUserObject instanceof OperationInputFieldUserObject) {
221: OperationInputFieldUserObject lUserObject = (OperationInputFieldUserObject) pUserObject;
222: if (pCopy) {
223: OperationInputField lField = (OperationInputField) Application.sModelRepository
224: .duplicateModelElement(lUserObject
225: .getField());
226: lField.setOperation(mOperation);
227: } else
228: lUserObject.getField().setOperation(mOperation);
229: } else if (pUserObject instanceof OperationOutputFieldUserObject) {
230: OperationOutputFieldUserObject lUserObject = (OperationOutputFieldUserObject) pUserObject;
231: if (pCopy) {
232: OperationOutputField lField = (OperationOutputField) Application.sModelRepository
233: .duplicateModelElement(lUserObject
234: .getField());
235: lField.setOperation(mOperation);
236: } else
237: lUserObject.getField().setOperation(mOperation);
238: } else if (pUserObject instanceof OperationOutputMessageUserObject) {
239: OperationOutputMessageUserObject lUserObject = (OperationOutputMessageUserObject) pUserObject;
240: if (pCopy) {
241: OperationOutputMessage lMessage = (OperationOutputMessage) Application.sModelRepository
242: .duplicateModelElement(lUserObject
243: .getMessage());
244: lMessage.setOperation(mOperation);
245: } else
246: lUserObject.getMessage().setOperation(mOperation);
247: } else if (pUserObject instanceof ModelElementConstraintUserObject) {
248: ModelElementConstraintUserObject lUserObject = (ModelElementConstraintUserObject) pUserObject;
249: if (pCopy) {
250: ModelElementConstraint lConstraint = (ModelElementConstraint) Application.sModelRepository
251: .duplicateModelElement(lUserObject
252: .getConstraint());
253: lConstraint.setOperationOwner(mOperation);
254: } else {
255: // Constraint may have may kinds of owners
256: // We need to set all of them to null to avoid containment constraint violation
257: ModelElementConstraint lConstraint = lUserObject
258: .getConstraint();
259: lConstraint.setEntityOwner(null);
260: lConstraint.setStructureOwner(null);
261: lConstraint.setOperationOwner(mOperation);
262: }
263: }
264: }
265: }
266:
267: /* Actions */
268:
269: public class AddNewInputFieldAction extends BaseAction {
270: public AddNewInputFieldAction() {
271: super ("Add New Input Field", Application
272: .getAddIcon(Application.INPUTFIELD_ICON));
273: }
274:
275: public void actionPerformed(ActionEvent e) {
276: try {
277: addInputField();
278: } catch (Throwable t) {
279: Application.processError(t);
280: }
281: }
282: }
283:
284: public class AddNewOutputFieldAction extends BaseAction {
285: public AddNewOutputFieldAction() {
286: super ("Add New Output Field", Application
287: .getAddIcon(Application.OUTPUTFIELD_ICON));
288: }
289:
290: public void actionPerformed(ActionEvent e) {
291: try {
292: addOutputField();
293: } catch (Throwable t) {
294: Application.processError(t);
295: }
296: }
297: }
298:
299: public class AddNewMessageFieldAction extends BaseAction {
300: public AddNewMessageFieldAction() {
301: super ("Add New Output Message", Application
302: .getAddIcon(Application.OUTMESSAGE_ICON));
303: }
304:
305: public void actionPerformed(ActionEvent e) {
306: try {
307: addOutputMessage();
308: } catch (Throwable t) {
309: Application.processError(t);
310: }
311: }
312: }
313:
314: /* Add New Model Element Constraint Action */
315:
316: public class AddNewConstraint extends BaseAction {
317: public AddNewConstraint() {
318: super ("Add New Input Constraint", Application
319: .getAddIcon(Application.CONSTRAINT_ICON));
320: }
321:
322: public void actionPerformed(ActionEvent arg0) {
323: try {
324: addNewConstraint();
325: } catch (Exception e) {
326: e.printStackTrace();
327: }
328: }
329: }
330: }
|