1 19 20 package org.netbeans.modules.versioning.system.cvss.ui.history; 21 22 import org.openide.explorer.view.TreeTableView; 23 import org.openide.explorer.ExplorerManager; 24 import org.openide.nodes.Node; 25 import org.openide.nodes.PropertySupport; 26 import org.openide.nodes.AbstractNode; 27 import org.openide.nodes.Children; 28 import org.openide.util.lookup.Lookups; 29 import org.openide.util.NbBundle; 30 import org.openide.ErrorManager; 31 import org.netbeans.modules.versioning.system.cvss.CvsModuleConfig; 32 33 import javax.swing.*; 34 import javax.swing.tree.DefaultTreeCellRenderer ; 35 import java.lang.reflect.InvocationTargetException ; 36 import java.util.*; 37 import java.beans.PropertyVetoException ; 38 import java.awt.Window ; 39 import java.awt.Point ; 40 import java.awt.Cursor ; 41 import java.awt.event.MouseListener ; 42 import java.awt.event.MouseEvent ; 43 import java.awt.event.MouseMotionListener ; 44 45 50 class DiffTreeTable extends TreeTableView implements MouseListener , MouseMotionListener { 51 52 private RevisionsRootNode rootNode; 53 private List results; 54 55 public DiffTreeTable() { 56 treeTable.setShowHorizontalLines(true); 57 treeTable.setShowVerticalLines(false); 58 setRootVisible(false); 59 setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); 60 setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); 61 setupColumns(); 62 63 DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer (); 64 renderer.setOpenIcon(null); 65 renderer.setClosedIcon(null); 66 renderer.setLeafIcon(null); 67 tree.setCellRenderer(renderer); 68 69 treeTable.addMouseListener(this); 70 treeTable.addMouseMotionListener(this); 71 } 72 73 private SearchHistoryPanel.DispRevision getRevisionWithTagsAt(Point p) { 74 int row = treeTable.rowAtPoint(p); 75 int column = treeTable.columnAtPoint(p); 76 if (row == -1 || column == -1) return null; 77 Object o = treeTable.getValueAt(row, column); 78 if (o instanceof Node.Property) { 79 Node.Property tags = (Node.Property) o; 80 SearchHistoryPanel.DispRevision drev = (SearchHistoryPanel.DispRevision) tags.getValue("dispRevision"); if (drev != null && drev.getBranches() != null && drev.getBranches().size() + drev.getTags().size() > 1) { 82 return drev; 83 } 84 } 85 return null; 86 } 87 88 public void mouseClicked(MouseEvent e) { 89 Point p = e.getPoint(); 90 SearchHistoryPanel.DispRevision drev = getRevisionWithTagsAt(p); 91 if (drev != null) { 92 Window w = SwingUtilities.windowForComponent(treeTable); 93 SwingUtilities.convertPointToScreen(p, treeTable); 94 p.x += 10; 95 p.y += 10; 96 SummaryView.showAllTags(w, p, drev); 97 } 98 } 99 100 public void mouseDragged(MouseEvent e) { 101 } 102 103 public void mouseMoved(MouseEvent e) { 104 if (getRevisionWithTagsAt(e.getPoint()) != null) { 105 treeTable.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); 106 } else { 107 treeTable.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 108 } 109 } 110 111 public void mousePressed(MouseEvent e) { 112 } 113 114 public void mouseReleased(MouseEvent e) { 115 } 116 117 public void mouseEntered(MouseEvent e) { 118 } 119 120 public void mouseExited(MouseEvent e) { 121 } 122 123 private void setupColumns() { 124 ResourceBundle loc = NbBundle.getBundle(DiffTreeTable.class); 125 Node.Property [] columns; 126 if (CvsModuleConfig.getDefault().getPreferences().getBoolean(CvsModuleConfig.PROP_SEARCHHISTORY_FETCHTAGS, true)) { 127 columns = new Node.Property[6]; 128 columns[4] = new ColumnDescriptor(RevisionNode.COLUMN_NAME_TAGS, List.class, loc.getString("LBL_DiffTree_Column_Tags"), loc.getString("LBL_DiffTree_Column_Tags_Desc")); 129 columns[5] = new ColumnDescriptor(RevisionNode.COLUMN_NAME_MESSAGE, String .class, loc.getString("LBL_DiffTree_Column_Message"), loc.getString("LBL_DiffTree_Column_Message_Desc")); 130 } else { 131 columns = new Node.Property[5]; 132 columns[4] = new ColumnDescriptor(RevisionNode.COLUMN_NAME_MESSAGE, String .class, loc.getString("LBL_DiffTree_Column_Message"), loc.getString("LBL_DiffTree_Column_Message_Desc")); 133 } 134 columns[0] = new ColumnDescriptor(RevisionNode.COLUMN_NAME_NAME, String .class, "", ""); columns[0].setValue("TreeColumnTTV", Boolean.TRUE); columns[1] = new ColumnDescriptor(RevisionNode.COLUMN_NAME_LOCATION, String .class, loc.getString("LBL_DiffTree_Column_Location"), loc.getString("LBL_DiffTree_Column_Location_Desc")); 137 columns[2] = new ColumnDescriptor(RevisionNode.COLUMN_NAME_DATE, String .class, loc.getString("LBL_DiffTree_Column_Time"), loc.getString("LBL_DiffTree_Column_Time_Desc")); 138 columns[3] = new ColumnDescriptor(RevisionNode.COLUMN_NAME_USERNAME, String .class, loc.getString("LBL_DiffTree_Column_Username"), loc.getString("LBL_DiffTree_Column_Username_Desc")); 139 setProperties(columns); 140 } 141 142 private void setDefaultColumnSizes() { 143 SwingUtilities.invokeLater(new Runnable () { 144 public void run() { 145 int width = getWidth(); 146 if (CvsModuleConfig.getDefault().getPreferences().getBoolean(CvsModuleConfig.PROP_SEARCHHISTORY_FETCHTAGS, true)) { 147 if (treeTable.getColumnModel().getColumnCount() != 6) return; 148 treeTable.getColumnModel().getColumn(0).setPreferredWidth(width * 15 / 100); 149 treeTable.getColumnModel().getColumn(1).setPreferredWidth(width * 15 / 100); 150 treeTable.getColumnModel().getColumn(2).setPreferredWidth(width * 10 / 100); 151 treeTable.getColumnModel().getColumn(3).setPreferredWidth(width * 10 / 100); 152 treeTable.getColumnModel().getColumn(4).setPreferredWidth(width * 10 / 100); 153 treeTable.getColumnModel().getColumn(5).setPreferredWidth(width * 40 / 100); 154 } else { 155 if (treeTable.getColumnModel().getColumnCount() != 5) return; 156 treeTable.getColumnModel().getColumn(0).setPreferredWidth(width * 20 / 100); 157 treeTable.getColumnModel().getColumn(1).setPreferredWidth(width * 20 / 100); 158 treeTable.getColumnModel().getColumn(2).setPreferredWidth(width * 10 / 100); 159 treeTable.getColumnModel().getColumn(3).setPreferredWidth(width * 10 / 100); 160 treeTable.getColumnModel().getColumn(4).setPreferredWidth(width * 40 / 100); 161 } 162 } 163 }); 164 } 165 166 void setSelection(int idx) { 167 treeTable.getSelectionModel().setValueIsAdjusting(false); 168 treeTable.scrollRectToVisible(treeTable.getCellRect(idx, 1, true)); 169 treeTable.getSelectionModel().setSelectionInterval(idx, idx); 170 } 171 172 void setSelection(SearchHistoryPanel.ResultsContainer container) { 173 RevisionNode node = (RevisionNode) getNode(rootNode, container); 174 if (node == null) return; 175 ExplorerManager em = ExplorerManager.find(this); 176 try { 177 em.setSelectedNodes(new Node [] { node }); 178 } catch (PropertyVetoException e) { 179 ErrorManager.getDefault().notify(e); 180 } 181 } 182 183 void setSelection(SearchHistoryPanel.DispRevision revision) { 184 RevisionNode node = (RevisionNode) getNode(rootNode, revision); 185 if (node == null) return; 186 ExplorerManager em = ExplorerManager.find(this); 187 try { 188 em.setSelectedNodes(new Node [] { node }); 189 } catch (PropertyVetoException e) { 190 ErrorManager.getDefault().notify(e); 191 } 192 } 193 194 private Node getNode(Node node, Object obj) { 195 Object object = node.getLookup().lookup(obj.getClass()); 196 if (obj.equals(object)) return node; 197 Enumeration children = node.getChildren().nodes(); 198 while (children.hasMoreElements()) { 199 Node child = (Node) children.nextElement(); 200 Node result = getNode(child, obj); 201 if (result != null) return result; 202 } 203 return null; 204 } 205 206 public int [] getSelection() { 207 return treeTable.getSelectedRows(); 208 } 209 210 public int getRowCount() { 211 return treeTable.getRowCount(); 212 } 213 214 private static class ColumnDescriptor extends PropertySupport.ReadOnly { 215 216 public ColumnDescriptor(String name, Class type, String displayName, String shortDescription) { 217 super(name, type, displayName, shortDescription); 218 } 219 220 public Object getValue() throws IllegalAccessException , InvocationTargetException { 221 return null; 222 } 223 } 224 225 public void addNotify() { 226 super.addNotify(); 227 ExplorerManager em = ExplorerManager.find(this); 228 em.setRootContext(rootNode); 229 setDefaultColumnSizes(); 230 } 231 232 public void setResults(List results) { 233 this.results = results; 234 rootNode = new RevisionsRootNode(); 235 ExplorerManager em = ExplorerManager.find(this); 236 if (em != null) { 237 em.setRootContext(rootNode); 238 } 239 } 240 241 private class RevisionsRootNode extends AbstractNode { 242 243 public RevisionsRootNode() { 244 super(new RevisionsRootNodeChildren(), Lookups.singleton(results)); 245 } 246 247 public String getName() { 248 return "revision"; } 250 251 public String getDisplayName() { 252 return NbBundle.getMessage(DiffTreeTable.class, "LBL_DiffTree_Column_Name"); } 254 255 public String getShortDescription() { 256 return NbBundle.getMessage(DiffTreeTable.class, "LBL_DiffTree_Column_Name_Desc"); } 258 } 259 260 private class RevisionsRootNodeChildren extends Children.Keys { 261 262 public RevisionsRootNodeChildren() { 263 } 264 265 protected void addNotify() { 266 refreshKeys(); 267 } 268 269 protected void removeNotify() { 270 setKeys(Collections.EMPTY_SET); 271 } 272 273 private void refreshKeys() { 274 setKeys(results); 275 } 276 277 protected Node[] createNodes(Object key) { 278 RevisionNode node; 279 if (key instanceof SearchHistoryPanel.ResultsContainer) { 280 node = new RevisionNode((SearchHistoryPanel.ResultsContainer) key); 281 } else { node = new RevisionNode(((SearchHistoryPanel.DispRevision) key)); 283 } 284 return new Node[] { node }; 285 } 286 } 287 } 288 | Popular Tags |