01: //THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
02: //CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
03: //BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
04: //FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
05: //OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
06: //INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
07: //LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
08: //OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
09: //LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
10: //NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
11: //EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
12: //POSSIBILITY OF SUCH DAMAGE.
13: //
14: //Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
15: package com.metaboss.applications.designstudio.userobjects;
16:
17: import java.util.Iterator;
18: import java.util.SortedSet;
19:
20: import javax.swing.JComboBox;
21:
22: import com.metaboss.applications.designstudio.Application;
23: import com.metaboss.sdlctools.models.metabossmodel.ModelElementUtils;
24: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Event;
25: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EventSubscription;
26:
27: /* Event combobox item class */
28:
29: public class EventItem {
30: // load Entites combobox
31: public static void loadBoxWithEvents(JComboBox pBox,
32: EventSubscription pEventSubscription, boolean pAddNull) {
33: pBox.removeAllItems();
34:
35: if (pAddNull)
36: pBox.addItem(new EventItem(null));
37:
38: if (pEventSubscription != null) {
39: try {
40: SortedSet lEntities = ModelElementUtils
41: .getSetOfModelElementsInAlphabeticalOrder(pEventSubscription
42: .getEvents());
43: if (lEntities.size() > 0)
44: for (Iterator lIterator = lEntities.iterator(); lIterator
45: .hasNext();)
46: pBox.addItem(new EventItem((Event) lIterator
47: .next()));
48: } catch (Exception e) {
49: e.printStackTrace();
50: }
51: }
52: }
53:
54: // find entity index
55: public static int findEventItemIndex(JComboBox pBox, Event pEvent)
56: throws Exception {
57: for (int i = 0; i < pBox.getItemCount(); i++) {
58: EventItem lItem = (EventItem) pBox.getItemAt(i);
59: if (pEvent == null && lItem.mEvent == null)
60: return i;
61: else if (pEvent != null && lItem.mEvent != null
62: && lItem.mEvent.equals(pEvent))
63: return i;
64: }
65: return -1;
66: }
67:
68: public Event mEvent = null;
69:
70: public EventItem(Event pEvent) {
71: mEvent = pEvent;
72: }
73:
74: public String toString() {
75: String lRedult = "";
76: try {
77: if (mEvent != null)
78: lRedult = mEvent.getName();
79: else
80: lRedult = Application.getString("unspecified");
81: } catch (Exception e) {
82: e.printStackTrace();
83: }
84: return lRedult;
85: }
86: }
|