001: /*
002: The contents of this file are subject to the Mozilla Public License Version 1.1
003: (the "License"); you may not use this file except in compliance with the License.
004: You may obtain a copy of the License at http://www.mozilla.org/MPL/
005:
006: Software distributed under the License is distributed on an "AS IS" basis,
007: WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: for the specific language governing rights and limitations under the License.
009:
010: The Original Code is "The Columba Project"
011:
012: The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013: Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014:
015: All Rights Reserved.
016: */
017: package org.columba.core.gui.scripting;
018:
019: import java.util.ArrayList;
020: import java.util.List;
021: import java.util.Observable;
022: import java.util.Observer;
023:
024: import javax.swing.SwingUtilities;
025: import javax.swing.table.AbstractTableModel;
026:
027: import org.columba.core.scripting.ScriptLogger;
028:
029: /**
030: @author Celso Pinto (cpinto@yimports.com)
031: */
032: public class ScriptLogTableModel extends AbstractTableModel implements
033: Observer {
034:
035: private static final String RES_MESSAGE_COLUMN = "Message";
036:
037: private String[] columns = new String[] { RES_MESSAGE_COLUMN };
038:
039: public static final int MESSAGE_COLUMN = 0;
040:
041: private List<ScriptLogger.LogEntry> logList;
042:
043: public ScriptLogTableModel() {
044: logList = new ArrayList<ScriptLogger.LogEntry>();
045: logList.addAll(ScriptLogger.getInstance().dumpCurrentLog());
046: ScriptLogger.getInstance().addObserver(this );
047: }
048:
049: public void clearLog() {
050: logList.clear();
051: ScriptLogger.getInstance().clear();
052: fireTableChangedEv();
053: }
054:
055: public int getColumnCount() {
056: return columns.length;
057: }
058:
059: public int getRowCount() {
060: return logList.size();
061: }
062:
063: public String getColumnName(int col) {
064: return columns[col];
065: }
066:
067: public Class getColumnClass(int columnIndex) {
068: if (columnIndex == 0)
069: return ScriptLogger.LogEntry.class;
070: else
071: return super .getColumnClass(columnIndex);
072: }
073:
074: public Object getValueAt(int row, int col) {
075: switch (col) {
076: case MESSAGE_COLUMN:
077: return logList.get(row);
078: default:
079: return "";
080: }
081:
082: }
083:
084: private void fireTableChangedEv() {
085: SwingUtilities.invokeLater(new Runnable() {
086: public void run() {
087: fireTableDataChanged();
088: }
089: });
090: }
091:
092: public void update(Observable o, Object arg) {
093: fireTableChangedEv();
094: }
095:
096: public void dispose() {
097: ScriptLogger.getInstance().deleteObserver(this);
098: }
099:
100: }
|