KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > suggestions > ui > SuggestionsTableModel


1 package org.netbeans.modules.tasklist.suggestions.ui;
2
3 import java.awt.Image JavaDoc;
4 import javax.swing.event.ChangeEvent JavaDoc;
5 import javax.swing.event.ChangeListener JavaDoc;
6 import javax.swing.event.ListDataEvent JavaDoc;
7 import javax.swing.event.ListDataListener JavaDoc;
8 import javax.swing.table.AbstractTableModel JavaDoc;
9 import org.netbeans.modules.tasklist.client.*;
10 import org.openide.filesystems.FileObject;
11 import org.openide.loaders.DataObject;
12 import org.openide.text.Line;
13 import org.openide.util.NbBundle;
14
15 /**
16  * A table model for suggestions.
17  *
18  * @author tl
19  */

20 public class SuggestionsTableModel extends AbstractTableModel JavaDoc
21         implements ListDataListener JavaDoc {
22     /**
23      * Columns
24      */

25     public static enum Columns {
26         SUMMARY, PRIORITY, DETAILS, FILE, LINE, TYPE
27     };
28     
29     private static final String JavaDoc[] COLUMNS = {
30         NbBundle.getMessage(SuggestionsTableModel.class, "SummaryCol"), // NOI18N
31
NbBundle.getMessage(SuggestionsTableModel.class, "PriorityCol"), // NOI18N
32
NbBundle.getMessage(SuggestionsTableModel.class, "DetailsCol"), // NOI18N
33
NbBundle.getMessage(SuggestionsTableModel.class, "FileCol"), // NOI18N
34
NbBundle.getMessage(SuggestionsTableModel.class, "LineCol"), // NOI18N
35
NbBundle.getMessage(SuggestionsTableModel.class, "TypeCol") // NOI18N
36
};
37     
38     private Suggestion[] list;
39
40     private Class JavaDoc<?>[] COLUMN_CLASSES = new Class JavaDoc[] {
41         String JavaDoc.class,
42         SuggestionPriority.class,
43         String JavaDoc.class,
44         String JavaDoc.class,
45         Integer JavaDoc.class,
46         Image JavaDoc.class,
47     };
48     
49     /**
50      * Creates a new instance of SuggestionsTableMode
51      */

52     public SuggestionsTableModel() {
53         StaticSuggestions sm = StaticSuggestions.getDefault();
54         list = sm.getAll();
55         sm.addListener(this);
56     }
57
58     public Object JavaDoc getValueAt(int rowIndex, int columnIndex) {
59         Suggestion sug = getSuggestion(rowIndex);
60         switch (columnIndex) {
61             case 0:
62                 return sug.getSummary();
63             case 1:
64                 return sug.getPriority();
65             case 2:
66                 return sug.getDetails();
67             case 3:
68                 FileObject fo = sug.getFileObject();
69                 if (fo == null) {
70                     Line l = sug.getLine();
71                     DataObject dobj = l.getLookup().lookup(DataObject.class);
72                     if (dobj == null)
73                         return null;
74                     else
75                         return dobj.getPrimaryFile().getNameExt();
76                 }
77                 return fo.getNameExt();
78             case 4:
79                 return sug.getLine().getLineNumber() + 1;
80             case 5:
81                 return sug;
82             default:
83                 return null;
84         }
85     }
86
87     public int getRowCount() {
88         return list.length;
89     }
90
91     public int getColumnCount() {
92         return 6;
93     }
94
95     public String JavaDoc getColumnName(int column) {
96        return COLUMNS[column];
97     }
98     
99     /**
100      * Returns the suggestion object for the specified row.
101      *
102      * @param row row number
103      * @return Suggestion
104      */

105     public Suggestion getSuggestion(int row) {
106         return list[row];
107     }
108
109     public void stateChanged(ChangeEvent JavaDoc e) {
110     }
111
112     public Class JavaDoc<?> getColumnClass(int columnIndex) {
113         return COLUMN_CLASSES[columnIndex];
114     }
115
116     public void intervalRemoved(ListDataEvent JavaDoc e) {
117         list = StaticSuggestions.getDefault().getAll();
118         fireTableRowsDeleted(e.getIndex0(), e.getIndex1());
119     }
120
121     public void intervalAdded(ListDataEvent JavaDoc e) {
122         list = StaticSuggestions.getDefault().getAll();
123         fireTableRowsInserted(e.getIndex0(), e.getIndex1());
124     }
125
126     public void contentsChanged(ListDataEvent JavaDoc e) {
127         list = StaticSuggestions.getDefault().getAll();
128         fireTableRowsUpdated(e.getIndex0(), e.getIndex1());
129     }
130 }
131
Popular Tags