001: /*
002:
003: The contents of this file are subject to the Mozilla Public License Version 1.1
004: (the "License") you may not use this file except in compliance with the License.
005:
006: You may obtain a copy of the License at http://www.mozilla.org/MPL/
007:
008: Software distributed under the License is distributed on an "AS IS" basis,
009: WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
010: for the specific language governing rights and limitations under the License.
011:
012: The Original Code is "BshInterpreter plugin for The Columba Project"
013:
014: The Initial Developer of the Original Code is Celso Pinto
015: Portions created by Celso Pinto are Copyright (C) 2005.
016: Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
017:
018: All Rights Reserved.
019:
020: */
021: package org.columba.core.gui.scripting;
022:
023: import java.util.List;
024:
025: import javax.swing.SwingUtilities;
026: import javax.swing.table.AbstractTableModel;
027:
028: import org.columba.core.scripting.IScriptsObserver;
029: import org.columba.core.scripting.model.ColumbaScript;
030:
031: /**
032: @author Celso Pinto (cpinto@yimports.com)
033: */
034: public class ScriptsTableModel extends AbstractTableModel implements
035: IScriptsObserver {
036:
037: private static final String RES_NAME_COLUMN = "Script name",
038: RES_AUTHOR_COLUMN = "Author",
039: RES_DESCRIPTION_COLUMN = "Description";
040:
041: private String[] columns = new String[] { RES_NAME_COLUMN,
042: RES_AUTHOR_COLUMN, RES_DESCRIPTION_COLUMN };
043:
044: public static final int NAME_COLUMN = 0, AUTHOR_COLUMN = 1,
045: DESCRIPTION_COLUMN = 2;
046:
047: private List scriptList;
048:
049: private ScriptManagerDocument document;
050:
051: public ScriptsTableModel(ScriptManagerDocument doc) {
052:
053: document = doc;
054: document.addObserver(this );
055:
056: scriptList = document.getScripts();
057: }
058:
059: public int getColumnCount() {
060: return columns.length;
061: }
062:
063: public int getRowCount() {
064: return scriptList.size();
065: }
066:
067: public String getColumnName(int col) {
068: return columns[col];
069: }
070:
071: public Class getColumnClass(int columnIndex) {
072: if (columnIndex == 0)
073: return ColumbaScript.class;
074: else
075: return super .getColumnClass(columnIndex);
076: }
077:
078: public Object getValueAt(int row, int col) {
079: ColumbaScript script = (ColumbaScript) scriptList.get(row);
080: switch (col) {
081: case NAME_COLUMN:
082: return script;
083: case AUTHOR_COLUMN:
084: return script.getAuthor();
085: case DESCRIPTION_COLUMN:
086: return script.getDescription();
087: default:
088: return "";
089: }
090:
091: }
092:
093: private void fireTableChangedEv() {
094: SwingUtilities.invokeLater(new Runnable() {
095: public void run() {
096: fireTableDataChanged();
097: }
098: });
099: }
100:
101: public void scriptsAdded(List scripts) {
102: scriptList.addAll(scripts);
103: fireTableChangedEv();
104: }
105:
106: public void scriptsRemoved(List scripts) {
107: scriptList.removeAll(scripts);
108: fireTableChangedEv();
109: }
110:
111: public void scriptsChanged(List scripts) {
112: fireTableChangedEv();
113: }
114:
115: }
|