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.components;
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.BaseUserObject;
023: import com.metaboss.applications.designstudio.Application.ObjectChangedEvent;
024:
025: /* Base class for fields table models */
026:
027: public abstract class FieldsModel extends AbstractTableModel {
028: protected ArrayList mFields = new ArrayList();
029: protected String mFirstColumnName = "Field";
030: protected String mSecondColumnName = "Type";
031:
032: public FieldsModel(String pFirstColumn, String pSecondColumn) {
033: this ();
034: mFirstColumnName = pFirstColumn;
035: mSecondColumnName = pSecondColumn;
036: }
037:
038: public FieldsModel() {
039: super ();
040:
041: Application
042: .addObjectChanged(new Application.ObjectChangedListener() {
043: public void onObjectChanged(ObjectChangedEvent event) {
044: try {
045: switch (event.getEventSource()) {
046: case ObjectChangedEvent.ET_INSERTED:
047: processObjectInserted(event
048: .getUserObject());
049: break;
050: case ObjectChangedEvent.ET_EDITED:
051: processObjectEdited(event
052: .getUserObject());
053: break;
054: case ObjectChangedEvent.ET_DELETED:
055: processObjectDeleted(event);
056: break;
057: }
058: } catch (Exception e) {
059: e.printStackTrace();
060: }
061: }
062: });
063: }
064:
065: public int getRowCount() {
066: return mFields.size();
067: }
068:
069: public int getColumnCount() {
070: return 4;
071: }
072:
073: public BaseUserObject findUserObjectByID(String pID) {
074: for (int i = 0; i < getRowCount(); i++) {
075: BaseUserObject lObject = getUserObject(i);
076: if (lObject != null && lObject.getID().equals(pID))
077: return lObject;
078: }
079: return null;
080: }
081:
082: public BaseUserObject getUserObject(int pIndex) {
083: return (BaseUserObject) mFields.get(pIndex);
084: }
085:
086: public Object getValueAt(int r, int c) {
087: BaseUserObject lField = getUserObject(r);
088: try {
089: switch (c) {
090: case 0:
091: return lField.getIcon();
092: case 1:
093: return lField.toString();
094: case 2:
095: return getObjectType(lField);
096: case 3:
097: return lField.getToolTip();
098: }
099: } catch (Exception e) {
100: e.printStackTrace();
101: }
102: return null;
103: }
104:
105: public String getObjectType(BaseUserObject pObject) {
106: return null;
107: }
108:
109: public String getColumnName(int c) {
110: switch (c) {
111: case 0:
112: return "..";
113: case 1:
114: return mFirstColumnName;
115: case 2:
116: return mSecondColumnName;
117: case 3:
118: return "Description";
119: }
120: return null;
121: }
122:
123: protected void processObjectInserted(BaseUserObject pObject) {
124: //???
125: }
126:
127: protected void processObjectEdited(BaseUserObject pObject) {
128: //???
129: }
130:
131: protected void processObjectDeleted(ObjectChangedEvent event) {
132: BaseUserObject lObject = event.getUserObject();
133: if (lObject == null)
134: lObject = findUserObjectByID(event.getObjectID());
135: if (lObject != null) {
136: mFields.remove(lObject);
137: fireTableDataChanged();
138: }
139: }
140: }
|