1 19 20 package org.netbeans.modules.tasklist.suggestions.ui; 21 22 import javax.swing.ButtonGroup ; 23 import org.netbeans.modules.tasklist.core.table.ChooseColumnsPanel; 24 import org.openide.util.NbBundle; 25 import org.openide.util.Utilities; 26 import org.openide.nodes.Node; 27 import org.openide.util.actions.SystemAction; 28 import org.openide.text.Line; 29 import org.netbeans.modules.tasklist.core.*; 30 import org.netbeans.modules.tasklist.core.filter.Filter; 31 import org.netbeans.modules.tasklist.core.filter.FilterAction; 32 import org.netbeans.modules.tasklist.core.filter.RemoveFilterAction; 33 import org.netbeans.modules.tasklist.client.*; 34 35 import java.util.Iterator ; 36 import java.util.Collection ; 37 import java.util.List ; 38 import java.util.ArrayList ; 39 import java.awt.*; 40 import javax.swing.BorderFactory ; 41 import javax.swing.JPanel ; 42 import javax.swing.JScrollPane ; 43 import javax.swing.JTabbedPane ; 44 import javax.swing.JTable ; 45 import javax.swing.JToggleButton ; 46 import javax.swing.JToolBar ; 47 import javax.swing.SwingUtilities ; 48 import javax.swing.border.Border ; 49 import org.netbeans.modules.tasklist.core.export.ExportAction; 50 import org.netbeans.modules.tasklist.suggestions.settings.ManagerSettings; 51 52 import org.netbeans.modules.tasklist.suggestions.*; 53 54 59 public class SuggestionsView extends TaskListView implements SuggestionView { 60 61 private static final long serialVersionUID = 1; 62 63 private static SuggestionsView theView; 64 65 69 public static SuggestionsView createSuggestionsView() { 70 if (theView == null) { 71 theView = new SuggestionsView(); 72 } 73 return theView; 74 } 75 76 public final static String CATEGORY = "suggestions"; 78 private String originalName; 79 private String originalIcon; 80 81 82 private boolean scan = false; 83 private SuggestionsBroker.Job broker; 84 85 private SuggestionType showingType = null; 86 87 90 public SuggestionsView() { 91 this(CATEGORY, 92 NbBundle.getMessage(SuggestionsView.class, "SuggestionsView"), null, 94 true, 95 "org/netbeans/modules/tasklist/suggestions/suggestion.gif" ); 97 scan = true; 98 } 99 100 110 public SuggestionsView(String category, String name, TaskList list, 111 boolean persistent, String icon) { 112 super( 113 category, 114 name, 115 Utilities.loadImage(icon), 118 persistent, 119 list); 120 121 this.originalName = name; 122 this.originalIcon = icon; 123 124 putClientProperty("TabPolicy", "HideWhenAlone"); } 128 129 static final String PROP_SUGG_DETAILS = "suggDetails"; static final String PROP_SUGG_PRIO = "suggPrio"; static final String PROP_SUGG_FILE = "suggFile"; static final String PROP_SUGG_LINE = "suggLine"; static final String PROP_SUGG_CAT = "suggCat"; static final String PROP_SUGG_LOC = "suggLoc"; 136 protected ColumnProperty[] createColumns() { 137 return new ColumnProperty[] { 141 getMainColumn(800), 142 getPriorityColumn(true, 100), 143 getDetailsColumn(false, 800), 144 getFileColumn(true, 150), 145 getLineColumn(true, 50), 146 getCategoryColumn(true, 150) 147 }; 148 }; 149 150 public ColumnProperty getMainColumn(int width) { 151 return new ColumnProperty( 154 0, SuggestionImplProperties.PROP_SUMMARY, 156 true, 157 width 158 ); 159 } 160 161 public ColumnProperty getPriorityColumn(boolean visible, int width) { 162 return new ColumnProperty( 163 1, SuggestionImplProperties.PROP_PRIORITY, 165 true, 166 visible, 167 width 168 ); 169 } 170 171 public ColumnProperty getFileColumn(boolean visible, int width) { 172 return new ColumnProperty( 173 2, SuggestionImplProperties.PROP_FILENAME, 175 true, 176 visible, 177 width 178 ); 179 } 180 181 public ColumnProperty getLineColumn(boolean visible, int width) { 182 return new ColumnProperty( 183 3, SuggestionImplProperties.PROP_LINE_NUMBER, 185 true, 186 visible, 187 width 188 ); 189 } 190 191 public ColumnProperty getCategoryColumn(boolean visible, int width) { 192 return new ColumnProperty( 193 4, SuggestionImplProperties.PROP_CATEGORY, 195 true, 196 visible, 197 width 198 ); 199 } 200 201 public ColumnProperty getDetailsColumn(boolean visible, int width) { 202 return new ColumnProperty( 203 5, SuggestionImplProperties.PROP_DETAILS, 205 true, 206 visible, 207 width 208 ); 209 } 210 211 protected Component createNorthComponent() { 212 SystemAction[] actions = new SystemAction[] { 213 SystemAction.get(FixAction.class), 214 SystemAction.get(ShowSuggestionAction.class), 215 SystemAction.get(FilterAction.class), 216 null, 217 SystemAction.get(RemoveFilterAction.class), 218 SystemAction.get(ShowCategoryAction.class), 219 SystemAction.get(EditTypesAction.class), 220 SystemAction.get(DisableAction.class), 221 null, 222 SystemAction.get(ExportAction.class) 223 }; 224 225 JToolBar toolbar = SystemAction.createToolbarPresenter(actions); 226 toolbar.setFloatable(false); 227 toolbar.putClientProperty("JToolBar.isRollover", Boolean.TRUE); 229 toolbar.setFloatable(false); 230 232 ButtonGroup bg = new ButtonGroup (); 233 JToggleButton cur = new JToggleButton ("Current File", true); bg.add(cur); 235 JToggleButton openedFiles = 236 new JToggleButton ("Opened Projects", false); bg.add(openedFiles); 238 JToggleButton openedProjects = 239 new JToggleButton ("Opened Files", false); bg.add(openedProjects); 241 242 toolbar.add(cur, 0); 243 toolbar.add(openedFiles, 1); toolbar.add(openedProjects, 2); 246 return toolbar; 247 } 248 249 protected String preferredID() { 250 return getClass().getName(); 251 } 252 253 public void readExternal(java.io.ObjectInput objectInput) throws java.io.IOException , java.lang.ClassNotFoundException { 254 int version = objectInput.readInt(); if (version == 1) { 256 scan = objectInput.readBoolean(); 257 theView = this; 258 } 259 super.readExternal(objectInput); 260 category = CATEGORY; 261 } 262 263 public void writeExternal(java.io.ObjectOutput objectOutput) throws java.io.IOException { 264 objectOutput.writeInt(1); objectOutput.writeBoolean(this == theView); super.writeExternal(objectOutput); 267 ObservableList list = getModel(); 268 if (list != null) { 269 flushExpansion(); 270 ManagerSettings.getDefault().store(); 271 } 272 } 273 274 protected void componentHidden() { 275 super.componentHidden(); 276 ObservableList list = getModel(); 278 if (list != null) { 279 flushExpansion(); 280 } 281 getManager().dispatchStop(); 282 283 if (scan) { 284 broker.stopBroker(); setModel(null); 286 } 287 } 288 289 protected void componentShowing() { 290 super.componentShowing(); 291 getManager().dispatchRun(); 292 if (scan) { 293 broker = SuggestionsBroker.getDefault().startBroker(ProviderAcceptor.ALL); 294 setModel(broker.getSuggestionsList()); 295 } 296 } 297 298 protected void componentOpened() { 299 super.componentOpened(); 300 getManager().dispatchPrepare(); 301 } 302 303 protected void componentClosed() { 304 super.componentClosed(); 305 getManager().notifyViewClosed(); 306 theView = null; 307 } 308 309 protected Node createRootNode() { 310 return new TaskListNode(getModel()); 311 } 312 313 public void setFilter(Filter f) { 316 super.setFilter(f); 317 notifyFiltered(null); 318 } 319 320 324 void notifyFiltered(SuggestionType type) { 325 showingType = type; 326 final Image icon; 327 final String title; 328 if (type != null) { 329 icon = type.getIconImage(); 330 title = type.getLocalizedName(); 331 } else { 332 title = originalName; 333 icon = Utilities.loadImage(originalIcon); 334 } 335 336 SwingUtilities.invokeLater(new Runnable () { 337 public void run() { 338 setName(title); 339 setIcon(icon); 340 } 341 }); 342 } 343 344 352 public static SuggestionsView getCurrentView() { 353 return theView; 354 } 355 356 protected TaskAnnotation getAnnotation(Task task) { 357 return new SuggestionAnno(task, this); 358 } 359 360 365 void setScanning(boolean scanning) { 366 final Image icon; 367 if (scanning) { 368 icon = Utilities.loadImage( 369 "org/netbeans/modules/tasklist/suggestions/scanning.gif"); 370 } else { 371 if (showingType != null) { 372 icon = showingType.getIconImage(); 373 } else { 374 icon = Utilities.loadImage(originalIcon); 375 } 376 } 377 SwingUtilities.invokeLater(new Runnable () { 378 public void run() { 379 setIcon(icon); 380 } 381 }); 382 } 383 384 public String toString() { 385 return "SuggestionsView@" + hashCode(); 386 } 387 388 private SuggestionList getSuggestionList() { 389 return (SuggestionList) getList(); 390 } 391 392 394 public boolean isObserved(String category) { 395 return isShowing(); 397 } 398 399 public SuggestionList getSuggestionsModel() { 400 return getSuggestionList(); 401 } 402 403 404 private void flushExpansion() { 405 Collection categoryTasks = getSuggestionList().getCategoryTasks(); 406 if (categoryTasks == null) { 407 return; 408 } 409 SuggestionManagerImpl manager = 410 (SuggestionManagerImpl)SuggestionManager.getDefault(); 411 Node root = getEffectiveRoot(); 412 Iterator it = categoryTasks.iterator(); 413 while (it.hasNext()) { 414 SuggestionImpl s = (SuggestionImpl)it.next(); 415 Node n = TaskNode.find(root, s); 416 if (n == null) { 417 continue; 418 } 419 SuggestionType type = s.getSType(); 420 boolean expanded = isExpanded(n); 421 if (expanded) { 422 manager.setExpandedType(type, true); 423 } else if (manager.isExpandedType(type)) { 424 manager.setExpandedType(type, false); 426 } 427 } 428 } 429 430 432 Line prevLine = null; 433 List erase = null; 434 List origIcon = null; 435 436 442 private void setCursorLine(Line line) { 443 if (line == prevLine) { 444 return; 445 } 446 prevLine = line; 447 448 if (erase != null) { 450 Iterator it = erase.iterator(); 451 Iterator itorig = origIcon.iterator(); 452 while (it.hasNext()) { 453 SuggestionImpl s = (SuggestionImpl) it.next(); 454 Image icon = (Image) itorig.next(); 455 s.setIcon(icon); 456 } 458 } 459 erase = null; 460 origIcon = null; 461 462 463 if (line == null) { 464 return; 467 } 468 469 SuggestionsView view = SuggestionsView.getCurrentView(); 470 if (view != null) { 471 Node node = view.getEffectiveRoot(); 472 highlightNode(node, line); 473 } 474 } 475 476 486 private void highlightNode(Node node, Line line) { 487 SuggestionImpl s = (SuggestionImpl) TaskNode.getTask(node); 488 if (s.getLine() == line) { 489 if (erase == null) { 490 origIcon = new ArrayList (20); 491 erase = new ArrayList (20); 492 } 493 origIcon.add(s.getIcon()); 494 Image badge = Utilities.loadImage( 496 "org/netbeans/modules/tasklist/suggestions/badge.gif"); Image image = Utilities.mergeImages(s.getIcon(), badge, 498 0, 0); 499 s.setIcon(image); 500 erase.add(s); 501 } 502 503 if (s.hasSubtasks() && (isExpanded(node))) { 505 Node[] nodes = node.getChildren().getNodes(); 506 int n = (nodes != null) ? nodes.length : 0; 507 for (int i = 0; i < n; i++) { 508 highlightNode(nodes[i], line); 509 } 510 } 511 } 512 513 private SuggestionManagerImpl getManager() { 514 return (SuggestionManagerImpl)SuggestionManager.getDefault(); 515 } 516 517 public Filter createFilter() { 518 return new SuggestionFilter("Simple"); } 520 521 protected Component createCenterComponent() { 522 Component cmp = super.createCenterComponent(); 523 JTabbedPane tp = new JTabbedPane (); 524 tp.addTab("Current File", cmp); JTable t = new SuggestionsTable(); 526 JScrollPane sp = new JScrollPane (t); 527 ChooseColumnsPanel.installChooseColumnsButton(sp); 528 tp.addTab("Open Projects", sp); return tp; 530 } 531 532 } 533 | Popular Tags |