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.Color;
018: import java.awt.Point;
019: import java.util.Map;
020: import java.util.Set;
021:
022: import org.jgraph.graph.DefaultEdge;
023: import org.jgraph.graph.DefaultGraphCell;
024: import org.jgraph.graph.DefaultPort;
025: import org.jgraph.graph.GraphConstants;
026:
027: import com.metaboss.applications.designstudio.Application;
028: import com.metaboss.applications.designstudio.BaseGraphModel;
029: import com.metaboss.applications.designstudio.BaseUserObject;
030: import com.metaboss.applications.designstudio.userobjects.SystemDependencyUserObject;
031: import com.metaboss.applications.designstudio.userobjects.SystemUserObject;
032: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
033: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Enterprise;
034: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System;
035: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.SystemDependency;
036: import com.metaboss.sdlctools.models.metabossmodel.visualmodel.DiagramModelElement;
037: import com.metaboss.sdlctools.models.metabossmodel.visualmodel.EnterpriseSystemsDiagram;
038:
039: /* Systems Diagram Model class */
040:
041: public class SystemsModel extends BaseGraphModel {
042: private boolean mChecking = false;
043:
044: /** Constructor. */
045: public SystemsModel(EnterpriseSystemsDiagram pDiagram)
046: throws Exception {
047: super (pDiagram.getEnterprise(), pDiagram);
048: }
049:
050: // load graph model
051: public void loadModel() throws Exception {
052: super .loadModel();
053:
054: EnterpriseSystemsDiagram lDiagram = (EnterpriseSystemsDiagram) mDiagram;
055: Object[] lElements = lDiagram.getElements().toArray();
056:
057: // systems
058: for (int i = 0; i < lElements.length; i++) {
059: DiagramModelElement lElement = (DiagramModelElement) lElements[i];
060: ModelElement lModelElement = lElement.getModelElement();
061: if (lModelElement != null
062: && lModelElement instanceof System) {
063: System lSystem = (System) lModelElement;
064: addSystemCell(lSystem, getPosition(lSystem));
065: }
066: }
067: // dependency
068: for (int i = 0; i < lElements.length; i++) {
069: DiagramModelElement lElement = (DiagramModelElement) lElements[i];
070: ModelElement lModelElement = lElement.getModelElement();
071: if (lModelElement != null
072: && lModelElement instanceof SystemDependency) {
073: SystemDependency lSystemDependency = (SystemDependency) lModelElement;
074: addDependencyCell(lSystemDependency,
075: loadEdgePoints(lSystemDependency));
076: }
077: }
078: }
079:
080: // add system cell
081: public DefaultGraphCell addSystemCell(System pSystem,
082: Point lPosition) throws Exception {
083: return addVertex(new SystemUserObject(pSystem), lPosition,
084: null, getVertexStyle());
085: }
086:
087: // add dependency cell
088: public void addDependencyCell(SystemDependency pSystemDependency,
089: java.util.List pPoints) {
090: if (pSystemDependency != null) {
091: String lFromID = (pSystemDependency.getClient() != null) ? pSystemDependency
092: .getClient().refMofId()
093: : null;
094: String lToID = (pSystemDependency.getServant() != null) ? pSystemDependency
095: .getServant().refMofId()
096: : null;
097:
098: addEdge(new SystemDependencyUserObject(pSystemDependency),
099: null, pPoints, lFromID, lToID, getDependencyStyle());
100: }
101: }
102:
103: public void removeAllConnectedEdges(BaseUserObject pObject) {
104: Set lEdgesSet = getEdges(this , getUserObjectCells(pObject));
105: Object[] lEdjes = lEdgesSet.toArray();
106: remove(lEdjes);
107: }
108:
109: // return Enterprise
110: public Enterprise getEnterprise() {
111: Object lObject = getBOObject();
112: if (lObject != null && lObject instanceof Enterprise)
113: return (Enterprise) lObject;
114: else
115: return null;
116: }
117:
118: // get diagram interface
119: /*public Diagram getDiaram() throws Exception
120: {
121: Enterprise lEnterprise = getEnterprise();
122: if (lEnterprise!=null)
123: {
124: Object[] lDigrams = lEnterprise.getEnterpriseSystemsDiagrams().toArray();
125: if (lDigrams.length>0)
126: return (Diagram)lDigrams[0];
127: else
128: {
129: Diagram lDiagram = null;
130: Application.beginTransaction();
131: try
132: {
133: lDiagram = getPackage().getVisualModel().getEnterpriseSystemsDiagram().createEnterpriseSystemsDiagram();
134: lDiagram.setName(lEnterprise.getRef()+"EnterpriseSystemsDiagrams");
135: lEnterprise.getEnterpriseSystemsDiagrams().add(lDiagram);
136: Application.commit();
137: }
138: finally
139: {
140: if (Application.isInTransaction()) Application.rollback();
141: }
142: return lDiagram;
143: }
144: }
145: return null;
146: }*/
147:
148: // process cell change
149: protected void processCellChange(DefaultGraphCell pCell) {
150: super .processCellChange(pCell);
151: if (pCell == null || mChecking)
152: return;
153:
154: Object lChangedCellUserObject = pCell.getUserObject();
155: if (lChangedCellUserObject instanceof SystemDependencyUserObject) {
156: SystemDependencyUserObject lDependency = (SystemDependencyUserObject) lChangedCellUserObject;
157: Object lTargetSystemObject = ((DefaultEdge) pCell)
158: .getTarget();
159: Object lSourceSystemObject = ((DefaultEdge) pCell)
160: .getSource();
161:
162: System lTargetSystem = null;
163: System lSourceSystem = null;
164: if (lTargetSystemObject != null) {
165: Object lObject = ((DefaultPort) lTargetSystemObject)
166: .getUserObject();
167: if (lObject != null
168: && lObject instanceof SystemUserObject)
169: lTargetSystem = ((SystemUserObject) (lObject))
170: .getSystem();
171: }
172: if (lSourceSystemObject != null) {
173: Object lObject = ((DefaultPort) lSourceSystemObject)
174: .getUserObject();
175: if (lObject != null
176: && lObject instanceof SystemUserObject)
177: lSourceSystem = ((SystemUserObject) (lObject))
178: .getSystem();
179: }
180:
181: try {
182: lDependency
183: .systemsChanged(lSourceSystem, lTargetSystem);
184: Application.fireRefreshDiagram(mDiagram, lDependency);
185: } catch (Exception e) {
186: e.printStackTrace();
187: }
188: }
189: }
190:
191: // save cell position
192: protected void saveCellPosition(DefaultGraphCell pCell)
193: throws Exception {
194: if (pCell != null) {
195: Object lCellUserObject = pCell.getUserObject();
196: if (lCellUserObject instanceof SystemDependencyUserObject) {
197: SystemDependencyUserObject lDependency = (SystemDependencyUserObject) lCellUserObject;
198: saveEdgePoints(lDependency.getSystemDependency(),
199: GraphConstants.getPoints(pCell.getAttributes()));
200: return;
201: }
202: }
203: super .saveCellPosition(pCell);
204: }
205:
206: public Map getVertexStyle() {
207: Map lVertexStyle = super .getVertexStyle();
208: GraphConstants.setBackground(lVertexStyle, Color.cyan);
209: return lVertexStyle;
210: }
211:
212: /*protected Object[] getVertexesObjects()
213: {
214: Enterprise lEnterprise = getEnterprise();
215: if (lEnterprise!=null) return lEnterprise.getSystems().toArray();
216: return null;
217: }*/
218: }
|