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.usecasesmodel;
016:
017: import java.awt.Point;
018: import java.util.ArrayList;
019:
020: import org.jgraph.JGraph;
021: import org.jgraph.graph.CellMapper;
022: import org.jgraph.graph.DefaultGraphCell;
023: import org.jgraph.graph.VertexView;
024:
025: import com.metaboss.applications.designstudio.Application;
026: import com.metaboss.applications.designstudio.BaseGraphModel;
027: import com.metaboss.applications.designstudio.BaseGraphPanel;
028: import com.metaboss.applications.designstudio.BaseUserObject;
029: import com.metaboss.applications.designstudio.components.DesignGraph;
030: import com.metaboss.applications.designstudio.components.VertexCell;
031: import com.metaboss.applications.designstudio.userobjects.ActorsUserObject;
032: import com.metaboss.applications.designstudio.userobjects.UseCaseUserObject;
033: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemusagemodel.AbstractNamespace;
034: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemusagemodel.Actor;
035: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemusagemodel.UseCase;
036: import com.metaboss.sdlctools.models.metabossmodel.visualmodel.SystemUseCasesDiagram;
037:
038: /* Use cases diagram container panel class */
039:
040: public class UseCasesPanel extends BaseGraphPanel {
041: public final static int ADD_USECASE = 1;
042: public final static int ADD_ACTOR = 2;
043:
044: public UseCasesPanel(SystemUseCasesDiagram pDiagram)
045: throws Exception {
046: super (pDiagram.getUsageSpecificationNamespace(), pDiagram);
047: mGraph.beginUpdate();
048: try {
049: mGraph.setShowClassVertex(false);
050: mGraph.setShowEdgesLabels(false);
051: mViewEdgesCaptionsAction.setChecked(false);
052: } finally {
053: mGraph.stopUpdate(false);
054: }
055: }
056:
057: public DesignGraph createGraph() throws Exception {
058: return new DesignGraph(mModel) {
059: protected VertexView createVertexView(JGraph graph,
060: CellMapper cm, Object v) {
061: if (((VertexCell) v).getUserObject() instanceof UseCaseUserObject)
062: return new UseCaseVertexView(v, this , cm);
063: else if (((VertexCell) v).getUserObject() instanceof ActorsUserObject)
064: return new ActorVertexView(v, this , cm);
065: else
066: return super .createVertexView(graph, cm, v);
067: }
068: };
069: }
070:
071: public BaseGraphModel createModel() throws Exception {
072: return new UseCasesModel((SystemUseCasesDiagram) mDiagram);
073: }
074:
075: // return absract namespace
076: public AbstractNamespace getNamespace() {
077: Object lObject = getBOObject();
078: if (lObject != null && lObject instanceof AbstractNamespace)
079: return (AbstractNamespace) lObject;
080: else
081: return null;
082: }
083:
084: protected void processObjectInserted(BaseUserObject pObject)
085: throws Exception {
086: Object[] cells = mModel.getUserObjectCells(pObject);
087: if (cells.length == 0) {
088: if (pObject instanceof UseCaseUserObject) {
089: UseCase lUseCase = ((UseCaseUserObject) pObject)
090: .getUseCase();
091: if (lUseCase != null
092: && lUseCase.getNamespace().getRef().equals(
093: getNamespace().getRef()))
094: ((UseCasesModel) mModel).addUseCaseCell(lUseCase,
095: new Point(0, 0));
096: } else if (pObject instanceof ActorsUserObject) {
097: Actor lActor = ((ActorsUserObject) pObject).getActor();
098: if (lActor != null
099: && lActor.getNamespace().getRef().equals(
100: getNamespace().getRef()))
101: ((UseCasesModel) mModel).addActorCell(lActor,
102: new Point(0, 0));
103: }
104: }
105: }
106:
107: protected void fillToolBarActions(ArrayList pActionsList) {
108: super .fillToolBarActions(pActionsList);
109:
110: pActionsList.add(new AddActorAction());
111: pActionsList.add(new AddUseCaseAction());
112: }
113:
114: // process selection
115: protected boolean processSelection(int pSelection, int X, int Y) {
116: switch (pSelection) {
117: case ADD_USECASE:
118: addNewUseCase(X, Y);
119: return true;
120: case ADD_ACTOR:
121: addActor(X, Y);
122: return true;
123: }
124: return false;
125: }
126:
127: // insert use case vertex into the model
128: private void addNewUseCase(int X, int Y) {
129: try {
130: UseCaseUserObject lObject = UseCaseUserObject
131: .addNewUseCase(getNamespace());
132: if (lObject != null)
133: ((UseCasesModel) mModel).addUseCaseCell(lObject
134: .getUseCase(), new Point(X, Y));
135: } catch (Exception e) {
136: Application.processError(e);
137: }
138: }
139:
140: // insert actor vertex into the model
141: private void addActor(int X, int Y) {
142: try {
143: ActorsUserObject lObject = ActorsUserObject
144: .addNewActor(getNamespace());
145: if (lObject != null)
146: ((UseCasesModel) mModel).addActorCell(lObject
147: .getActor(), new Point(X, Y));
148: } catch (Exception e) {
149: Application.processError(e);
150: }
151: }
152:
153: // check object excepted by current diagram
154: public boolean isObjectExcepted(BaseUserObject pObject) {
155: boolean lResult = false;
156: if (pObject != null && mModel != null) {
157: UseCasesModel lModel = (UseCasesModel) mModel;
158: DefaultGraphCell lCell = lModel.findElementCell(pObject);
159: if (lCell == null) {
160: if (pObject instanceof UseCaseUserObject) {
161: UseCaseUserObject lUseCaseUserObject = (UseCaseUserObject) pObject;
162: UseCase lUseCase = lUseCaseUserObject.getUseCase();
163: if (lUseCase != null
164: && lUseCase.getNamespace().equals(
165: lModel.getNamespace()))
166: lResult = true;
167: } else if (pObject instanceof ActorsUserObject) {
168: ActorsUserObject lActorsUserObject = (ActorsUserObject) pObject;
169: Actor lActor = lActorsUserObject.getActor();
170: if (lActor != null
171: && lActor.getNamespace().equals(
172: lModel.getNamespace()))
173: lResult = true;
174: }
175: }
176: }
177: return lResult;
178: }
179:
180: // insert new object into the diagram
181: public void dropObject(BaseUserObject pObject, Point aLocation) {
182: if (pObject == null || mModel == null)
183: return;
184:
185: UseCasesModel lModel = (UseCasesModel) mModel;
186: if (pObject instanceof UseCaseUserObject) {
187: UseCaseUserObject lUseCaseUserObject = (UseCaseUserObject) pObject;
188: try {
189: lModel.addUseCaseCell(lUseCaseUserObject.getUseCase(),
190: aLocation);
191: } catch (Exception e) {
192: e.printStackTrace();
193: }
194: } else if (pObject instanceof ActorsUserObject) {
195: ActorsUserObject lActorsUserObject = (ActorsUserObject) pObject;
196: try {
197: lModel.addActorCell(lActorsUserObject.getActor(),
198: aLocation);
199: } catch (Exception e) {
200: e.printStackTrace();
201: }
202: }
203: }
204:
205: /* Actions */
206:
207: /* Add Use Case Action */
208:
209: public class AddUseCaseAction extends BaseSelectionAction {
210: public AddUseCaseAction() {
211: super (ADD_USECASE, "New Use Case", Application.USECASE_ICON);
212: }
213: }
214:
215: /* Add Actor Action */
216:
217: public class AddActorAction extends BaseSelectionAction {
218: public AddActorAction() {
219: super (ADD_ACTOR, "New Actor", Application.ACTOR_ICON);
220: }
221: }
222: }
|