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 com.metaboss.applications.designstudio.Application;
021: import com.metaboss.applications.designstudio.BaseAction;
022: import com.metaboss.applications.designstudio.BasePropertiesDialog;
023: import com.metaboss.applications.designstudio.BaseUserObject;
024: import com.metaboss.applications.designstudio.components.SeparatorAction;
025: import com.metaboss.applications.designstudio.propertiesdialogs.SimpleObjectPropertiesdialog;
026: import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
027: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataDictionary;
028: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataDictionaryClass;
029: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataType;
030: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Namespace;
031: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Structure;
032: import com.metaboss.sdlctools.models.metabossmodel.designlibrarymodel.DesignLibrary;
033: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Message;
034:
035: /* DataDictionary user object */
036:
037: public class DataDictionaryUserObject extends BaseUserObject {
038: public static final int NAMESPACE_ACTION = 1;
039: public static final int TYPETEMPLATE_ACTION = 2;
040: public static final int DATATYPE_ACTION = 3;
041: public static final int STRUCTURE_ACTION = 4;
042: public static final int MESSAGES_ACTION = 5;
043:
044: private DataDictionary mDataDictionary = null;
045: private AddNamespaceAction mAddNamespaceAction = new AddNamespaceAction();
046: private AddDataTypeAction mAddDataTypeAction = new AddDataTypeAction();
047: private AddTypeTemplateAction mAddTypeTemplateAction = new AddTypeTemplateAction();
048: private AddStructureAction mAddStrucureAction = new AddStructureAction();
049: private AddMessageAction mAddMessageAction = new AddMessageAction();
050: private StudyDependenciesAction mShowDataTypeDependenciesAction = new StudyDependenciesAction();
051:
052: public DataDictionaryUserObject(DataDictionary pDictionary) {
053: super (pDictionary, Application.DATADICTIONARY_ICON);
054: mDataDictionary = pDictionary;
055: }
056:
057: public DataDictionaryUserObject(DataDictionary pDictionary,
058: String pCaption, int pMode) {
059: super (pDictionary, pCaption, pMode);
060: mDataDictionary = pDictionary;
061: }
062:
063: // create new Entity
064: public static DataDictionaryUserObject addNewDataDictionary(
065: DesignLibrary pDesignLibrary) throws Exception {
066: return (DataDictionaryUserObject) new DataDictionaryUserObject(
067: null).addNewObject(getObjectPackage(pDesignLibrary),
068: pDesignLibrary.getDataDictionaries());
069: }
070:
071: // create new DataDictionary
072: //public static DataDictionary createDataDictionary(MetaBossModelPackage pPackage)
073: //{
074: // return pPackage.getDataDictionaryModel().getDataDictionary().createDataDictionary("default", "default dictionary", "default");
075: //}
076: public static DataDictionaryUserObject createDataDictionary(
077: DesignLibrary pDesignLibrary) throws Exception {
078: return (DataDictionaryUserObject) new DataDictionaryUserObject(
079: null).addNewObject(getObjectPackage(pDesignLibrary),
080: pDesignLibrary.getDataDictionaries());
081: }
082:
083: public BaseUserObject createNewObject(MetaBossModelPackage pPackage) {
084: DataDictionaryClass lClass = pPackage.getDataDictionaryModel()
085: .getDataDictionary();
086: return new DataDictionaryUserObject(lClass
087: .createDataDictionary());
088: }
089:
090: // return object root node captions
091: public String getRootNodeName() {
092: return (isSystemDictionary()) ? null : Application
093: .getString("datadictionaries_node");
094: }
095:
096: public String toString() {
097: if (isSystemDictionary() && mMode == 0)
098: return Application.getString("datadictionary_node");
099: else
100: return super .toString();
101: }
102:
103: // fill actions list
104: public void fillActionsList(ArrayList pList) {
105: switch (mMode) {
106: case ALL_ACTIONS:
107: if (!isSystemDictionary()) {
108: super .fillActionsList(pList);
109: pList.add(new SeparatorAction());
110: }
111: pList.add(mAddNamespaceAction);
112: pList.add(mAddTypeTemplateAction);
113: pList.add(mAddDataTypeAction);
114: pList.add(mAddStrucureAction);
115: pList.add(mAddMessageAction);
116: pList.add(new SeparatorAction());
117: pList.add(mShowDataTypeDependenciesAction);
118: break;
119: case NAMESPACE_ACTION:
120: pList.add(mAddNamespaceAction);
121: break;
122: case TYPETEMPLATE_ACTION:
123: pList.add(mAddTypeTemplateAction);
124: break;
125: case DATATYPE_ACTION:
126: pList.add(mAddDataTypeAction);
127: break;
128: case STRUCTURE_ACTION:
129: pList.add(mAddStrucureAction);
130: break;
131: case MESSAGES_ACTION:
132: pList.add(mAddMessageAction);
133: break;
134: }
135: }
136:
137: // get object editor
138: public BasePropertiesDialog getObjectEditor() {
139: return new SimpleObjectPropertiesdialog("Data Dictionary");
140: }
141:
142: // check the Dictionary is defined for System
143: private boolean isSystemDictionary() {
144: return (mDataDictionary != null && mDataDictionary.getSystem() != null);
145: }
146:
147: // add namespace
148: private void addNamespace() throws Exception {
149: NamespaceUserObject.addNewNamespace(mDataDictionary);
150: }
151:
152: // add data type
153: private void addDataType() throws Exception {
154: DataTypeUserObject.addNewDataType(mDataDictionary);
155: }
156:
157: // add typetemplate
158: private void addTypeTemplate() throws Exception {
159: TypeTemplateUserObject.addNewTypeTemplate(mDataDictionary);
160: }
161:
162: // add structure
163: private void addStructure() throws Exception {
164: StructureUserObject.addNewStructure(mDataDictionary);
165: }
166:
167: // add new message
168: public void addNewMessage() throws Exception {
169: MessageUserObject.addNewMessage(mDataDictionary);
170: }
171:
172: // returns true if drop object could be accepted
173: public boolean canAcceptDropObject(BaseUserObject pUserObject,
174: boolean pCopy) {
175: if (pUserObject != null
176: && super .canAcceptDropObject(pUserObject, pCopy)) {
177: if ((pUserObject instanceof NamespaceUserObject && (mMode == BaseUserObject.ALL_ACTIONS || mMode == DataDictionaryUserObject.NAMESPACE_ACTION))
178: || (pUserObject instanceof DataTypeUserObject && (mMode == BaseUserObject.ALL_ACTIONS || mMode == DataDictionaryUserObject.DATATYPE_ACTION))
179: || (pUserObject instanceof MessageUserObject && (mMode == BaseUserObject.ALL_ACTIONS || mMode == DataDictionaryUserObject.MESSAGES_ACTION))
180: || (pUserObject instanceof StructureUserObject && (mMode == BaseUserObject.ALL_ACTIONS || mMode == DataDictionaryUserObject.STRUCTURE_ACTION))) {
181: return (pCopy) ? pUserObject.canDuplicate() : true;
182: }
183: }
184: return false;
185: }
186:
187: // acccept drop target in transaction
188: protected void transactionalAccept(BaseUserObject pUserObject,
189: boolean pCopy) throws Exception {
190: if (pUserObject != null) {
191: if (pUserObject instanceof NamespaceUserObject) {
192: NamespaceUserObject lUserObject = (NamespaceUserObject) pUserObject;
193: if (pCopy) {
194: Namespace lNamespace = (Namespace) Application.sModelRepository
195: .duplicateModelElement(lUserObject
196: .getNamespace());
197: lNamespace.setNamespace(mDataDictionary);
198: } else
199: lUserObject.getNamespace().setNamespace(
200: mDataDictionary);
201: } else if (pUserObject instanceof DataTypeUserObject) {
202: DataTypeUserObject lUserObject = (DataTypeUserObject) pUserObject;
203: if (pCopy) {
204: DataType lDataType = (DataType) Application.sModelRepository
205: .duplicateModelElement(lUserObject
206: .getDataType());
207: lDataType.setNamespace(mDataDictionary);
208: } else
209: lUserObject.getDataType().setNamespace(
210: mDataDictionary);
211: } else if (pUserObject instanceof StructureUserObject) {
212: StructureUserObject lUserObject = (StructureUserObject) pUserObject;
213: if (pCopy) {
214: Structure lStructure = (Structure) Application.sModelRepository
215: .duplicateModelElement(lUserObject
216: .getStructure());
217: lStructure.setNamespace(mDataDictionary);
218: } else
219: lUserObject.getStructure().setNamespace(
220: mDataDictionary);
221: } else if (pUserObject instanceof MessageUserObject) {
222: MessageUserObject lUserObject = (MessageUserObject) pUserObject;
223: if (pCopy) {
224: Message lMessage = (Message) Application.sModelRepository
225: .duplicateModelElement(lUserObject
226: .getMessage());
227: lMessage.setNamespace(mDataDictionary);
228: } else {
229: // Ensure that all other possible owners are set to null
230: lUserObject.getMessage().setServicemodule(null);
231: lUserObject.getMessage().setNamespace(
232: mDataDictionary);
233: }
234: }
235: }
236: }
237:
238: /* Actions */
239:
240: public class AddNamespaceAction extends BaseAction {
241: public AddNamespaceAction() {
242: super ("Add New Namespace", Application
243: .getAddIcon(Application.NAMESPACE_ICON));
244: }
245:
246: public void actionPerformed(ActionEvent e) {
247: try {
248: addNamespace();
249: } catch (Throwable t) {
250: Application.processError(t);
251: }
252: }
253: }
254:
255: public class AddDataTypeAction extends BaseAction {
256: public AddDataTypeAction() {
257: super ("Add New DataType", Application
258: .getAddIcon(Application.DATATYPE_ICON));
259: }
260:
261: public void actionPerformed(ActionEvent e) {
262: try {
263: addDataType();
264: } catch (Throwable t) {
265: Application.processError(t);
266: }
267: }
268: }
269:
270: public class AddTypeTemplateAction extends BaseAction {
271: public AddTypeTemplateAction() {
272: super ("Add New TypeTemplate", Application
273: .getAddIcon(Application.TYPETEMPLATE_ICON));
274: }
275:
276: public void actionPerformed(ActionEvent e) {
277: try {
278: addTypeTemplate();
279: } catch (Throwable t) {
280: Application.processError(t);
281: }
282: }
283: }
284:
285: public class AddStructureAction extends BaseAction {
286: public AddStructureAction() {
287: super ("Add New Structure", Application
288: .getAddIcon(Application.STRUCTURE_ICON));
289: }
290:
291: public void actionPerformed(ActionEvent e) {
292: try {
293: addStructure();
294: } catch (Throwable t) {
295: Application.processError(t);
296: }
297: }
298: }
299:
300: public class AddMessageAction extends BaseAction {
301: public AddMessageAction() {
302: super ("Add New Message", Application
303: .getAddIcon(Application.MESSAGE_ICON));
304: }
305:
306: public void actionPerformed(ActionEvent e) {
307: try {
308: addNewMessage();
309: } catch (Throwable t) {
310: t.printStackTrace();
311: }
312: }
313: }
314: }
|