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: import java.util.Iterator;
020: import java.util.SortedSet;
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.auxilarydialogs.DiagramSelectDialog;
027: import com.metaboss.applications.designstudio.components.SeparatorAction;
028: import com.metaboss.applications.designstudio.domainmodel.DomainViewPanel;
029: import com.metaboss.applications.designstudio.propertiesdialogs.SimpleObjectPropertiesdialog;
030: import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
031: import com.metaboss.sdlctools.models.metabossmodel.ModelElementUtils;
032: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System;
033: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Domain;
034: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.DomainClass;
035: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.SystemImplementationModelPackage;
036: import com.metaboss.sdlctools.models.metabossmodel.visualmodel.DomainEntitiesDiagram;
037:
038: /* Domain user object class */
039:
040: public class DomainUserObject extends BaseUserObject {
041: public static final int ADD_ASSOCIATION = 1;
042: public static final int ADD_ENTITY = 2;
043: public static final int ADD_REPORT = 3;
044: public static final int ADD_RELATIONALIMPLEMENTATION = 4;
045: public static final int ADD_DIAGRAM = 5;
046:
047: private Domain mDomain = null;
048: private ViewStructureAction mViewStructureAction = new ViewStructureAction();
049: private AddAssociationAction mAssociationAction = new AddAssociationAction();
050: private AddEntityAction mEntityAction = new AddEntityAction();
051: private AddReportAction mReportAction = new AddReportAction();
052: private AddStorageDefinitionAction mAddStorageDefinitionAction = new AddStorageDefinitionAction();
053: private AddDiagramAction mAddDiagramAction = new AddDiagramAction();
054: private StudyDependenciesAction mShowDataTypeDependenciesAction = new StudyDependenciesAction();
055:
056: public DomainUserObject(Domain pDomain) {
057: super (pDomain, Application.DOMAIN_ICON);
058: mDomain = pDomain;
059: }
060:
061: public DomainUserObject(Domain pDomain, String pCaption, int pMode) {
062: super (pDomain, pCaption, pMode);
063: mDomain = pDomain;
064: }
065:
066: public static void addNewDomain(System pSystem) throws Exception {
067: new DomainUserObject(null).addNewObject(
068: getObjectPackage(pSystem), pSystem.getDomains());
069: }
070:
071: public BaseUserObject createNewObject(MetaBossModelPackage pPackage) {
072: SystemImplementationModelPackage lSystemImplementationModelPackage = pPackage
073: .getEnterpriseModel().getSystemImplementationModel();
074: DomainClass lClass = lSystemImplementationModelPackage
075: .getDomain();
076: return new DomainUserObject(lClass.createDomain());
077: }
078:
079: public Domain getDomain() {
080: return mDomain;
081: }
082:
083: // return object root node captions
084: public String getRootNodeName() {
085: return Application.getString("implemetationcomponents_node")
086: + "." + Application.getString("domains_node");
087: }
088:
089: // convert tree element to an action code
090: public int convertCaptionToAction(String pCaption) {
091: if (pCaption.equals(Application.getString("associations_node")))
092: return ADD_ASSOCIATION;
093: else if (pCaption
094: .equals(Application.getString("entities_node")))
095: return ADD_ENTITY;
096: else if (pCaption.equals(Application.getString("reports_node")))
097: return ADD_REPORT;
098: else if (pCaption.equals(Application
099: .getString("domainimplementations_node")))
100: return ADD_RELATIONALIMPLEMENTATION;
101: else if (pCaption
102: .equals(Application.getString("diagrams_node")))
103: return ADD_DIAGRAM;
104: else
105: return super .convertCaptionToAction(pCaption);
106: }
107:
108: // view structure diagram panel
109: public void viewStructureDiagram() {
110: if (mDomain == null)
111: return;
112:
113: try {
114: SortedSet lDiagrams = ModelElementUtils
115: .getSetOfModelElementsInAlphabeticalOrder(mDomain
116: .getEntityClassDiagrams());
117: if (lDiagrams != null) {
118: if (lDiagrams.size() == 0) {
119: DomainEntitiesDiagramUserObject lDiagramObject = DomainEntitiesDiagramUserObject
120: .addNewDomainEntitiesDiagram(mDomain);
121: if (lDiagramObject != null)
122: lDiagramObject.viewDiagram();
123: } else if (lDiagrams.size() == 1) {
124: DomainEntitiesDiagram lDiagram = (DomainEntitiesDiagram) lDiagrams
125: .first();
126: Application.fireShowContainer(new DomainViewPanel(
127: lDiagram), UserObjectFactory
128: .createUserObject(lDiagram),
129: Application.DOMAINCLASSDIAGRAM_ICON);
130: } else {
131: ArrayList lDiagramsArray = new ArrayList();
132: for (Iterator lIterator = lDiagrams.iterator(); lIterator
133: .hasNext();) {
134: DomainEntitiesDiagram lDiagram = (DomainEntitiesDiagram) lIterator
135: .next();
136: lDiagramsArray
137: .add(new DomainEntitiesDiagramUserObject(
138: lDiagram));
139: }
140: DiagramSelectDialog lDialog = new DiagramSelectDialog(
141: Application.mainFrame, lDiagramsArray);
142: if (lDialog.getModalResult() == DiagramSelectDialog.MR_OK) {
143: for (int i = 0; i < lDiagramsArray.size(); i++) {
144: DomainEntitiesDiagramUserObject lEntitiesDiagramUserObject = (DomainEntitiesDiagramUserObject) lDiagramsArray
145: .get(i);
146: Application
147: .fireShowContainer(
148: new DomainViewPanel(
149: lEntitiesDiagramUserObject
150: .getEntitiesDiagram()),
151: lEntitiesDiagramUserObject,
152: Application.DOMAINCLASSDIAGRAM_ICON);
153: }
154: }
155: }
156: }
157: } catch (Exception e) {
158: e.printStackTrace();
159: }
160: }
161:
162: // fill actions list
163: public void fillActionsList(ArrayList pList) {
164: switch (mMode) {
165: case ALL_ACTIONS:
166: super .fillActionsList(pList);
167: pList.add(new SeparatorAction());
168: pList.add(mViewStructureAction);
169: pList.add(new SeparatorAction());
170: pList.add(mAssociationAction);
171: pList.add(mEntityAction);
172: pList.add(mReportAction);
173: pList.add(mAddStorageDefinitionAction);
174: pList.add(mAddDiagramAction);
175: pList.add(new SeparatorAction());
176: pList.add(mShowDataTypeDependenciesAction);
177: break;
178: case ADD_ASSOCIATION:
179: pList.add(mAssociationAction);
180: break;
181: case ADD_ENTITY:
182: pList.add(mEntityAction);
183: break;
184: case ADD_REPORT:
185: pList.add(mReportAction);
186: break;
187: case ADD_RELATIONALIMPLEMENTATION:
188: pList.add(mAddStorageDefinitionAction);
189: break;
190: case ADD_DIAGRAM:
191: pList.add(mAddDiagramAction);
192: break;
193: }
194: }
195:
196: public BasePropertiesDialog getObjectEditor() {
197: return new SimpleObjectPropertiesdialog("Domain");
198: }
199:
200: // add New Association
201: private void addNewAssociation() {
202: try {
203: AssociationUserObject.addNewAssociation(mDomain);
204: } catch (Throwable t) {
205: Application.processError(t);
206: }
207: }
208:
209: // add New Entity
210: private void addNewEntity() {
211: try {
212: EntityUserObject.addNewEntity(mDomain);
213: } catch (Throwable t) {
214: Application.processError(t);
215: }
216: }
217:
218: // add New Report
219: private void addNewReport() {
220: try {
221: ReportUserObject.addNewReport(mDomain);
222: } catch (Throwable t) {
223: Application.processError(t);
224: }
225: }
226:
227: // add New Storage Definition
228: private void addNewStorageDefinition() {
229: try {
230: RelationalStorageDefinitionUserObject
231: .addNewStorageDefinition(mDomain);
232: } catch (Throwable t) {
233: Application.processError(t);
234: }
235: }
236:
237: // add new diagram
238: protected void addNewDiagram() {
239: try {
240: DomainEntitiesDiagramUserObject
241: .addNewDomainEntitiesDiagram(mDomain);
242: } catch (Throwable t) {
243: Application.processError(t);
244: }
245: }
246:
247: /* Actions */
248:
249: public class ViewStructureAction extends BaseAction {
250: public ViewStructureAction() {
251: super (Application.getString("view_domainclassdiagram"),
252: Application.DOMAINCLASSDIAGRAM_ICON);
253: }
254:
255: public void actionPerformed(ActionEvent e) {
256: try {
257: viewStructureDiagram();
258: } catch (Throwable t) {
259: t.printStackTrace();
260: }
261: }
262: }
263:
264: /* Add Association Action */
265:
266: public class AddAssociationAction extends BaseAction {
267: public AddAssociationAction() {
268: super ("Add New Association", Application
269: .getAddIcon(Application.ASSOCIATION_ICON));
270: }
271:
272: public void actionPerformed(ActionEvent e) {
273: addNewAssociation();
274: }
275: }
276:
277: /* Add Entity Action */
278:
279: public class AddEntityAction extends BaseAction {
280: public AddEntityAction() {
281: super ("Add New Entity", Application
282: .getAddIcon(Application.ENTITY_ICON));
283: }
284:
285: public void actionPerformed(ActionEvent e) {
286: addNewEntity();
287: }
288: }
289:
290: /* Add Report Action */
291:
292: public class AddReportAction extends BaseAction {
293: public AddReportAction() {
294: super ("Add New Report", Application
295: .getAddIcon(Application.REPORT_ICON));
296: }
297:
298: public void actionPerformed(ActionEvent e) {
299: addNewReport();
300: }
301: }
302:
303: /* Add Relational Storage Definition Action */
304:
305: public class AddStorageDefinitionAction extends BaseAction {
306: public AddStorageDefinitionAction() {
307: super ("Add New Domain Implementation", Application
308: .getAddIcon(Application.DOMAINIMPL_ICON));
309: }
310:
311: public void actionPerformed(ActionEvent e) {
312: addNewStorageDefinition();
313: }
314: }
315: }
|