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.userobjects;
016:
017: import java.util.ArrayList;
018: import java.util.Arrays;
019:
020: import javax.swing.JComboBox;
021:
022: import com.metaboss.applications.designstudio.Application;
023: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.PropertyDescriptor;
024: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.TypeTemplate;
025:
026: /* Property combobox item class */
027:
028: public class PropertyDescriptorItem implements Comparable {
029: // load datatypes into sorted array
030: public static Object[] preloadProperties(
031: TypeTemplate pTypeTemplate, boolean pAddNull) {
032: ArrayList lArray = new ArrayList();
033:
034: if (pAddNull)
035: lArray.add(new PropertyDescriptorItem(null));
036:
037: if (pTypeTemplate != null) {
038: Object[] lList = pTypeTemplate.getPropertyDescriptors()
039: .toArray();
040: if (lList != null) {
041: for (int i = 0; i < lList.length; i++) {
042: PropertyDescriptor lProperty = (PropertyDescriptor) lList[i];
043: lArray.add(new PropertyDescriptorItem(lProperty));
044: }
045: }
046: }
047:
048: Object[] lResult = lArray.toArray();
049: Arrays.sort(lResult);
050: return lResult;
051: }
052:
053: public static Object[] preloadProperties(
054: PropertyDescriptor pPropertyDescriptor, boolean pAddNull) {
055: ArrayList lArray = new ArrayList();
056:
057: if (pAddNull)
058: lArray.add(new PropertyDescriptorItem(null));
059:
060: if (pPropertyDescriptor != null) {
061: Object[] lList = pPropertyDescriptor
062: .getSubPropertyDescriptors().toArray();
063: if (lList != null) {
064: for (int i = 0; i < lList.length; i++) {
065: PropertyDescriptor lProperty = (PropertyDescriptor) lList[i];
066: lArray.add(new PropertyDescriptorItem(lProperty));
067: }
068: }
069: }
070:
071: Object[] lResult = lArray.toArray();
072: Arrays.sort(lResult);
073: return lResult;
074: }
075:
076: // load combobox with BODataTypes
077: public static void loadBoxWithProperties(JComboBox pComboBox,
078: Object[] pProperties) {
079: if (pComboBox != null) {
080: pComboBox.removeAllItems();
081: if (pProperties != null)
082: for (int i = 0; i < pProperties.length; i++)
083: pComboBox.addItem(pProperties[i]);
084: }
085: }
086:
087: // find typetemplate index
088: public static int findPropertyItemIndex(
089: PropertyDescriptor pProperty, Object[] pProperties) {
090: if (pProperties != null) {
091: try {
092: for (int i = 0; i < pProperties.length; i++) {
093: PropertyDescriptorItem lItem = (PropertyDescriptorItem) pProperties[i];
094: if (pProperty == null && lItem.mProperty == null)
095: return i;
096: else if (pProperty != null
097: && lItem.mProperty.equals(pProperty))
098: return i;
099: }
100: } catch (Exception e) {
101: e.printStackTrace();
102: }
103: }
104: return -1;
105: }
106:
107: public PropertyDescriptor mProperty = null;
108:
109: //constructor
110: public PropertyDescriptorItem(PropertyDescriptor pProperty) {
111: mProperty = pProperty;
112: }
113:
114: public String toString() {
115: String lResult = "";
116: try {
117: if (mProperty != null)
118: lResult = mProperty.getName();
119: else
120: lResult = Application.getString("unspecified");
121: } catch (Exception e) {
122: e.printStackTrace();
123: }
124: return lResult;
125: }
126:
127: public int compareTo(Object o) {
128: int lResult = 0;
129: try {
130: if (mProperty == null || o == null)
131: lResult = -1;
132: else if (mProperty != null && o != null
133: && o instanceof DatatypeItem)
134: lResult = mProperty.getName().compareTo(
135: ((PropertyDescriptorItem) o).mProperty
136: .getName());
137: } catch (Exception e) {
138: e.printStackTrace();
139: }
140: return lResult;
141: }
142: }
|