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.JTextField;
025: import javax.swing.JToolBar;
026: import javax.swing.ListSelectionModel;
027: import javax.swing.border.Border;
028: import javax.swing.event.ListSelectionEvent;
029: import javax.swing.event.ListSelectionListener;
030:
031: import com.metaboss.applications.designstudio.Application;
032: import com.metaboss.applications.designstudio.BaseAction;
033: import com.metaboss.applications.designstudio.components.FieldsTable;
034: import com.metaboss.applications.designstudio.constraintstable.ConstraintsTableModel;
035: import com.metaboss.applications.designstudio.fieldstable.FieldsEditPanel;
036: import com.metaboss.applications.designstudio.userobjects.ModelElementConstraintUserObject;
037: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
038: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Structure;
039:
040: /* Structure properties dialog */
041:
042: public class StructurePropertiesDialog extends
043: ModelElementPropertiesDialog {
044: private Structure mStructure = null;
045: // UI constrols
046: private FieldsEditPanel mFieldsPanel = new FieldsEditPanel();
047: private JPanel mConstraintsPanel = new JPanel();
048: //constraints
049: private ConstraintsTableModel mConstraintsTableModel = new ConstraintsTableModel();
050: private FieldsTable mConstraintsTable = new FieldsTable(
051: mConstraintsTableModel);
052: private JToolBar mConstraintsToolBar = new JToolBar();
053: // properties
054: private JTextField mNameField = new JTextField();
055: private JTextArea mDescriptionField = new JTextArea(8, 40);
056: // actions
057: private AddConstraintAction mAddConstraintAction = new AddConstraintAction();
058: private EditConstraintAction mEditConstraintAction = new EditConstraintAction();
059: private DeleteConstraintAction mDeleteConstraintAction = new DeleteConstraintAction();
060:
061: public StructurePropertiesDialog() {
062: super ("Structure", new Dimension(420, 320));
063:
064: mConstraintsPanel.setLayout(new BorderLayout());
065:
066: // properties
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("Fields", null, mFieldsPanel, null, 1);
093: mTabControl.insertTab("Constraints", null, mConstraintsPanel,
094: null, 2);
095: }
096:
097: // load entity properties
098: public void loadProperties(ModelElement pObject) throws Exception {
099: mStructure = null;
100: if (pObject != null && pObject instanceof Structure) {
101: mStructure = (Structure) pObject;
102:
103: mNameField.setText(mStructure.getName());
104: mDescriptionField.setText(mStructure.getDescription());
105:
106: mFieldsPanel.loadFields(mStructure);
107: mConstraintsTableModel.loadConstraints(mStructure,
108: mStructure.getConstraints().toArray());
109: }
110:
111: checkActions();
112: mConstraintsTable.getSelectionModel().addListSelectionListener(
113: new ListSelectionListener() {
114: public void valueChanged(ListSelectionEvent e) {
115: checkActions();
116: }
117: });
118:
119: super .loadProperties(pObject);
120: }
121:
122: // save entity proeprties
123: public void saveProperties(ModelElement pObject) throws Exception {
124: super .saveProperties(pObject);
125: if (pObject != null && pObject instanceof Structure) {
126: Structure lStructure = (Structure) pObject;
127:
128: lStructure.setName(mNameField.getText());
129: lStructure.setDescription(mDescriptionField.getText());
130: }
131: }
132:
133: // add attribute
134: private void addConstraint() {
135: if (mStructure != null) {
136: try {
137: ModelElementConstraintUserObject
138: .addNewConstraint(mStructure);
139: } catch (Exception e) {
140: Application.processError(e);
141: }
142: }
143: }
144:
145: // edit current attribute
146: private void editConstraint() {
147: ModelElementConstraintUserObject lConstraint = mConstraintsTableModel
148: .getConstraint(mConstraintsTable.getSelectedRow());
149: if (lConstraint != null)
150: lConstraint.getEditAction().run();
151: }
152:
153: // delete Attribute
154: private void deleteConstraint() {
155: ModelElementConstraintUserObject lConstraint = mConstraintsTableModel
156: .getConstraint(mConstraintsTable.getSelectedRow());
157: if (lConstraint != null)
158: lConstraint.getDeleteAction().run();
159: }
160:
161: // check edit actins
162: private void checkActions() {
163: boolean lConstraintEditOk = mConstraintsTable != null
164: && mConstraintsTable.getSelectedRow() > -1;
165:
166: mAddConstraintAction.setEnabled(true);
167: mEditConstraintAction.setEnabled(lConstraintEditOk);
168: mDeleteConstraintAction.setEnabled(lConstraintEditOk);
169: }
170:
171: /* Actions */
172:
173: public class AddConstraintAction extends BaseAction {
174: public AddConstraintAction() {
175: super ("Add New Constraint", Application.ADDNEW_ICON);
176: }
177:
178: public void actionPerformed(ActionEvent arg0) {
179: addConstraint();
180: }
181: }
182:
183: public class EditConstraintAction extends BaseAction {
184: public EditConstraintAction() {
185: super ("Edit Constraint", Application.EDIT_ICON);
186: }
187:
188: public void actionPerformed(ActionEvent arg0) {
189: editConstraint();
190: }
191: }
192:
193: public class DeleteConstraintAction extends BaseAction {
194: public DeleteConstraintAction() {
195: super ("Delete Constraint", Application.DELETE_ICON);
196: }
197:
198: public void actionPerformed(ActionEvent arg0) {
199: deleteConstraint();
200: }
201: }
202: }
|