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.propertiesdialogs.SimpleObjectPropertiesdialog;
029: import com.metaboss.applications.designstudio.propertiesview.PropertiesTableModel;
030: import com.metaboss.applications.designstudio.systemsmodel.SystemsPanel;
031: import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
032: import com.metaboss.sdlctools.models.metabossmodel.ModelElementUtils;
033: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Enterprise;
034: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EnterpriseClass;
035: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EnterpriseModelPackage;
036: import com.metaboss.sdlctools.models.metabossmodel.visualmodel.EnterpriseSystemsDiagram;
037:
038: /* User objects Enterprises */
039:
040: public class EnterpriseUserObject extends BaseUserObject {
041: public static final int SYSTEMS_ACTION = 1;
042: public static final int DATADICTIONARY_ACTION = 2;
043: public static final int ADD_DIAGRAM = 3;
044:
045: private Enterprise mEnterprise = null;
046: private AddNewSystemAction mAddSystemAction = new AddNewSystemAction();
047: private ShowSystemsDiagramAction mShowSystemsDiagramAction = new ShowSystemsDiagramAction();
048: private AddDiagramAction mAddDiagramAction = new AddDiagramAction();
049: private StudyDependenciesAction mShowDataTypeDependenciesAction = new StudyDependenciesAction();
050:
051: public EnterpriseUserObject(Enterprise pEnterprise) {
052: super (pEnterprise, Application.ENTERPRISE_ICON);
053: mEnterprise = pEnterprise;
054: }
055:
056: public EnterpriseUserObject(Enterprise pEnterprise,
057: String pCaption, int pMode) {
058: super (pEnterprise, pCaption, pMode);
059: mEnterprise = pEnterprise;
060: }
061:
062: // create new system
063: public static EnterpriseUserObject addNewEnterprise(
064: MetaBossModelPackage pPackage) throws Exception {
065: return (EnterpriseUserObject) new EnterpriseUserObject(null)
066: .addNewObject(pPackage);
067: }
068:
069: public BaseUserObject createNewObject(MetaBossModelPackage pPackage) {
070: EnterpriseModelPackage lEnterpriseModelPackage = pPackage
071: .getEnterpriseModel();
072: EnterpriseClass lEntepriseClass = lEnterpriseModelPackage
073: .getEnterprise();
074: return new EnterpriseUserObject(lEntepriseClass
075: .createEnterprise());
076: }
077:
078: // return object root node captions
079: public String getRootNodeName() {
080: return null;
081: }
082:
083: public Enterprise getEnterprise() {
084: return mEnterprise;
085: }
086:
087: // view systems diagram
088: public void viewSystemsDiagram() {
089: if (mEnterprise == null)
090: return;
091:
092: try {
093: SortedSet lDiagrams = ModelElementUtils
094: .getSetOfModelElementsInAlphabeticalOrder(mEnterprise
095: .getEnterpriseSystemsDiagrams());
096: if (lDiagrams != null) {
097: if (lDiagrams.size() == 0) {
098: EnterpriseSystemsDiagramUserObject lDiagramObject = EnterpriseSystemsDiagramUserObject
099: .addNewEntrpriseEntitiesDiagram(mEnterprise);
100: if (lDiagramObject != null)
101: lDiagramObject.viewSystemsDiagram();
102: } else if (lDiagrams.size() == 1) {
103: EnterpriseSystemsDiagram lDiagram = (EnterpriseSystemsDiagram) lDiagrams
104: .first();
105: Application.fireShowContainer(new SystemsPanel(
106: lDiagram), UserObjectFactory
107: .createUserObject(lDiagram),
108: Application.SYSTEMSDIAGRAM_ICON);
109: } else {
110: ArrayList lDiagramsArray = new ArrayList();
111: for (Iterator lIterator = lDiagrams.iterator(); lIterator
112: .hasNext();) {
113: EnterpriseSystemsDiagram lDiagram = (EnterpriseSystemsDiagram) lIterator
114: .next();
115: lDiagramsArray
116: .add(new EnterpriseSystemsDiagramUserObject(
117: lDiagram));
118: }
119: DiagramSelectDialog lDialog = new DiagramSelectDialog(
120: Application.mainFrame, lDiagramsArray);
121: if (lDialog.getModalResult() == DiagramSelectDialog.MR_OK) {
122: for (int i = 0; i < lDiagramsArray.size(); i++) {
123: EnterpriseSystemsDiagramUserObject lEnterpriseSystemsDiagram = (EnterpriseSystemsDiagramUserObject) lDiagramsArray
124: .get(i);
125: Application
126: .fireShowContainer(
127: new SystemsPanel(
128: lEnterpriseSystemsDiagram
129: .getEnterpriseSystemsDiagram()),
130: lEnterpriseSystemsDiagram,
131: Application.SYSTEMSDIAGRAM_ICON);
132: }
133: }
134: }
135: }
136: } catch (Exception e) {
137: e.printStackTrace();
138: }
139: }
140:
141: // view systems diagram
142: /*public void viewDependencies()
143: {
144: if (mEnterprise==null) return;
145: try
146: {
147: Application.fireShowContainer(new DependencyViewPanel(mEnterprise,2), this, Application.SYSTEMSDIAGRAM_ICON);
148: }
149: catch (Exception e)
150: {
151: e.printStackTrace();
152: }
153: }*/
154:
155: // add new System object
156: public void addNewSystem() throws Exception {
157: SystemUserObject.addNewSystem(mEnterprise);
158: }
159:
160: // add new diagram
161: protected void addNewDiagram() {
162: try {
163: EnterpriseSystemsDiagramUserObject
164: .addNewEntrpriseEntitiesDiagram(mEnterprise);
165: } catch (Throwable t) {
166: Application.processError(t);
167: }
168: }
169:
170: public void fillActionsList(ArrayList pList) {
171: switch (mMode) {
172: case ALL_ACTIONS:
173: super .fillActionsList(pList);
174: pList.add(new SeparatorAction());
175: pList.add(mShowSystemsDiagramAction);
176: pList.add(new SeparatorAction());
177: pList.add(mAddSystemAction);
178: pList.add(mAddDiagramAction);
179: pList.add(new SeparatorAction());
180: pList.add(mShowDataTypeDependenciesAction);
181: break;
182: case SYSTEMS_ACTION:
183: pList.add(mShowSystemsDiagramAction);
184: pList.add(new SeparatorAction());
185: pList.add(mAddSystemAction);
186: pList.add(mAddDiagramAction);
187: pList.add(new SeparatorAction());
188: pList.add(mShowDataTypeDependenciesAction);
189: break;
190: case ADD_DIAGRAM:
191: pList.add(mAddDiagramAction);
192: break;
193: }
194: }
195:
196: // get object editor
197: public BasePropertiesDialog getObjectEditor() {
198: return new SimpleObjectPropertiesdialog("Enterprise");
199: }
200:
201: // load object properties into grid control
202: public void loadObjectProperties(PropertiesTableModel pModel)
203: throws Exception {
204: super .loadObjectProperties(pModel);
205: if (pModel == null || mEnterprise == null)
206: return;
207:
208: addModelElement(pModel, "Design Library", mEnterprise
209: .getDesignLibrary());
210: addModelElement(pModel, "Technology Library", mEnterprise
211: .getTechnologyLibrary());
212: }
213:
214: /* Actions */
215:
216: /* Show Systems diagram */
217:
218: public class ShowSystemsDiagramAction extends BaseAction {
219: public ShowSystemsDiagramAction() {
220: super (Application
221: .getString("view_enterprisesystemsdiagram"),
222: Application.SYSTEMSDIAGRAM_ICON);
223: }
224:
225: public void actionPerformed(ActionEvent arg0) {
226: viewSystemsDiagram();
227: }
228: }
229:
230: /* Add New System Action class */
231:
232: public class AddNewSystemAction extends BaseAction {
233: public AddNewSystemAction() {
234: super ("Add New System", Application
235: .getAddIcon(Application.SYSTEM_ICON));
236: }
237:
238: public void actionPerformed(ActionEvent arg0) {
239: try {
240: addNewSystem();
241: } catch (Throwable t) {
242: t.printStackTrace();
243: }
244: }
245: }
246: }
|