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.userobjects;
016:
017: import java.util.ArrayList;
018:
019: import com.metaboss.applications.designstudio.Application;
020: import com.metaboss.applications.designstudio.BasePropertiesDialog;
021: import com.metaboss.applications.designstudio.BaseUserObject;
022: import com.metaboss.applications.designstudio.propertiesdialogs.AssociationPropertiesDialog;
023: import com.metaboss.applications.designstudio.propertiesview.PropertiesTableModel;
024: import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
025: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AggregationTypeEnum;
026: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Association;
027: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AssociationClass;
028: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AssociationRole;
029: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Domain;
030: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Entity;
031: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.SystemImplementationModelPackage;
032:
033: /* Association user object */
034:
035: public class AssociationUserObject extends BaseUserObject {
036: public static final int ADD_ASSOCIATIOROLE = 1;
037: private Association mAssociation = null;
038:
039: public AssociationUserObject(Association pAssociation) {
040: super (pAssociation, Application.ASSOCIATION_ICON);
041: mAssociation = pAssociation;
042: }
043:
044: public AssociationUserObject(Association pAssociation,
045: String pCaption, int pMode) {
046: super (pAssociation, pCaption, pMode);
047: mAssociation = pAssociation;
048: }
049:
050: // create new Association
051: public static AssociationUserObject addNewAssociation(Domain pDomain)
052: throws Exception {
053: return (AssociationUserObject) new AssociationUserObject(null)
054: .addNewObject(getObjectPackage(pDomain), pDomain
055: .getAssociations());
056: }
057:
058: private static AssociationUserObject createAssociation(
059: Domain pDomain, Entity pFromEntity, Entity pToEntity)
060: throws Exception {
061: MetaBossModelPackage lPackage = getObjectPackage(pDomain);
062: AssociationUserObject lResult = (AssociationUserObject) new AssociationUserObject(
063: null).createNewObject(lPackage);
064:
065: pDomain.getAssociations().add(lResult.getAssociation());
066:
067: if (lResult.getAssociation().getRoles().size() == 0) {
068: lResult.getAssociation().getRoles().add(
069: createNewRole(lPackage));
070: lResult.getAssociation().getRoles().add(
071: createNewRole(lPackage));
072: }
073: lResult.setNewEntities(pFromEntity, pToEntity);
074:
075: return lResult;
076: }
077:
078: private static AssociationRole createNewRole(
079: MetaBossModelPackage pPackage) {
080: return (AssociationRole) new AssociationRoleUserObject(null)
081: .createNewObject(pPackage).getBOObject();
082: }
083:
084: // create new Composition
085: public static AssociationUserObject addNewComposisiton(
086: Domain pDomain, Entity pFromEntity, Entity pToEntity)
087: throws Exception {
088: AssociationUserObject lResult = null;
089: Application.beginTransaction();
090: try {
091: lResult = createAssociation(pDomain, pFromEntity, pToEntity);
092:
093: java.util.List lList = lResult.getAssociation().getRoles();
094: AssociationRole lRoleA = (lList != null && lList.size() > 0) ? (AssociationRole) lList
095: .get(0)
096: : null;
097: lRoleA.setAggregationType(AggregationTypeEnum.COMPOSITION);
098:
099: Application.commit();
100: } finally {
101: if (Application.isInTransaction()) {
102: Application.rollback();
103: lResult = null;
104: }
105: }
106: Application.fireObjectSelect(lResult);
107: return lResult;
108: }
109:
110: // create new Aggregatin
111: public static AssociationUserObject addNewAggregation(
112: Domain pDomain, Entity pFromEntity, Entity pToEntity)
113: throws Exception {
114: AssociationUserObject lResult = null;
115: Application.beginTransaction();
116: try {
117: lResult = createAssociation(pDomain, pFromEntity, pToEntity);
118:
119: java.util.List lList = lResult.getAssociation().getRoles();
120: AssociationRole lRoleA = (lList != null && lList.size() > 0) ? (AssociationRole) lList
121: .get(0)
122: : null;
123: lRoleA.setAggregationType(AggregationTypeEnum.AGGREGATION);
124:
125: Application.commit();
126: } finally {
127: if (Application.isInTransaction()) {
128: Application.rollback();
129: lResult = null;
130: }
131: }
132: Application.fireObjectSelect(lResult);
133: return lResult;
134: }
135:
136: public BaseUserObject createNewObject(MetaBossModelPackage pPackage) {
137: SystemImplementationModelPackage lSystemImplementationModelPackage = pPackage
138: .getEnterpriseModel().getSystemImplementationModel();
139: AssociationClass lClass = lSystemImplementationModelPackage
140: .getAssociation();
141: return new AssociationUserObject(lClass.createAssociation());
142: }
143:
144: // set new entities to roles
145: public void setNewEntities(Entity pARoleEntity, Entity pBRoleEntity)
146: throws Exception {
147: java.util.List lList = mAssociation.getRoles();
148: AssociationRole lRoleA = (lList != null && lList.size() > 0) ? (AssociationRole) lList
149: .get(0)
150: : null;
151: AssociationRole lRoleB = (lList != null && lList.size() > 1) ? (AssociationRole) lList
152: .get(1)
153: : null;
154:
155: setRoleEntity(lRoleA, pARoleEntity, "_RoleA");
156: setRoleEntity(lRoleB, pBRoleEntity, "_RoleB");
157: }
158:
159: // set Entity fo role
160: public void setRoleEntity(AssociationRole pRole, Entity pEntity,
161: String pName) {
162: if (pRole == null)
163: return;
164:
165: Entity lOldEntity = pRole.getEntity();
166: if (lOldEntity == null) {
167: pRole.setEntity(pEntity);
168: if (pEntity != null) {
169: pRole.setName(pEntity.getName() + pName);
170: pRole.setPluralName(pEntity.getName() + pName);
171: }
172: } else {
173: if (!lOldEntity.equals(pEntity)) {
174: pRole.setEntity(pEntity);
175: if (pEntity != null) {
176: if (pRole.getName().equals(lOldEntity.getName())
177: || pRole.getName().equals(
178: lOldEntity.getName() + pName))
179: pRole.setName(pEntity.getName() + pName);
180: if (pRole.getPluralName().equals(
181: lOldEntity.getName())
182: || pRole.getPluralName().equals(
183: lOldEntity.getName() + pName))
184: pRole.setPluralName(pEntity.getName() + pName);
185: }
186: }
187: }
188: }
189:
190: public Association getAssociation() {
191: return mAssociation;
192: }
193:
194: // return object root node captions
195: public String getRootNodeName() {
196: return Application.getString("associations_node");
197: }
198:
199: public BasePropertiesDialog getObjectEditor() {
200: return new AssociationPropertiesDialog();
201: }
202:
203: // fill actions list
204: public void fillActionsList(ArrayList pList) {
205: switch (mMode) {
206: case ALL_ACTIONS:
207: super .fillActionsList(pList);
208: break;
209: case ADD_ASSOCIATIOROLE:
210: //???
211: break;
212: }
213: }
214:
215: // load object properties into grid control
216: public void loadObjectProperties(PropertiesTableModel pModel)
217: throws Exception {
218: super .loadObjectProperties(pModel);
219: if (pModel == null || mAssociation == null)
220: return;
221:
222: java.util.List lList = mAssociation.getRoles();
223: AssociationRole lRoleA = (lList != null && lList.size() > 0) ? (AssociationRole) lList
224: .get(0)
225: : null;
226: AssociationRole lRoleB = (lList != null && lList.size() > 1) ? (AssociationRole) lList
227: .get(1)
228: : null;
229:
230: loadAssociationRole(pModel, "Role A", lRoleA);
231: loadAssociationRole(pModel, "Role B", lRoleB);
232: }
233:
234: // add datatype
235: public void loadAssociationRole(PropertiesTableModel pModel,
236: String pName, AssociationRole pRole) {
237: pModel.AddProperty(pName, (pRole != null) ? pRole.getName()
238: : "");
239: }
240: }
|