KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2003, 2006 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.IAction;
14 import org.eclipse.jface.action.IMenuManager;
15 import org.eclipse.jface.viewers.TreeViewer;
16
17 import org.eclipse.ui.IActionBars;
18 import org.eclipse.ui.IViewPart;
19 import org.eclipse.ui.actions.ActionContext;
20 import org.eclipse.ui.navigator.CommonActionProvider;
21 import org.eclipse.ui.navigator.ICommonActionConstants;
22 import org.eclipse.ui.navigator.ICommonActionExtensionSite;
23 import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite;
24
25 import org.eclipse.jdt.ui.actions.OpenAction;
26 import org.eclipse.jdt.ui.actions.OpenEditorActionGroup;
27
28 public class PackageExplorerOpenActionProvider extends CommonActionProvider {
29     
30
31     private IAction fOpenAndExpand;
32     private OpenEditorActionGroup fOpenGroup;
33
34     private boolean fInViewPart = false;
35
36     public void fillActionBars(IActionBars actionBars) {
37         if (fInViewPart) {
38             fOpenGroup.fillActionBars(actionBars);
39             
40             if (fOpenAndExpand == null && fOpenGroup.getOpenAction().isEnabled()) // TODO: is not updated!
41
actionBars.setGlobalActionHandler(ICommonActionConstants.OPEN, fOpenGroup.getOpenAction());
42             else if (fOpenAndExpand != null && fOpenAndExpand.isEnabled())
43                 actionBars.setGlobalActionHandler(ICommonActionConstants.OPEN, fOpenAndExpand);
44         }
45
46     }
47
48     public void fillContextMenu(IMenuManager menu) {
49
50         if (fInViewPart) {
51             if (fOpenGroup.getOpenAction().isEnabled()) {
52                 fOpenGroup.fillContextMenu(menu);
53             }
54         }
55     }
56
57     public void init(ICommonActionExtensionSite site) {
58
59         ICommonViewerWorkbenchSite workbenchSite = null;
60         if (site.getViewSite() instanceof ICommonViewerWorkbenchSite)
61             workbenchSite = (ICommonViewerWorkbenchSite) site.getViewSite();
62  
63         if (workbenchSite != null) {
64             if (workbenchSite.getPart() != null && workbenchSite.getPart() instanceof IViewPart) {
65                 IViewPart viewPart = (IViewPart) workbenchSite.getPart();
66
67                 fOpenGroup = new OpenEditorActionGroup(viewPart);
68
69                 if (site.getStructuredViewer() instanceof TreeViewer)
70                     fOpenAndExpand = new OpenAndExpand(workbenchSite.getSite(), (OpenAction) fOpenGroup.getOpenAction(), (TreeViewer) site.getStructuredViewer());
71                 fInViewPart = true;
72             }
73         }
74     }
75
76     public void setContext(ActionContext context) {
77         super.setContext(context);
78         if (fInViewPart) {
79             fOpenGroup.setContext(context);
80         }
81     }
82
83 }
84
Popular Tags