1 13 14 package org.eclipse.ui.views.markers.internal; 15 16 import com.ibm.icu.text.MessageFormat; 17 import java.util.ArrayList ; 18 import java.util.Collection ; 19 import java.util.Iterator ; 20 21 import org.eclipse.core.resources.IMarker; 22 import org.eclipse.core.runtime.IProgressMonitor; 23 import org.eclipse.core.runtime.IStatus; 24 import org.eclipse.core.runtime.Status; 25 import org.eclipse.core.runtime.jobs.Job; 26 import org.eclipse.jface.action.Action; 27 import org.eclipse.jface.action.IAction; 28 import org.eclipse.jface.action.IMenuManager; 29 import org.eclipse.jface.action.IToolBarManager; 30 import org.eclipse.jface.action.MenuManager; 31 import org.eclipse.jface.action.Separator; 32 import org.eclipse.jface.commands.ActionHandler; 33 import org.eclipse.jface.dialogs.IDialogSettings; 34 import org.eclipse.jface.viewers.ColumnLayoutData; 35 import org.eclipse.jface.viewers.IStructuredSelection; 36 import org.eclipse.jface.viewers.TableLayout; 37 import org.eclipse.jface.viewers.ViewerComparator; 38 import org.eclipse.osgi.util.NLS; 39 import org.eclipse.swt.widgets.Composite; 40 import org.eclipse.ui.IActionBars; 41 import org.eclipse.ui.IMemento; 42 import org.eclipse.ui.PlatformUI; 43 import org.eclipse.ui.XMLMemento; 44 import org.eclipse.ui.activities.ActivityManagerEvent; 45 import org.eclipse.ui.activities.IActivityManagerListener; 46 import org.eclipse.ui.handlers.IHandlerActivation; 47 import org.eclipse.ui.handlers.IHandlerService; 48 import org.eclipse.ui.internal.ide.IDEInternalPreferences; 49 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; 50 import org.eclipse.ui.progress.IWorkbenchSiteProgressService; 51 52 56 public class ProblemView extends MarkerView { 57 58 private final static String [] ROOT_TYPES = { IMarker.PROBLEM }; 59 60 private final static String TAG_DIALOG_SECTION = "org.eclipse.ui.views.problem"; 62 private static final String TAG_SYSTEM_FILTER_ENTRY = "systemFilter"; 64 private ActionResolveMarker resolveMarkerAction; 65 66 private IHandlerService handlerService; 67 68 private IHandlerActivation resolveMarkerHandlerActivation; 69 70 private IActivityManagerListener activityManagerListener; 71 72 private IField severityAndMessage = new FieldSeverityAndMessage(); 73 74 private IField folder = new FieldFolder(); 75 76 private IField resource = new FieldResource(); 77 78 private IField lineNumber = new FieldLineNumber(); 79 80 private IField creationTime = new FieldCreationTime(); 81 82 private static IField id = new FieldId(); 85 86 private class GroupingAction extends Action { 87 88 IField groupingField; 89 90 ProblemView problemView; 91 92 99 public GroupingAction(String label, IField field, ProblemView view) { 100 super(label, IAction.AS_RADIO_BUTTON); 101 102 groupingField = field; 103 problemView = view; 104 IField categoryField = view.getMarkerAdapter().getCategorySorter() 105 .getCategoryField(); 106 if (categoryField == null) { 107 setChecked(groupingField == null); 108 } else { 109 setChecked(categoryField.equals(groupingField)); 110 } 111 } 112 113 118 public void run() { 119 120 if (isChecked()) { 121 Job categoryJob = new Job( 122 MarkerMessages.ProblemView_UpdateCategoryJob) { 123 128 protected IStatus run(IProgressMonitor monitor) { 129 try { 130 markerProcessJob.join(); 131 } catch (InterruptedException e) { 132 return Status.CANCEL_STATUS; 133 } 134 problemView.selectCategoryField(groupingField, 135 problemView.getMarkerAdapter() 136 .getCategorySorter()); 137 138 getMarkerAdapter().getCategorySorter().saveState( 139 getDialogSettings()); 140 return Status.OK_STATUS; 141 } 142 }; 143 categoryJob.setSystem(true); 144 problemView.preserveSelection(); 145 146 IWorkbenchSiteProgressService progressService = getProgressService(); 147 if (progressService == null) 148 categoryJob.schedule(); 149 else 150 getProgressService().schedule(categoryJob); 151 152 } 153 154 } 155 } 156 157 160 public ProblemView() { 161 super(); 162 creationTime.setShowing(false); 163 } 164 165 170 public void dispose() { 171 if (resolveMarkerAction != null) { 172 resolveMarkerAction.dispose(); 173 } 174 if (resolveMarkerHandlerActivation != null && handlerService != null) { 175 handlerService.deactivateHandler(resolveMarkerHandlerActivation); 176 } 177 178 PlatformUI.getWorkbench().getActivitySupport().getActivityManager() 179 .removeActivityManagerListener(activityManagerListener); 180 super.dispose(); 181 } 182 183 188 protected IField[] getSortingFields() { 189 return new IField[] { severityAndMessage, folder, resource, lineNumber, 190 creationTime, 191 id }; 194 } 195 196 201 protected IDialogSettings getDialogSettings() { 202 IDialogSettings workbenchSettings = IDEWorkbenchPlugin.getDefault() 203 .getDialogSettings(); 204 IDialogSettings settings = workbenchSettings 205 .getSection(TAG_DIALOG_SECTION); 206 207 if (settings == null) { 208 settings = workbenchSettings.addNewSection(TAG_DIALOG_SECTION); 209 } 210 211 return settings; 212 } 213 214 219 protected void createActions() { 220 super.createActions(); 221 propertiesAction = new ActionProblemProperties(this, getViewer()); 222 resolveMarkerAction = new ActionResolveMarker(this, getViewer()); 223 } 224 225 230 protected void registerGlobalActions(IActionBars actionBars) { 231 super.registerGlobalActions(actionBars); 232 233 String quickFixId = "org.eclipse.jdt.ui.edit.text.java.correction.assist.proposals"; resolveMarkerAction.setActionDefinitionId(quickFixId); 235 236 handlerService = (IHandlerService) getViewSite().getService( 237 IHandlerService.class); 238 if (handlerService != null) { 239 resolveMarkerHandlerActivation = handlerService.activateHandler( 240 quickFixId, new ActionHandler(resolveMarkerAction)); 241 } 242 } 243 244 249 protected void fillContextMenuAdditions(IMenuManager manager) { 250 manager.add(new Separator()); 251 manager.add(resolveMarkerAction); 252 } 253 254 protected String [] getRootTypes() { 255 return ROOT_TYPES; 256 } 257 258 263 protected IField[] getAllFields() { 264 265 return new IField[] { severityAndMessage, resource, folder, lineNumber, 268 creationTime }; 269 } 270 271 void updateTitle() { 272 MarkerList visibleMarkers = getVisibleMarkers(); 273 String breakdown = formatSummaryBreakDown(visibleMarkers); 274 int filteredCount = visibleMarkers.getItemCount(); 275 int totalCount = getTotalMarkers(); 276 if (filteredCount != totalCount) { 277 breakdown = NLS.bind(MarkerMessages.problem_filter_matchedMessage, 278 new Object [] { breakdown, new Integer (filteredCount), 279 new Integer (totalCount) }); 280 } 281 setContentDescription(breakdown); 282 } 283 284 private String formatSummaryBreakDown(MarkerList visibleMarkers) { 285 return MessageFormat.format( 286 MarkerMessages.problem_statusSummaryBreakdown, new Object [] { 287 new Integer (visibleMarkers.getErrors()), 288 new Integer (visibleMarkers.getWarnings()), 289 new Integer (visibleMarkers.getInfos()) }); 290 } 291 292 private String getSummary(MarkerList markers) { 293 String message = MessageFormat.format( 294 MarkerMessages.marker_statusSummarySelected, new Object [] { 295 new Integer (markers.getItemCount()), 296 formatSummaryBreakDown(markers) }); 297 return message; 298 } 299 300 310 protected String updateSummarySelected(IStructuredSelection selection) { 311 Collection selectionList; 312 313 selectionList = new ArrayList (); 314 Iterator selectionIterator = selection.iterator(); 315 while (selectionIterator.hasNext()) { 316 MarkerNode next = (MarkerNode) selectionIterator.next(); 317 if (next.isConcrete()) { 318 selectionList.add(next); 319 } 320 } 321 322 return getSummary(new MarkerList(selectionList)); 323 } 324 325 330 protected String [] getMarkerTypes() { 331 return new String [] { IMarker.PROBLEM }; 332 } 333 334 protected String getStaticContextId() { 335 return PlatformUI.PLUGIN_ID + ".problem_view_context"; } 337 338 343 protected DialogMarkerFilter createFiltersDialog() { 344 345 MarkerFilter[] filters = getUserFilters(); 346 ProblemFilter[] problemFilters = new ProblemFilter[filters.length]; 347 System.arraycopy(filters, 0, problemFilters, 0, filters.length); 348 return new DialogProblemFilter(getSite().getShell(), problemFilters); 349 } 350 351 356 protected MarkerFilter createFilter(String name) { 357 return new ProblemFilter(name); 358 } 359 360 365 protected String getSectionTag() { 366 return TAG_DIALOG_SECTION; 367 } 368 369 374 String getMarkerEnablementPreferenceName() { 375 return IDEInternalPreferences.LIMIT_PROBLEMS; 376 } 377 378 383 String getMarkerLimitPreferenceName() { 384 return IDEInternalPreferences.PROBLEMS_LIMIT; 385 } 386 387 392 String getFiltersPreferenceName() { 393 return IDEInternalPreferences.PROBLEMS_FILTERS; 394 } 395 396 401 MarkerFilter[] getAllFilters() { 402 MarkerFilter[] userFilters = super.getAllFilters(); 403 Collection declaredFilters = MarkerSupportRegistry.getInstance() 404 .getRegisteredFilters(); 405 Iterator iterator = declaredFilters.iterator(); 406 407 MarkerFilter[] allFilters = new MarkerFilter[userFilters.length 408 + declaredFilters.size()]; 409 System.arraycopy(userFilters, 0, allFilters, 0, userFilters.length); 410 int index = userFilters.length; 411 412 while (iterator.hasNext()) { 413 allFilters[index] = (MarkerFilter) iterator.next(); 414 index++; 415 } 416 return allFilters; 417 418 } 419 420 425 void addDropDownContributions(IMenuManager menu) { 426 427 MenuManager groupByMenu = new MenuManager( 428 MarkerMessages.ProblemView_GroupByMenu); 429 groupByMenu.add(new GroupingAction(MarkerMessages.ProblemView_Type, 430 new FieldCategory(), this)); 431 432 Iterator definedGroups = MarkerSupportRegistry.getInstance() 433 .getMarkerGroups().iterator(); 434 435 while (definedGroups.hasNext()) { 436 FieldMarkerGroup group = (FieldMarkerGroup) definedGroups.next(); 437 groupByMenu.add(new GroupingAction(group.getDescription(), group, 438 this)); 439 } 440 441 groupByMenu.add(new GroupingAction(MarkerMessages.ProblemView_None, 442 null, this)); 443 menu.add(groupByMenu); 444 445 super.addDropDownContributions(menu); 446 } 447 448 451 protected void regenerateLayout() { 452 TableLayout layout = new TableLayout(); 453 getViewer().getTree().setLayout(layout); 454 455 ColumnLayoutData[] columnWidths = getDefaultColumnLayouts(); 456 for (int i = 0; i < columnWidths.length; i++) { 457 layout.addColumnData(columnWidths[i]); 458 459 } 460 getViewer().getTree().layout(true); 461 462 } 463 464 469 void setComparator(TableComparator sorter2) { 470 getMarkerAdapter().getCategorySorter().setTableSorter(sorter2); 471 getMarkerAdapter().getCategorySorter().saveState(getDialogSettings()); 472 updateForNewComparator(sorter2); 473 474 } 475 476 481 public TableComparator getTableSorter() { 482 return ((CategoryComparator) getViewer().getComparator()).innerSorter; 483 } 484 485 490 public void createPartControl(Composite parent) { 491 super.createPartControl(parent); 492 createActivityManagerListener(); 493 PlatformUI.getWorkbench().getActivitySupport().getActivityManager() 494 .addActivityManagerListener(activityManagerListener); 495 } 496 497 500 private void createActivityManagerListener() { 501 activityManagerListener = new IActivityManagerListener() { 502 507 public void activityManagerChanged( 508 ActivityManagerEvent activityManagerEvent) { 509 clearEnabledFilters(); 510 refreshViewer(); 511 } 512 }; 513 514 } 515 516 522 public IField findField(String description) { 523 IField[] fields = getSortingFields(); 524 for (int i = 0; i < fields.length; i++) { 525 if (fields[i].getDescription().equals(description)) { 526 return fields[i]; 527 } 528 } 529 return null; 530 } 531 532 537 protected ViewerComparator buildComparator() { 538 539 TableComparator sorter = createTableComparator(); 540 CategoryComparator category = new CategoryComparator(sorter); 541 category.restoreState(getDialogSettings(), this); 542 return category; 543 } 544 545 550 boolean canBeEditable() { 551 return false; 552 } 553 554 559 protected void initToolBar(IToolBarManager tbm) { 560 tbm.add(getFilterAction()); 561 tbm.update(false); 562 } 563 564 571 public void selectCategory(String description, CategoryComparator sorter) { 572 573 if (description == null) 574 selectCategoryField(null, sorter); 575 576 Iterator definedGroups = MarkerSupportRegistry.getInstance() 577 .getMarkerGroups().iterator(); 578 while (definedGroups.hasNext()) { 579 FieldMarkerGroup group = (FieldMarkerGroup) definedGroups.next(); 580 if (group.getDescription().equals(description)) { 581 selectCategoryField(group, sorter); 582 return; 583 } 584 } 585 selectCategoryField(null, sorter); 586 587 } 588 589 595 void selectCategoryField(IField groupingField, CategoryComparator sorter) { 596 sorter.setCategoryField(groupingField); 597 598 if (getMarkerAdapter() != null) { 600 getMarkerAdapter().getCurrentMarkers().clearGroups(); 601 refreshViewer(); 602 } 603 } 604 605 610 protected void writeFiltersSettings(XMLMemento memento) { 611 super.writeFiltersSettings(memento); 612 613 Iterator filters = MarkerSupportRegistry.getInstance() 615 .getRegisteredFilters().iterator(); 616 617 while (filters.hasNext()) { 618 MarkerFilter filter = (MarkerFilter) filters.next(); 619 IMemento child = memento.createChild(TAG_SYSTEM_FILTER_ENTRY, 620 filter.getName()); 621 child.putString(MarkerFilter.TAG_ENABLED, String.valueOf(filter 622 .isEnabled())); 623 } 624 625 } 626 627 632 void restoreFilters(IMemento memento) { 633 634 super.restoreFilters(memento); 635 636 if (memento == null) 637 return; 638 639 IMemento[] sections = memento.getChildren(TAG_SYSTEM_FILTER_ENTRY); 640 641 Collection registered = MarkerSupportRegistry.getInstance() 642 .getRegisteredFilters(); 643 MarkerFilter[] filters = new MarkerFilter[registered.size()]; 644 registered.toArray(filters); 645 646 if (sections != null) { 647 648 for (int i = 0; i < sections.length; i++) { 649 String filterName = sections[i].getID(); 650 boolean enabled = Boolean.valueOf( 651 sections[i].getString(MarkerFilter.TAG_ENABLED)) 652 .booleanValue(); 653 setEnablement(filterName, enabled, filters); 654 655 } 656 } 657 658 } 659 660 667 private void setEnablement(String filterName, boolean enabled, 668 MarkerFilter[] filters) { 669 for (int i = 0; i < filters.length; i++) { 670 if (filters[i].getName().equals(filterName)) { 671 filters[i].setEnabled(enabled); 672 return; 673 } 674 } 675 676 } 677 678 683 protected String getMarkerName() { 684 return MarkerMessages.problem_title; 685 } 686 } 687 | Popular Tags |