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.primarykeytable;
016:
017: import java.util.ArrayList;
018:
019: import javax.swing.table.AbstractTableModel;
020:
021: import com.metaboss.applications.designstudio.Application;
022: import com.metaboss.applications.designstudio.userobjects.PrimaryKeyElementUserObject;
023: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
024: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AssociationRole;
025: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Attribute;
026: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Entity;
027:
028: /* Primary Key Table model */
029:
030: public class PrimaryKeyTableModel extends AbstractTableModel {
031: private Entity mEntity = null;
032: private ArrayList mList = new ArrayList();
033:
034: // load primary key elements
035: public void loadElements(Entity pEntity) {
036: mEntity = pEntity;
037: mList.clear();
038: mList.addAll(pEntity.getAttributes());
039: mList.addAll(pEntity.getCombinedReferences());
040: }
041:
042: public int getRowCount() {
043: return mList.size();
044: }
045:
046: public int getColumnCount() {
047: return 4;
048: }
049:
050: public Object getValueAt(int r, int c) {
051: ModelElement lElement = (ModelElement) mList.get(r);
052: if (lElement != null) {
053: switch (c) {
054: case 0:
055: return isRowInPrimaryKey(r);
056: case 1:
057: if (lElement instanceof Attribute)
058: return Application.ATTRIBUTE_ICON;
059: else if (lElement instanceof AssociationRole)
060: return Application.ASSOCIATIONROLE_ICON;
061: case 2:
062: return lElement.getName();
063: case 3:
064: if (lElement instanceof Attribute) {
065: Attribute lAttribute = (Attribute) lElement;
066: if (lAttribute.getDataType() != null)
067: return lAttribute.getDataType().getName();
068: } else if (lElement instanceof AssociationRole)
069: return "Association Role";
070: }
071: }
072: return null;
073: }
074:
075: public String getColumnName(int c) {
076: switch (c) {
077: case 0:
078: return "..";
079: case 1:
080: return "..";
081: case 2:
082: return "Element Name";
083: case 3:
084: return "Element Type";
085: }
086: return null;
087: }
088:
089: public boolean isCellEditable(int rowIndex, int columnIndex) {
090: if (columnIndex == 0)
091: return true;
092: else
093: return false;
094: }
095:
096: public Class getColumnClass(int columnIndex) {
097: if (columnIndex == 0)
098: return Boolean.class;
099: else
100: return super .getColumnClass(columnIndex);
101: }
102:
103: public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
104: if (columnIndex == 0) {
105: try {
106: ModelElement lElement = (ModelElement) mList
107: .get(rowIndex);
108: Boolean lValue = (Boolean) aValue;
109: if (lValue.equals(Boolean.TRUE))
110: PrimaryKeyElementUserObject
111: .createNewPrimaryKeyElement(mEntity,
112: lElement);
113: else
114: PrimaryKeyElementUserObject
115: .deletePrimaryKeyElement(mEntity, lElement);
116: } catch (Exception e) {
117: e.printStackTrace();
118: }
119: }
120: super .setValueAt(aValue, rowIndex, columnIndex);
121: }
122:
123: // check element included into primary key
124: private Boolean isRowInPrimaryKey(int pIndex) {
125: ModelElement lElement = (ModelElement) mList.get(pIndex);
126: if (lElement != null && mEntity != null) {
127: Object[] lList = mEntity.getPrimaryKeyElements().toArray();
128: for (int i = 0; i < lList.length; i++)
129: if (lList[i].equals(lElement))
130: return Boolean.TRUE;
131: }
132: return Boolean.FALSE;
133: }
134: }
|