KickJava   Java API By Example, From Geeks To Geeks.

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


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.jface.action.Action;
14 import org.eclipse.jface.action.IAction;
15 import org.eclipse.jface.viewers.ISelection;
16
17 import org.eclipse.ui.IWorkbenchWindow;
18 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
19
20 /**
21  * Opens the Search Dialog.
22  */

23 public class OpenSearchDialogAction extends Action implements IWorkbenchWindowActionDelegate {
24
25     private IWorkbenchWindow fWindow;
26     private String JavaDoc fPageId;
27
28     public OpenSearchDialogAction() {
29         super(SearchMessages.OpenSearchDialogAction_label);
30         SearchPluginImages.setImageDescriptors(this, SearchPluginImages.T_TOOL, SearchPluginImages.IMG_TOOL_SEARCH);
31         setToolTipText(SearchMessages.OpenSearchDialogAction_tooltip);
32     }
33
34     public OpenSearchDialogAction(IWorkbenchWindow window, String JavaDoc pageId) {
35         this();
36         fPageId= pageId;
37         fWindow= window;
38     }
39
40     public void init(IWorkbenchWindow window) {
41         fWindow= window;
42     }
43
44     public void run(IAction action) {
45         run();
46     }
47
48     public void run() {
49         if (getWorkbenchWindow().getActivePage() == null) {
50             SearchPlugin.beep();
51             return;
52         }
53         SearchDialog dialog= new SearchDialog(getWorkbenchWindow(), fPageId);
54         dialog.open();
55     }
56
57     public void selectionChanged(IAction action, ISelection selection) {
58         // do nothing since the action isn't selection dependent.
59
}
60
61     private IWorkbenchWindow getWorkbenchWindow() {
62         if (fWindow == null)
63             fWindow= SearchPlugin.getActiveWorkbenchWindow();
64         return fWindow;
65     }
66
67     public void dispose() {
68         fWindow= null;
69     }
70 }
71
Popular Tags