001: /*
002: * Copyright (C) 2005 Jeff Tassin
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package com.jeta.swingbuilder.gui.formmgr;
020:
021: import java.util.ArrayList;
022: import java.util.Collection;
023: import java.util.Iterator;
024:
025: import javax.swing.table.AbstractTableModel;
026:
027: import com.jeta.forms.gui.form.FormComponent;
028: import com.jeta.forms.gui.formmgr.FormManager;
029: import com.jeta.open.i18n.I18N;
030: import com.jeta.open.registry.JETARegistry;
031:
032: /**
033: * This class is the table model for the FormManagerView. It gets the list of
034: * forms from the FormManager and stores them in this model. This is mainly used
035: * to help debugging.
036: *
037: * @author Jeff Tassin
038: */
039: public class FormsModel extends AbstractTableModel {
040: /** an array of Trigger object */
041: private ArrayList m_data;
042:
043: /** an array of column names for the table */
044: private String[] m_colnames;
045:
046: /** an array of column types for the table */
047: private Class[] m_coltypes;
048:
049: /** column definitions */
050: static final int EMBEDDED_COLUMN = 0;
051: static final int ID_COLUMN = 1;
052: static final int NAME_COLUMN = 2;
053: static final int PARENT_COLUMN = 3;
054:
055: /**
056: * ctor.
057: */
058: public FormsModel() {
059: super ();
060:
061: m_data = new ArrayList();
062:
063: String[] values = { I18N.getLocalizedMessage("Embedded"),
064: I18N.getLocalizedMessage("Form Id"),
065: I18N.getLocalizedMessage("Name"),
066: I18N.getLocalizedMessage("Parent Form Id") };
067:
068: m_colnames = values;
069:
070: Class[] types = { Boolean.class, String.class, String.class,
071: String.class };
072: m_coltypes = types;
073: reload();
074: }
075:
076: /**
077: * Adds the given trigger object to the table
078: */
079: public void addRow(FormComponent fc) {
080: if (m_data == null)
081: m_data = new ArrayList();
082:
083: m_data.add(fc);
084: fireTableRowsInserted(m_data.size() - 1, m_data.size() - 1);
085: }
086:
087: /**
088: * @return the number of columns in this model
089: */
090: public int getColumnCount() {
091: return m_colnames.length;
092: }
093:
094: /**
095: * @return the number of rows objects in this model
096: */
097: public int getRowCount() {
098: return m_data.size();
099: }
100:
101: /**
102: * @return the name of a column at a given index
103: */
104: public String getColumnName(int column) {
105: return m_colnames[column];
106: }
107:
108: /**
109: * @return the type of column at a given index
110: */
111: public Class getColumnClass(int column) {
112: return m_coltypes[column];
113: }
114:
115: /**
116: * @return the object at the given row in the model
117: */
118: public FormComponent getRow(int row) {
119: if (row >= 0 && row < m_data.size())
120: return (FormComponent) m_data.get(row);
121: else
122: return null;
123: }
124:
125: /**
126: * @return the column value at the given row
127: */
128: public Object getValueAt(int row, int column) {
129: /** "Embedded", "Form Id", "Name", "Parent Id" */
130: FormComponent fc = getRow(row);
131: if (column == EMBEDDED_COLUMN) {
132: return Boolean.valueOf(fc.isEmbedded());
133: } else if (column == ID_COLUMN) {
134: return fc.getId();
135: } else if (column == NAME_COLUMN) {
136: return fc.getChildView().getName();
137: } else if (column == PARENT_COLUMN) {
138: FormComponent parent = fc.getParentForm();
139: if (parent == null)
140: return "null";
141: else
142: return parent.getId();
143: } else
144: return "";
145: }
146:
147: /**
148: * Reload the model
149: */
150: public void reload() {
151: removeAll();
152: FormManager fm = (FormManager) JETARegistry
153: .lookup(FormManager.COMPONENT_ID);
154: Collection form_ids = fm.getForms();
155: Iterator iter = form_ids.iterator();
156: while (iter.hasNext()) {
157: String form_id = (String) iter.next();
158: addRow(fm.getForm(form_id));
159: }
160: }
161:
162: /**
163: * Remove all data items from this model
164: */
165: public void removeAll() {
166: m_data.clear();
167: }
168:
169: }
|