001: /**
002: * ===========================================
003: * JFreeReport : a free Java reporting library
004: * ===========================================
005: *
006: * Project Info: http://reporting.pentaho.org/
007: *
008: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
009: *
010: * This library is free software; you can redistribute it and/or modify it under the terms
011: * of the GNU Lesser General Public License as published by the Free Software Foundation;
012: * either version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: * See the GNU Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public License along with this
019: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020: * Boston, MA 02111-1307, USA.
021: *
022: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023: * in the United States and other countries.]
024: *
025: * ------------
026: * ConfigReferenceTableModel.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.modules.misc.referencedoc;
030:
031: import java.io.IOException;
032: import java.io.InputStream;
033: import java.util.ArrayList;
034: import java.util.Collections;
035: import javax.swing.table.AbstractTableModel;
036: import javax.xml.parsers.ParserConfigurationException;
037:
038: import org.jfree.report.modules.gui.config.ConfigEditor;
039: import org.jfree.report.modules.gui.config.model.ClassConfigDescriptionEntry;
040: import org.jfree.report.modules.gui.config.model.ConfigDescriptionEntry;
041: import org.jfree.report.modules.gui.config.model.ConfigDescriptionModel;
042: import org.jfree.report.modules.gui.config.model.EnumConfigDescriptionEntry;
043: import org.jfree.report.modules.gui.config.model.TextConfigDescriptionEntry;
044: import org.jfree.util.ObjectUtilities;
045: import org.xml.sax.SAXException;
046:
047: /**
048: * Creation-Date: 02.10.2007, 20:59:09
049: *
050: * @author Thomas Morgner
051: */
052: public class ConfigReferenceTableModel extends AbstractTableModel {
053: private static class ConfigEntry implements Comparable {
054: private Boolean global;
055: private String keyName;
056: private String description;
057: private String type;
058: private String value;
059:
060: public ConfigEntry(final Boolean global, final String keyName,
061: final String description, final String type,
062: final String value) {
063: if (global == null) {
064: throw new NullPointerException();
065: }
066: if (keyName == null) {
067: throw new NullPointerException();
068: }
069: this .global = global;
070: this .keyName = keyName;
071: this .description = description;
072: this .type = type;
073: this .value = value;
074: }
075:
076: public int compareTo(final Object o) {
077: final ConfigEntry co = (ConfigEntry) o;
078: if (Boolean.FALSE.equals(global)
079: && Boolean.TRUE.equals(co.global)) {
080: return 1;
081: }
082: if (Boolean.TRUE.equals(global)
083: && Boolean.FALSE.equals(co.global)) {
084: return -1;
085: }
086: return keyName.compareTo(co.keyName);
087: }
088:
089: public Boolean getGlobal() {
090: return global;
091: }
092:
093: public String getKeyName() {
094: return keyName;
095: }
096:
097: public String getDescription() {
098: return description;
099: }
100:
101: public String getType() {
102: return type;
103: }
104:
105: public String getValue() {
106: return value;
107: }
108: }
109:
110: private ArrayList entries;
111:
112: public ConfigReferenceTableModel() throws IOException,
113: ParserConfigurationException, SAXException {
114: final ConfigDescriptionModel model = new ConfigDescriptionModel();
115: final InputStream in = ObjectUtilities
116: .getResourceRelativeAsStream(
117: ConfigEditor.CONFIG_DESCRIPTION_FILENAME,
118: ConfigEditor.class);
119: if (in == null) {
120: throw new IllegalStateException("Fatal: No model found");
121: }
122: try {
123: model.load(in);
124: } finally {
125: in.close();
126: }
127:
128: entries = new ArrayList();
129: // entries.add(new ConfigEntry(Boolean.TRUE, "org.jfree.Key", "aasdoa asdasd kawkea aqw asihasldk aiwer aslkdhawoie alsdh aiwhaldhasl kdhaoweh alsdknasl khiowehalksd", "class", "org.free.Cass.asd.asd.asd.asd.asd.asd"));
130: final int size = model.getSize();
131: for (int i = 0; i < size; i++) {
132: final ConfigDescriptionEntry o = model.get(i);
133: if (o.isHidden()) {
134: continue;
135: }
136: final String keyName = o.getKeyName();
137: final String description = o.getDescription();
138: final Boolean global;
139: if (o.isGlobal()) {
140: global = Boolean.TRUE;
141: } else {
142: global = Boolean.FALSE;
143: }
144: if (o instanceof TextConfigDescriptionEntry) {
145: entries.add(new ConfigEntry(global, keyName,
146: description, "text", null));
147: } else if (o instanceof ClassConfigDescriptionEntry) {
148: final ClassConfigDescriptionEntry co = (ClassConfigDescriptionEntry) o;
149: entries.add(new ConfigEntry(global, keyName,
150: description, "class", co.getBaseClass()
151: .getName()));
152: } else if (o instanceof EnumConfigDescriptionEntry) {
153: final EnumConfigDescriptionEntry co = (EnumConfigDescriptionEntry) o;
154: final String[] strings = co.getOptions();
155: final StringBuffer b = new StringBuffer();
156: for (int j = 0; j < strings.length; j++) {
157: if (j != 0) {
158: b.append(", ");
159: }
160: b.append(strings[j]);
161: }
162: entries.add(new ConfigEntry(global, keyName,
163: description, "enum", b.toString()));
164: }
165: }
166:
167: Collections.sort(entries);
168: }
169:
170: public String getColumnName(final int column) {
171: switch (column) {
172: case 0:
173: return "key-name";
174: case 1:
175: return "description";
176: case 2:
177: return "global";
178: case 3:
179: return "type";
180: case 4:
181: return "value";
182: default:
183: throw new IndexOutOfBoundsException();
184: }
185: }
186:
187: public Class getColumnClass(final int columnIndex) {
188: switch (columnIndex) {
189: case 0:
190: return String.class;
191: case 1:
192: return String.class;
193: case 2:
194: return Boolean.class;
195: case 3:
196: return String.class;
197: case 4:
198: return String.class;
199: default:
200: throw new IndexOutOfBoundsException();
201: }
202: }
203:
204: public int getRowCount() {
205: return entries.size();
206: }
207:
208: public int getColumnCount() {
209: return 5;
210: }
211:
212: public Object getValueAt(final int rowIndex, final int columnIndex) {
213: final ConfigEntry o = (ConfigEntry) entries.get(rowIndex);
214:
215: switch (columnIndex) {
216: case 0:
217: return o.getKeyName();
218: case 1:
219: return o.getDescription();
220: case 2:
221: return o.getGlobal();
222: case 3:
223: return o.getType();
224: case 4:
225: return o.getValue();
226: default:
227: throw new IndexOutOfBoundsException();
228: }
229: }
230: }
|