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.propertiesdialogs;
016:
017: import java.awt.BorderLayout;
018: import java.awt.Dimension;
019: import java.awt.event.ActionEvent;
020:
021: import javax.swing.JCheckBox;
022: import javax.swing.JComboBox;
023: import javax.swing.JPanel;
024: import javax.swing.JScrollPane;
025: import javax.swing.JTextArea;
026: import javax.swing.JToolBar;
027: import javax.swing.ListSelectionModel;
028: import javax.swing.border.Border;
029: import javax.swing.event.ListSelectionEvent;
030: import javax.swing.event.ListSelectionListener;
031:
032: import com.metaboss.applications.designstudio.Application;
033: import com.metaboss.applications.designstudio.BaseAction;
034: import com.metaboss.applications.designstudio.components.FieldsTable;
035: import com.metaboss.applications.designstudio.constraintstable.ConstraintsTableModel;
036: import com.metaboss.applications.designstudio.fieldstable.FieldsEditPanel;
037: import com.metaboss.applications.designstudio.userobjects.ModelElementConstraintUserObject;
038: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
039: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Operation;
040: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.TransactionPolicy;
041: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.TransactionPolicyEnum;
042:
043: /* BOOperation proeprties tuning dialog class */
044:
045: public class OperationPropertiesDialog extends
046: ModelElementPropertiesDialog {
047: private Operation mOperation = null;
048: // UI constrols
049: private FieldsEditPanel mInputFieldsPanel = new FieldsEditPanel(1);
050: private FieldsEditPanel mOutputFieldsPanel = new FieldsEditPanel(2);
051: private FieldsEditPanel mOutputMessagesPanel = new FieldsEditPanel(
052: 3);
053: private JPanel mConstraintsPanel = new JPanel();
054: // properties
055: private JComboBox mPolicyField = new JComboBox();
056: private JTextArea mDescriptionField = new JTextArea(8, 40);
057: private JCheckBox mIsQueryCheckBox = new JCheckBox();
058: //constraints
059: private ConstraintsTableModel mConstraintsTableModel = new ConstraintsTableModel();
060: private FieldsTable mConstraintsTable = new FieldsTable(
061: mConstraintsTableModel);
062: private JToolBar mConstraintsToolBar = new JToolBar();
063: //actions
064: private AddConstraintAction mAddConstraintAction = new AddConstraintAction();
065: private EditConstraintAction mEditConstraintAction = new EditConstraintAction();
066: private DeleteConstraintAction mDeleteConstraintAction = new DeleteConstraintAction();
067:
068: public OperationPropertiesDialog() {
069: super ("Operation", new Dimension(450, 320));
070:
071: mConstraintsPanel.setLayout(new BorderLayout());
072:
073: mPolicyField.addItem(TransactionPolicyEnum.MANDATORY);
074: mPolicyField.addItem(TransactionPolicyEnum.NEVER);
075: mPolicyField.addItem(TransactionPolicyEnum.NOT_SUPPORTED);
076: mPolicyField.addItem(TransactionPolicyEnum.REQUIRED);
077: mPolicyField.addItem(TransactionPolicyEnum.REQUIRED_NEW);
078: mPolicyField.addItem(TransactionPolicyEnum.SUPPORTED);
079:
080: addTextField(mPropertiesPanel, "Name: ", mNameField, 1, true);
081: addComboBox(mPropertiesPanel, "Transaction Policy: ",
082: mPolicyField, 2, false);
083: addTextArea(mPropertiesPanel, "Description: ",
084: mDescriptionField, 3, false);
085: addCheckBox(mPropertiesPanel, "- is query", mIsQueryCheckBox,
086: 4, false);
087: //constraints
088: mConstraintsPanel.add(new JScrollPane(mConstraintsTable),
089: BorderLayout.CENTER);
090: mConstraintsPanel.add(mConstraintsToolBar, BorderLayout.SOUTH);
091:
092: mConstraintsTable.setCellSelectionEnabled(true);
093: mConstraintsTable.setRowSelectionAllowed(true);
094: mConstraintsTable.setColumnSelectionAllowed(false);
095: mConstraintsTable
096: .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
097:
098: mConstraintsToolBar.setBorder(null);
099: mConstraintsToolBar.add(Application
100: .createButton(mAddConstraintAction));
101: mConstraintsToolBar.add(Application
102: .createButton(mEditConstraintAction));
103: mConstraintsToolBar.add(Application
104: .createButton(mDeleteConstraintAction));
105:
106: Border lBorder = createEditorBorder();
107: mConstraintsPanel.setBorder(lBorder);
108:
109: mTabControl.insertTab("Input Fields", null, mInputFieldsPanel,
110: null, 1);
111: mTabControl.insertTab("Input Constraints", null,
112: mConstraintsPanel, null, 2);
113: mTabControl.insertTab("Output Fields", null,
114: mOutputFieldsPanel, null, 3);
115: mTabControl.insertTab("Output Messages", null,
116: mOutputMessagesPanel, null, 4);
117: }
118:
119: // load service module properties
120: public void loadProperties(ModelElement pObject) throws Exception {
121: mOperation = null;
122: if (pObject != null && pObject instanceof Operation) {
123: mOperation = (Operation) pObject;
124:
125: mNameField.setText(mOperation.getName());
126: mPolicyField.setSelectedIndex(findPolicyIndex(mOperation
127: .getTransactionPolicy()));
128: mDescriptionField.setText(mOperation.getDescription());
129: mIsQueryCheckBox.setSelected(mOperation.isQuery());
130:
131: mInputFieldsPanel.loadFields(mOperation);
132: mOutputFieldsPanel.loadFields(mOperation);
133: mOutputMessagesPanel.loadFields(mOperation);
134: mConstraintsTableModel.loadConstraints(mOperation,
135: mOperation.getInputConstraints().toArray());
136: }
137:
138: checkActions();
139: mConstraintsTable.getSelectionModel().addListSelectionListener(
140: new ListSelectionListener() {
141: public void valueChanged(ListSelectionEvent e) {
142: checkActions();
143: }
144: });
145:
146: super .loadProperties(pObject);
147: }
148:
149: // save service module proeprties
150: public void saveProperties(ModelElement pObject) throws Exception {
151: super .saveProperties(pObject);
152: if (pObject != null && pObject instanceof Operation) {
153: Operation lOperation = (Operation) pObject;
154: lOperation.setName(mNameField.getText());
155: lOperation
156: .setTransactionPolicy((TransactionPolicy) mPolicyField
157: .getSelectedItem());
158: lOperation.setDescription(mDescriptionField.getText());
159: lOperation.setQuery(mIsQueryCheckBox.isSelected());
160: }
161: }
162:
163: // check fields data
164: public boolean checkProperties() {
165: if (mNameField.getText().length() == 0) {
166: Application.showError("Name field could not be blank!");
167: return false;
168: }
169: return super .checkProperties();
170: }
171:
172: // find message type index
173: private int findPolicyIndex(TransactionPolicy pPolicy) {
174: for (int i = 0; i < mPolicyField.getItemCount(); i++) {
175: TransactionPolicy lItem = (TransactionPolicy) mPolicyField
176: .getItemAt(i);
177: if (lItem.equals(pPolicy))
178: return i;
179: }
180: return -1;
181: }
182:
183: // add attribute
184: private void addConstraint() {
185: if (mOperation != null) {
186: try {
187: ModelElementConstraintUserObject
188: .addNewConstraint(mOperation);
189: } catch (Exception e) {
190: Application.processError(e);
191: }
192: }
193: }
194:
195: // edit current attribute
196: private void editConstraint() {
197: ModelElementConstraintUserObject lConstraint = mConstraintsTableModel
198: .getConstraint(mConstraintsTable.getSelectedRow());
199: if (lConstraint != null)
200: lConstraint.getEditAction().run();
201: }
202:
203: // delete Attribute
204: private void deleteConstraint() {
205: ModelElementConstraintUserObject lConstraint = mConstraintsTableModel
206: .getConstraint(mConstraintsTable.getSelectedRow());
207: if (lConstraint != null)
208: lConstraint.getDeleteAction().run();
209: }
210:
211: // check edit actins
212: private void checkActions() {
213: boolean lConstraintEditOk = mConstraintsTable != null
214: && mConstraintsTable.getSelectedRow() > -1;
215:
216: mAddConstraintAction.setEnabled(true);
217: mEditConstraintAction.setEnabled(lConstraintEditOk);
218: mDeleteConstraintAction.setEnabled(lConstraintEditOk);
219: }
220:
221: /* Actions */
222:
223: public class AddConstraintAction extends BaseAction {
224: public AddConstraintAction() {
225: super ("Add New Constraint", Application.ADDNEW_ICON);
226: }
227:
228: public void actionPerformed(ActionEvent arg0) {
229: addConstraint();
230: }
231: }
232:
233: public class EditConstraintAction extends BaseAction {
234: public EditConstraintAction() {
235: super ("Edit Constraint", Application.EDIT_ICON);
236: }
237:
238: public void actionPerformed(ActionEvent arg0) {
239: editConstraint();
240: }
241: }
242:
243: public class DeleteConstraintAction extends BaseAction {
244: public DeleteConstraintAction() {
245: super ("Delete Constraint", Application.DELETE_ICON);
246: }
247:
248: public void actionPerformed(ActionEvent arg0) {
249: deleteConstraint();
250: }
251: }
252: }
|