KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > navigator > JavaNavigatorActionProvider


1 /*******************************************************************************
2  * Copyright (c) 2003, 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.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.CCPActionGroup;
23 import org.eclipse.jdt.ui.actions.GenerateActionGroup;
24 import org.eclipse.jdt.ui.actions.JavaSearchActionGroup;
25 import org.eclipse.jdt.ui.actions.OpenViewActionGroup;
26
27 import org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage.GenerateBuildPathActionGroup;
28
29 /**
30  * Contributes the following actions to the menu on behalf of the JDT content
31  * extension.
32  *
33  * <ul>
34  * <li>{@link OpenViewActionGroup}. Contributes the Open View actions (type
35  * hierarchy, call hierarchy, etc).</li>
36  * <li>{@link CCPActionGroup}. Contributes the Cut/Copy/Paste/Delete.</li>
37  * <li>{@link JavaSearchActionGroup}. Contributes the search functionality (find in workspace, project, etc).</li>
38  * <li>{@link GenerateBuildPathActionGroup}. Contributes the "Build Path>" convenience submenu option.</li>
39  * <li>{@link GenerateActionGroup}. Contributes the "Source>" and "Generate>" submenu .</li>
40  * </ul>
41  */

42 public class JavaNavigatorActionProvider extends CommonActionProvider {
43
44     private OpenViewActionGroup fOpenViewGroup;
45
46     private CCPActionGroup fCCPGroup;
47
48     private JavaSearchActionGroup fSearchGroup;
49
50     private GenerateBuildPathActionGroup fBuildPathGroup;
51
52     private GenerateActionGroup fGenerateGroup;
53
54     private boolean fInViewPart= false;
55
56     public void fillActionBars(IActionBars actionBars) {
57         if (fInViewPart) {
58             fOpenViewGroup.fillActionBars(actionBars);
59             fCCPGroup.fillActionBars(actionBars);
60             fBuildPathGroup.fillActionBars(actionBars);
61             fGenerateGroup.fillActionBars(actionBars);
62             fSearchGroup.fillActionBars(actionBars);
63         }
64     }
65
66     public void fillContextMenu(IMenuManager menu) {
67         if (fInViewPart) {
68             fOpenViewGroup.fillContextMenu(menu);
69             fCCPGroup.fillContextMenu(menu);
70             fBuildPathGroup.fillContextMenu(menu);
71             fGenerateGroup.fillContextMenu(menu);
72             fSearchGroup.fillContextMenu(menu);
73         }
74     }
75
76     public void init(ICommonActionExtensionSite site) {
77
78         ICommonViewerWorkbenchSite workbenchSite= null;
79         if (site.getViewSite() instanceof ICommonViewerWorkbenchSite)
80             workbenchSite= (ICommonViewerWorkbenchSite) site.getViewSite();
81
82         if (workbenchSite != null) {
83             if (workbenchSite.getPart() != null && workbenchSite.getPart() instanceof IViewPart) {
84                 IViewPart viewPart= (IViewPart) workbenchSite.getPart();
85
86                 fOpenViewGroup= new OpenViewActionGroup(viewPart, site.getStructuredViewer());
87                 fOpenViewGroup.containsOpenPropertiesAction(false);
88                 fCCPGroup= new CCPActionGroup(viewPart);
89                 fGenerateGroup= new GenerateActionGroup(viewPart);
90                 fSearchGroup= new JavaSearchActionGroup(viewPart);
91                 fBuildPathGroup= new GenerateBuildPathActionGroup(viewPart);
92
93                 fInViewPart= true;
94             }
95         }
96     }
97
98     public void setContext(ActionContext context) {
99         super.setContext(context);
100         if (fInViewPart) {
101             fOpenViewGroup.setContext(context);
102             fCCPGroup.setContext(context);
103             fGenerateGroup.setContext(context);
104             fSearchGroup.setContext(context);
105             fBuildPathGroup.setContext(context);
106         }
107     }
108 }
109
Popular Tags