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 javax.swing.Icon;
023:
024: import com.metaboss.applications.designstudio.Application;
025: import com.metaboss.applications.designstudio.BaseAction;
026: import com.metaboss.applications.designstudio.BasePropertiesDialog;
027: import com.metaboss.applications.designstudio.BaseUserObject;
028: import com.metaboss.applications.designstudio.auxilarydialogs.DiagramSelectDialog;
029: import com.metaboss.applications.designstudio.components.SeparatorAction;
030: import com.metaboss.applications.designstudio.propertiesdialogs.SimpleObjectPropertiesdialog;
031: import com.metaboss.applications.designstudio.usecasesmodel.UseCasesPanel;
032: import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
033: import com.metaboss.sdlctools.models.metabossmodel.ModelElementUtils;
034: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemusagemodel.AbstractNamespace;
035: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemusagemodel.NamespaceClass;
036: import com.metaboss.sdlctools.models.metabossmodel.visualmodel.SystemUseCasesDiagram;
037:
038: /* Abstrct namespace user object */
039:
040: public class AbstractNamespaceUserObject extends BaseUserObject {
041: public static final int ADD_NAMESPACE = 1;
042: public static final int ADD_ACTORS = 2;
043: public static final int ADD_USECASE = 3;
044: public static final int ADD_DIAGRAM = 4;
045:
046: private AbstractNamespace mAbstractNamespace = null;
047: private System mMasterSystem = null;
048: private AddNamespaceAction mAddNamespaceAction = new AddNamespaceAction();
049: private AddActorAction mAddActorAction = new AddActorAction();
050: private AddUseCaseAction mAddUseCaseAction = new AddUseCaseAction();
051: private AddDiagramAction mAddDiagramAction = new AddDiagramAction();
052: private UseCaseDiagramAction mUseCaseDiagramAction = new UseCaseDiagramAction();
053:
054: public AbstractNamespaceUserObject(
055: AbstractNamespace pAbstractNamespace) {
056: super (pAbstractNamespace, Application.NAMESPACE_ICON);
057: mAbstractNamespace = pAbstractNamespace;
058: }
059:
060: public AbstractNamespaceUserObject(
061: AbstractNamespace pAbstractNamespace, Icon aIcon) {
062: super (pAbstractNamespace, aIcon);
063: mAbstractNamespace = pAbstractNamespace;
064: }
065:
066: public AbstractNamespaceUserObject(
067: AbstractNamespace pAbstractNamespace, String pCaption,
068: int pMode) {
069: super (pAbstractNamespace, pCaption, pMode);
070: mAbstractNamespace = pAbstractNamespace;
071: }
072:
073: // create new namespace
074: public static void addNewNamespace(AbstractNamespace pNamespace)
075: throws Exception {
076: new AbstractNamespaceUserObject(null).addNewObject(
077: getObjectPackage(pNamespace), pNamespace
078: .getSubNamespaces());
079: }
080:
081: public BaseUserObject createNewObject(MetaBossModelPackage pPackage) {
082: NamespaceClass lClass = pPackage.getEnterpriseModel()
083: .getSystemUsageModel().getNamespace();
084: return new AbstractNamespaceUserObject(lClass.createNamespace());
085: }
086:
087: // return object root node captions
088: public String getRootNodeName() {
089: return Application.getString("namespaces_node");
090: }
091:
092: // get object editor
093: public BasePropertiesDialog getObjectEditor() {
094: return new SimpleObjectPropertiesdialog("Namespace");
095: }
096:
097: // fill actions list
098: public void fillActionsList(ArrayList pList) {
099: switch (mMode) {
100: case ALL_ACTIONS:
101: super .fillActionsList(pList);
102: pList.add(mUseCaseDiagramAction);
103: pList.add(new SeparatorAction());
104: pList.add(mAddNamespaceAction);
105: pList.add(mAddActorAction);
106: pList.add(mAddUseCaseAction);
107: pList.add(mAddDiagramAction);
108: break;
109: case ADD_NAMESPACE:
110: pList.add(mAddNamespaceAction);
111: break;
112: case ADD_ACTORS:
113: pList.add(mAddActorAction);
114: break;
115: case ADD_USECASE:
116: pList.add(mAddUseCaseAction);
117: break;
118: case ADD_DIAGRAM:
119: pList.add(mAddDiagramAction);
120: break;
121: }
122: }
123:
124: // add namespace
125: private void addNamespace() throws Exception {
126: AbstractNamespaceUserObject.addNewNamespace(mAbstractNamespace);
127: }
128:
129: // add actor
130: private void addActor() throws Exception {
131: ActorsUserObject.addNewActor(mAbstractNamespace);
132: }
133:
134: // add use case
135: private void addUseCase() throws Exception {
136: UseCaseUserObject.addNewUseCase(mAbstractNamespace);
137: }
138:
139: // add new diagram
140: protected void addNewDiagram() {
141: try {
142: SystemUseCasesDiagramUserObject
143: .addNewUseCaseDiagram(mAbstractNamespace);
144: } catch (Throwable t) {
145: Application.processError(t);
146: }
147: }
148:
149: // view use cases diagram
150: private void showUseCaseDiagram() {
151: if (mAbstractNamespace == null)
152: return;
153:
154: try {
155: SortedSet lDiagrams = ModelElementUtils
156: .getSetOfModelElementsInAlphabeticalOrder(mAbstractNamespace
157: .getUseCaseDiagrams());
158: if (lDiagrams != null) {
159: if (lDiagrams.size() == 0) {
160: SystemUseCasesDiagramUserObject lDiagramObject = SystemUseCasesDiagramUserObject
161: .addNewUseCaseDiagram(mAbstractNamespace);
162: if (lDiagramObject != null)
163: lDiagramObject.viewDiagram();
164: } else if (lDiagrams.size() == 1) {
165: SystemUseCasesDiagram lDiagram = (SystemUseCasesDiagram) lDiagrams
166: .first();
167: Application.fireShowContainer(new UseCasesPanel(
168: lDiagram), this ,
169: Application.SYSTEMUSECASEDIAGRAM_ICON);
170: } else {
171: ArrayList lDiagramsArray = new ArrayList();
172: for (Iterator lIterator = lDiagrams.iterator(); lIterator
173: .hasNext();) {
174: SystemUseCasesDiagram lDiagram = (SystemUseCasesDiagram) lIterator
175: .next();
176: lDiagramsArray
177: .add(new SystemUseCasesDiagramUserObject(
178: lDiagram));
179: }
180: DiagramSelectDialog lDialog = new DiagramSelectDialog(
181: Application.mainFrame, lDiagramsArray);
182: if (lDialog.getModalResult() == DiagramSelectDialog.MR_OK) {
183: for (int i = 0; i < lDiagramsArray.size(); i++) {
184: SystemUseCasesDiagramUserObject lSystemUseCasesDiagramUserObject = (SystemUseCasesDiagramUserObject) lDiagramsArray
185: .get(i);
186: Application
187: .fireShowContainer(
188: new UseCasesPanel(
189: lSystemUseCasesDiagramUserObject
190: .getServicemoduleStructuresDiagram()),
191: this ,
192: Application.SYSTEMUSECASEDIAGRAM_ICON);
193: }
194: }
195: }
196: }
197: } catch (Exception e) {
198: e.printStackTrace();
199: }
200: }
201:
202: /* Actions */
203:
204: /* Add new Namespace */
205:
206: public class AddNamespaceAction extends BaseAction {
207: public AddNamespaceAction() {
208: super ("Add New Namespace", Application
209: .getAddIcon(Application.NAMESPACE_ICON));
210: }
211:
212: public void actionPerformed(ActionEvent e) {
213: try {
214: addNamespace();
215: } catch (Throwable t) {
216: Application.processError(t);
217: }
218: }
219: }
220:
221: /* Add new Actor */
222:
223: public class AddActorAction extends BaseAction {
224: public AddActorAction() {
225: super ("Add New Actor", Application
226: .getAddIcon(Application.ACTOR_ICON));
227: }
228:
229: public void actionPerformed(ActionEvent e) {
230: try {
231: addActor();
232: } catch (Throwable t) {
233: Application.processError(t);
234: }
235: }
236: }
237:
238: /* Add new Use Case */
239:
240: public class AddUseCaseAction extends BaseAction {
241: public AddUseCaseAction() {
242: super ("Add New Use Case", Application
243: .getAddIcon(Application.USECASE_ICON));
244: }
245:
246: public void actionPerformed(ActionEvent e) {
247: try {
248: addUseCase();
249: } catch (Throwable t) {
250: Application.processError(t);
251: }
252: }
253: }
254:
255: /* Structures Diagram */
256:
257: public class UseCaseDiagramAction extends BaseAction {
258: public UseCaseDiagramAction() {
259: super (Application.getString("view_usecasediagram"),
260: Application.SYSTEMUSECASEDIAGRAM_ICON);
261: }
262:
263: public void actionPerformed(ActionEvent arg0) {
264: showUseCaseDiagram();
265: }
266: }
267: }
|