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.propertiesdialogs;
16:
17: import java.awt.Dimension;
18:
19: import javax.swing.JComboBox;
20: import javax.swing.JTextArea;
21: import javax.swing.JTextField;
22:
23: import com.metaboss.applications.designstudio.Application;
24: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
25: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.State;
26: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateType;
27: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateTypeEnum;
28:
29: /* BOState object properties tuning dialog */
30:
31: public class StatePropertiesDialog extends ModelElementPropertiesDialog {
32: private JTextField mNameField = new JTextField();
33: private JTextArea mDescriptionField = new JTextArea(8, 40);
34: private JComboBox mTypeField = new JComboBox();
35:
36: public StatePropertiesDialog() {
37: super ("State", new Dimension(400, 290));
38:
39: mTypeField.addItem(StateTypeEnum.FINAL);
40: mTypeField.addItem(StateTypeEnum.INITIAL);
41: mTypeField.addItem(StateTypeEnum.NORMAL);
42:
43: addTextField(mPropertiesPanel, "Name: ", mNameField, 1, true);
44: addComboBox(mPropertiesPanel, "Type: ", mTypeField, 2, false);
45: addTextArea(mPropertiesPanel, "Description: ",
46: mDescriptionField, 3, false);
47: }
48:
49: // load service module properties
50: public void loadProperties(ModelElement pObject) throws Exception {
51: if (pObject != null && pObject instanceof State) {
52: State lState = (State) pObject;
53: mNameField.setText(lState.getName());
54: mTypeField
55: .setSelectedIndex(findItemIndex(lState.getType()));
56: mDescriptionField.setText(lState.getDescription());
57: }
58: super .loadProperties(pObject);
59: }
60:
61: // save service module proeprties
62: public void saveProperties(ModelElement pObject) throws Exception {
63: super .saveProperties(pObject);
64: if (pObject != null && pObject instanceof State) {
65: State lState = (State) pObject;
66: lState.setName(mNameField.getText());
67: lState.setType((StateType) mTypeField.getSelectedItem());
68: lState.setDescription(mDescriptionField.getText());
69: }
70: }
71:
72: // check fields data
73: public boolean checkProperties() {
74: if (mNameField.getText().length() == 0) {
75: Application.showError("Name field could not be blank!");
76: return false;
77: }
78: return super .checkProperties();
79: }
80:
81: public String getStateName() {
82: return mNameField.getText();
83: }
84:
85: // find message type index
86: private int findItemIndex(StateType pStateType) {
87: for (int i = 0; i < mTypeField.getItemCount(); i++) {
88: StateType lItem = (StateType) mTypeField.getItemAt(i);
89: if (lItem == pStateType)
90: return i;
91: }
92: return -1;
93: }
94: }
|