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.propertiesdialogs;
016:
017: import java.awt.Dimension;
018:
019: import javax.swing.JCheckBox;
020: import javax.swing.JTextArea;
021:
022: import com.metaboss.applications.designstudio.Application;
023: import com.metaboss.applications.designstudio.BaseUserObject;
024: import com.metaboss.applications.designstudio.datatypefield.DataTypeBox;
025: import com.metaboss.applications.designstudio.structuresfield.StructuresBox;
026: import com.metaboss.applications.designstudio.userobjects.StructureItem;
027: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
028: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataDictionary;
029: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataType;
030: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Structure;
031: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.StructureField;
032: import com.metaboss.sdlctools.models.metabossmodel.designlibrarymodel.DesignLibrary;
033: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.AbstractOperation;
034: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EventDataField;
035: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EventSubscriptionOperation;
036: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Message;
037: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.MessageField;
038: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Operation;
039: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.OperationInputField;
040: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.OperationOutputField;
041: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Servicemodule;
042: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System;
043: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Report;
044: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.ReportInputField;
045: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.ReportOutputElement;
046: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.ReportOutputField;
047: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.SelectorInputField;
048:
049: /* BOField object properties tuning dialog */
050:
051: public class FieldPropertiesDialog extends ModelElementPropertiesDialog {
052: private DataTypeBox mDataTypeField = new DataTypeBox("DataType");
053: private StructuresBox mStructureTypeField = new StructuresBox(
054: "StructureType");
055: private JCheckBox mIsArrayCheckBox = new JCheckBox();
056: private JTextArea mDescriptionField = new JTextArea(8, 40);
057:
058: public FieldPropertiesDialog() {
059: super ("Field", new Dimension(400, 340));
060: }
061:
062: // load service module properties
063: public void loadProperties(ModelElement pObject) throws Exception {
064: if (pObject != null) {
065: createUserInterface(pObject);
066: mNameField.setText(pObject.getName());
067: mDescriptionField.setText(pObject.getDescription());
068:
069: if (pObject instanceof OperationInputField) {
070: OperationInputField lField = (OperationInputField) pObject;
071: AbstractOperation lOperation = lField.getOperation();
072: System lSystem = null;
073: if (lOperation instanceof Operation)
074: lSystem = ((Operation) lOperation).getService()
075: .getServicemodule().getSystem();
076: else if (lOperation instanceof EventSubscriptionOperation)
077: lSystem = ((EventSubscriptionOperation) lOperation)
078: .getSubscription().getServicemodule()
079: .getSystem();
080:
081: mDataTypeField.setSystem(lSystem);
082: mStructureTypeField.setSystem(lSystem);
083:
084: mDataTypeField
085: .setSelectedDataType(lField.getDataType());
086: mStructureTypeField.setSelectedStructure(lField
087: .getStructureType());
088: mIsArrayCheckBox.setSelected(lField.isArray());
089: } else if (pObject instanceof OperationOutputField) {
090: OperationOutputField lField = (OperationOutputField) pObject;
091: AbstractOperation lOperation = lField.getOperation();
092: System lSystem = null;
093: if (lOperation instanceof Operation)
094: lSystem = ((Operation) lOperation).getService()
095: .getServicemodule().getSystem();
096: else if (lOperation instanceof EventSubscriptionOperation)
097: lSystem = ((EventSubscriptionOperation) lOperation)
098: .getSubscription().getServicemodule()
099: .getSystem();
100:
101: mDataTypeField.setSystem(lSystem);
102: mStructureTypeField.setSystem(lSystem);
103:
104: mDataTypeField
105: .setSelectedDataType(lField.getDataType());
106: mStructureTypeField.setSelectedStructure(lField
107: .getStructureType());
108: mIsArrayCheckBox.setSelected(lField.isArray());
109: } else if (pObject instanceof StructureField) {
110: StructureField lField = (StructureField) pObject;
111: Structure lStructure = lField.getOwnerStructure();
112: Servicemodule lServiceModule = lStructure
113: .getServicemodule();
114: DataDictionary lDataDictionary = lStructure
115: .getOwnerDataDictionary();
116: DesignLibrary lDesignLibrary = null;
117:
118: System lSystem = null;
119: if (lServiceModule != null) {
120: lSystem = lServiceModule.getSystem();
121: } else if (lDataDictionary != null) {
122: lSystem = lDataDictionary.getSystem();
123: if (lSystem == null)
124: lDesignLibrary = lDataDictionary
125: .getDesignLibrary();
126: }
127:
128: if (lSystem != null) {
129: mDataTypeField.setSystem(lSystem);
130: mStructureTypeField.setSystem(lSystem);
131: } else if (lDesignLibrary != null) {
132: mDataTypeField.setDesignLibrary(lDesignLibrary);
133: mStructureTypeField
134: .setDesignLibrary(lDesignLibrary);
135: }
136:
137: mDataTypeField
138: .setSelectedDataType(lField.getDataType());
139: mStructureTypeField.setSelectedStructure(lField
140: .getStructureType());
141: mIsArrayCheckBox.setSelected(lField.isArray());
142: } else if (pObject instanceof ReportInputField) {
143: ReportInputField lField = (ReportInputField) pObject;
144: mDataTypeField.setSystem(lField.getReport().getDomain()
145: .getSystem());
146: mDataTypeField
147: .setSelectedDataType(lField.getDataType());
148: mIsArrayCheckBox.setSelected(lField.isArray());
149: } else if (pObject instanceof ReportOutputField) {
150: ReportOutputField lField = (ReportOutputField) pObject;
151: mDataTypeField.setSystem(getSystemForField(lField));
152: mDataTypeField
153: .setSelectedDataType(lField.getDataType());
154: mIsArrayCheckBox.setSelected(lField.isArray());
155: } else if (pObject instanceof MessageField) {
156: MessageField lField = (MessageField) pObject;
157: Message lMessage = lField.getMessage();
158: Servicemodule lServiceModule = lMessage
159: .getServicemodule();
160: DataDictionary lDataDictionary = lMessage
161: .getOwnerDataDictionary();
162: DesignLibrary lDesignLibrary = null;
163:
164: System lSystem = null;
165: if (lServiceModule != null) {
166: lSystem = lServiceModule.getSystem();
167: } else if (lDataDictionary != null) {
168: lSystem = lDataDictionary.getSystem();
169: if (lSystem == null)
170: lDesignLibrary = lDataDictionary
171: .getDesignLibrary();
172: }
173:
174: if (lSystem != null) {
175: mDataTypeField.setSystem(lSystem);
176: } else if (lDesignLibrary != null) {
177: mDataTypeField.setDesignLibrary(lDesignLibrary);
178: }
179: mDataTypeField
180: .setSelectedDataType(lField.getDataType());
181: } else if (pObject instanceof SelectorInputField) {
182: SelectorInputField lField = (SelectorInputField) pObject;
183: mDataTypeField.setSystem(lField.getSelector()
184: .getEntity().getDomain().getSystem());
185: mDataTypeField
186: .setSelectedDataType(lField.getDataType());
187: } else if (pObject instanceof EventDataField) {
188: EventDataField lField = (EventDataField) pObject;
189: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Event lEvent = lField
190: .getEvent();
191: System lSystem = lEvent.getSubscription()
192: .getServicemodule().getSystem();
193:
194: mDataTypeField.setSystem(lSystem);
195: mStructureTypeField.setSystem(lSystem);
196:
197: mDataTypeField
198: .setSelectedDataType(lField.getDataType());
199: mStructureTypeField.setSelectedStructure(lField
200: .getStructureType());
201: mIsArrayCheckBox.setSelected(lField.isArray());
202: }
203: }
204: super .loadProperties(pObject);
205: }
206:
207: // save service module proeprties
208: public void saveProperties(ModelElement pObject) throws Exception {
209: super .saveProperties(pObject);
210: if (pObject != null) {
211: pObject.setName(mNameField.getText());
212: pObject.setDescription(mDescriptionField.getText());
213:
214: DataType lDataType = mDataTypeField.getSelectedDataType();
215: Structure lStructure = mStructureTypeField
216: .getSelectedSrtucture();
217: if (pObject instanceof OperationInputField) {
218: OperationInputField lField = (OperationInputField) pObject;
219: lField.setDataType(lDataType);
220: lField.setStructureType(lStructure);
221: lField.setArray(mIsArrayCheckBox.isSelected());
222: } else if (pObject instanceof OperationOutputField) {
223: OperationOutputField lField = (OperationOutputField) pObject;
224: lField.setDataType(lDataType);
225: lField.setStructureType(lStructure);
226: lField.setArray(mIsArrayCheckBox.isSelected());
227: } else if (pObject instanceof StructureField) {
228: StructureField lField = (StructureField) pObject;
229: lField.setDataType(lDataType);
230: lField.setStructureType(lStructure);
231: lField.setArray(mIsArrayCheckBox.isSelected());
232: } else if (pObject instanceof ReportInputField) {
233: ReportInputField lField = (ReportInputField) pObject;
234: lField.setDataType(lDataType);
235: lField.setArray(mIsArrayCheckBox.isSelected());
236: } else if (pObject instanceof ReportOutputField) {
237: ReportOutputField lField = (ReportOutputField) pObject;
238: lField.setDataType(lDataType);
239: lField.setArray(mIsArrayCheckBox.isSelected());
240: } else if (pObject instanceof MessageField) {
241: MessageField lField = (MessageField) pObject;
242: lField.setDataType(lDataType);
243: } else if (pObject instanceof SelectorInputField) {
244: SelectorInputField lField = (SelectorInputField) pObject;
245: lField.setDataType(lDataType);
246: } else if (pObject instanceof EventDataField) {
247: EventDataField lField = (EventDataField) pObject;
248: lField.setDataType(lDataType);
249: lField.setStructureType(lStructure);
250: lField.setArray(mIsArrayCheckBox.isSelected());
251: }
252: }
253: }
254:
255: // check fields data
256: public boolean checkProperties() {
257: if (mNameField.getText().length() == 0) {
258: Application.showError("Name field could not be blank!");
259: return false;
260: }
261: return super .checkProperties();
262: }
263:
264: // create UI fields
265: private void createUserInterface(ModelElement pObject) {
266: int n = 1;
267: addTextField(mPropertiesPanel, "Name: ", mNameField, n++, true);
268: addComplexFieldWithEdit(mPropertiesPanel, mDataTypeField, n++,
269: false);
270:
271: if (pObject instanceof OperationInputField
272: || pObject instanceof OperationOutputField
273: || pObject instanceof StructureField
274: || pObject instanceof EventDataField) {
275: addComplexFieldWithEdit(mPropertiesPanel,
276: mStructureTypeField, n++, false);
277: addCheckBox(mPropertiesPanel, "- is array",
278: mIsArrayCheckBox, n++, false);
279: } else if (pObject instanceof ReportInputField
280: || pObject instanceof ReportOutputField) {
281: addCheckBox(mPropertiesPanel, "- is array",
282: mIsArrayCheckBox, n++, false);
283: }
284:
285: addTextArea(mPropertiesPanel, "Description: ",
286: mDescriptionField, n++, false);
287: }
288:
289: // load Structures ComboBox
290: private Object[] loadStructures(Servicemodule pServiceModule) {
291: Object[] lStructures = StructureItem.preloadStructures(
292: BaseUserObject.getObjectPackage(pServiceModule), true);
293: StructureItem.loadBoxWithStructures(mStructureTypeField,
294: lStructures);
295: return lStructures;
296: }
297:
298: private System getSystemForField(ReportOutputField pField) {
299: if (pField != null) {
300: ReportOutputElement lElement = pField.getOutputElement();
301: Report lReport = lElement.getReport();
302: while (lReport == null) {
303: lElement = lElement.getParenElement();
304: lReport = lElement.getReport();
305: }
306: return lReport.getDomain().getSystem();
307: }
308: return null;
309: }
310: }
|