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: import java.awt.event.ItemEvent;
019: import java.awt.event.ItemListener;
020:
021: import javax.swing.JCheckBox;
022: import javax.swing.JComboBox;
023: import javax.swing.JTextArea;
024: import javax.swing.JTextField;
025:
026: import com.metaboss.applications.designstudio.userobjects.EntityItem;
027: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
028: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Domain;
029: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Entity;
030: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.ReportOutputElement;
031: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.ReportOutputEntity;
032:
033: /* ReportEntity user object */
034:
035: public class ReportEntityPropertiesDialog extends
036: ModelElementPropertiesDialog {
037: private boolean mLoading = true;
038: private Entity mOldEntity = null;
039: //UI
040: private JTextField mNameField = new JTextField();
041: private JComboBox mEntityField = new JComboBox();
042: private JCheckBox mIsArrayCheckBox = new JCheckBox();
043: private JTextArea mDescriptionField = new JTextArea(8, 40);
044:
045: public ReportEntityPropertiesDialog() {
046: super ("Report Output Entity", new Dimension(400, 310));
047:
048: addTextField(mPropertiesPanel, "Name: ", mNameField, 1, true);
049: addComboBox(mPropertiesPanel, "Entity: ", mEntityField, 2, true);
050: addCheckBox(mPropertiesPanel, "- array", mIsArrayCheckBox, 3,
051: false);
052: addTextArea(mPropertiesPanel, "Description: ",
053: mDescriptionField, 4, false);
054:
055: mEntityField.addItemListener(new ItemListener() {
056: public void itemStateChanged(ItemEvent e) {
057: processEntityChange();
058: }
059: });
060: }
061:
062: // load service module properties
063: public void loadProperties(ModelElement pObject) throws Exception {
064: if (pObject != null && pObject instanceof ReportOutputEntity) {
065: ReportOutputEntity lReportOutputEntity = (ReportOutputEntity) pObject;
066: EntityItem.loadBoxWithEntities(mEntityField,
067: getDomain(lReportOutputEntity), false);
068:
069: mNameField.setText(lReportOutputEntity.getName());
070: mEntityField.setSelectedIndex(EntityItem
071: .findEntityItemIndex(mEntityField,
072: lReportOutputEntity.getEntity()));
073: mIsArrayCheckBox.setSelected(lReportOutputEntity.isArray());
074: mDescriptionField.setText(lReportOutputEntity
075: .getDescription());
076: }
077: super .loadProperties(pObject);
078:
079: mOldEntity = getBoxEntity(mEntityField);
080: mLoading = false;
081: }
082:
083: // save service module proeprties
084: public void saveProperties(ModelElement pObject) throws Exception {
085: super .saveProperties(pObject);
086: if (pObject != null && pObject instanceof ReportOutputEntity) {
087: ReportOutputEntity lReportOutputEntity = (ReportOutputEntity) pObject;
088:
089: lReportOutputEntity.setName(mNameField.getText());
090: lReportOutputEntity.setArray(mIsArrayCheckBox.isSelected());
091: lReportOutputEntity.setDescription(mDescriptionField
092: .getText());
093: EntityItem lItem = (EntityItem) mEntityField
094: .getSelectedItem();
095: if (lItem != null)
096: lReportOutputEntity.setEntity(lItem.mEntity);
097: else
098: lReportOutputEntity.setEntity(null);
099: }
100: }
101:
102: // find domain
103: private Domain getDomain(ReportOutputEntity pEntity) {
104: ReportOutputElement lElement = pEntity.getOutptuElement();
105: while (lElement != null) {
106: if (lElement.getReport() != null)
107: return lElement.getReport().getDomain();
108: lElement = lElement.getParenElement();
109: }
110: return null;
111: }
112:
113: // provcess Entity change
114: private void processEntityChange() {
115: if (mLoading)
116: return;
117:
118: Entity lNewEnitity = getBoxEntity(mEntityField);
119: if (lNewEnitity != null) {
120: if (mOldEntity != null) {
121: if (mNameField.getText().equals(mOldEntity.getName()))
122: mNameField.setText(lNewEnitity.getName());
123: } else {
124: if (mNameField.getText().length() == 0)
125: mNameField.setText(lNewEnitity.getName());
126: }
127: }
128: mOldEntity = lNewEnitity;
129: }
130:
131: private Entity getBoxEntity(JComboBox pBox) {
132: EntityItem lItem = (EntityItem) pBox.getSelectedItem();
133: if (lItem != null)
134: return lItem.mEntity;
135: else
136: return null;
137: }
138: }
|