]> git.uio.no Git - ifi-stolz-refaktor.git/blame - case-study/jdt-after/ui/org/eclipse/jdt/ui/actions/ShowInPackageViewAction.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-after / ui / org / eclipse / jdt / ui / actions / ShowInPackageViewAction.java
CommitLineData
1b2798f6
EK
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 *******************************************************************************/
11package org.eclipse.jdt.ui.actions;
12
13import org.eclipse.jface.dialogs.ErrorDialog;
14import org.eclipse.jface.viewers.ISelection;
15import org.eclipse.jface.viewers.ISelectionProvider;
16import org.eclipse.jface.viewers.IStructuredSelection;
17
18import org.eclipse.jface.text.ITextSelection;
19
20import org.eclipse.ui.IWorkbenchSite;
21import org.eclipse.ui.PlatformUI;
22
23import org.eclipse.jdt.core.IJavaElement;
24import org.eclipse.jdt.core.JavaModelException;
25
26import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
27import org.eclipse.jdt.internal.ui.JavaPlugin;
28import org.eclipse.jdt.internal.ui.actions.ActionMessages;
29import org.eclipse.jdt.internal.ui.actions.SelectionConverter;
30import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
31import org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart;
32
33/**
34 * This action reveals the currently selected Java element in the package explorer.
35 * <p>
36 * The action is applicable to selections containing elements of type <code>IJavaElement</code>.
37 *
38 * <p>
39 * This class may be instantiated; it is not intended to be subclassed.
40 * </p>
41 *
42 * @since 2.0
43 *
44 * @noextend This class is not intended to be subclassed by clients.
45 * @deprecated As of 3.5, got replaced by generic Navigate &gt; Show In &gt;
46 */
47public class ShowInPackageViewAction extends SelectionDispatchAction {
48
49 private JavaEditor fEditor;
50
51 /**
52 * Creates a new <code>ShowInPackageViewAction</code>. The action requires
53 * that the selection provided by the site's selection provider is of type
54 * <code>org.eclipse.jface.viewers.IStructuredSelection</code>.
55 *
56 * @param site the site providing context information for this action
57 */
58 public ShowInPackageViewAction(IWorkbenchSite site) {
59 super(site);
60 setText(ActionMessages.ShowInPackageViewAction_label);
61 setDescription(ActionMessages.ShowInPackageViewAction_description);
62 setToolTipText(ActionMessages.ShowInPackageViewAction_tooltip);
63 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.SHOW_IN_PACKAGEVIEW_ACTION);
64 }
65
66 /**
67 * Note: This constructor is for internal use only. Clients should not call this constructor.
68 * @param editor the Java editor
69 *
70 * @noreference This constructor is not intended to be referenced by clients.
71 */
72 public ShowInPackageViewAction(JavaEditor editor) {
73 this(editor.getEditorSite());
74 fEditor= editor;
75 setEnabled(SelectionConverter.canOperateOn(fEditor));
76 }
77
78 /* (non-Javadoc)
79 * Method declared on SelectionDispatchAction.
80 */
81 @Override
82 public void selectionChanged(ITextSelection selection) {
83 }
84
85 /* (non-Javadoc)
86 * Method declared on SelectionDispatchAction.
87 */
88 @Override
89 public void selectionChanged(IStructuredSelection selection) {
90 setEnabled(checkEnabled(selection));
91 }
92
93 private boolean checkEnabled(IStructuredSelection selection) {
94 if (selection.size() != 1)
95 return false;
96 return selection.getFirstElement() instanceof IJavaElement;
97 }
98
99 /* (non-Javadoc)
100 * Method declared on SelectionDispatchAction.
101 */
102 @Override
103 public void run(ITextSelection selection) {
104 try {
105 IJavaElement element= SelectionConverter.getElementAtOffset(fEditor);
106 if (element != null)
107 run(element);
108 } catch (JavaModelException e) {
109 JavaPlugin.log(e);
110 String message= ActionMessages.ShowInPackageViewAction_error_message;
111 ErrorDialog.openError(getShell(), getDialogTitle(), message, e.getStatus());
112 }
113 }
114
115 /* (non-Javadoc)
116 * Method declared on SelectionDispatchAction.
117 */
118 @Override
119 public void run(IStructuredSelection selection) {
120 if (!checkEnabled(selection))
121 return;
122 run((IJavaElement)selection.getFirstElement());
123 }
124
125 /**
126 * Tries to reveal the given Java element
127 *
128 * @param element the element to reveal
129 */
130 public void run(IJavaElement element) {
131 if (element == null)
132 return;
133
134 PackageExplorerPart view= PackageExplorerPart.openInActivePerspective();
135 view.tryToReveal(element);
136 }
137
138 public void generated_8019497110545412081(ShowActionGroup showactiongroup, boolean isJavaEditor) {
139 ISelectionProvider provider= showactiongroup.fSite.getSelectionProvider();
140 ISelection selection= provider.getSelection();
141 update(selection);
142 if (!isJavaEditor) {
143 provider.addSelectionChangedListener(this);
144 }
145 }
146
147 private static String getDialogTitle() {
148 return ActionMessages.ShowInPackageViewAction_dialog_title;
149 }
150}