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.complexfield;
16:
17: import java.awt.event.KeyAdapter;
18: import java.awt.event.KeyEvent;
19:
20: import javax.swing.JComboBox;
21:
22: import com.metaboss.applications.designstudio.Application;
23: import com.metaboss.applications.designstudio.BaseUserObject;
24: import com.metaboss.applications.designstudio.userobjects.UserObjectFactory;
25: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
26:
27: /* Complex Combobox class UI */
28:
29: public class ComplexBox extends JComboBox {
30: private String mCaption = null;
31: private boolean mLoading = false;
32:
33: public ComplexBox() {
34: this (null);
35: }
36:
37: public ComplexBox(String pCaption) {
38: super ();
39:
40: mCaption = pCaption;
41: setUI(new ComplexBoxUI());
42:
43: addKeyListener(new KeyAdapter() {
44: public void keyPressed(KeyEvent e) {
45: super .keyPressed(e);
46: if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE) {
47: setSelectedModelElement(null);
48: }
49: }
50: });
51: }
52:
53: public BaseUserObject getSelectedUserObject() {
54: Object lObject = getSelectedItem();
55: if (lObject != null && lObject instanceof BaseUserObject)
56: return (BaseUserObject) lObject;
57: else
58: return null;
59: }
60:
61: public ModelElement getSelectedModelElement() {
62: Object lObject = getSelectedItem();
63: if (lObject != null && lObject instanceof BaseUserObject)
64: return ((BaseUserObject) lObject).getBOObject();
65: else
66: return null;
67: }
68:
69: public void setSelectedModelElement(ModelElement pModelElement) {
70: mLoading = true;
71: try {
72: removeAllItems();
73: BaseUserObject lObject = UserObjectFactory
74: .createUserObject(pModelElement);
75: if (lObject != null)
76: addItem(lObject);
77: else
78: addItem(Application.getString("unspecified"));
79: } finally {
80: mLoading = false;
81: }
82: setSelectedIndex(0);
83: //selectedItemChanged();
84: }
85:
86: protected void selectedItemChanged() {
87: if (!mLoading)
88: super .selectedItemChanged();
89: }
90:
91: public ComplexSelectDialog createSelectDialog() {
92: return null;
93: }
94:
95: public String getCaption() {
96: return mCaption;
97: }
98: }
|