1 11 12 package org.eclipse.ui.views.markers.internal; 13 14 import java.lang.reflect.InvocationTargetException ; 15 16 import org.eclipse.core.resources.IMarker; 17 import org.eclipse.core.runtime.IProgressMonitor; 18 import org.eclipse.jface.dialogs.Dialog; 19 import org.eclipse.jface.dialogs.ErrorDialog; 20 import org.eclipse.jface.dialogs.MessageDialog; 21 import org.eclipse.jface.dialogs.ProgressMonitorDialog; 22 import org.eclipse.jface.operation.IRunnableContext; 23 import org.eclipse.jface.operation.IRunnableWithProgress; 24 import org.eclipse.jface.viewers.ISelectionProvider; 25 import org.eclipse.jface.viewers.IStructuredSelection; 26 import org.eclipse.osgi.util.NLS; 27 import org.eclipse.ui.IMarkerResolution; 28 import org.eclipse.ui.PlatformUI; 29 import org.eclipse.ui.ide.IDE; 30 import org.eclipse.ui.internal.ide.IDEInternalWorkbenchImages; 31 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; 32 import org.eclipse.ui.progress.IWorkbenchSiteProgressService; 33 34 39 public class ActionResolveMarker extends MarkerSelectionProviderAction { 40 41 private MarkerView view; 42 43 49 public ActionResolveMarker(MarkerView markerView, 50 ISelectionProvider provider) { 51 super(provider, MarkerMessages.resolveMarkerAction_title); 52 setEnabled(false); 53 setImageDescriptor(IDEInternalWorkbenchImages 54 .getImageDescriptor(IDEInternalWorkbenchImages.IMG_ELCL_QUICK_FIX_ENABLED)); 55 setDisabledImageDescriptor(IDEInternalWorkbenchImages 56 .getImageDescriptor(IDEInternalWorkbenchImages.IMG_DLCL_QUICK_FIX_DISABLED)); 57 view = markerView; 58 } 59 60 63 public void run() { 64 65 IRunnableContext context = new ProgressMonitorDialog(view.getSite() 66 .getShell()); 67 final Object [] resolutions = new Object [1]; 68 69 IRunnableWithProgress resolutionsRunnable = new IRunnableWithProgress() { 70 public void run(IProgressMonitor monitor) { 71 monitor.beginTask(NLS.bind( 72 MarkerMessages.resolveMarkerAction_computationAction, 73 getMarkerDescription()), 100); 74 monitor.worked(25); 75 resolutions[0] = IDE.getMarkerHelpRegistry().getResolutions( 76 getSelectedMarker()); 77 monitor.done(); 78 } 79 }; 80 81 Object service = view.getSite().getAdapter( 82 IWorkbenchSiteProgressService.class); 83 84 try { 85 if (service == null) { 86 PlatformUI.getWorkbench().getProgressService().runInUI(context, 87 resolutionsRunnable, null); 88 } else { 89 ((IWorkbenchSiteProgressService) service).runInUI(context, 90 resolutionsRunnable, null); 91 } 92 } catch (InvocationTargetException exception) { 93 handleException(exception); 94 return; 95 } catch (InterruptedException exception) { 96 handleException(exception); 97 return; 98 } 99 100 IMarkerResolution[] foundResolutions = (IMarkerResolution[]) resolutions[0]; 101 if (foundResolutions.length == 0) 102 MessageDialog 103 .openInformation( 104 view.getSite().getShell(), 105 MarkerMessages.MarkerResolutionDialog_CannotFixTitle, 106 NLS 107 .bind( 108 MarkerMessages.MarkerResolutionDialog_CannotFixMessage, 109 getMarkerDescription())); 110 else { 111 Dialog dialog = new MarkerResolutionDialog(view.getSite() 112 .getShell(), getSelectedMarker(), foundResolutions, view); 113 dialog.open(); 114 } 115 116 } 117 118 123 private void handleException(Exception exception) { 124 IDEWorkbenchPlugin.log(exception.getLocalizedMessage(), exception); 125 ErrorDialog.openError(view.getSite().getShell(), MarkerMessages.Error, 126 NLS.bind( 127 MarkerMessages.MarkerResolutionDialog_CannotFixMessage, 128 getMarkerDescription()), Util.errorStatus(exception)); 129 } 130 131 136 private String getMarkerDescription() { 137 return Util.getProperty(IMarker.MESSAGE, getSelectedMarker()); 138 } 139 140 145 public void selectionChanged(IStructuredSelection selection) { 146 147 if (Util.isSingleConcreteSelection(selection)) { 148 if (IDE.getMarkerHelpRegistry().hasResolutions(getSelectedMarker())) { 149 setEnabled(true); 150 return; 151 } 152 } 153 154 setEnabled(false); 155 } 156 } 157 | Popular Tags |