1 11 12 package org.eclipse.ui.views.tasklist; 13 14 import org.eclipse.core.resources.IMarker; 15 import org.eclipse.jface.dialogs.MessageDialog; 16 import org.eclipse.jface.viewers.IStructuredSelection; 17 import org.eclipse.jface.window.Window; 18 import org.eclipse.ui.IMarkerResolution; 19 import org.eclipse.ui.PlatformUI; 20 import org.eclipse.ui.dialogs.MarkerResolutionSelectionDialog; 21 import org.eclipse.ui.ide.IDE; 22 import org.eclipse.ui.internal.views.tasklist.TaskListMessages; 23 24 29 class ResolveMarkerAction extends TaskAction { 30 31 34 protected ResolveMarkerAction(TaskList tasklist, String id) { 35 super(tasklist, id); 36 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, 37 ITaskListHelpContextIds.RESOLVE_MARKER_ACTION); 38 } 39 40 46 public boolean shouldEnable(IStructuredSelection selection) { 47 if (selection.size() != 1) { 48 return false; 49 } 50 IMarker marker = (IMarker) selection.getFirstElement(); 51 if (marker == null) { 52 return false; 53 } 54 return IDE.getMarkerHelpRegistry().hasResolutions(marker); 55 } 56 57 60 public void run() { 61 IMarker marker = getMarker(); 62 if (marker == null) { 63 return; 64 } 65 getTaskList().cancelEditing(); 66 IMarkerResolution[] resolutions = getResolutions(marker); 67 if (resolutions.length == 0) { 68 MessageDialog.openInformation(getShell(), TaskListMessages.Resolve_title, 69 TaskListMessages.Resolve_noResolutionsLabel); 70 return; 71 } 72 MarkerResolutionSelectionDialog d = new MarkerResolutionSelectionDialog( 73 getShell(), resolutions); 74 if (d.open() != Window.OK) { 75 return; 76 } 77 Object [] result = d.getResult(); 78 if (result != null && result.length > 0) { 79 ((IMarkerResolution) result[0]).run(marker); 80 } 81 } 82 83 89 private IMarkerResolution[] getResolutions(IMarker marker) { 90 return IDE.getMarkerHelpRegistry().getResolutions(marker); 91 } 92 93 98 private IMarker getMarker() { 99 IStructuredSelection selection = (IStructuredSelection) getTaskList() 100 .getSelection(); 101 if (selection.size() != 1) { 103 return null; 104 } 105 return (IMarker) selection.getFirstElement(); 106 } 107 } 108 | Popular Tags |