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.structuresmodel;
016:
017: import java.awt.Point;
018: import java.util.ArrayList;
019:
020: import org.jgraph.graph.DefaultGraphCell;
021:
022: import com.metaboss.applications.designstudio.Application;
023: import com.metaboss.applications.designstudio.BaseGraphModel;
024: import com.metaboss.applications.designstudio.BaseGraphPanel;
025: import com.metaboss.applications.designstudio.BaseUserObject;
026: import com.metaboss.applications.designstudio.userobjects.StructureFieldUserObject;
027: import com.metaboss.applications.designstudio.userobjects.StructureUserObject;
028: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Structure;
029: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.StructureField;
030: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Servicemodule;
031: import com.metaboss.sdlctools.models.metabossmodel.visualmodel.ServicemoduleStructuresDiagram;
032:
033: /* Structure diagram container panel class */
034:
035: public class StructuresPanel extends BaseGraphPanel {
036: public final static int ADD_STRUCTURE = 1;
037:
038: public StructuresPanel(ServicemoduleStructuresDiagram pDiagram)
039: throws Exception {
040: super (pDiagram.getServicemodule(), pDiagram);
041: mGraph.beginUpdate();
042: try {
043: mGraph.setVertexHaveFields(true);
044: } finally {
045: mGraph.stopUpdate(false);
046: }
047: reLoadModel(); //???
048: }
049:
050: public BaseGraphModel createModel() throws Exception {
051: return new StructuresModel(
052: (ServicemoduleStructuresDiagram) mDiagram);
053: }
054:
055: // return service module
056: public Servicemodule getServiceModule() {
057: Object lObject = getBOObject();
058: if (lObject != null && lObject instanceof Servicemodule)
059: return (Servicemodule) lObject;
060: else
061: return null;
062: }
063:
064: protected void processObjectInserted(BaseUserObject pObject)
065: throws Exception {
066: Object[] cells = mModel.getUserObjectCells(pObject);
067: if (cells.length == 0) {
068: if (pObject instanceof StructureUserObject) {
069: Structure lStructure = ((StructureUserObject) pObject)
070: .getStructure();
071: if (lStructure != null
072: && lStructure.getServicemodule().getRef()
073: .equals(getServiceModule().getRef()))
074: ((StructuresModel) mModel).addStructureCell(
075: lStructure, new Point(0, 0));
076: } else if (pObject instanceof StructureFieldUserObject) {
077: Structure lStructure = ((StructureField) pObject
078: .getBOObject()).getOwnerStructure();
079: if (lStructure != null)
080: updateObject(lStructure);
081: }
082: }
083: }
084:
085: protected void processObjectEdited(BaseUserObject pObject)
086: throws Exception {
087: if (pObject instanceof StructureFieldUserObject) {
088: Structure lStructure = ((StructureField) pObject
089: .getBOObject()).getOwnerStructure();
090: if (lStructure != null)
091: updateObject(lStructure);
092: } else
093: super .processObjectEdited(pObject);
094: }
095:
096: protected void processObjectDeleted(
097: Application.ObjectChangedEvent event) throws Exception {
098: /*if (pObject instanceof StructureFieldUserObject)
099: updateAll();
100: else*/
101: super .processObjectDeleted(event);
102: }
103:
104: protected void fillToolBarActions(ArrayList pActionsList) {
105: super .fillToolBarActions(pActionsList);
106: pActionsList.add(new AddStructureAction());
107: }
108:
109: // process selection
110: protected boolean processSelection(int pSelection, int X, int Y) {
111: switch (pSelection) {
112: case ADD_STRUCTURE:
113: addNewStructure(X, Y);
114: return true;
115: }
116: return false;
117: }
118:
119: // insert entity vertex into the model
120: private void addNewStructure(int X, int Y) {
121: try {
122: StructureUserObject lObject = StructureUserObject
123: .addNewStructure(getServiceModule());
124: if (lObject != null)
125: ((StructuresModel) mModel).addStructureCell(lObject
126: .getStructure(), new Point(X, Y));
127: } catch (Exception e) {
128: Application.processError(e);
129: }
130: }
131:
132: // check object excepted by current diagram
133: public boolean isObjectExcepted(BaseUserObject pObject) {
134: boolean lResult = false;
135: if (pObject != null && mModel != null
136: && (pObject instanceof StructureUserObject)) {
137: StructuresModel lModel = (StructuresModel) mModel;
138: DefaultGraphCell lCell = lModel.findElementCell(pObject);
139: if (lCell == null) {
140: StructureUserObject lStructureUserObject = (StructureUserObject) pObject;
141: Structure lStructure = lStructureUserObject
142: .getStructure();
143: if (lStructure != null
144: && lStructure.getServicemodule().equals(
145: lModel.getServiceModule())) {
146: lResult = true;
147: }
148: }
149: }
150: return lResult;
151: }
152:
153: // insert new object into the diagram
154: public void dropObject(BaseUserObject pObject, Point aLocation) {
155: if (pObject == null || mModel == null)
156: return;
157:
158: StructuresModel lModel = (StructuresModel) mModel;
159: if (pObject instanceof StructureUserObject) {
160: StructureUserObject lStructureUserObject = (StructureUserObject) pObject;
161: try {
162: lModel.addStructureCell(lStructureUserObject
163: .getStructure(), aLocation);
164: } catch (Exception e) {
165: e.printStackTrace();
166: }
167: }
168: }
169:
170: /* Actions */
171:
172: /* Add Structure Action */
173:
174: public class AddStructureAction extends BaseSelectionAction {
175: public AddStructureAction() {
176: super (ADD_STRUCTURE, "New Structure",
177: Application.GRAPH_CLASS_ICON);
178: }
179: }
180: }
|