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.JTextField;
027: import javax.swing.JToolBar;
028: import javax.swing.ListSelectionModel;
029: import javax.swing.border.Border;
030: import javax.swing.event.ListSelectionEvent;
031: import javax.swing.event.ListSelectionListener;
032:
033: import com.metaboss.applications.designstudio.Application;
034: import com.metaboss.applications.designstudio.BaseAction;
035: import com.metaboss.applications.designstudio.attributestable.AttributesTableModel;
036: import com.metaboss.applications.designstudio.components.FieldsTable;
037: import com.metaboss.applications.designstudio.constraintstable.ConstraintsTableModel;
038: import com.metaboss.applications.designstudio.datatypefield.DataTypeBox;
039: import com.metaboss.applications.designstudio.primarykeytable.PrimaryKeyTable;
040: import com.metaboss.applications.designstudio.primarykeytable.PrimaryKeyTableModel;
041: import com.metaboss.applications.designstudio.userobjects.AttributeUserObject;
042: import com.metaboss.applications.designstudio.userobjects.EntityItem;
043: import com.metaboss.applications.designstudio.userobjects.ModelElementConstraintUserObject;
044: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
045: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System;
046: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Entity;
047: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.EntityStereotype;
048: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.EntityStereotypeEnum;
049:
050: /* Entity object properties tuning dialog class */
051:
052: public class EntityPropertiesDialog extends
053: ModelElementPropertiesDialog {
054: private Entity mEntity = null;
055: // UI constrols
056: private JPanel mDataTypesPanel = new JPanel();
057: private JPanel mAttributesPanel = new JPanel();
058: private JPanel mPrimaryKeyPanel = new JPanel();
059: private JPanel mConstraintsPanel = new JPanel();
060: //proeprties
061: private JComboBox mStereotypeField = new JComboBox();
062: private JTextField mPluralNameField = new JTextField();
063: private JComboBox mSuperEntityField = new JComboBox();
064: private JCheckBox mIsAbstractCheckBox = new JCheckBox();
065: private JCheckBox mIsFinalCheckBox = new JCheckBox();
066: private JTextArea mDescriptionField = new JTextArea(8, 40);
067: //datatypes
068: private DataTypeBox mCollectionContainsField = new DataTypeBox(
069: "Collection Contains Flag");
070: private DataTypeBox mCollectionEmptyField = new DataTypeBox(
071: "Collection Empty Flag");
072: private DataTypeBox mCollectionOffsetField = new DataTypeBox(
073: "Collection Offset");
074: private DataTypeBox mCollectionSizeField = new DataTypeBox(
075: "Collection Size");
076: private DataTypeBox mInstanceIDField = new DataTypeBox("InstanceID");
077: private DataTypeBox mOrderingInstrutionField = new DataTypeBox(
078: "Ordering Instruction");
079: private DataTypeBox mStateField = new DataTypeBox("State");
080: private DataTypeBox mSubsetSizeField = new DataTypeBox(
081: "Subset Size");
082: private DataTypeBox mVersionIDField = new DataTypeBox("VersionID");
083: //attributes
084: private EntityAttributesTableModel mAttributesModel = new EntityAttributesTableModel();
085: private FieldsTable mAttributesTable = new FieldsTable(
086: mAttributesModel);
087: private JToolBar mToolBar = new JToolBar();
088: //primary key
089: private PrimaryKeyTableModel mPrimaryKeysModel = new PrimaryKeyTableModel();
090: private PrimaryKeyTable mPrimaryKeyTable = new PrimaryKeyTable(
091: mPrimaryKeysModel);
092: //constraints
093: private ConstraintsTableModel mConstraintsTableModel = new ConstraintsTableModel();
094: private FieldsTable mConstraintsTable = new FieldsTable(
095: mConstraintsTableModel);
096: private JToolBar mConstraintsToolBar = new JToolBar();
097: // actions
098: private AddAttributeAction mAddAttributeAction = new AddAttributeAction();
099: private EditAttributeAction mEditAttributeAction = new EditAttributeAction();
100: private DeleteAttributeAction mDeleteAttributeAction = new DeleteAttributeAction();
101: private AddConstraintAction mAddConstraintAction = new AddConstraintAction();
102: private EditConstraintAction mEditConstraintAction = new EditConstraintAction();
103: private DeleteConstraintAction mDeleteConstraintAction = new DeleteConstraintAction();
104:
105: public EntityPropertiesDialog() {
106: super ("Entity", new Dimension(420, 390));
107:
108: mDataTypesPanel.setLayout(mClientGridBagLayout);
109: mAttributesPanel.setLayout(new BorderLayout());
110: mPrimaryKeyPanel.setLayout(new BorderLayout());
111: mConstraintsPanel.setLayout(new BorderLayout());
112:
113: loadBoxWithStereotypes(mStereotypeField);
114:
115: // properties
116: addTextField(mPropertiesPanel, "Name: ", mNameField, 1, true);
117: addTextField(mPropertiesPanel, "Plural Name: ",
118: mPluralNameField, 2, true);
119: addComboBox(mPropertiesPanel, "Stereotype: ", mStereotypeField,
120: 3, false);
121: addComboBox(mPropertiesPanel, "Supertype: ", mSuperEntityField,
122: 4, false);
123: addCheckBox(mPropertiesPanel, "- abstract",
124: mIsAbstractCheckBox, 5, false);
125: addCheckBox(mPropertiesPanel, "- final", mIsFinalCheckBox, 6,
126: false);
127: addTextArea(mPropertiesPanel, "Description: ",
128: mDescriptionField, 7, false);
129: // datatypes
130: addComplexField(mDataTypesPanel, mCollectionContainsField, 1,
131: false);
132: addComplexField(mDataTypesPanel, mCollectionEmptyField, 2,
133: false);
134: addComplexField(mDataTypesPanel, mCollectionOffsetField, 3,
135: false);
136: addComplexField(mDataTypesPanel, mCollectionSizeField, 4, false);
137: addComplexField(mDataTypesPanel, mInstanceIDField, 5, false);
138: addComplexField(mDataTypesPanel, mOrderingInstrutionField, 6,
139: false);
140: addComplexField(mDataTypesPanel, mStateField, 7, false);
141: addComplexField(mDataTypesPanel, mSubsetSizeField, 8, false);
142: addComplexField(mDataTypesPanel, mVersionIDField, 9, false);
143: //attributes
144: mAttributesPanel.add(new JScrollPane(mAttributesTable),
145: BorderLayout.CENTER);
146: mAttributesPanel.add(mToolBar, BorderLayout.SOUTH);
147: // primary key
148: mPrimaryKeyPanel.add(new JScrollPane(mPrimaryKeyTable),
149: BorderLayout.CENTER);
150: //constraints
151: mConstraintsPanel.add(new JScrollPane(mConstraintsTable),
152: BorderLayout.CENTER);
153: mConstraintsPanel.add(mConstraintsToolBar, BorderLayout.SOUTH);
154:
155: mAttributesTable.setRowHeight(20);
156: mAttributesTable.setCellSelectionEnabled(true);
157: mAttributesTable.setRowSelectionAllowed(true);
158: mAttributesTable.setColumnSelectionAllowed(false);
159: mAttributesTable
160: .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
161:
162: mPrimaryKeyTable.setCellSelectionEnabled(true);
163: mPrimaryKeyTable.setRowSelectionAllowed(false);
164: mPrimaryKeyTable.setColumnSelectionAllowed(false);
165: mPrimaryKeyTable
166: .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
167:
168: mConstraintsTable.setCellSelectionEnabled(true);
169: mConstraintsTable.setRowSelectionAllowed(true);
170: mConstraintsTable.setColumnSelectionAllowed(false);
171: mConstraintsTable
172: .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
173:
174: mToolBar.setBorder(null);
175: mToolBar.add(Application.createButton(mAddAttributeAction));
176: mToolBar.add(Application.createButton(mEditAttributeAction));
177: mToolBar.add(Application.createButton(mDeleteAttributeAction));
178:
179: mConstraintsToolBar.setBorder(null);
180: mConstraintsToolBar.add(Application
181: .createButton(mAddConstraintAction));
182: mConstraintsToolBar.add(Application
183: .createButton(mEditConstraintAction));
184: mConstraintsToolBar.add(Application
185: .createButton(mDeleteConstraintAction));
186:
187: Border lBorder = createEditorBorder();
188: mAttributesPanel.setBorder(lBorder);
189: mPrimaryKeyPanel.setBorder(lBorder);
190: mConstraintsPanel.setBorder(lBorder);
191:
192: //???mTabControl.addTab("DataTypes", mDataTypesPanel);
193: mTabControl.insertTab("Attributes", null, mAttributesPanel,
194: null, 1);
195: mTabControl.insertTab("Primary Key", null, mPrimaryKeyPanel,
196: null, 2);
197: mTabControl.insertTab("Constraints", null, mConstraintsPanel,
198: null, 3);
199: }
200:
201: // load entity properties
202: public void loadProperties(ModelElement pObject) throws Exception {
203: mEntity = null;
204: if (pObject != null && pObject instanceof Entity) {
205: mEntity = (Entity) pObject;
206: System lSystem = mEntity.getDomain().getSystem();
207:
208: /*mCollectionContainsField.setSystem(lSystem);
209: mCollectionEmptyField.setSystem(lSystem);
210: mCollectionOffsetField.setSystem(lSystem);
211: mCollectionSizeField.setSystem(lSystem);
212: mInstanceIDField.setSystem(lSystem);
213: mOrderingInstrutionField.setSystem(lSystem);
214: mStateField.setSystem(lSystem);
215: mSubsetSizeField.setSystem(lSystem);
216: mVersionIDField.setSystem(lSystem);*/
217:
218: EntityItem.loadBoxWithEntities(mSuperEntityField, mEntity
219: .getDomain(), true);
220:
221: mNameField.setText(mEntity.getName());
222: mDescriptionField.setText(mEntity.getDescription());
223: mStereotypeField
224: .setSelectedIndex(findStereotypeItemIndex(mEntity
225: .getStereotype()));
226: mPluralNameField.setText(mEntity.getPluralName());
227: mSuperEntityField.setSelectedIndex(EntityItem
228: .findEntityItemIndex(mSuperEntityField, mEntity
229: .getSupertype()));
230: mIsAbstractCheckBox.setSelected(mEntity.isAbstract());
231: mIsFinalCheckBox.setSelected(mEntity.isFinal());
232:
233: /*mCollectionContainsField.setSelectedDataType(mEntity.getCollectionContainsFlagDataType());
234: mCollectionEmptyField.setSelectedDataType(mEntity.getCollectionEmptyFlagDataType());
235: mCollectionOffsetField.setSelectedDataType(mEntity.getCollectionOffsetDataType());
236: mCollectionSizeField.setSelectedDataType(mEntity.getCollectionSizeDataType());
237: mInstanceIDField.setSelectedDataType(mEntity.getInstanceIdDataType());
238: mOrderingInstrutionField.setSelectedDataType(mEntity.getOrderingInstructionDataType());
239: mStateField.setSelectedDataType(mEntity.getStateDataType());
240: mSubsetSizeField.setSelectedDataType(mEntity.getSubsetSizeDataType());
241: mVersionIDField.setSelectedDataType(mEntity.getVersionIdDataType());*/
242:
243: mAttributesModel.loadAttributes(mEntity, mEntity
244: .getAttributes().toArray());
245: mPrimaryKeysModel.loadElements(mEntity);
246: mConstraintsTableModel.loadConstraints(mEntity, mEntity
247: .getConstraints().toArray());
248: }
249:
250: checkActions();
251: mAttributesTable.getSelectionModel().addListSelectionListener(
252: new ListSelectionListener() {
253: public void valueChanged(ListSelectionEvent e) {
254: checkActions();
255: }
256: });
257: mConstraintsTable.getSelectionModel().addListSelectionListener(
258: new ListSelectionListener() {
259: public void valueChanged(ListSelectionEvent e) {
260: checkActions();
261: }
262: });
263:
264: super .loadProperties(pObject);
265: }
266:
267: // save entity proeprties
268: public void saveProperties(ModelElement pObject) throws Exception {
269: super .saveProperties(pObject);
270: if (pObject != null && pObject instanceof Entity) {
271: Entity lEntity = (Entity) pObject;
272:
273: lEntity.setName(mNameField.getText());
274: lEntity.setPluralName(mPluralNameField.getText());
275: lEntity.setStereotype((EntityStereotype) mStereotypeField
276: .getSelectedItem());
277: lEntity.setDescription(mDescriptionField.getText());
278: EntityItem lItem = (EntityItem) mSuperEntityField
279: .getSelectedItem();
280: if (lItem != null)
281: lEntity.setSupertype(lItem.mEntity);
282: else
283: lEntity.setSupertype(null);
284: lEntity.setAbstract(mIsAbstractCheckBox.isSelected());
285: lEntity.setFinal(mIsFinalCheckBox.isSelected());
286:
287: /*lEntity.setCollectionContainsFlagDataType(mCollectionContainsField.getSelectedDataType());
288: lEntity.setCollectionEmptyFlagDataType(mCollectionEmptyField.getSelectedDataType());
289: lEntity.setCollectionOffsetDataType(mCollectionOffsetField.getSelectedDataType());
290: lEntity.setCollectionSizeDataType(mCollectionSizeField.getSelectedDataType());
291: lEntity.setInstanceIdDataType(mInstanceIDField.getSelectedDataType());
292: lEntity.setOrderingInstructionDataType(mOrderingInstrutionField.getSelectedDataType());
293: lEntity.setStateDataType(mStateField.getSelectedDataType());
294: lEntity.setSubsetSizeDataType(mSubsetSizeField.getSelectedDataType());
295: lEntity.setVersionIdDataType(mVersionIDField.getSelectedDataType());*/
296: }
297: }
298:
299: // find message type index
300: private int findStereotypeItemIndex(EntityStereotype lStereotype) {
301: for (int i = 0; i < mStereotypeField.getItemCount(); i++) {
302: EntityStereotype lItem = (EntityStereotype) mStereotypeField
303: .getItemAt(i);
304: if (lItem == lStereotype)
305: return i;
306: }
307: return -1;
308: }
309:
310: // load combobox with stereotypes
311: private void loadBoxWithStereotypes(JComboBox pComboBox) {
312: pComboBox.removeAllItems();
313: pComboBox.addItem(EntityStereotypeEnum.CARD_FILE);
314: pComboBox.addItem(EntityStereotypeEnum.LOG_FILE);
315: }
316:
317: // add attribute
318: private void addAttribute() {
319: if (mEntity != null) {
320: try {
321: AttributeUserObject.addNewAttribute(mEntity);
322: } catch (Exception e) {
323: Application.processError(e);
324: }
325: }
326: }
327:
328: // edit current attribute
329: private void editAttribute() {
330: AttributeUserObject lAttribute = mAttributesModel
331: .getAttribute(mAttributesTable.getSelectedRow());
332: if (lAttribute != null)
333: lAttribute.getEditAction().run();
334: }
335:
336: // delete Attribute
337: private void deleteAttribute() {
338: AttributeUserObject lAttribute = mAttributesModel
339: .getAttribute(mAttributesTable.getSelectedRow());
340: if (lAttribute != null)
341: lAttribute.getDeleteAction().run();
342: }
343:
344: // add attribute
345: private void addConstraint() {
346: if (mEntity != null) {
347: try {
348: ModelElementConstraintUserObject
349: .addNewConstraint(mEntity);
350: } catch (Exception e) {
351: Application.processError(e);
352: }
353: }
354: }
355:
356: // edit current attribute
357: private void editConstraint() {
358: ModelElementConstraintUserObject lConstraint = mConstraintsTableModel
359: .getConstraint(mConstraintsTable.getSelectedRow());
360: if (lConstraint != null)
361: lConstraint.getEditAction().run();
362: }
363:
364: // delete Attribute
365: private void deleteConstraint() {
366: ModelElementConstraintUserObject lConstraint = mConstraintsTableModel
367: .getConstraint(mConstraintsTable.getSelectedRow());
368: if (lConstraint != null)
369: lConstraint.getDeleteAction().run();
370: }
371:
372: // check edit actins
373: private void checkActions() {
374: boolean lEditOk = mAttributesTable != null
375: && mAttributesTable.getSelectedRow() > -1;
376: boolean lConstraintEditOk = mConstraintsTable != null
377: && mConstraintsTable.getSelectedRow() > -1;
378:
379: mAddAttributeAction.setEnabled(true);
380: mEditAttributeAction.setEnabled(lEditOk);
381: mDeleteAttributeAction.setEnabled(lEditOk);
382:
383: mAddConstraintAction.setEnabled(true);
384: mEditConstraintAction.setEnabled(lConstraintEditOk);
385: mDeleteConstraintAction.setEnabled(lConstraintEditOk);
386: }
387:
388: /* Auxilary classes */
389:
390: /* Attributes table model */
391:
392: public class EntityAttributesTableModel extends
393: AttributesTableModel {
394: public int getColumnCount() {
395: return 3;
396: }
397: }
398:
399: /* Actions */
400:
401: public class AddAttributeAction extends BaseAction {
402: public AddAttributeAction() {
403: super ("Add New Attribute", Application.ADDNEW_ICON);
404: }
405:
406: public void actionPerformed(ActionEvent arg0) {
407: addAttribute();
408: }
409: }
410:
411: public class EditAttributeAction extends BaseAction {
412: public EditAttributeAction() {
413: super ("Edit Attribute", Application.EDIT_ICON);
414: }
415:
416: public void actionPerformed(ActionEvent arg0) {
417: editAttribute();
418: }
419: }
420:
421: public class DeleteAttributeAction extends BaseAction {
422: public DeleteAttributeAction() {
423: super ("Delete Attribute", Application.DELETE_ICON);
424: }
425:
426: public void actionPerformed(ActionEvent arg0) {
427: deleteAttribute();
428: }
429: }
430:
431: public class AddConstraintAction extends BaseAction {
432: public AddConstraintAction() {
433: super ("Add New Constraint", Application.ADDNEW_ICON);
434: }
435:
436: public void actionPerformed(ActionEvent arg0) {
437: addConstraint();
438: }
439: }
440:
441: public class EditConstraintAction extends BaseAction {
442: public EditConstraintAction() {
443: super ("Edit Constraint", Application.EDIT_ICON);
444: }
445:
446: public void actionPerformed(ActionEvent arg0) {
447: editConstraint();
448: }
449: }
450:
451: public class DeleteConstraintAction extends BaseAction {
452: public DeleteConstraintAction() {
453: super ("Delete Constraint", Application.DELETE_ICON);
454: }
455:
456: public void actionPerformed(ActionEvent arg0) {
457: deleteConstraint();
458: }
459: }
460: }
|