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.MetaBossModelPackage;
023: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Structure;
024:
025: /* Structure combobox item */
026:
027: public class StructureItem {
028: /*public static Object[] preloadStructures(Servicemodule pServiceModule, boolean pAddNull)
029: {
030: ArrayList lArray = new ArrayList();
031:
032: if (pAddNull) lArray.add(new StructureItem(null));
033:
034: if (pServiceModule!=null)
035: {
036: try
037: {
038: Object[] pList = pServiceModule.getStructures().toArray();
039: for (int i=0; i<pList.length; i++)
040: lArray.add(new StructureItem((Structure)pList[i]));
041: }
042: catch (Exception e)
043: {
044: e.printStackTrace();
045: }
046: }
047:
048: return lArray.toArray();
049: }*/
050:
051: public static Object[] preloadStructures(
052: MetaBossModelPackage pPackage, boolean pAddNull) {
053: int lCount = pPackage.getDataDictionaryModel().getStructure()
054: .refAllOfClass().size();
055: ArrayList lArray = new ArrayList();
056:
057: if (pAddNull)
058: lArray.add(new StructureItem(null));
059:
060: if (lCount > 0) {
061: Structure[] lStructures = (Structure[]) pPackage
062: .getDataDictionaryModel().getStructure()
063: .refAllOfClass().toArray(new Structure[lCount]);
064: if (lStructures.length > 0) {
065: for (int i = 0; i < lStructures.length; i++)
066: lArray.add(new StructureItem(lStructures[i]));
067: }
068: }
069:
070: return lArray.toArray();
071: }
072:
073: // load Structures combobox
074: public static void loadBoxWithStructures(JComboBox pComboBox,
075: Object[] pEntities) {
076: if (pComboBox != null) {
077: pComboBox.removeAllItems();
078: if (pEntities != null)
079: for (int i = 0; i < pEntities.length; i++)
080: pComboBox.addItem(pEntities[i]);
081: }
082: }
083:
084: // find datatype index
085: public static int findStructureItemIndex(Structure lStructure,
086: JComboBox pBox) throws Exception {
087: for (int i = 0; i < pBox.getItemCount(); i++) {
088: StructureItem lItem = (StructureItem) pBox.getItemAt(i);
089: if (lStructure == null && lItem.mStructure == null)
090: return i;
091: else if (lStructure != null && lItem.mStructure != null
092: && lItem.toString().equals(lStructure.getName()))
093: return i;
094: }
095: return -1;
096: }
097:
098: public Structure mStructure = null;
099:
100: public StructureItem(Structure pStructure) {
101: mStructure = pStructure;
102: }
103:
104: public String toString() {
105: String lRedult = "";
106: try {
107: if (mStructure != null)
108: lRedult = mStructure.getName();
109: else
110: lRedult = Application.getString("unspecified");
111: } catch (Exception e) {
112: e.printStackTrace();
113: }
114: return lRedult;
115: }
116: }
|