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.constraintstable;
016:
017: import com.metaboss.applications.designstudio.BaseUserObject;
018: import com.metaboss.applications.designstudio.components.FieldsModel;
019: import com.metaboss.applications.designstudio.userobjects.ModelElementConstraintUserObject;
020: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
021: import com.metaboss.sdlctools.models.metabossmodel.ModelElementConstraint;
022:
023: /* Constraints table model */
024:
025: public class ConstraintsTableModel extends FieldsModel {
026: private ModelElement mMasterElement = null;
027:
028: public void loadConstraints(ModelElement pModelElement,
029: Object[] pConstraintsList) {
030: this .loadConstraints(pConstraintsList);
031: mMasterElement = pModelElement;
032: }
033:
034: public void loadConstraints(Object[] pConstraintsList) {
035: mFields.clear();
036: if (pConstraintsList != null) {
037: for (int i = 0; i < pConstraintsList.length; i++)
038: mFields.add(new ModelElementConstraintUserObject(
039: (ModelElementConstraint) pConstraintsList[i]));
040: }
041: fireTableDataChanged();
042: }
043:
044: public ModelElementConstraintUserObject getConstraint(int pIndex) {
045: return (ModelElementConstraintUserObject) mFields.get(pIndex);
046: }
047:
048: public Object getValueAt(int r, int c) {
049: ModelElementConstraintUserObject lConstraint = null;
050: try {
051: lConstraint = (ModelElementConstraintUserObject) mFields
052: .get(r);
053: } catch (Exception e) {
054: lConstraint = null;
055: }
056: if (lConstraint != null) {
057: try {
058: switch (c) {
059: case 0:
060: return lConstraint.getIcon();
061: case 1:
062: return lConstraint.toString();
063: case 2:
064: String xExpression = lConstraint.getConstraint()
065: .getOclExpression();
066: if (xExpression != null)
067: return xExpression.toString();
068: case 3:
069: String xErrorText = lConstraint.getConstraint()
070: .getDefaultErrorText();
071: if (xErrorText != null)
072: return xErrorText.toString();
073: }
074: } catch (Exception e) {
075: e.printStackTrace();
076: }
077: }
078: return null;
079: }
080:
081: public String getColumnName(int c) {
082: switch (c) {
083: case 0:
084: return "..";
085: case 1:
086: return "Name";
087: case 2:
088: return "Ocl Expression";
089: case 3:
090: return "Default Error Text";
091: }
092: return null;
093: }
094:
095: protected void processObjectInserted(BaseUserObject pObject) {
096: if (pObject instanceof ModelElementConstraintUserObject) {
097: ModelElementConstraint lConstraint = ((ModelElementConstraintUserObject) pObject)
098: .getConstraint();
099: if (lConstraint != null) {
100: ModelElement lContextElement = lConstraint
101: .getContextElement();
102: if (lContextElement != null
103: && lContextElement.equals(mMasterElement)) {
104: mFields.add(pObject);
105: fireTableDataChanged();
106: }
107: }
108: }
109: }
110:
111: protected void processObjectEdited(BaseUserObject pObject) {
112: if (pObject instanceof ModelElementConstraintUserObject) {
113: ModelElementConstraint lConstraint = ((ModelElementConstraintUserObject) pObject)
114: .getConstraint();
115: if (lConstraint != null) {
116: ModelElement lContextElement = lConstraint
117: .getContextElement();
118: if (lContextElement != null
119: && lContextElement.equals(mMasterElement))
120: fireTableDataChanged();
121: }
122: }
123: }
124: }
|