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.DataDictionary;
024: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Namespace;
025:
026: /* Namespace combobox item class */
027:
028: public class NamespaceItem implements Comparable {
029: // load datatypes into sorted array
030: public static Object[] preloadNamespaces(
031: DataDictionary pDataDictionary, boolean pAddNull) {
032: ArrayList lArray = new ArrayList();
033:
034: if (pAddNull)
035: lArray.add(new NamespaceItem(null));
036:
037: if (pDataDictionary != null) {
038: Object[] lList = pDataDictionary.getSubNamespaces()
039: .toArray();
040: if (lList != null) {
041: for (int i = 0; i < lList.length; i++) {
042: Namespace lNamespace = (Namespace) lList[i];
043: lArray.add(new NamespaceItem(lNamespace));
044: }
045: }
046: }
047:
048: Object[] lResult = lArray.toArray();
049: Arrays.sort(lResult);
050: return lResult;
051: }
052:
053: // load combobox with BODataTypes
054: public static void loadBoxWithNamespaces(JComboBox pComboBox,
055: Object[] pNamespace) {
056: if (pComboBox != null) {
057: pComboBox.removeAllItems();
058: if (pNamespace != null)
059: for (int i = 0; i < pNamespace.length; i++)
060: pComboBox.addItem(pNamespace[i]);
061: }
062: }
063:
064: // find typetemplate index
065: public static int findNamespaceItemIndex(Namespace pNamespace,
066: Object[] pNamespaces) {
067: if (pNamespaces != null) {
068: try {
069: for (int i = 0; i < pNamespaces.length; i++) {
070: NamespaceItem lItem = (NamespaceItem) pNamespaces[i];
071: if (pNamespace == null && lItem.mNamespace == null)
072: return i;
073: else if (pNamespace != null
074: && lItem.toString().equals(
075: pNamespace.getName()))
076: return i;
077: }
078: } catch (Exception e) {
079: e.printStackTrace();
080: }
081: }
082: return -1;
083: }
084:
085: public Namespace mNamespace = null;
086:
087: //constructor
088: public NamespaceItem(Namespace pNamespace) {
089: mNamespace = pNamespace;
090: }
091:
092: public String toString() {
093: String lResult = "";
094: try {
095: if (mNamespace != null)
096: lResult = mNamespace.getName();
097: else
098: lResult = Application.getString("unspecified");
099: } catch (Exception e) {
100: e.printStackTrace();
101: }
102: return lResult;
103: }
104:
105: public int compareTo(Object o) {
106: int lResult = 0;
107: try {
108: if (mNamespace == null || o == null)
109: lResult = -1;
110: else if (mNamespace != null && o != null
111: && o instanceof DatatypeItem)
112: lResult = mNamespace.getName().compareTo(
113: ((TypeTemplateItem) o).mTypeTemplate.getName());
114: } catch (Exception e) {
115: e.printStackTrace();
116: }
117: return lResult;
118: }
119: }
|