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 com.metaboss.applications.designstudio.Application;
018: import com.metaboss.applications.designstudio.BasePropertiesDialog;
019: import com.metaboss.applications.designstudio.BaseUserObject;
020: import com.metaboss.applications.designstudio.propertiesdialogs.ModelElementConstraintPropertiesDialog;
021: import com.metaboss.applications.designstudio.propertiesview.PropertiesTableModel;
022: import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
023: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
024: import com.metaboss.sdlctools.models.metabossmodel.ModelElementConstraint;
025: import com.metaboss.sdlctools.models.metabossmodel.ModelElementConstraintClass;
026: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Structure;
027: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.AbstractOperation;
028: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EventSubscriptionOperation;
029: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Operation;
030: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Entity;
031:
032: /* ModelElementConstraint user object */
033:
034: public class ModelElementConstraintUserObject extends BaseUserObject {
035: protected ModelElementConstraint mModelElementConstraint = null;
036:
037: public ModelElementConstraintUserObject(
038: ModelElementConstraint pModelElementConstraint) {
039: super (pModelElementConstraint, Application.CONSTRAINT_ICON);
040: mModelElementConstraint = pModelElementConstraint;
041: }
042:
043: // create new Model Element Constraint
044: public static ModelElementConstraintUserObject addNewConstraint(
045: Entity pEntity) throws Exception {
046: return (ModelElementConstraintUserObject) new ModelElementConstraintUserObject(
047: null).addNewObject(getObjectPackage(pEntity), pEntity
048: .getConstraints());
049: }
050:
051: public static ModelElementConstraintUserObject addNewConstraint(
052: Structure pStructure) throws Exception {
053: return (ModelElementConstraintUserObject) new ModelElementConstraintUserObject(
054: null).addNewObject(getObjectPackage(pStructure),
055: pStructure.getConstraints());
056: }
057:
058: public static ModelElementConstraintUserObject addNewConstraint(
059: Operation pOperation) throws Exception {
060: return (ModelElementConstraintUserObject) new ModelElementConstraintUserObject(
061: null).addNewObject(getObjectPackage(pOperation),
062: pOperation.getInputConstraints());
063: }
064:
065: public static ModelElementConstraintUserObject addNewConstraint(
066: EventSubscriptionOperation pOperation) throws Exception {
067: return (ModelElementConstraintUserObject) new ModelElementConstraintUserObject(
068: null).addNewObject(getObjectPackage(pOperation),
069: pOperation.getInputConstraints());
070: }
071:
072: // create new user object
073: public BaseUserObject createNewObject(MetaBossModelPackage pPackage) {
074: ModelElementConstraintClass xClass = pPackage
075: .getModelElementConstraint();
076: return new ModelElementConstraintUserObject(xClass
077: .createModelElementConstraint());
078: }
079:
080: // get model element constraint object
081: public ModelElementConstraint getConstraint() {
082: return mModelElementConstraint;
083: }
084:
085: // return object root node captions
086: public String getRootNodeName() {
087: if (mModelElementConstraint != null) {
088: ModelElement lContextElement = mModelElementConstraint
089: .getContextElement();
090: if (lContextElement != null
091: && (lContextElement instanceof Operation || lContextElement instanceof EventSubscriptionOperation)) {
092: return Application.getString("inputconstraints_node");
093: }
094: }
095: return Application.getString("constraints_node");
096: }
097:
098: public BasePropertiesDialog getObjectEditor() {
099: return new ModelElementConstraintPropertiesDialog();
100: }
101:
102: // load object properties into grid control
103: public void loadObjectProperties(PropertiesTableModel pModel)
104: throws Exception {
105: super .loadObjectProperties(pModel);
106: if (pModel == null || mModelElementConstraint == null)
107: return;
108:
109: String xErrorText = mModelElementConstraint
110: .getDefaultErrorText();
111: if (xErrorText != null)
112: pModel.AddProperty("Default Error Text", xErrorText
113: .toString());
114: String xOclExpression = mModelElementConstraint
115: .getOclExpression();
116: if (xOclExpression != null)
117: pModel.AddProperty("Ocl Expression", xOclExpression
118: .toString());
119: }
120:
121: // return master collection
122: protected ModelCollectionInfo extractMasterCollection() {
123: ModelCollectionInfo lResult = new ModelCollectionInfo(null,
124: null);
125: if (mModelElementConstraint != null) {
126: if (mModelElementConstraint.getEntityOwner() != null) {
127: Entity lEntity = mModelElementConstraint
128: .getEntityOwner();
129: if (lEntity != null) {
130: lResult.mCollection = lEntity.getConstraints();
131: lResult.mElement = lEntity;
132: }
133: } else if (mModelElementConstraint.getOperationOwner() != null) {
134: AbstractOperation lOperation = mModelElementConstraint
135: .getOperationOwner();
136: if (lOperation != null) {
137: lResult.mCollection = lOperation
138: .getInputConstraints();
139: lResult.mElement = lOperation;
140: }
141: } else if (mModelElementConstraint.getStructureOwner() != null) {
142: Structure lStructure = mModelElementConstraint
143: .getStructureOwner();
144: if (lStructure != null) {
145: lResult.mCollection = lStructure.getConstraints();
146: lResult.mElement = lStructure;
147: }
148: }
149: }
150: return lResult;
151: }
152:
153: // can duplicate model element
154: public boolean canDuplicate() {
155: return true;
156: }
157:
158: // duplicate model element
159: public ModelElement duplicate() throws Exception {
160: ModelElementConstraint lModelElementConstraint = (ModelElementConstraint) Application.sModelRepository
161: .duplicateModelElement(mModelElementConstraint);
162:
163: if (mModelElementConstraint.getEntityOwner() != null)
164: lModelElementConstraint
165: .setEntityOwner(mModelElementConstraint
166: .getEntityOwner());
167: else if (mModelElementConstraint.getStructureOwner() != null)
168: lModelElementConstraint
169: .setStructureOwner(mModelElementConstraint
170: .getStructureOwner());
171: else if (mModelElementConstraint.getOperationOwner() != null)
172: lModelElementConstraint
173: .setOperationOwner(mModelElementConstraint
174: .getOperationOwner());
175: return lModelElementConstraint;
176: }
177:
178: /* Actions */
179:
180: /* Move model element up action */
181:
182: /*public class MoveUpAction extends BaseAction
183: {
184: public MoveUpAction()
185: {
186: super("Move Up", Application.MOVEUP_ICON);
187: }
188:
189: public void actionPerformed(ActionEvent e)
190: {
191: try
192: {
193: moveUserObject(true);
194: }
195: catch (Exception ex)
196: {
197: ex.printStackTrace();
198: }
199: }
200: }*/
201:
202: /* Move model element down action */
203:
204: /*public class MoveDownAction extends BaseAction
205: {
206: public MoveDownAction()
207: {
208: super("Move Down", Application.MOVEDOWN_ICON);
209: }
210:
211: public void actionPerformed(ActionEvent e)
212: {
213: try
214: {
215: moveUserObject(false);
216: }
217: catch (Exception ex)
218: {
219: ex.printStackTrace();
220: }
221: }
222: }*/
223: }
|