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