1 11 12 package org.eclipse.ui.views.markers.internal; 13 14 import java.lang.reflect.InvocationTargetException ; 15 import java.util.List ; 16 17 import org.eclipse.core.runtime.IProgressMonitor; 18 import org.eclipse.core.runtime.IStatus; 19 import org.eclipse.jface.operation.IRunnableWithProgress; 20 import org.eclipse.jface.viewers.IStructuredSelection; 21 import org.eclipse.jface.viewers.StructuredSelection; 22 import org.eclipse.ui.PlatformUI; 23 import org.eclipse.ui.internal.ide.StatusUtil; 24 import org.eclipse.ui.statushandlers.StatusManager; 25 import org.eclipse.ui.views.markers.internal.MarkerAdapter.MarkerCategory; 26 27 31 public class ActionSelectAll extends MarkerSelectionProviderAction { 32 33 private MarkerView view; 34 35 40 public ActionSelectAll(MarkerView markerView) { 41 super(markerView.getViewer(), MarkerMessages.selectAllAction_title); 42 setEnabled(true); 43 view = markerView; 44 } 45 46 51 public void run() { 52 53 if (view.getMarkerAdapter().isBuilding()) 54 return; 55 56 IRunnableWithProgress selectionRunnableWithProgress = new IRunnableWithProgress() { 57 62 public void run(IProgressMonitor monitor) { 63 64 try { 65 monitor.beginTask(MarkerMessages.selectAllAction_title, 66 100); 67 monitor.subTask(MarkerMessages.selectAllAction_calculating); 68 if (view.getMarkerAdapter().isShowingHierarchy()) { 69 70 if (monitor.isCanceled()) 71 return; 72 73 monitor.worked(10); 74 PlatformUI.getWorkbench().getDisplay() 75 .readAndDispatch(); 76 MarkerCategory[] categories = view.getMarkerAdapter() 77 .getCategories(); 78 int totalSize = 0; 79 for (int i = 0; i < categories.length; i++) { 80 MarkerCategory markerCategory = categories[i]; 81 totalSize += markerCategory.getDisplayedSize(); 82 } 83 monitor.worked(10); 84 PlatformUI.getWorkbench().getDisplay() 85 .readAndDispatch(); 86 Object [] selection = new Object [totalSize]; 87 int index = 0; 88 for (int i = 0; i < categories.length; i++) { 89 MarkerNode[] children = categories[i].getChildren(); 90 System.arraycopy(children, 0, selection, index, 91 children.length); 92 index += children.length; 93 } 94 monitor.worked(10); 95 if (monitor.isCanceled()) 96 return; 97 PlatformUI.getWorkbench().getDisplay() 98 .readAndDispatch(); 99 monitor 100 .subTask(MarkerMessages.selectAllAction_applying); 101 getSelectionProvider().setSelection( 102 new StructuredSelection(selection)); 103 } else { 104 if (monitor.isCanceled()) 105 return; 106 monitor.worked(10); 107 List selection = view.getMarkerAdapter() 108 .getCurrentMarkers().asList(); 109 monitor.worked(10); 110 monitor 111 .subTask(MarkerMessages.selectAllAction_applying); 112 PlatformUI.getWorkbench().getDisplay() 113 .readAndDispatch(); 114 getSelectionProvider().setSelection( 115 new StructuredSelection(selection)); 116 } 117 } finally { 118 monitor.done(); 119 } 120 121 } 122 }; 123 124 try { 125 PlatformUI.getWorkbench().getProgressService().run(false, false, 126 selectionRunnableWithProgress); 127 } catch (InvocationTargetException e) { 128 StatusManager.getManager().handle( 129 StatusUtil.newStatus(IStatus.ERROR, 130 e.getLocalizedMessage(), e), StatusManager.LOG); 131 } catch (InterruptedException e) { 132 StatusManager.getManager().handle( 133 StatusUtil.newStatus(IStatus.ERROR, 134 e.getLocalizedMessage(), e), StatusManager.LOG); 135 } 136 137 } 138 139 144 public void selectionChanged(IStructuredSelection selection) { 145 setEnabled(!selection.isEmpty()); 146 } 147 } 148 | Popular Tags |