]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-before/ui/org/eclipse/jdt/internal/ui/navigator/JavaNavigatorRefactorActionProvider.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-before / ui / org / eclipse / jdt / internal / ui / navigator / JavaNavigatorRefactorActionProvider.java
1 /*******************************************************************************
2  * Copyright (c) 2003, 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.navigator;
12
13 import org.eclipse.jface.action.IMenuManager;
14
15 import org.eclipse.ui.IActionBars;
16 import org.eclipse.ui.IViewPart;
17 import org.eclipse.ui.actions.ActionContext;
18 import org.eclipse.ui.navigator.CommonActionProvider;
19 import org.eclipse.ui.navigator.ICommonActionExtensionSite;
20 import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite;
21
22 import org.eclipse.jdt.ui.actions.RefactorActionGroup;
23
24 /**
25  * Contributes the following actions to the menu on behalf of the JDT content
26  * extension.
27  *
28  * <ul>
29  * <li>{@link RefactorActionGroup}. Contributes the "Refactor>" and "Source>" submenus to the context menu.</li>
30  * </ul>
31  */
32 public class JavaNavigatorRefactorActionProvider extends CommonActionProvider {
33
34         private RefactorActionGroup fRefactorGroup;
35
36         @Override
37         public void fillActionBars(IActionBars actionBars) {
38                 if (fRefactorGroup != null) {
39                         fRefactorGroup.fillActionBars(actionBars);
40                         fRefactorGroup.retargetFileMenuActions(actionBars);
41                 }
42         }
43
44         @Override
45         public void fillContextMenu(IMenuManager menu) {
46                 if (fRefactorGroup != null) {
47                         fRefactorGroup.fillContextMenu(menu);
48                 }
49         }
50
51         @Override
52         public void init(ICommonActionExtensionSite site) {
53                 ICommonViewerWorkbenchSite workbenchSite= null;
54                 if (site.getViewSite() instanceof ICommonViewerWorkbenchSite)
55                         workbenchSite= (ICommonViewerWorkbenchSite) site.getViewSite();
56
57                 // we only initialize the refactor group when in a view part
58                 // (required for the constructor)
59                 if (workbenchSite != null) {
60                         if (workbenchSite.getPart() != null && workbenchSite.getPart() instanceof IViewPart) {
61                                 IViewPart viewPart= (IViewPart) workbenchSite.getPart();
62
63                                 fRefactorGroup= new RefactorActionGroup(viewPart);
64                         }
65                 }
66         }
67
68         @Override
69         public void setContext(ActionContext context) {
70                 if (fRefactorGroup != null) {
71                         fRefactorGroup.setContext(context);
72                 }
73         }
74
75         /*
76          * @see org.eclipse.ui.actions.ActionGroup#dispose()
77          * @since 3.5
78          */
79         @Override
80         public void dispose() {
81                 if (fRefactorGroup != null)
82                         fRefactorGroup.dispose();
83                 super.dispose();
84         }
85 }