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.fieldstable;
016:
017: import com.metaboss.applications.designstudio.BaseUserObject;
018: import com.metaboss.applications.designstudio.components.FieldsModel;
019: import com.metaboss.applications.designstudio.userobjects.AbstractDataFieldUserObject;
020: import com.metaboss.applications.designstudio.userobjects.EventDataFieldUserObject;
021: import com.metaboss.applications.designstudio.userobjects.EventMessageFieldUserObject;
022: import com.metaboss.applications.designstudio.userobjects.MessageFieldUserObject;
023: import com.metaboss.applications.designstudio.userobjects.OperationInputFieldUserObject;
024: import com.metaboss.applications.designstudio.userobjects.OperationOutputFieldUserObject;
025: import com.metaboss.applications.designstudio.userobjects.OperationOutputMessageUserObject;
026: import com.metaboss.applications.designstudio.userobjects.OperationUserObject;
027: import com.metaboss.applications.designstudio.userobjects.StructureFieldUserObject;
028: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
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.enterprisemodel.Event;
033: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EventDataField;
034: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EventMessageField;
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.OperationOutputMessage;
042: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Service;
043: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.TransactionPolicy;
044:
045: /* Fields table model */
046:
047: public class FieldsTableModel extends FieldsModel {
048: private int mMode = 0;
049: private ModelElement mMaster = null;
050: private Class mElementClass = null;
051:
052: public FieldsTableModel(String pFirstColumn, String pSecondColumn) {
053: super (pFirstColumn, pSecondColumn);
054: }
055:
056: public FieldsTableModel() {
057: super ();
058: }
059:
060: public void loadFields(ModelElement pElement) {
061: mMaster = pElement;
062: mFields.clear();
063: if (pElement != null) {
064: if (pElement instanceof Structure) {
065: mElementClass = StructureField.class;
066: Structure lStructure = (Structure) pElement;
067: Object[] lList = lStructure.getFields().toArray();
068: for (int i = 0; i < lList.length; i++)
069: mFields.add(new StructureFieldUserObject(
070: (StructureField) lList[i]));
071: } else if (pElement instanceof Message) {
072: mElementClass = MessageField.class;
073: Message lMessage = (Message) pElement;
074: Object[] lList = lMessage.getFields().toArray();
075: for (int i = 0; i < lList.length; i++)
076: mFields.add(new MessageFieldUserObject(
077: (MessageField) lList[i]));
078: } else if (pElement instanceof Service) {
079: mElementClass = Operation.class;
080: Service lService = (Service) pElement;
081: Object[] lList = lService.getOperations().toArray();
082: for (int i = 0; i < lList.length; i++)
083: mFields.add(new OperationUserObject(
084: (Operation) lList[i]));
085: } else if (pElement instanceof Operation) {
086: Operation lOperation = (Operation) pElement;
087: Object[] lList = null;
088: switch (mMode) {
089: case 1:
090: mElementClass = OperationInputField.class;
091: lList = lOperation.getInputFields().toArray();
092: for (int i = 0; i < lList.length; i++)
093: mFields.add(new OperationInputFieldUserObject(
094: (OperationInputField) lList[i]));
095: break;
096: case 2:
097: mElementClass = OperationOutputField.class;
098: lList = lOperation.getOutputFields().toArray();
099: for (int i = 0; i < lList.length; i++)
100: mFields.add(new OperationOutputFieldUserObject(
101: (OperationOutputField) lList[i]));
102: break;
103: case 3:
104: mElementClass = OperationOutputMessage.class;
105: lList = lOperation.getOutputMessages().toArray();
106: for (int i = 0; i < lList.length; i++)
107: mFields
108: .add(new OperationOutputMessageUserObject(
109: (OperationOutputMessage) lList[i]));
110: break;
111: }
112: } else if (pElement instanceof EventSubscriptionOperation) {
113: EventSubscriptionOperation lOperation = (EventSubscriptionOperation) pElement;
114: Object[] lList = null;
115: switch (mMode) {
116: case 1:
117: mElementClass = OperationInputField.class;
118: lList = lOperation.getInputFields().toArray();
119: for (int i = 0; i < lList.length; i++)
120: mFields.add(new OperationInputFieldUserObject(
121: (OperationInputField) lList[i]));
122: break;
123: case 2:
124: mElementClass = OperationOutputField.class;
125: lList = lOperation.getOutputFields().toArray();
126: for (int i = 0; i < lList.length; i++)
127: mFields.add(new OperationOutputFieldUserObject(
128: (OperationOutputField) lList[i]));
129: break;
130: case 3:
131: mElementClass = OperationOutputMessage.class;
132: lList = lOperation.getOutputMessages().toArray();
133: for (int i = 0; i < lList.length; i++)
134: mFields
135: .add(new OperationOutputMessageUserObject(
136: (OperationOutputMessage) lList[i]));
137: break;
138: }
139: } else if (pElement instanceof Event) {
140: Event lEvent = (Event) pElement;
141: Object[] lList = null;
142: switch (mMode) {
143: case 1:
144: mElementClass = EventDataField.class;
145: lList = lEvent.getDataFields().toArray();
146: for (int i = 0; i < lList.length; i++)
147: mFields.add(new EventDataFieldUserObject(
148: (EventDataField) lList[i]));
149: break;
150: case 2:
151: mElementClass = EventMessageField.class;
152: lList = lEvent.getMessageFields().toArray();
153: for (int i = 0; i < lList.length; i++)
154: mFields.add(new EventMessageFieldUserObject(
155: (EventMessageField) lList[i]));
156: break;
157: }
158: }
159: }
160: fireTableDataChanged();
161: }
162:
163: public void loadFields(ModelElement pElemnt, int pMode) {
164: mMode = pMode;
165: loadFields(pElemnt);
166: }
167:
168: public String getObjectType(BaseUserObject pObject) {
169: DataType lDataType = null;
170: if (pObject instanceof AbstractDataFieldUserObject) {
171: lDataType = ((AbstractDataFieldUserObject) pObject)
172: .getAbstractField().getDataType();
173: if (lDataType == null) {
174: Structure lStructure = ((AbstractDataFieldUserObject) pObject)
175: .getAbstractField().getStructureType();
176: if (lStructure != null)
177: return lStructure.getName();
178: }
179: } else if (pObject instanceof StructureFieldUserObject) {
180: lDataType = ((StructureFieldUserObject) pObject).getField()
181: .getDataType();
182: if (lDataType == null) {
183: Structure lStructure = ((StructureFieldUserObject) pObject)
184: .getField().getStructureType();
185: if (lStructure != null)
186: return lStructure.getName();
187: }
188: } else if (pObject instanceof MessageFieldUserObject)
189: lDataType = ((MessageFieldUserObject) pObject).getField()
190: .getDataType();
191: else if (pObject instanceof OperationInputFieldUserObject) {
192: lDataType = ((OperationInputFieldUserObject) pObject)
193: .getField().getDataType();
194: if (lDataType == null) {
195: Structure lStructure = ((OperationInputFieldUserObject) pObject)
196: .getField().getStructureType();
197: if (lStructure != null)
198: return lStructure.getName();
199: }
200: } else if (pObject instanceof OperationUserObject) {
201: TransactionPolicy lPolicy = ((OperationUserObject) pObject)
202: .getOperation().getTransactionPolicy();
203: if (lPolicy != null)
204: return lPolicy.toString();
205: } else if (pObject instanceof OperationOutputFieldUserObject) {
206: lDataType = ((OperationOutputFieldUserObject) pObject)
207: .getField().getDataType();
208: if (lDataType == null) {
209: Structure lStructure = ((OperationOutputFieldUserObject) pObject)
210: .getField().getStructureType();
211: if (lStructure != null)
212: return lStructure.getName();
213: }
214: } else if (pObject instanceof EventMessageFieldUserObject) {
215: Message lMessage = ((EventMessageFieldUserObject) pObject)
216: .getField().getMessageType();
217: if (lMessage != null)
218: return lMessage.getName();
219: } else if (pObject instanceof OperationOutputMessageUserObject) {
220: Message lMessage = ((OperationOutputMessageUserObject) pObject)
221: .getMessage().getMessageType();
222: if (lMessage != null)
223: return lMessage.getName();
224: }
225: return (lDataType != null) ? lDataType.getName() : super
226: .getObjectType(pObject);
227: }
228:
229: protected void processObjectInserted(BaseUserObject pObject) {
230: if (mMaster != null && pObject != null
231: && mMaster.equals(pObject.getMasterElement())) {
232: Class[] lInterfaces = pObject.getBOObject().getClass()
233: .getInterfaces();
234: for (int i = 0; i < lInterfaces.length; i++) {
235: if (mElementClass != null
236: && mElementClass.equals(lInterfaces[i])) {
237: mFields.add(pObject);
238: fireTableDataChanged();
239: break;
240: }
241: }
242: }
243: }
244:
245: protected void processObjectEdited(BaseUserObject pObject) {
246: if (mMaster != null && pObject != null
247: && mMaster.equals(pObject.getMasterElement())) {
248: Class[] lInterfaces = pObject.getBOObject().getClass()
249: .getInterfaces();
250: for (int i = 0; i < lInterfaces.length; i++) {
251: if (mElementClass != null
252: && mElementClass.equals(lInterfaces[i])) {
253: fireTableDataChanged();
254: break;
255: }
256: }
257: }
258: }
259: }
|