KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > views > navigator > GotoActionGroup


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.ui.views.navigator;
12
13 import org.eclipse.core.resources.IFolder;
14 import org.eclipse.core.resources.IProject;
15 import org.eclipse.core.resources.IResource;
16 import org.eclipse.jface.action.IMenuManager;
17 import org.eclipse.jface.action.IToolBarManager;
18 import org.eclipse.jface.viewers.IStructuredSelection;
19 import org.eclipse.ui.IActionBars;
20 import org.eclipse.ui.IWorkbenchActionConstants;
21 import org.eclipse.ui.actions.ActionContext;
22 import org.eclipse.ui.actions.ActionFactory;
23 import org.eclipse.ui.internal.views.navigator.ResourceNavigatorMessages;
24 import org.eclipse.ui.views.framelist.BackAction;
25 import org.eclipse.ui.views.framelist.ForwardAction;
26 import org.eclipse.ui.views.framelist.FrameList;
27 import org.eclipse.ui.views.framelist.GoIntoAction;
28 import org.eclipse.ui.views.framelist.UpAction;
29
30 /**
31  * This is the action group for the goto actions.
32  */

33 public class GotoActionGroup extends ResourceNavigatorActionGroup {
34
35     private BackAction backAction;
36
37     private ForwardAction forwardAction;
38
39     private GoIntoAction goIntoAction;
40
41     private UpAction upAction;
42
43     private GotoResourceAction goToResourceAction;
44
45     public GotoActionGroup(IResourceNavigator navigator) {
46         super(navigator);
47     }
48
49     public void fillContextMenu(IMenuManager menu) {
50         IStructuredSelection selection = (IStructuredSelection) getContext()
51                 .getSelection();
52         if (selection.size() == 1) {
53             if (ResourceSelectionUtil.allResourcesAreOfType(selection,
54                     IResource.FOLDER)) {
55                 menu.add(goIntoAction);
56             } else {
57                 IStructuredSelection resourceSelection = ResourceSelectionUtil
58                         .allResources(selection, IResource.PROJECT);
59                 if (resourceSelection != null && !resourceSelection.isEmpty()) {
60                     IProject project = (IProject) resourceSelection
61                             .getFirstElement();
62                     if (project.isOpen()) {
63                         menu.add(goIntoAction);
64                     }
65                 }
66             }
67         }
68     }
69
70     public void fillActionBars(IActionBars actionBars) {
71         actionBars.setGlobalActionHandler(IWorkbenchActionConstants.GO_INTO,
72                 goIntoAction);
73         actionBars.setGlobalActionHandler(ActionFactory.BACK.getId(),
74                 backAction);
75         actionBars.setGlobalActionHandler(ActionFactory.FORWARD.getId(),
76                 forwardAction);
77         actionBars.setGlobalActionHandler(IWorkbenchActionConstants.UP,
78                 upAction);
79         actionBars.setGlobalActionHandler(
80                 IWorkbenchActionConstants.GO_TO_RESOURCE, goToResourceAction);
81
82         IToolBarManager toolBar = actionBars.getToolBarManager();
83         toolBar.add(backAction);
84         toolBar.add(forwardAction);
85         toolBar.add(upAction);
86     }
87
88     protected void makeActions() {
89         FrameList frameList = navigator.getFrameList();
90         goIntoAction = new GoIntoAction(frameList);
91         backAction = new BackAction(frameList);
92         forwardAction = new ForwardAction(frameList);
93         upAction = new UpAction(frameList);
94         goToResourceAction = new GotoResourceAction(navigator,
95                 ResourceNavigatorMessages.GoToResource_label);
96     }
97
98     public void updateActionBars() {
99         ActionContext context = getContext();
100         boolean enable = false;
101
102         // Fix for bug 26126. Resource change listener could call
103
// updateActionBars without a context being set.
104
// This should never happen because resource navigator sets
105
// context immediately after this group is created.
106
if (context != null) {
107             IStructuredSelection selection = (IStructuredSelection) context
108                     .getSelection();
109
110             if (selection.size() == 1) {
111                 Object JavaDoc object = selection.getFirstElement();
112                 if (object instanceof IProject) {
113                     enable = ((IProject) object).isOpen();
114                 } else if (object instanceof IFolder) {
115                     enable = true;
116                 }
117             }
118         }
119         goIntoAction.setEnabled(enable);
120         // the rest of the actions update by listening to frame list changes
121
}
122 }
123
Popular Tags