1 11 package org.eclipse.search.internal.ui; 12 13 import org.eclipse.core.resources.IMarker; 14 import org.eclipse.core.runtime.CoreException; 15 16 import org.eclipse.jface.action.Action; 17 import org.eclipse.jface.viewers.ISelection; 18 import org.eclipse.jface.viewers.ISelectionProvider; 19 import org.eclipse.jface.viewers.IStructuredSelection; 20 21 import org.eclipse.search.ui.ISearchResultViewEntry; 22 23 import org.eclipse.search.internal.ui.util.ExceptionHandler; 24 25 28 class RemoveMatchAction extends Action { 29 30 private ISelectionProvider fSelectionProvider; 31 32 public RemoveMatchAction(ISelectionProvider provider) { 33 super(SearchMessages.SearchResultView_removeMatch_text); 34 setToolTipText(SearchMessages.SearchResultView_removeMatch_tooltip); 35 fSelectionProvider= provider; 36 } 37 38 public void run() { 39 IMarker[] markers= getMarkers(fSelectionProvider.getSelection()); 40 if (markers != null) 41 try { 42 SearchPlugin.getWorkspace().deleteMarkers(markers); 43 } catch (CoreException ex) { 44 ExceptionHandler.handle(ex, SearchMessages.Search_Error_deleteMarkers_title, SearchMessages.Search_Error_deleteMarkers_message); 45 } 46 } 47 48 private IMarker[] getMarkers(ISelection s) { 49 if (! (s instanceof IStructuredSelection) || s.isEmpty()) 50 return null; 51 52 IStructuredSelection selection= (IStructuredSelection)s; 53 int size= selection.size(); 54 if (size != 1) 55 return null; 56 if (selection.getFirstElement() instanceof ISearchResultViewEntry) { 57 IMarker marker= ((ISearchResultViewEntry)selection.getFirstElement()).getSelectedMarker(); 58 if (marker != null) 59 return new IMarker[] {marker}; 60 } 61 return null; 62 } 63 } 64 | Popular Tags |