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:
019: import javax.swing.JComboBox;
020:
021: import com.metaboss.applications.designstudio.Application;
022: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataType;
023: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System;
024:
025: /* DataType combobox item class */
026:
027: public class DatatypeItem implements Comparable {
028: public static Object[] preloadDataTypes(System pSystem,
029: boolean pAddNull) {
030: ArrayList lArray = new ArrayList();
031:
032: if (pAddNull)
033: lArray.add(new DatatypeItem(null));
034:
035: if (pSystem != null) {
036: Object[] lDataTypes = pSystem.getAvailableDatatypes()
037: .toArray();
038: if (lDataTypes.length > 0) {
039: for (int i = 0; i < lDataTypes.length; i++)
040: lArray.add(new DatatypeItem(
041: (DataType) lDataTypes[i]));
042: }
043: }
044: Object[] lResult = lArray.toArray();
045: return lResult;
046: }
047:
048: // load combobox with BODataTypes
049: public static void loadBoxWithDatatypes(JComboBox pComboBox,
050: Object[] pDataTypes) {
051: if (pComboBox != null) {
052: pComboBox.removeAllItems();
053: if (pDataTypes != null)
054: for (int i = 0; i < pDataTypes.length; i++)
055: pComboBox.addItem(pDataTypes[i]);
056: }
057: }
058:
059: // find datatype index
060: public static int findDataTypeItemIndex(DataType lDataType,
061: JComboBox pBox) throws Exception {
062: for (int i = 0; i < pBox.getItemCount(); i++) {
063: DatatypeItem lItem = (DatatypeItem) pBox.getItemAt(i);
064: if (lDataType == null && lItem.mDataType == null)
065: return i;
066: else if (lDataType != null && lItem.mDataType != null
067: && lItem.toString().equals(lDataType.getName()))
068: return i;
069: }
070: return -1;
071: }
072:
073: public DataType mDataType = null;
074:
075: //constructor
076: public DatatypeItem(DataType pDataType) {
077: mDataType = pDataType;
078: }
079:
080: public String toString() {
081: String lResult = "";
082: try {
083: if (mDataType != null)
084: lResult = mDataType.getName();
085: else
086: lResult = Application.getString("unspecified");
087: } catch (Exception e) {
088: e.printStackTrace();
089: }
090: return lResult;
091: }
092:
093: public int compareTo(Object o) {
094: int lResult = 0;
095: try {
096: if (mDataType == null || o == null)
097: lResult = -1;
098: else if (mDataType != null && o != null
099: && o instanceof DatatypeItem)
100: lResult = mDataType.getName().compareTo(
101: ((DatatypeItem) o).mDataType.getName());
102: } catch (Exception e) {
103: e.printStackTrace();
104: }
105: return lResult;
106: }
107: }
|