1 /*******************************************************************************
2 * Copyright (c) 2000, 2011 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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.jdt.internal.ui.packageview;
13 import org.eclipse.swt.widgets.Shell;
15 import org.eclipse.jface.action.Action;
16 import org.eclipse.jface.dialogs.IDialogConstants;
17 import org.eclipse.jface.dialogs.ProgressMonitorDialog;
18 import org.eclipse.jface.viewers.IStructuredSelection;
20 import org.eclipse.ui.PlatformUI;
21 import org.eclipse.ui.dialogs.SelectionDialog;
23 import org.eclipse.jdt.core.ICompilationUnit;
24 import org.eclipse.jdt.core.IJavaElement;
25 import org.eclipse.jdt.core.IType;
26 import org.eclipse.jdt.core.JavaModelException;
27 import org.eclipse.jdt.core.search.SearchEngine;
29 import org.eclipse.jdt.ui.IJavaElementSearchConstants;
30 import org.eclipse.jdt.ui.JavaUI;
32 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
33 import org.eclipse.jdt.internal.ui.JavaPlugin;
34 import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
36 class GotoTypeAction extends Action {
38 PackageExplorerPart fPackageExplorer;
40 GotoTypeAction(PackageExplorerPart part) {
42 setText(PackagesMessages.GotoType_action_label);
43 setDescription(PackagesMessages.GotoType_action_description);
44 fPackageExplorer= part;
45 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.GOTO_TYPE_ACTION);
50 Shell shell= JavaPlugin.getActiveWorkbenchShell();
51 SelectionDialog dialog= null;
53 dialog= JavaUI.createTypeDialog(shell, new ProgressMonitorDialog(shell),
54 SearchEngine.createWorkspaceScope(), IJavaElementSearchConstants.CONSIDER_ALL_TYPES, false);
55 } catch (JavaModelException e) {
56 String title= getDialogTitle();
57 String message= PackagesMessages.GotoType_error_message;
58 ExceptionHandler.handle(e, title, message);
62 dialog.setTitle(getDialogTitle());
63 dialog.setMessage(PackagesMessages.GotoType_dialog_message);
64 if (dialog.open() == IDialogConstants.CANCEL_ID) {
68 Object[] types= dialog.getResult();
69 if (types != null && types.length > 0) {
70 gotoType((IType) types[0]);
74 private void gotoType(IType type) {
75 ICompilationUnit cu= (ICompilationUnit) type.getAncestor(IJavaElement.COMPILATION_UNIT);
76 IJavaElement element= null;
78 element= cu.getPrimary();
81 element= type.getAncestor(IJavaElement.CLASS_FILE);
83 if (element != null) {
84 PackageExplorerPart view= PackageExplorerPart.openInActivePerspective();
86 view.generated_4824484528801798530(element, this);
91 Object getSelectedElement(PackageExplorerPart view) {
92 return ((IStructuredSelection)view.getSite().getSelectionProvider().getSelection()).getFirstElement();
95 String getDialogTitle() {
96 return PackagesMessages.GotoType_dialog_title;