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.structuresfield;
016:
017: import java.util.Collection;
018: import java.util.Iterator;
019: import java.util.SortedSet;
020:
021: import javax.swing.tree.DefaultMutableTreeNode;
022:
023: import com.metaboss.applications.designstudio.Application;
024: import com.metaboss.applications.designstudio.complexfield.ComplexModel;
025: import com.metaboss.applications.designstudio.userobjects.DataDictionaryUserObject;
026: import com.metaboss.applications.designstudio.userobjects.NamespaceUserObject;
027: import com.metaboss.applications.designstudio.userobjects.ServicemoduleUserObject;
028: import com.metaboss.applications.designstudio.userobjects.StructureUserObject;
029: import com.metaboss.applications.designstudio.userobjects.SystemUserObject;
030: import com.metaboss.sdlctools.models.metabossmodel.ModelElementUtils;
031: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataDictionary;
032: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Namespace;
033: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Structure;
034: import com.metaboss.sdlctools.models.metabossmodel.designlibrarymodel.DesignLibrary;
035: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Servicemodule;
036: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System;
037:
038: /* Structure selection tree model */
039:
040: public class StructuresModel extends ComplexModel {
041: public StructuresModel() {
042: super ();
043: }
044:
045: public void loadModel(System pSystem, DesignLibrary pDesignLibrary) {
046: mList.clear();
047: if (root != null)
048: ((DefaultMutableTreeNode) root).removeAllChildren();
049:
050: root = new DefaultMutableTreeNode("root", true);
051: if (pSystem != null) {
052: addCurrentSystemNode((DefaultMutableTreeNode) root, pSystem);
053: addUsedSystemsNode((DefaultMutableTreeNode) root, pSystem);
054: // design library
055: DesignLibrary lDesignLibrary = pSystem.getEnterprise()
056: .getDesignLibrary();
057: if (lDesignLibrary != null)
058: addDesignLibraryNode((DefaultMutableTreeNode) root,
059: lDesignLibrary, true);
060: } else if (pDesignLibrary != null) {
061: addDesignLibraryNode((DefaultMutableTreeNode) root,
062: pDesignLibrary, true);
063: }
064: reload();
065: }
066:
067: private void addCurrentSystemNode(
068: DefaultMutableTreeNode pParentNode, System pSystem) {
069: DefaultMutableTreeNode lSystemNode = new DefaultMutableTreeNode(
070: new SystemUserObject(pSystem), true);
071: addNode(pParentNode, lSystemNode);
072:
073: // add system services tree
074: SortedSet lServiceModules = ModelElementUtils
075: .getSetOfModelElementsInAlphabeticalOrder(pSystem
076: .getServicemodules());
077: if (lServiceModules.size() > 0)
078: addServiceModulesNodes(lSystemNode, lServiceModules);
079:
080: // add system DataDictionary nodes
081: DataDictionary lSystemDataDictionary = pSystem
082: .getDataDictionary();
083: if (lSystemDataDictionary != null)
084: addDataDictionaryNodes(lSystemNode, lSystemDataDictionary);
085: }
086:
087: /* Helper. Adds Service Modules nodes */
088: protected void addServiceModulesNodes(
089: DefaultMutableTreeNode pParentNode,
090: SortedSet pServiceModules) {
091: for (Iterator lIterator = pServiceModules.iterator(); lIterator
092: .hasNext();) {
093: Servicemodule lServicemodule = (Servicemodule) lIterator
094: .next();
095: Collection lServicemoduleStructures = lServicemodule
096: .getStructures();
097: // Only add nodes if there are some structures inside
098: if (!lServicemoduleStructures.isEmpty()) {
099: DefaultMutableTreeNode lServicemoduleNode = new DefaultMutableTreeNode(
100: new ServicemoduleUserObject(lServicemodule),
101: true);
102: addNode(pParentNode, lServicemoduleNode);
103:
104: // structures
105: SortedSet lStructures = ModelElementUtils
106: .getSetOfModelElementsInAlphabeticalOrder(lServicemoduleStructures);
107: if (lStructures.size() > 0)
108: addStructuresNodes(lServicemoduleNode, lStructures);
109: }
110: }
111: }
112:
113: /* Helper. Add Structures tree */
114: protected void addStructuresNodes(
115: DefaultMutableTreeNode pParentNode, SortedSet pStructures) {
116: for (Iterator lIterator = pStructures.iterator(); lIterator
117: .hasNext();) {
118: Structure lStructure = (Structure) lIterator.next();
119: DefaultMutableTreeNode lNode = new DefaultMutableTreeNode(
120: new StructureUserObject(lStructure), true);
121: addNode(pParentNode, lNode);
122: }
123: }
124:
125: private void addUsedSystemsNode(DefaultMutableTreeNode pParentNode,
126: System pSystem) {
127: SortedSet lSystems = ModelElementUtils
128: .getSetOfModelElementsInAlphabeticalOrder(pSystem
129: .getServants());
130: if (lSystems.size() > 0) {
131: DefaultMutableTreeNode lSystemsNode = new DefaultMutableTreeNode(
132: Application.getString("usedsystems_node"), true);
133: ;
134: pParentNode.add(lSystemsNode);
135: mList.add(lSystemsNode);
136:
137: for (Iterator lIterator = lSystems.iterator(); lIterator
138: .hasNext();) {
139: System lSystem = (System) lIterator.next();
140: addCurrentSystemNode(lSystemsNode, lSystem);
141: }
142: }
143: }
144:
145: // add DataDictionary object nodes
146: protected void addDataDictionaryNodes(
147: DefaultMutableTreeNode pParentNode,
148: DataDictionary pDictionary) {
149: // Only add nodes if there are some structures inside
150: if (!pDictionary.getCombinedStructures().isEmpty()) {
151: DefaultMutableTreeNode lDictionaryNode = new DefaultMutableTreeNode(
152: new DataDictionaryUserObject(pDictionary), true);
153: pParentNode.add(lDictionaryNode);
154:
155: // namespaces
156: SortedSet lNameSpaces = ModelElementUtils
157: .getSetOfModelElementsInAlphabeticalOrder(pDictionary
158: .getSubNamespaces());
159: if (lNameSpaces.size() > 0)
160: addNameSpacesNodes(lDictionaryNode, lNameSpaces);
161:
162: // structures
163: Collection lStructures = sortCollection(pDictionary
164: .getStructures());
165: if (lStructures.size() > 0)
166: addStructuresNodes(lDictionaryNode, lStructures);
167: }
168: }
169:
170: // add NameSpaces nodes
171: protected void addNameSpacesNodes(
172: DefaultMutableTreeNode pParentNode, SortedSet pNameSpaces) {
173: for (Iterator lIterator = pNameSpaces.iterator(); lIterator
174: .hasNext();) {
175: Namespace lNameSpace = (Namespace) lIterator.next();
176: // Only add nodes if there are some structures inside
177: if (!lNameSpace.getCombinedStructures().isEmpty()) {
178: DefaultMutableTreeNode lNode = new DefaultMutableTreeNode(
179: new NamespaceUserObject(lNameSpace), true);
180: addNode(pParentNode, lNode);
181:
182: // namespaces
183: SortedSet lNameSpaces = ModelElementUtils
184: .getSetOfModelElementsInAlphabeticalOrder(lNameSpace
185: .getSubNamespaces());
186: if (lNameSpaces.size() > 0)
187: addNameSpacesNodes(lNode, lNameSpaces);
188: // structures
189: Collection lStructures = sortCollection(lNameSpace
190: .getStructures());
191: if (lStructures.size() > 0)
192: addStructuresNodes(lNode, lStructures);
193: }
194: }
195: }
196:
197: /* Helper. Add Structures tree */
198: protected void addStructuresNodes(
199: DefaultMutableTreeNode pParentNode, Collection pStructures) {
200: for (Iterator lIterator = pStructures.iterator(); lIterator
201: .hasNext();) {
202: Structure lStructure = (Structure) lIterator.next();
203: DefaultMutableTreeNode lNode = new DefaultMutableTreeNode(
204: new StructureUserObject(lStructure), true);
205: pParentNode.add(lNode);
206: }
207: }
208: }
|