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 javax.swing.JComboBox;
18:
19: import com.metaboss.applications.designstudio.Application;
20: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Attribute;
21: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Entity;
22:
23: /* Attribute combobox item class */
24:
25: public class AttributeItem {
26: // load Association Roles combobox
27: public static void loadBoxWithAttributes(JComboBox pBox,
28: Entity pEntity, boolean pAddNull) {
29: pBox.removeAllItems();
30:
31: if (pAddNull)
32: pBox.addItem(new AttributeItem(null));
33:
34: if (pEntity != null) {
35: try {
36: Object[] pList = pEntity.getAttributes().toArray();
37: for (int i = 0; i < pList.length; i++)
38: pBox
39: .addItem(new AttributeItem(
40: (Attribute) pList[i]));
41: } catch (Exception e) {
42: e.printStackTrace();
43: }
44: }
45: }
46:
47: // find entity index
48: public static int findAttributeItemIndex(JComboBox pBox,
49: Attribute lAttribute) throws Exception {
50: for (int i = 0; i < pBox.getItemCount(); i++) {
51: AttributeItem lItem = (AttributeItem) pBox.getItemAt(i);
52: if (lAttribute == null && lItem.mAttribute == null)
53: return i;
54: else if (lAttribute != null && lItem.mAttribute != null
55: && lItem.mAttribute.equals(lAttribute))
56: return i;
57: }
58: return -1;
59: }
60:
61: public Attribute mAttribute = null;
62:
63: public AttributeItem(Attribute pAttribute) {
64: mAttribute = pAttribute;
65: }
66:
67: public String toString() {
68: String lRedult = "";
69: try {
70: if (mAttribute != null)
71: lRedult = mAttribute.getName();
72: else
73: lRedult = Application.getString("unspecified");
74: } catch (Exception e) {
75: e.printStackTrace();
76: }
77: return lRedult;
78: }
79: }
|