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.JComboBox;
020: import javax.swing.JSpinner;
021: import javax.swing.JTextArea;
022: import javax.swing.JTextField;
023: import javax.swing.SpinnerNumberModel;
024:
025: import com.metaboss.applications.designstudio.userobjects.PropertyDescriptorItem;
026: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
027: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Property;
028: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.PropertyDescriptor;
029: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.TypeTemplate;
030:
031: /* Datatype properties dialog */
032:
033: public class PropertyPropertiesDialog extends
034: ModelElementPropertiesDialog {
035: private Object[] mDescriptors = null;
036: // UI constrols
037: private JComboBox mDescriptorField = new JComboBox();
038: private JTextField mValueField = new JTextField();
039: private JSpinner mArrayIndexField = new JSpinner(
040: new SpinnerNumberModel(0, 0, 10000, 1));
041: private JTextArea mDescriptionField = new JTextArea(8, 40);
042:
043: public PropertyPropertiesDialog() {
044: super ("Property", new Dimension(400, 340));
045:
046: addTextField(mPropertiesPanel, "Name: ", mNameField, 1, true);
047: addComboBox(mPropertiesPanel, "Descriptor: ", mDescriptorField,
048: 2, true);
049: addTextField(mPropertiesPanel, "Value: ", mValueField, 3, false);
050: addSpinner(mPropertiesPanel, "Array Index: ", mArrayIndexField,
051: 4, 10, false);
052: addTextArea(mPropertiesPanel, "Description: ",
053: mDescriptionField, 5, false);
054:
055: mDescriptorField
056: .addItemListener(new NameElementChangeListener());
057: }
058:
059: // load entity properties
060: public void loadProperties(ModelElement pObject) throws Exception {
061: if (pObject != null && pObject instanceof Property) {
062: Property lProperty = (Property) pObject;
063:
064: loadTypetemplates(lProperty);
065:
066: mNameField.setText(lProperty.getName());
067: mDescriptorField.setSelectedIndex(PropertyDescriptorItem
068: .findPropertyItemIndex(lProperty.getDescriptor(),
069: mDescriptors));
070: mValueField.setText(lProperty.getValue());
071: mDescriptionField.setText(lProperty.getDescription());
072:
073: // Display array inddex, but disable it because it is now derived attribute
074: Integer lIndex = lProperty.getArrayIndex();
075: if (lIndex == null)
076: lIndex = new Integer(0);
077: mArrayIndexField.setValue(lIndex);
078: mArrayIndexField.setEnabled(false);
079:
080: PropertyDescriptor lDescriptor = lProperty.getDescriptor();
081: if (lDescriptor != null) {
082: if (lDescriptor.isContainer())
083: mValueField.setEnabled(false);
084: }
085: }
086: super .loadProperties(pObject);
087: }
088:
089: // save entity proeprties
090: public void saveProperties(ModelElement pObject) throws Exception {
091: super .saveProperties(pObject);
092: if (pObject != null && pObject instanceof Property) {
093: Property lProperty = (Property) pObject;
094: lProperty.setName(mNameField.getText());
095: lProperty
096: .setDescriptor(((PropertyDescriptorItem) mDescriptorField
097: .getSelectedItem()).mProperty);
098: lProperty.setValue(mValueField.getText());
099: lProperty.setDescription(mDescriptionField.getText());
100: }
101: }
102:
103: // load DataTypes ComboBox
104: private void loadTypetemplates(Property pProperty) {
105: if (pProperty.getParentProperty() == null)
106: mDescriptors = PropertyDescriptorItem.preloadProperties(
107: getTypeTemplate(pProperty), false);
108: else
109: mDescriptors = PropertyDescriptorItem.preloadProperties(
110: pProperty.getParentProperty().getDescriptor(),
111: false);
112: PropertyDescriptorItem.loadBoxWithProperties(mDescriptorField,
113: mDescriptors);
114: }
115:
116: // find TypeTemplate
117: private TypeTemplate getTypeTemplate(Property pProperty) {
118: if (pProperty.getDataType() != null)
119: return pProperty.getDataType().getTypetemplate();
120: else {
121: Property lMaster = pProperty.getParentProperty();
122: while (lMaster != null) {
123: if (lMaster.getDataType() != null)
124: return lMaster.getDataType().getTypetemplate();
125: lMaster = lMaster.getParentProperty();
126: }
127: }
128: return null;
129: }
130:
131: protected ModelElement getNameElement() {
132: ModelElement lResult = null;
133: try {
134: lResult = ((PropertyDescriptorItem) mDescriptorField
135: .getSelectedItem()).mProperty;
136: } catch (Exception e) {
137: lResult = null;
138: }
139: return lResult;
140: }
141: }
|