]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-after/ui/org/eclipse/jdt/internal/ui/packageview/GotoTypeAction.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-after / ui / org / eclipse / jdt / internal / ui / packageview / GotoTypeAction.java
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
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package org.eclipse.jdt.internal.ui.packageview;
12
13 import org.eclipse.swt.widgets.Shell;
14
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;
19
20 import org.eclipse.ui.PlatformUI;
21 import org.eclipse.ui.dialogs.SelectionDialog;
22
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;
28
29 import org.eclipse.jdt.ui.IJavaElementSearchConstants;
30 import org.eclipse.jdt.ui.JavaUI;
31
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;
35
36 class GotoTypeAction extends Action {
37
38         PackageExplorerPart fPackageExplorer;
39
40         GotoTypeAction(PackageExplorerPart part) {
41                 super();
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);
46         }
47
48         @Override
49         public void run() {
50                 Shell shell= JavaPlugin.getActiveWorkbenchShell();
51                 SelectionDialog dialog= null;
52                 try {
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);
59                         return;
60                 }
61
62                 dialog.setTitle(getDialogTitle());
63                 dialog.setMessage(PackagesMessages.GotoType_dialog_message);
64                 if (dialog.open() == IDialogConstants.CANCEL_ID) {
65                         return;
66                 }
67
68                 Object[] types= dialog.getResult();
69                 if (types != null && types.length > 0) {
70                         gotoType((IType) types[0]);
71                 }
72         }
73
74         private void gotoType(IType type) {
75                 ICompilationUnit cu= (ICompilationUnit) type.getAncestor(IJavaElement.COMPILATION_UNIT);
76                 IJavaElement element= null;
77                 if (cu != null) {
78                         element= cu.getPrimary();
79                 }
80                 else {
81                         element= type.getAncestor(IJavaElement.CLASS_FILE);
82                 }
83                 if (element != null) {
84                         PackageExplorerPart view= PackageExplorerPart.openInActivePerspective();
85                         if (view != null) {
86                                 view.generated_4824484528801798530(element, this);
87                         }
88                 }
89         }
90
91         Object getSelectedElement(PackageExplorerPart view) {
92                 return ((IStructuredSelection)view.getSite().getSelectionProvider().getSelection()).getFirstElement();
93         }
94
95         String getDialogTitle() {
96                 return PackagesMessages.GotoType_dialog_title;
97         }
98 }