1 package org.netbeans.modules.tasklist.suggestions.ui; 2 3 import java.awt.event.MouseAdapter ; 4 import java.awt.event.MouseEvent ; 5 import java.beans.PropertyVetoException ; 6 import javax.swing.Action ; 7 import javax.swing.JPopupMenu ; 8 import javax.swing.JTable ; 9 import javax.swing.event.ListSelectionListener ; 10 import javax.swing.table.TableColumn ; 11 import org.netbeans.modules.tasklist.client.Suggestion; 12 import org.netbeans.modules.tasklist.core.editors.PriorityTableCellRenderer; 13 import org.netbeans.modules.tasklist.suggestions.SuggestionImpl; 14 import org.netbeans.modules.tasklist.suggestions.SuggestionNode; 15 import org.openide.ErrorManager; 16 import org.openide.awt.MouseUtils; 17 import org.openide.explorer.ExplorerManager; 18 import org.openide.nodes.Node; 19 import org.openide.text.Line; 20 import org.openide.util.Utilities; 21 22 27 public class SuggestionsTable extends JTable { 28 31 public SuggestionsTable() { 32 super(new SuggestionsTableModel()); 33 34 addMouseListener(new MouseUtils.PopupMouseAdapter() { 35 public void showPopup(MouseEvent e) { 36 int row = rowAtPoint(e.getPoint()); 37 int col = columnAtPoint(e.getPoint()); 38 Action [] actions; 39 if (row < 0 || col < 0) 40 return; 41 42 if (!getSelectionModel().isSelectedIndex(row)) { 43 setRowSelectionInterval(row, row); 44 } 45 Node n = createNode(row); 46 47 actions = n.getActions(false); 48 49 JPopupMenu pm = Utilities.actionsToPopup(actions, 50 SuggestionsTable.this); 51 if(pm != null) 52 pm.show(SuggestionsTable.this, e.getX(), e.getY()); 53 } 54 }); 55 56 getSelectionModel().addListSelectionListener( 57 new ListSelectionListener () { 58 public void valueChanged(javax.swing.event.ListSelectionEvent e) { 59 int row = getSelectedRow(); 60 ExplorerManager em = ExplorerManager.find( 61 SuggestionsTable.this); 62 if (em == null) 63 return; 64 try { 65 if (row < 0) 66 em.setSelectedNodes(new Node[0]); 67 else { 68 Node sn = createNode(row); 69 em.setRootContext(sn); 70 em.setSelectedNodes(new Node[] {sn}); 71 } 72 } catch (PropertyVetoException ex) { 73 ErrorManager.getDefault().notify(ex); 74 } 75 } 76 } 77 ); 78 addMouseListener(new MouseAdapter () { 79 public void mouseClicked(MouseEvent e) { 80 if (e.getClickCount() != 2) 81 return; 82 JTable tt = (JTable ) e.getSource(); 83 int row = tt.rowAtPoint(e.getPoint()); 84 if (row < 0) 85 return; 86 Suggestion s = 87 ((SuggestionsTableModel) tt.getModel()).getSuggestion(row); 88 Line l = s.getLine(); 89 if (l != null) 90 l.show(Line.SHOW_GOTO); 91 } 92 }); 93 94 setAutoResizeMode(AUTO_RESIZE_OFF); 95 96 TableColumn tc = getColumnModel().getColumn( 97 SuggestionsTableModel.Columns.TYPE.ordinal()); 98 tc.setCellRenderer(new CategoryTableCellRenderer()); 99 tc.setPreferredWidth(100); 100 101 tc = getColumnModel().getColumn( 102 SuggestionsTableModel.Columns.PRIORITY.ordinal()); 103 tc.setPreferredWidth(60); 104 tc.setCellRenderer(new PriorityTableCellRenderer()); 105 106 tc = getColumnModel().getColumn( 107 SuggestionsTableModel.Columns.SUMMARY.ordinal()); 108 tc.setPreferredWidth(400); 109 110 tc = getColumnModel().getColumn( 111 SuggestionsTableModel.Columns.DETAILS.ordinal()); 112 tc.setPreferredWidth(300); 113 114 tc = getColumnModel().getColumn( 115 SuggestionsTableModel.Columns.FILE.ordinal()); 116 tc.setPreferredWidth(200); 117 118 tc = getColumnModel().getColumn( 119 SuggestionsTableModel.Columns.LINE.ordinal()); 120 tc.setPreferredWidth(40); 121 } 122 123 129 private Node createNode(int row) { 130 Suggestion s = 131 ((SuggestionsTableModel) getModel()).getSuggestion(row); 132 return new SuggestionNode((SuggestionImpl) s); 133 } 134 } 135 | Popular Tags |