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 javax.swing.Icon;
020: import javax.swing.ImageIcon;
021:
022: import com.metaboss.applications.designstudio.Application;
023: import com.metaboss.applications.designstudio.BasePropertiesDialog;
024: import com.metaboss.applications.designstudio.BaseUserObject;
025: import com.metaboss.applications.designstudio.propertiesdialogs.AssociationRolePropertiesDialog;
026: import com.metaboss.applications.designstudio.propertiesview.PropertiesTableModel;
027: import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
028: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AggregationTypeEnum;
029: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AssociationRole;
030: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AssociationRoleCardinalityEnum;
031: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AssociationRoleClass;
032: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Entity;
033: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.SystemImplementationModelPackage;
034:
035: /* Association Role user object class */
036:
037: public class AssociationRoleUserObject extends BaseUserObject {
038: private AssociationRole mRole = null;
039:
040: public AssociationRoleUserObject(AssociationRole pRole) {
041: super (pRole, Application.ASSOCIATIONROLE_ICON);
042: mRole = pRole;
043: }
044:
045: // create new Entity
046: public static AssociationRoleUserObject addNewAssociationRole(
047: Entity pEntity) throws Exception {
048: return (AssociationRoleUserObject) new AssociationRoleUserObject(
049: null).addNewObject(getObjectPackage(pEntity), pEntity
050: .getCombinedReferences());
051: }
052:
053: public BaseUserObject createNewObject(MetaBossModelPackage pPackage) {
054: SystemImplementationModelPackage lSystemImplementationModelPackage = pPackage
055: .getEnterpriseModel().getSystemImplementationModel();
056: AssociationRoleClass lClass = lSystemImplementationModelPackage
057: .getAssociationRole();
058: AssociationRole lRole = lClass.createAssociationRole();
059:
060: lRole.setAggregationType(AggregationTypeEnum.NONE);
061: lRole
062: .setCardinality(AssociationRoleCardinalityEnum.ZERO_TO_MANY);
063:
064: return new AssociationRoleUserObject(lRole);
065: }
066:
067: public AssociationRole getAssociationRole() {
068: return mRole;
069: }
070:
071: // get icon
072: public Icon getIcon() {
073: if (isPartOfKey())
074: return Application.getKeyIcon((ImageIcon) super .getIcon());
075: else
076: return super .getIcon();
077: }
078:
079: // get icon for opened node
080: public Icon getOpenIcon() {
081: if (isPartOfKey())
082: return Application.getKeyIcon((ImageIcon) super
083: .getOpenIcon());
084: else
085: return super .getOpenIcon();
086: }
087:
088: // get icon for closed mode
089: public Icon getClosedIcon() {
090: if (isPartOfKey())
091: return Application.getKeyIcon((ImageIcon) super
092: .getClosedIcon());
093: else
094: return super .getClosedIcon();
095: }
096:
097: // return object root node captions
098: public String getRootNodeName() {
099: return Application.getString("associationsroles_node");
100: }
101:
102: public BasePropertiesDialog getObjectEditor() {
103: return new AssociationRolePropertiesDialog();
104: }
105:
106: // fill actions list
107: public void fillActionsList(ArrayList pList) {
108: pList.add(mEditAction);
109: }
110:
111: // load object properties into grid control
112: public void loadObjectProperties(PropertiesTableModel pModel)
113: throws Exception {
114: super .loadObjectProperties(pModel);
115: if (pModel == null || mRole == null)
116: return;
117:
118: pModel.AddProperty("Plural Name", mRole.getPluralName());
119: pModel.AddProperty("Aggregation Type", mRole
120: .getAggregationType().toString());
121: pModel.AddProperty("Cardinality", mRole.getCardinality()
122: .toString());
123:
124: addModelElement(pModel, "Association", mRole.getAssociation());
125: addModelElement(pModel, "Entity", mRole.getEntity());
126: addModelElement(pModel, "Opposite Role", mRole
127: .getOppositeRole());
128:
129: pModel.AddProperty("Plural", boolToString(mRole.isPlural()));
130: pModel
131: .AddProperty("Optional", boolToString(mRole
132: .isOptional()));
133: pModel.AddProperty("Part Of Primary Key",
134: boolToString(isPartOfKey()));
135: }
136:
137: private boolean isPartOfKey() {
138: boolean lResult = false;
139: try {
140: lResult = mRole != null
141: && mRole.isPartOfPrimaryKey(mRole
142: .getReferencingEntity());
143: } catch (Exception e) {
144: lResult = false;
145: }
146: return lResult;
147: }
148: }
|