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