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.Dimension;
018:
019: import javax.swing.JCheckBox;
020: import javax.swing.JComboBox;
021: import javax.swing.JTextArea;
022:
023: import com.metaboss.applications.designstudio.Application;
024: import com.metaboss.applications.designstudio.datatypefield.DataTypeBox;
025: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
026: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Attribute;
027: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AttributeStereotype;
028: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AttributeStereotypeEnum;
029:
030: /* Attribute properties tuning dialog class */
031:
032: public class AttributePropertiesDialog extends
033: ModelElementPropertiesDialog {
034: private JComboBox mStereotypeField = new JComboBox();
035: private DataTypeBox mDatatypeField = new DataTypeBox("Datatype");
036: private JCheckBox mCanUseCheckBox = new JCheckBox();
037: private JTextArea mDescriptionField = new JTextArea(8, 40);
038:
039: public AttributePropertiesDialog() {
040: super ("Attribute", new Dimension(400, 340));
041:
042: loadStereotypeBox(mStereotypeField);
043:
044: addTextField(mPropertiesPanel, "Name: ", mNameField, 1, true);
045: addComboBox(mPropertiesPanel, "Stereotype: ", mStereotypeField,
046: 2, false);
047: addComplexFieldWithEdit(mPropertiesPanel, mDatatypeField, 3,
048: false);
049: addCheckBox(mPropertiesPanel, "- used for ordering",
050: mCanUseCheckBox, 4, false);
051: addTextArea(mPropertiesPanel, "Description: ",
052: mDescriptionField, 5, false);
053: }
054:
055: // load entity properties
056: public void loadProperties(ModelElement pObject) throws Exception {
057: Attribute lAttribute = (Attribute) pObject;
058: if (lAttribute != null) {
059: mDatatypeField.setSystem(lAttribute.getEntity().getDomain()
060: .getSystem());
061:
062: mNameField.setText(lAttribute.getName());
063: mStereotypeField
064: .setSelectedIndex(findStereotypeItemIndex(lAttribute
065: .getStereotype()));
066: mDatatypeField
067: .setSelectedDataType(lAttribute.getDataType());
068: mCanUseCheckBox.setSelected(lAttribute.isUsedForOrdering());
069: mDescriptionField.setText(lAttribute.getDescription());
070: }
071: super .loadProperties(pObject);
072: }
073:
074: // save entity proeprties
075: public void saveProperties(ModelElement pObject) throws Exception {
076: super .saveProperties(pObject);
077: if (pObject != null && pObject instanceof Attribute) {
078: Attribute lAttribute = (Attribute) pObject;
079: lAttribute.setName(mNameField.getText());
080: lAttribute.setDescription(mDescriptionField.getText());
081: lAttribute
082: .setStereotype((AttributeStereotype) mStereotypeField
083: .getSelectedItem());
084: lAttribute.setUsedForOrdering(mCanUseCheckBox.isSelected());
085: lAttribute
086: .setDataType(mDatatypeField.getSelectedDataType());
087: }
088: }
089:
090: // check fields data
091: public boolean checkProperties() {
092: if (mNameField.getText().length() == 0) {
093: Application.showError("Name field could not be blank!");
094: return false;
095: }
096: Object lObject = mStereotypeField.getSelectedItem();
097: if (lObject == null) {
098: Application
099: .showError("Stereotype field could not be blank!");
100: return false;
101: }
102: lObject = mDatatypeField.getSelectedItem();
103: if (lObject == null) {
104: Application.showError("DataType field could not be blank!");
105: return false;
106: }
107: return super .checkProperties();
108: }
109:
110: // load stereotype combobox
111: private void loadStereotypeBox(JComboBox pBox) {
112: pBox.removeAllItems();
113: pBox.addItem(AttributeStereotypeEnum.CREATE_STAMP);
114: pBox.addItem(AttributeStereotypeEnum.MANDATORY);
115: pBox.addItem(AttributeStereotypeEnum.OPTIONAL);
116: pBox.addItem(AttributeStereotypeEnum.UPDATE_STAMP);
117: }
118:
119: // find message type index
120: private int findStereotypeItemIndex(AttributeStereotype lStereotype) {
121: for (int i = 0; i < mStereotypeField.getItemCount(); i++) {
122: AttributeStereotype lItem = (AttributeStereotype) mStereotypeField
123: .getItemAt(i);
124: if (lItem.equals(lStereotype))
125: return i;
126: }
127: return -1;
128: }
129: }
|