KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > gui > scripting > ScriptsTableModel


1 /*
2
3 The contents of this file are subject to the Mozilla Public License Version 1.1
4 (the "License") you may not use this file except in compliance with the License.
5
6 You may obtain a copy of the License at http://www.mozilla.org/MPL/
7
8 Software distributed under the License is distributed on an "AS IS" basis,
9 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10 for the specific language governing rights and limitations under the License.
11
12 The Original Code is "BshInterpreter plugin for The Columba Project"
13
14 The Initial Developer of the Original Code is Celso Pinto
15 Portions created by Celso Pinto are Copyright (C) 2005.
16 Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
17
18 All Rights Reserved.
19
20 */

21 package org.columba.core.gui.scripting;
22
23 import java.util.List JavaDoc;
24
25 import javax.swing.SwingUtilities JavaDoc;
26 import javax.swing.table.AbstractTableModel JavaDoc;
27
28 import org.columba.core.scripting.IScriptsObserver;
29 import org.columba.core.scripting.model.ColumbaScript;
30
31 /**
32     @author Celso Pinto (cpinto@yimports.com)
33  */

34 public class ScriptsTableModel
35     extends AbstractTableModel JavaDoc
36     implements IScriptsObserver
37 {
38
39     private static final String JavaDoc
40         RES_NAME_COLUMN = "Script name",
41         RES_AUTHOR_COLUMN = "Author",
42         RES_DESCRIPTION_COLUMN = "Description";
43
44     private String JavaDoc[] columns = new String JavaDoc[]
45         {
46             RES_NAME_COLUMN,
47             RES_AUTHOR_COLUMN,
48             RES_DESCRIPTION_COLUMN
49         };
50
51     public static final int
52         NAME_COLUMN = 0,
53         AUTHOR_COLUMN = 1,
54         DESCRIPTION_COLUMN = 2;
55
56     private List JavaDoc scriptList;
57
58     private ScriptManagerDocument document;
59
60     public ScriptsTableModel(ScriptManagerDocument doc)
61     {
62
63         document = doc;
64         document.addObserver(this);
65
66         scriptList = document.getScripts();
67     }
68
69     public int getColumnCount()
70     {
71         return columns.length;
72     }
73
74     public int getRowCount()
75     {
76         return scriptList.size();
77     }
78
79     public String JavaDoc getColumnName(int col)
80     {
81         return columns[col];
82     }
83
84
85     public Class JavaDoc getColumnClass(int columnIndex)
86     {
87         if (columnIndex == 0) return ColumbaScript.class;
88         else return super.getColumnClass(columnIndex);
89     }
90
91     public Object JavaDoc getValueAt(int row, int col)
92     {
93         ColumbaScript script = (ColumbaScript) scriptList.get(row);
94         switch (col)
95         {
96             case NAME_COLUMN:
97                 return script;
98             case AUTHOR_COLUMN:
99                 return script.getAuthor();
100             case DESCRIPTION_COLUMN:
101                 return script.getDescription();
102             default:
103                 return "";
104         }
105
106     }
107
108     private void fireTableChangedEv()
109     {
110         SwingUtilities.invokeLater(new Runnable JavaDoc()
111         {
112             public void run()
113             {
114                 fireTableDataChanged();
115             }
116         });
117     }
118
119     public void scriptsAdded(List JavaDoc scripts)
120     {
121         scriptList.addAll(scripts);
122         fireTableChangedEv();
123     }
124
125     public void scriptsRemoved(List JavaDoc scripts)
126     {
127         scriptList.removeAll(scripts);
128         fireTableChangedEv();
129     }
130
131     public void scriptsChanged(List JavaDoc scripts)
132     {
133         fireTableChangedEv();
134     }
135
136 }
137
Popular Tags