KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > search > internal > ui > RemoveMatchAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
26  * @deprecated old search
27  */

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