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.systemsmodel;
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.Port;
024: import org.jgraph.graph.VertexView;
025:
026: import com.metaboss.applications.designstudio.Application;
027: import com.metaboss.applications.designstudio.BaseGraphModel;
028: import com.metaboss.applications.designstudio.BaseGraphPanel;
029: import com.metaboss.applications.designstudio.BaseUserObject;
030: import com.metaboss.applications.designstudio.components.DesignGraph;
031: import com.metaboss.applications.designstudio.components.VertexCell;
032: import com.metaboss.applications.designstudio.userobjects.SystemDependencyUserObject;
033: import com.metaboss.applications.designstudio.userobjects.SystemUserObject;
034: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Enterprise;
035: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System;
036: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.SystemDependency;
037: import com.metaboss.sdlctools.models.metabossmodel.visualmodel.EnterpriseSystemsDiagram;
038:
039: /* Systems diagram panel class */
040:
041: public class SystemsPanel extends BaseGraphPanel {
042: public final static int ADD_SYSTEM = 1;
043: public final static int ADD_USEDSYSTEM = 2;
044:
045: public SystemsPanel(EnterpriseSystemsDiagram pDiagram)
046: throws Exception {
047: super (pDiagram.getEnterprise(), pDiagram);
048:
049: mGraph.beginUpdate();
050: mLoading = true;
051: try {
052: mGraph.setShowEdgesLabels(false);
053: mViewEdgesCaptionsAction.setChecked(false);
054: } finally {
055: mGraph.stopUpdate(true);
056: mLoading = false;
057: }
058: }
059:
060: public DesignGraph createGraph() throws Exception {
061: return new DesignGraph(mModel) {
062: protected VertexView createVertexView(JGraph graph,
063: CellMapper cm, Object v) {
064: if (((VertexCell) v).getUserObject() instanceof SystemUserObject)
065: return new SystemVertexView(v, this , cm);
066: else
067: return super .createVertexView(graph, cm, v);
068: }
069: };
070: }
071:
072: public BaseGraphModel createModel() throws Exception {
073: return new SystemsModel((EnterpriseSystemsDiagram) mDiagram);
074: }
075:
076: // connect Edges
077: public void connectEdges(Port pFrom, Port pTo) {
078: System lFromSystem = null;
079: System lToSystem = null;
080:
081: if (pFrom != null) {
082: Object lFromObject = ((DefaultGraphCell) pFrom)
083: .getUserObject();
084: if (lFromObject instanceof SystemUserObject)
085: lFromSystem = ((SystemUserObject) lFromObject)
086: .getSystem();
087: }
088: if (pTo != null) {
089: Object lToObject = ((DefaultGraphCell) pTo).getUserObject();
090: if (lToObject instanceof SystemUserObject)
091: lToSystem = ((SystemUserObject) lToObject).getSystem();
092: }
093:
094: SystemDependencyUserObject lDependency = null;
095:
096: switch (mState) {
097: case ADD_USEDSYSTEM:
098: try {
099: lDependency = SystemDependencyUserObject
100: .addSystemDependency(lFromSystem, lToSystem);
101: } catch (Exception e) {
102: Application.processError(e);
103: }
104: setSelection(NO_SELECTION);
105: mGraph.repaint();
106: break;
107: }
108:
109: if (lDependency != null) {
110: try {
111: ((SystemsModel) mModel).addDependencyCell(lDependency
112: .getSystemDependency(), null);
113: } catch (Exception e) {
114: Application.processError(e);
115: }
116: }
117: }
118:
119: // return Enterprise
120: public Enterprise getEnterprise() {
121: Object lObject = getBOObject();
122: if (lObject != null && lObject instanceof Enterprise)
123: return (Enterprise) lObject;
124: else
125: return null;
126: }
127:
128: protected void processObjectInserted(BaseUserObject pObject)
129: throws Exception {
130: Object[] cells = mModel.getUserObjectCells(pObject);
131: if (cells.length == 0) {
132: if (pObject instanceof SystemUserObject) {
133: System lSystem = ((SystemUserObject) pObject)
134: .getSystem();
135: if (lSystem != null
136: && lSystem.getEnterprise().getRef().equals(
137: getEnterprise().getRef()))
138: ((SystemsModel) mModel).addSystemCell(lSystem,
139: new Point(0, 0));
140: } else if (pObject instanceof SystemDependencyUserObject) {
141: SystemDependencyUserObject lDependency = (SystemDependencyUserObject) pObject;
142: ((SystemsModel) mModel).addDependencyCell(lDependency
143: .getSystemDependency(), null);
144: }
145: }
146: }
147:
148: protected void processObjectDeleted(
149: Application.ObjectChangedEvent event) throws Exception {
150: if (event != null) {
151: BaseUserObject lObject = event.getUserObject();
152: if (lObject == null)
153: lObject = mModel
154: .findUserObjectByID(event.getObjectID());
155: if (lObject != null && lObject instanceof SystemUserObject)
156: ((SystemsModel) mModel)
157: .removeAllConnectedEdges(lObject);
158: }
159: super .processObjectDeleted(event);
160: }
161:
162: protected void fillToolBarActions(ArrayList pActionsList) {
163: super .fillToolBarActions(pActionsList);
164: pActionsList.add(new AddSystemAction());
165: pActionsList.add(new AddUsedSystemAction());
166: }
167:
168: // process selection
169: protected boolean processSelection(int pSelection, int X, int Y) {
170: switch (pSelection) {
171: case ADD_SYSTEM:
172: addNewSystem(X, Y);
173: return true;
174: case ADD_USEDSYSTEM:
175: Application.showWarning(Application
176: .getString("selectvertex_message"));
177: return true;
178: }
179: return false;
180: }
181:
182: // insert entity vertex into the model
183: private void addNewSystem(int X, int Y) {
184: try {
185: SystemUserObject lObject = SystemUserObject
186: .addNewSystem(getEnterprise());
187: if (lObject != null)
188: ((SystemsModel) mModel).addSystemCell(lObject
189: .getSystem(), new Point(X, Y));
190: } catch (Exception e) {
191: Application.processError(e);
192: }
193: }
194:
195: // check object excepted by current diagram
196: public boolean isObjectExcepted(BaseUserObject pObject) {
197: boolean lResult = false;
198: if (pObject != null
199: && mModel != null
200: && (pObject instanceof SystemUserObject || pObject instanceof SystemDependencyUserObject)) {
201: SystemsModel lModel = (SystemsModel) mModel;
202: DefaultGraphCell lCell = lModel.findElementCell(pObject);
203: if (lCell == null) {
204: if (pObject instanceof SystemUserObject) {
205: SystemUserObject lSystemUserObject = (SystemUserObject) pObject;
206: System lSystem = lSystemUserObject.getSystem();
207: if (lSystem != null
208: && lSystem.getEnterprise().equals(
209: lModel.getEnterprise())) {
210: lResult = true;
211: }
212: } else if (pObject instanceof SystemDependencyUserObject) {
213: SystemDependencyUserObject lDependencyUserObject = (SystemDependencyUserObject) pObject;
214: SystemDependency lDependency = lDependencyUserObject
215: .getSystemDependency();
216: if (lDependency != null
217: && lDependency.getClient() != null
218: && lDependency.getClient().getEnterprise()
219: .equals(lModel.getEnterprise())) {
220: DefaultGraphCell lCellA = lModel
221: .findElementCell(lDependency
222: .getClient());
223: DefaultGraphCell lCellB = lModel
224: .findElementCell(lDependency
225: .getServant());
226: lResult = (lCellA != null && lCellB != null);
227: }
228: }
229: }
230: }
231: return lResult;
232: }
233:
234: // insert new object into the diagram
235: public void dropObject(BaseUserObject pObject, Point aLocation) {
236: if (pObject == null || mModel == null)
237: return;
238:
239: SystemsModel lModel = (SystemsModel) mModel;
240: if (pObject instanceof SystemUserObject) {
241: SystemUserObject lSystemUserObject = (SystemUserObject) pObject;
242: try {
243: lModel.addSystemCell(lSystemUserObject.getSystem(),
244: aLocation);
245: } catch (Exception e) {
246: e.printStackTrace();
247: }
248: } else if (pObject instanceof SystemDependencyUserObject) {
249: SystemDependencyUserObject lSystemDependencyUserObject = (SystemDependencyUserObject) pObject;
250: try {
251: lModel.addDependencyCell(lSystemDependencyUserObject
252: .getSystemDependency(), null);
253: } catch (Exception e) {
254: e.printStackTrace();
255: }
256: }
257: }
258:
259: /* Actions */
260:
261: /* Add System Action */
262:
263: public class AddSystemAction extends BaseSelectionAction {
264: public AddSystemAction() {
265: super (ADD_SYSTEM, "New System",
266: Application.GRAPH_SYSTEM_ICON);
267: }
268: }
269:
270: /* Add Used System Action */
271:
272: public class AddUsedSystemAction extends BaseSelectionAction {
273: public AddUsedSystemAction() {
274: super (ADD_USEDSYSTEM, "New Dependency",
275: Application.GRAPH_DEPENDENCY_ICON);
276: }
277: }
278: }
|