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.MetaBossModelPackage;
024: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.TypeTemplate;
025:
026: /* Typetemplate combobox item class */
027:
028: public class TypeTemplateItem implements Comparable {
029: // load datatypes into sorted array
030: /*public static Object[] preloadTypetemplates(DataDictionary pDataDictionary, boolean pAddNull)
031: {
032: ArrayList lArray = new ArrayList();
033:
034: if (pAddNull) lArray.add(new TypetemplateItem(null));
035:
036: if (pDataDictionary!=null)
037: {
038: Object[] lList = pDataDictionary.getTypeTemplates().toArray();
039: if (lList!=null)
040: {
041: for (int i=0; i<lList.length; i++)
042: {
043: TypeTemplate lTypetemplate = (TypeTemplate)lList[i];
044: lArray.add(new TypetemplateItem(lTypetemplate));
045: }
046: }
047: }
048:
049: Object[] lResult = lArray.toArray();
050: Arrays.sort(lResult);
051: return lResult;
052: }*/
053: public static Object[] preloadTypetemplates(
054: MetaBossModelPackage pPackage, boolean pAddNull) {
055: ArrayList lArray = new ArrayList();
056:
057: if (pAddNull)
058: lArray.add(new TypeTemplateItem(null));
059:
060: if (pPackage != null) {
061: int lCount = pPackage.getDataDictionaryModel()
062: .getTypeTemplate().refAllOfClass().size();
063: TypeTemplate[] lList = (TypeTemplate[]) pPackage
064: .getDataDictionaryModel().getTypeTemplate()
065: .refAllOfClass().toArray(new TypeTemplate[lCount]);
066: if (lList != null) {
067: for (int i = 0; i < lList.length; i++) {
068: TypeTemplate lTypetemplate = (TypeTemplate) lList[i];
069: lArray.add(new TypeTemplateItem(lTypetemplate));
070: }
071: }
072: }
073:
074: Object[] lResult = lArray.toArray();
075: Arrays.sort(lResult);
076: return lResult;
077: }
078:
079: // load combobox with BODataTypes
080: public static void loadBoxWithTypetemplates(JComboBox pComboBox,
081: Object[] pTypetemplates) {
082: if (pComboBox != null) {
083: pComboBox.removeAllItems();
084: if (pTypetemplates != null)
085: for (int i = 0; i < pTypetemplates.length; i++)
086: pComboBox.addItem(pTypetemplates[i]);
087: }
088: }
089:
090: // find typetemplate index
091: public static int findTypetemplateItemIndex(
092: TypeTemplate pTypetempalte, Object[] pTypetemplates) {
093: if (pTypetemplates != null) {
094: try {
095: for (int i = 0; i < pTypetemplates.length; i++) {
096: TypeTemplateItem lItem = (TypeTemplateItem) pTypetemplates[i];
097: if (pTypetempalte == null
098: && lItem.mTypeTemplate == null)
099: return i;
100: else if (pTypetempalte != null
101: && lItem.mTypeTemplate != null
102: && lItem.mTypeTemplate
103: .equals(pTypetempalte))
104: return i;
105: }
106: } catch (Exception e) {
107: e.printStackTrace();
108: }
109: }
110: return -1;
111: }
112:
113: public TypeTemplate mTypeTemplate = null;
114:
115: //constructor
116: public TypeTemplateItem(TypeTemplate pTypetemplate) {
117: mTypeTemplate = pTypetemplate;
118: }
119:
120: public String toString() {
121: String lResult = "";
122: try {
123: if (mTypeTemplate != null)
124: lResult = mTypeTemplate.getName();
125: else
126: lResult = Application.getString("unspecified");
127: } catch (Exception e) {
128: e.printStackTrace();
129: }
130: return lResult;
131: }
132:
133: public int compareTo(Object o) {
134: int lResult = 0;
135: try {
136: if (mTypeTemplate == null || o == null)
137: lResult = -1;
138: else if (mTypeTemplate != null && o != null
139: && o instanceof DatatypeItem)
140: lResult = mTypeTemplate.getName().compareTo(
141: ((TypeTemplateItem) o).mTypeTemplate.getName());
142: } catch (Exception e) {
143: e.printStackTrace();
144: }
145: return lResult;
146: }
147: }
|