KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > search2 > internal > ui > SearchAgainAction


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.search2.internal.ui;
12
13 import org.eclipse.core.runtime.IStatus;
14
15 import org.eclipse.swt.widgets.Shell;
16
17 import org.eclipse.jface.action.Action;
18 import org.eclipse.jface.dialogs.ErrorDialog;
19 import org.eclipse.jface.dialogs.ProgressMonitorDialog;
20
21 import org.eclipse.search.ui.ISearchQuery;
22 import org.eclipse.search.ui.ISearchResult;
23 import org.eclipse.search.ui.NewSearchUI;
24
25 import org.eclipse.search.internal.ui.SearchPluginImages;
26
27 class SearchAgainAction extends Action {
28     private SearchView fView;
29     
30     public SearchAgainAction(SearchView view) {
31         setText(SearchMessages.SearchAgainAction_label);
32         setToolTipText(SearchMessages.SearchAgainAction_tooltip);
33         SearchPluginImages.setImageDescriptors(this, SearchPluginImages.T_LCL, SearchPluginImages.IMG_LCL_SEARCH_AGAIN);
34         fView= view;
35     }
36
37     public void run() {
38         final ISearchResult search= fView.getCurrentSearchResult();
39         if (search != null) {
40             ISearchQuery query= search.getQuery();
41             NewSearchUI.cancelQuery(query);
42             if (query.canRerun()) {
43                 if (query.canRunInBackground())
44                     NewSearchUI.runQueryInBackground(query, fView);
45                 else {
46                     Shell shell= fView.getSite().getShell();
47                     ProgressMonitorDialog pmd= new ProgressMonitorDialog(shell);
48                     IStatus status= NewSearchUI.runQueryInForeground(pmd, query, fView);
49                     if (!status.isOK() && status.getSeverity() != IStatus.CANCEL) {
50                         ErrorDialog.openError(shell, SearchMessages.SearchAgainAction_Error_title, SearchMessages.SearchAgainAction_Error_message, status);
51                     }
52                 }
53             }
54         }
55     }
56 }
57
Popular Tags