01: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
02: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
03: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
04: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
05: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
06: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
07: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
08: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
09: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
10: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
11: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
12: // POSSIBILITY OF SUCH DAMAGE.
13: //
14: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
15: package com.metaboss.applications.designstudio.userobjects;
16:
17: import java.util.Iterator;
18: import java.util.SortedSet;
19:
20: import javax.swing.JComboBox;
21:
22: import com.metaboss.applications.designstudio.Application;
23: import com.metaboss.sdlctools.models.metabossmodel.ModelElementUtils;
24: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Domain;
25: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Entity;
26:
27: /* Entity combobox item class */
28:
29: public class EntityItem {
30: // load Entites combobox
31: public static void loadBoxWithEntities(JComboBox pBox,
32: Domain pDomain, boolean pAddNull) {
33: pBox.removeAllItems();
34:
35: if (pAddNull)
36: pBox.addItem(new EntityItem(null));
37:
38: if (pDomain != null) {
39: try {
40: SortedSet lEntities = ModelElementUtils
41: .getSetOfModelElementsInAlphabeticalOrder(pDomain
42: .getEntities());
43: if (lEntities.size() > 0)
44: for (Iterator lIterator = lEntities.iterator(); lIterator
45: .hasNext();)
46: pBox.addItem(new EntityItem((Entity) lIterator
47: .next()));
48: } catch (Exception e) {
49: e.printStackTrace();
50: }
51: }
52: }
53:
54: // find entity index
55: public static int findEntityItemIndex(JComboBox pBox, Entity lEntity)
56: throws Exception {
57: for (int i = 0; i < pBox.getItemCount(); i++) {
58: EntityItem lItem = (EntityItem) pBox.getItemAt(i);
59: if (lEntity == null && lItem.mEntity == null)
60: return i;
61: else if (lEntity != null && lItem.mEntity != null
62: && lItem.mEntity.equals(lEntity))
63: return i;
64: }
65: return -1;
66: }
67:
68: public Entity mEntity = null;
69:
70: public EntityItem(Entity pEntity) {
71: mEntity = pEntity;
72: }
73:
74: public String toString() {
75: String lRedult = "";
76: try {
77: if (mEntity != null)
78: lRedult = mEntity.getName();
79: else
80: lRedult = Application.getString("unspecified");
81: } catch (Exception e) {
82: e.printStackTrace();
83: }
84: return lRedult;
85: }
86: }
|