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.JComboBox;
022: import javax.swing.JPanel;
023: import javax.swing.JTextArea;
024: import javax.swing.JTextField;
025:
026: import com.metaboss.applications.designstudio.BaseUserObject;
027: import com.metaboss.applications.designstudio.userobjects.AggregationTypeItem;
028: import com.metaboss.applications.designstudio.userobjects.AssociationRoleCardinalityItem;
029: import com.metaboss.applications.designstudio.userobjects.EntityItem;
030: import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
031: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
032: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AggregationType;
033: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Association;
034: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AssociationRole;
035: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AssociationRoleCardinality;
036: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AssociationRoleClass;
037: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Domain;
038: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Entity;
039: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.SystemImplementationModelPackage;
040:
041: /* Association properties tuning dialog */
042:
043: public class AssociationPropertiesDialog extends
044: ModelElementPropertiesDialog {
045: private boolean mLoading = true;
046: private Entity mOldRoleAEntity = null;
047: private Entity mOldRoleBEntity = null;
048: // UI constrols
049: private JPanel mRoleAPanel = new JPanel();
050: private JPanel mRoleBPanel = new JPanel();
051: // properties
052: private JTextArea mDescriptionField = new JTextArea(8, 40);
053: // RoleA
054: private JTextField mRoleANameField = new JTextField();
055: private JTextField mRoleAPluralNameField = new JTextField();
056: private JComboBox mRoleAEntityField = new JComboBox();
057: private JComboBox mRoleAStereotypeField = new JComboBox();
058: private JComboBox mRoleACardinalityField = new JComboBox();
059: private JTextArea mRoleADescriptionField = new JTextArea(8, 40);
060: // RoleB
061: private JTextField mRoleBNameField = new JTextField();
062: private JTextField mRoleBPluralNameField = new JTextField();
063: private JComboBox mRoleBEntityField = new JComboBox();
064: private JComboBox mRoleBStereotypeField = new JComboBox();
065: private JComboBox mRoleBCardinalityField = new JComboBox();
066: private JTextArea mRoleBDescriptionField = new JTextArea(8, 40);
067:
068: public AssociationPropertiesDialog() {
069: super ("Association", new Dimension(400, 370));
070:
071: mRoleAPanel.setLayout(mClientGridBagLayout);
072: mRoleBPanel.setLayout(mClientGridBagLayout);
073:
074: AggregationTypeItem
075: .loadBoxWithAggregationTypes(mRoleAStereotypeField);
076: AggregationTypeItem
077: .loadBoxWithAggregationTypes(mRoleBStereotypeField);
078: AssociationRoleCardinalityItem
079: .loadBoxWithCardinalities(mRoleACardinalityField);
080: AssociationRoleCardinalityItem
081: .loadBoxWithCardinalities(mRoleBCardinalityField);
082:
083: // properties
084: addTextField(mPropertiesPanel, "Name: ", mNameField, 1, true);
085: addTextArea(mPropertiesPanel, "Description: ",
086: mDescriptionField, 2, false);
087: // RoleA
088: addComboBox(mRoleAPanel, "Entity: ", mRoleAEntityField, 1, true);
089: addTextField(mRoleAPanel, "Name: ", mRoleANameField, 2, true);
090: addTextField(mRoleAPanel, "Plural Name: ",
091: mRoleAPluralNameField, 3, true);
092: addComboBox(mRoleAPanel, "Aggregation Type: ",
093: mRoleAStereotypeField, 4, false);
094: addComboBox(mRoleAPanel, "Cardinality: ",
095: mRoleACardinalityField, 5, false);
096: addTextArea(mRoleAPanel, "Description: ",
097: mRoleADescriptionField, 6, false);
098: // RoleB
099: addComboBox(mRoleBPanel, "Entity: ", mRoleBEntityField, 1, true);
100: addTextField(mRoleBPanel, "Name: ", mRoleBNameField, 2, true);
101: addTextField(mRoleBPanel, "Plural Name: ",
102: mRoleBPluralNameField, 3, true);
103: addComboBox(mRoleBPanel, "Aggregation Type: ",
104: mRoleBStereotypeField, 4, false);
105: addComboBox(mRoleBPanel, "Cardinality: ",
106: mRoleBCardinalityField, 5, false);
107: addTextArea(mRoleBPanel, "Description: ",
108: mRoleBDescriptionField, 6, false);
109:
110: mTabControl.insertTab("Role A", null, mRoleAPanel, null, 1);
111: mTabControl.insertTab("Role B", null, mRoleBPanel, null, 2);
112:
113: mRoleAEntityField.addItemListener(new ItemListener() {
114: public void itemStateChanged(ItemEvent e) {
115: processRoleAEntityChange();
116: }
117: });
118: mRoleBEntityField.addItemListener(new ItemListener() {
119: public void itemStateChanged(ItemEvent e) {
120: processRoleBEntityChange();
121: }
122: });
123: }
124:
125: // load Association properties
126: public void loadProperties(ModelElement pObject) throws Exception {
127: if (pObject != null && pObject instanceof Association) {
128: Association lAssociation = (Association) pObject;
129: loadBoxesWithEntities(lAssociation.getDomain());
130:
131: //properties
132: mNameField.setText(lAssociation.getName());
133: mDescriptionField.setText(lAssociation.getDescription());
134:
135: java.util.List lList = lAssociation.getRoles();
136: AssociationRole lRoleA = (lList != null && lList.size() > 0) ? (AssociationRole) lList
137: .get(0)
138: : null;
139: AssociationRole lRoleB = (lList != null && lList.size() > 1) ? (AssociationRole) lList
140: .get(1)
141: : null;
142:
143: //rolea
144: if (lRoleA != null) {
145: mRoleANameField.setText(lRoleA.getName());
146: mRoleAPluralNameField.setText(lRoleA.getPluralName());
147: mRoleAEntityField.setSelectedIndex(EntityItem
148: .findEntityItemIndex(mRoleAEntityField, lRoleA
149: .getEntity()));
150: mRoleAStereotypeField
151: .setSelectedIndex(AggregationTypeItem
152: .findAggregationTypeItemIndex(
153: mRoleAStereotypeField, lRoleA
154: .getAggregationType()));
155: mRoleACardinalityField
156: .setSelectedIndex(AssociationRoleCardinalityItem
157: .findCardinalityItemIndex(
158: mRoleACardinalityField, lRoleA
159: .getCardinality()));
160: mRoleADescriptionField.setText(lRoleA.getDescription());
161: }
162: //roleb
163: if (lRoleB != null) {
164: mRoleBNameField.setText(lRoleB.getName());
165: mRoleBPluralNameField.setText(lRoleB.getPluralName());
166: mRoleBEntityField.setSelectedIndex(EntityItem
167: .findEntityItemIndex(mRoleBEntityField, lRoleB
168: .getEntity()));
169: mRoleBStereotypeField
170: .setSelectedIndex(AggregationTypeItem
171: .findAggregationTypeItemIndex(
172: mRoleBStereotypeField, lRoleB
173: .getAggregationType()));
174: mRoleBCardinalityField
175: .setSelectedIndex(AssociationRoleCardinalityItem
176: .findCardinalityItemIndex(
177: mRoleBCardinalityField, lRoleB
178: .getCardinality()));
179: mRoleBDescriptionField.setText(lRoleB.getDescription());
180: }
181: }
182: super .loadProperties(pObject);
183:
184: mOldRoleAEntity = getRoleEntity(mRoleAEntityField);
185: mOldRoleBEntity = getRoleEntity(mRoleBEntityField);
186: mLoading = false;
187: }
188:
189: // save association proeprties
190: public void saveProperties(ModelElement pObject) throws Exception {
191: super .saveProperties(pObject);
192: if (pObject != null && pObject instanceof Association) {
193: Association lAssociation = (Association) pObject;
194: MetaBossModelPackage lPackage = BaseUserObject
195: .getObjectPackage(lAssociation);
196:
197: lAssociation.setName(mNameField.getText());
198: lAssociation.setDescription(mDescriptionField.getText());
199:
200: java.util.List lList = lAssociation.getRoles();
201: AssociationRole lRoleA = (lList != null && lList.size() > 0) ? (AssociationRole) lList
202: .get(0)
203: : null;
204: AssociationRole lRoleB = (lList != null && lList.size() > 1) ? (AssociationRole) lList
205: .get(1)
206: : null;
207:
208: if (lRoleA == null) {
209: lRoleA = createAssociationRole(lPackage);
210: lAssociation.getRoles().add(lRoleA);
211: }
212: if (lRoleB == null) {
213: lRoleB = createAssociationRole(lPackage);
214: lAssociation.getRoles().add(lRoleB);
215: }
216:
217: //rolea
218: if (lRoleA != null) {
219: lRoleA.setEntity(getRoleEntity(mRoleAEntityField));
220: lRoleA.setName(mRoleANameField.getText());
221: lRoleA.setPluralName(mRoleAPluralNameField.getText());
222: lRoleA
223: .setAggregationType((AggregationType) mRoleAStereotypeField
224: .getSelectedItem());
225: lRoleA
226: .setCardinality((AssociationRoleCardinality) mRoleACardinalityField
227: .getSelectedItem());
228: lRoleA.setDescription(mRoleADescriptionField.getText());
229: }
230: //roleb
231: if (lRoleB != null) {
232: lRoleB.setEntity(getRoleEntity(mRoleBEntityField));
233: lRoleB.setName(mRoleBNameField.getText());
234: lRoleB.setPluralName(mRoleBPluralNameField.getText());
235: lRoleB
236: .setAggregationType((AggregationType) mRoleBStereotypeField
237: .getSelectedItem());
238: lRoleB
239: .setCardinality((AssociationRoleCardinality) mRoleBCardinalityField
240: .getSelectedItem());
241: lRoleB.setDescription(mRoleBDescriptionField.getText());
242: }
243: }
244: super .saveProperties(pObject);
245: }
246:
247: // load Entities Boxes
248: private void loadBoxesWithEntities(Domain pDomain) {
249: EntityItem
250: .loadBoxWithEntities(mRoleAEntityField, pDomain, true);
251: EntityItem
252: .loadBoxWithEntities(mRoleBEntityField, pDomain, true);
253: }
254:
255: // create new AssociationRole
256: private AssociationRole createAssociationRole(
257: MetaBossModelPackage pPackage) {
258: SystemImplementationModelPackage lSystemImplementationModelPackage = pPackage
259: .getEnterpriseModel().getSystemImplementationModel();
260: AssociationRoleClass lClass = lSystemImplementationModelPackage
261: .getAssociationRole();
262: return lClass.createAssociationRole();
263: }
264:
265: // provcess roleA Entity change
266: private void processRoleAEntityChange() {
267: if (mLoading)
268: return;
269:
270: Entity lNewEnitity = getRoleEntity(mRoleAEntityField);
271: if (lNewEnitity != null) {
272: if (mOldRoleAEntity != null) {
273: if (mRoleANameField.getText().equals(
274: mOldRoleAEntity.getName()))
275: mRoleANameField.setText(lNewEnitity.getName());
276: if (mRoleAPluralNameField.getText().equals(
277: mOldRoleAEntity.getName()))
278: mRoleAPluralNameField
279: .setText(lNewEnitity.getName());
280: } else {
281: if (mRoleANameField.getText().length() == 0)
282: mRoleANameField.setText(lNewEnitity.getName());
283: if (mRoleAPluralNameField.getText().length() == 0)
284: mRoleAPluralNameField
285: .setText(lNewEnitity.getName());
286: }
287: }
288: mOldRoleAEntity = lNewEnitity;
289: }
290:
291: // provcess roleB Entity change
292: private void processRoleBEntityChange() {
293: if (mLoading)
294: return;
295:
296: Entity lNewEnitity = getRoleEntity(mRoleBEntityField);
297: if (lNewEnitity != null) {
298: if (mOldRoleBEntity != null) {
299: if (mRoleBNameField.getText().equals(
300: mOldRoleBEntity.getName()))
301: mRoleBNameField.setText(lNewEnitity.getName());
302: if (mRoleBPluralNameField.getText().equals(
303: mOldRoleBEntity.getName()))
304: mRoleBPluralNameField
305: .setText(lNewEnitity.getName());
306: } else {
307: if (mRoleBNameField.getText().length() == 0)
308: mRoleBNameField.setText(lNewEnitity.getName());
309: if (mRoleBPluralNameField.getText().length() == 0)
310: mRoleBPluralNameField
311: .setText(lNewEnitity.getName());
312: }
313: }
314: mOldRoleBEntity = lNewEnitity;
315: }
316:
317: private Entity getRoleEntity(JComboBox pBox) {
318: EntityItem lItem = (EntityItem) pBox.getSelectedItem();
319: if (lItem != null)
320: return lItem.mEntity;
321: else
322: return null;
323: }
324: }
|