1 package org.netbeans.modules.tasklist.suggestions.ui; 2 3 import java.awt.Image ; 4 import javax.swing.event.ChangeEvent ; 5 import javax.swing.event.ChangeListener ; 6 import javax.swing.event.ListDataEvent ; 7 import javax.swing.event.ListDataListener ; 8 import javax.swing.table.AbstractTableModel ; 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 20 public class SuggestionsTableModel extends AbstractTableModel 21 implements ListDataListener { 22 25 public static enum Columns { 26 SUMMARY, PRIORITY, DETAILS, FILE, LINE, TYPE 27 }; 28 29 private static final String [] COLUMNS = { 30 NbBundle.getMessage(SuggestionsTableModel.class, "SummaryCol"), NbBundle.getMessage(SuggestionsTableModel.class, "PriorityCol"), NbBundle.getMessage(SuggestionsTableModel.class, "DetailsCol"), NbBundle.getMessage(SuggestionsTableModel.class, "FileCol"), NbBundle.getMessage(SuggestionsTableModel.class, "LineCol"), NbBundle.getMessage(SuggestionsTableModel.class, "TypeCol") }; 37 38 private Suggestion[] list; 39 40 private Class <?>[] COLUMN_CLASSES = new Class [] { 41 String .class, 42 SuggestionPriority.class, 43 String .class, 44 String .class, 45 Integer .class, 46 Image .class, 47 }; 48 49 52 public SuggestionsTableModel() { 53 StaticSuggestions sm = StaticSuggestions.getDefault(); 54 list = sm.getAll(); 55 sm.addListener(this); 56 } 57 58 public Object 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 getColumnName(int column) { 96 return COLUMNS[column]; 97 } 98 99 105 public Suggestion getSuggestion(int row) { 106 return list[row]; 107 } 108 109 public void stateChanged(ChangeEvent e) { 110 } 111 112 public Class <?> getColumnClass(int columnIndex) { 113 return COLUMN_CLASSES[columnIndex]; 114 } 115 116 public void intervalRemoved(ListDataEvent e) { 117 list = StaticSuggestions.getDefault().getAll(); 118 fireTableRowsDeleted(e.getIndex0(), e.getIndex1()); 119 } 120 121 public void intervalAdded(ListDataEvent e) { 122 list = StaticSuggestions.getDefault().getAll(); 123 fireTableRowsInserted(e.getIndex0(), e.getIndex1()); 124 } 125 126 public void contentsChanged(ListDataEvent e) { 127 list = StaticSuggestions.getDefault().getAll(); 128 fireTableRowsUpdated(e.getIndex0(), e.getIndex1()); 129 } 130 } 131 | Popular Tags |