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 javax.swing.JComboBox;
18:
19: import com.metaboss.applications.designstudio.Application;
20: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.State;
21: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateMachine;
22:
23: /* State combobox item */
24:
25: public class StateItem {
26: // load Association Roles combobox
27: public static void loadBoxWithStates(JComboBox pBox,
28: StateMachine pMachine, boolean pAddNull) {
29: pBox.removeAllItems();
30:
31: if (pAddNull)
32: pBox.addItem(new StateItem(null));
33:
34: if (pMachine != null) {
35: try {
36: Object[] pList = pMachine.getStates().toArray();
37: for (int i = 0; i < pList.length; i++)
38: pBox.addItem(new StateItem((State) pList[i]));
39: } catch (Exception e) {
40: e.printStackTrace();
41: }
42: }
43: }
44:
45: // find entity index
46: public static int findStateItemIndex(JComboBox pBox, State lState)
47: throws Exception {
48: for (int i = 0; i < pBox.getItemCount(); i++) {
49: StateItem lItem = (StateItem) pBox.getItemAt(i);
50: if (lState == null && lItem.mState == null)
51: return i;
52: else if (lState != null && lItem.mState != null
53: && lItem.mState.equals(lState))
54: return i;
55: }
56: return -1;
57: }
58:
59: public State mState = null;
60:
61: public StateItem(State pState) {
62: mState = pState;
63: }
64:
65: public String toString() {
66: String lRedult = "";
67: try {
68: if (mState != null)
69: lRedult = mState.getName();
70: else
71: lRedult = Application.getString("unspecified");
72: } catch (Exception e) {
73: e.printStackTrace();
74: }
75: return lRedult;
76: }
77: }
|