KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > actions > OpenTypeInHierarchyAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.jdt.internal.ui.actions;
12
13 import org.eclipse.swt.widgets.Shell;
14
15 import org.eclipse.jface.action.Action;
16 import org.eclipse.jface.action.IAction;
17 import org.eclipse.jface.dialogs.IDialogConstants;
18 import org.eclipse.jface.viewers.ISelection;
19
20 import org.eclipse.ui.IWorkbenchWindow;
21 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
22 import org.eclipse.ui.PlatformUI;
23
24 import org.eclipse.jdt.core.IType;
25 import org.eclipse.jdt.core.search.IJavaSearchConstants;
26 import org.eclipse.jdt.core.search.SearchEngine;
27
28 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
29 import org.eclipse.jdt.internal.ui.JavaPlugin;
30 import org.eclipse.jdt.internal.ui.dialogs.OpenTypeSelectionDialog;
31 import org.eclipse.jdt.internal.ui.util.OpenTypeHierarchyUtil;
32
33 public class OpenTypeInHierarchyAction extends Action implements IWorkbenchWindowActionDelegate {
34     
35     private IWorkbenchWindow fWindow;
36     
37     public OpenTypeInHierarchyAction() {
38         super();
39         setText(ActionMessages.OpenTypeInHierarchyAction_label);
40         setDescription(ActionMessages.OpenTypeInHierarchyAction_description);
41         setToolTipText(ActionMessages.OpenTypeInHierarchyAction_tooltip);
42         PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.OPEN_TYPE_IN_HIERARCHY_ACTION);
43     }
44
45     public void run() {
46         Shell parent= JavaPlugin.getActiveWorkbenchShell();
47         OpenTypeSelectionDialog dialog= new OpenTypeSelectionDialog(parent, false,
48             PlatformUI.getWorkbench().getProgressService(),
49             SearchEngine.createWorkspaceScope(), IJavaSearchConstants.TYPE);
50         
51         dialog.setTitle(ActionMessages.OpenTypeInHierarchyAction_dialogTitle);
52         dialog.setMessage(ActionMessages.OpenTypeInHierarchyAction_dialogMessage);
53         int result= dialog.open();
54         if (result != IDialogConstants.OK_ID)
55             return;
56         
57         Object JavaDoc[] types= dialog.getResult();
58         if (types != null && types.length > 0) {
59             IType type= (IType)types[0];
60             OpenTypeHierarchyUtil.open(new IType[] { type }, fWindow);
61         }
62     }
63
64     //---- IWorkbenchWindowActionDelegate ------------------------------------------------
65

66     public void run(IAction action) {
67         run();
68     }
69     
70     public void dispose() {
71         fWindow= null;
72     }
73     
74     public void init(IWorkbenchWindow window) {
75         fWindow= window;
76     }
77     
78     public void selectionChanged(IAction action, ISelection selection) {
79         // do nothing. Action doesn't depend on selection.
80
}
81 }
82
Popular Tags