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 javax.swing.Icon;
018: import javax.swing.ImageIcon;
019:
020: import com.metaboss.applications.designstudio.Application;
021: import com.metaboss.applications.designstudio.BasePropertiesDialog;
022: import com.metaboss.applications.designstudio.BaseUserObject;
023: import com.metaboss.applications.designstudio.propertiesdialogs.AttributePropertiesDialog;
024: import com.metaboss.applications.designstudio.propertiesview.PropertiesTableModel;
025: import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
026: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
027: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Attribute;
028: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AttributeClass;
029: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Entity;
030: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.ReportOutputEntity;
031: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.SystemImplementationModelPackage;
032:
033: /* Attribute user object */
034:
035: public class AttributeUserObject extends BaseUserObject {
036: protected Attribute mAttribute = null;
037:
038: public AttributeUserObject(Attribute pAttribute) {
039: super (pAttribute, Application.ATTRIBUTE_ICON);
040: mAttribute = pAttribute;
041: }
042:
043: // create new Attribute
044: public static AttributeUserObject addNewAttribute(Entity pEntity)
045: throws Exception {
046: return (AttributeUserObject) new AttributeUserObject(null)
047: .addNewObject(getObjectPackage(pEntity), pEntity
048: .getAttributes());
049: }
050:
051: public static AttributeUserObject addNewAttribute(
052: ReportOutputEntity pEntity) throws Exception {
053: return (AttributeUserObject) new AttributeUserObject(null)
054: .addNewObject(getObjectPackage(pEntity), pEntity
055: .getAttributes());
056: }
057:
058: // create and add new attribute
059: public static void createAndAddAttribute(
060: ReportOutputEntity pEntity, Attribute pAttribute)
061: throws Exception {
062: BaseUserObject lObject = null;
063: Application.beginTransaction();
064: try {
065: lObject = new AttributeUserObject(null)
066: .createNewObject(getObjectPackage(pEntity));
067: if (lObject != null) {
068: Attribute lAttribute = (Attribute) lObject
069: .getBOObject();
070: pEntity.getAttributes().add(lAttribute);
071: lAttribute.setName(pAttribute.getName());
072: lAttribute.setDescription(pAttribute.getDescription());
073: lAttribute.setDataType(pAttribute.getDataType());
074: lAttribute.setStereotype(pAttribute.getStereotype());
075: }
076: Application.commit();
077: } finally {
078: Application.checkAndRollback();
079: }
080: }
081:
082: public BaseUserObject createNewObject(MetaBossModelPackage pPackage) {
083: SystemImplementationModelPackage lSystemImplementationModelPackage = pPackage
084: .getEnterpriseModel().getSystemImplementationModel();
085: AttributeClass lClass = lSystemImplementationModelPackage
086: .getAttribute();
087: return new AttributeUserObject(lClass.createAttribute());
088: }
089:
090: public Attribute getAttribute() {
091: return mAttribute;
092: }
093:
094: // get icon
095: public Icon getIcon() {
096: if (isPartOfKey())
097: return Application.getKeyIcon((ImageIcon) super .getIcon());
098: else
099: return super .getIcon();
100: }
101:
102: // get icon for opened node
103: public Icon getOpenIcon() {
104: if (isPartOfKey())
105: return Application.getKeyIcon((ImageIcon) super
106: .getOpenIcon());
107: else
108: return super .getOpenIcon();
109: }
110:
111: // get icon for closed mode
112: public Icon getClosedIcon() {
113: if (isPartOfKey())
114: return Application.getKeyIcon((ImageIcon) super
115: .getClosedIcon());
116: else
117: return super .getClosedIcon();
118: }
119:
120: public BasePropertiesDialog getObjectEditor() {
121: return new AttributePropertiesDialog();
122: }
123:
124: // return object root node captions
125: public String getRootNodeName() {
126: return Application.getString("attributes_node");
127: }
128:
129: // load object properties into grid control
130: public void loadObjectProperties(PropertiesTableModel pModel)
131: throws Exception {
132: super .loadObjectProperties(pModel);
133: if (pModel == null || mAttribute == null)
134: return;
135:
136: pModel.AddProperty("Used For Ordering", boolToString(mAttribute
137: .isUsedForOrdering()));
138: try {
139: pModel.AddProperty("Optional", boolToString(mAttribute
140: .isOptional()));
141: } catch (Exception e) {
142: e.printStackTrace();
143: }
144: pModel.AddProperty("Stereotype", mAttribute.getStereotype()
145: .toString());
146: addModelElement(pModel, "Datatype", mAttribute.getDataType());
147: pModel.AddProperty("Part Of Primary Key",
148: boolToString(isPartOfKey()));
149: }
150:
151: // check attribute is part of primary key
152: private boolean isPartOfKey() {
153: boolean lResult = false;
154: if (mAttribute != null) {
155: try {
156: lResult = mAttribute.isPartOfPrimaryKey(mAttribute
157: .getEntity());
158: } catch (Exception e) {
159: lResult = false;
160: }
161: }
162: return lResult;
163: }
164:
165: // can duplicate model element
166: public boolean canDuplicate() {
167: return true;
168: }
169:
170: // duplicate model element
171: public ModelElement duplicate() throws Exception {
172: Attribute lAttribute = (Attribute) Application.sModelRepository
173: .duplicateModelElement(mAttribute);
174: lAttribute.setEntity(mAttribute.getEntity());
175: return lAttribute;
176: }
177: }
|