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.Collection;
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.PrimaryKeyPropertiesDialog;
023: import com.metaboss.applications.designstudio.propertiesview.PropertiesTableModel;
024: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
025: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AssociationRole;
026: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Attribute;
027: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Entity;
028: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.PrimaryKeyElement;
029:
030: /* BOPrimaryKeyElement user object class */
031:
032: public class PrimaryKeyElementUserObject extends BaseUserObject {
033: private PrimaryKeyElement mObject = null;
034: private Entity mEntity = null;
035: private BaseUserObject mUserObject = null;
036:
037: public PrimaryKeyElementUserObject(PrimaryKeyElement pObject) {
038: super (pObject, Application.PRIMARYKEY_ICON);
039: mObject = pObject;
040: if (mObject instanceof AssociationRole) {
041: AssociationRole lAssociation = (AssociationRole) mObject;
042: mUserObject = new AssociationRoleUserObject(lAssociation);
043: } else if (mObject instanceof Attribute) {
044: Attribute lAttribute = (Attribute) mObject;
045: mUserObject = new AttributeUserObject(lAttribute);
046: }
047: }
048:
049: // create new primary key element
050: public static void addNewPrimaryKeyElement(Entity pEntity)
051: throws Exception {
052: PrimaryKeyElementUserObject lObject = new PrimaryKeyElementUserObject(
053: null);
054: lObject.mEntity = pEntity;
055: lObject.addNewObject(pEntity.getPrimaryKeyElements());
056: }
057:
058: // add new primary key element
059: public static void createNewPrimaryKeyElement(Entity pEntity,
060: ModelElement pElement) throws Exception {
061: if (pEntity == null || pElement == null)
062: return;
063:
064: Application.beginTransaction();
065: try {
066: pEntity.getPrimaryKeyElements().add(pElement);
067: Application.commit();
068: } finally {
069: Application.checkAndRollback();
070: }
071: }
072:
073: // delete primary key element
074: public static void deletePrimaryKeyElement(Entity pEntity,
075: ModelElement pElement) throws Exception {
076: if (pEntity == null || pElement == null)
077: return;
078:
079: Application.beginTransaction();
080: try {
081: pEntity.getPrimaryKeyElements().remove(pElement);
082: Application.commit();
083: } finally {
084: Application.checkAndRollback();
085: }
086: }
087:
088: // add new object
089: public BaseUserObject addNewObject(Collection pMasterCollection)
090: throws Exception {
091: BaseUserObject lResult = null;
092: PrimaryKeyPropertiesDialog lDialog = new PrimaryKeyPropertiesDialog();
093: if (lDialog != null) {
094: Application.beginTransaction();
095: try {
096: lDialog.loadProperties(mEntity);
097: if (lDialog.getModalResult() == BasePropertiesDialog.MR_OK) {
098: PrimaryKeyElement lElement = lDialog
099: .getPrimaryKeyElement();
100: if (lElement != null && pMasterCollection != null)
101: pMasterCollection.add(lElement);
102: Application.commit();
103: lResult = new PrimaryKeyElementUserObject(lElement);
104: Application.fireObjectInserted(lResult);
105: }
106: } finally {
107: Application.checkAndRollback();
108: }
109: }
110: return lResult;
111: }
112:
113: /*public BaseUserObject addNewObject() throws Exception
114: {
115: Collection lList = null;
116: if (mObject instanceof AssociationRole)
117: {
118: AssociationRole lAssociation = (AssociationRole)mObject;
119: lList = (lAssociation!=null) ? lAssociation.getEntity().getPrimaryKeyElements() : null;
120: } else
121: if (mObject instanceof Attribute)
122: {
123: Attribute lAttribute = (Attribute)mObject;
124: lList = (lAttribute!=null) ? lAttribute.getEntity().getPrimaryKeyElements() : null;
125: }
126: return addNewObject(lList);
127: }*/
128:
129: // delete object
130: public void deleteObject() throws Exception {
131: if (mObject == null)
132: return;
133:
134: Application.beginTransaction();
135: try {
136: Collection lList = null;
137: if (mObject instanceof AssociationRole) {
138: AssociationRole lAssociation = (AssociationRole) mObject;
139: lList = (lAssociation != null) ? lAssociation
140: .getEntity().getPrimaryKeyElements() : null;
141: } else if (mObject instanceof Attribute) {
142: Attribute lAttribute = (Attribute) mObject;
143: lList = (lAttribute != null) ? lAttribute.getEntity()
144: .getPrimaryKeyElements() : null;
145: }
146: if (lList != null)
147: lList.remove(mObject);
148: mObject = null;
149: Application.commit();
150: } finally {
151: Application.checkAndRollback();
152: }
153: Application.fireObjectDeleted(this );
154: }
155:
156: public String toString() {
157: if (mUserObject != null)
158: return mUserObject.toString();
159: else
160: return null;
161: }
162:
163: public PrimaryKeyElement getObject() {
164: return mObject;
165: }
166:
167: // return object root node captions
168: public String getRootNodeName() {
169: return Application.getString("primarykeyelements_node");
170: }
171:
172: public BasePropertiesDialog getObjectEditor() {
173: if (mUserObject != null)
174: return mUserObject.getObjectEditor();
175: else
176: return new PrimaryKeyPropertiesDialog();
177: }
178:
179: // load object properties into grid control
180: public void loadObjectProperties(PropertiesTableModel pModel)
181: throws Exception {
182: //super.loadObjectProperties(pModel);
183: if (pModel == null || mUserObject == null)
184: return;
185: mUserObject.loadObjectProperties(pModel);
186: }
187: }
|