001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.views.navigator;
011:
012: import org.eclipse.core.resources.IFolder;
013: import org.eclipse.core.resources.IProject;
014: import org.eclipse.core.resources.IResource;
015: import org.eclipse.jface.action.IMenuManager;
016: import org.eclipse.jface.action.IToolBarManager;
017: import org.eclipse.jface.viewers.IStructuredSelection;
018: import org.eclipse.ui.IActionBars;
019: import org.eclipse.ui.IWorkbenchActionConstants;
020: import org.eclipse.ui.actions.ActionContext;
021: import org.eclipse.ui.actions.ActionFactory;
022: import org.eclipse.ui.internal.views.navigator.ResourceNavigatorMessages;
023: import org.eclipse.ui.views.framelist.BackAction;
024: import org.eclipse.ui.views.framelist.ForwardAction;
025: import org.eclipse.ui.views.framelist.FrameList;
026: import org.eclipse.ui.views.framelist.GoIntoAction;
027: import org.eclipse.ui.views.framelist.UpAction;
028:
029: /**
030: * This is the action group for the goto actions.
031: */
032: public class GotoActionGroup extends ResourceNavigatorActionGroup {
033:
034: private BackAction backAction;
035:
036: private ForwardAction forwardAction;
037:
038: private GoIntoAction goIntoAction;
039:
040: private UpAction upAction;
041:
042: private GotoResourceAction goToResourceAction;
043:
044: public GotoActionGroup(IResourceNavigator navigator) {
045: super (navigator);
046: }
047:
048: public void fillContextMenu(IMenuManager menu) {
049: IStructuredSelection selection = (IStructuredSelection) getContext()
050: .getSelection();
051: if (selection.size() == 1) {
052: if (ResourceSelectionUtil.allResourcesAreOfType(selection,
053: IResource.FOLDER)) {
054: menu.add(goIntoAction);
055: } else {
056: IStructuredSelection resourceSelection = ResourceSelectionUtil
057: .allResources(selection, IResource.PROJECT);
058: if (resourceSelection != null
059: && !resourceSelection.isEmpty()) {
060: IProject project = (IProject) resourceSelection
061: .getFirstElement();
062: if (project.isOpen()) {
063: menu.add(goIntoAction);
064: }
065: }
066: }
067: }
068: }
069:
070: public void fillActionBars(IActionBars actionBars) {
071: actionBars.setGlobalActionHandler(
072: IWorkbenchActionConstants.GO_INTO, goIntoAction);
073: actionBars.setGlobalActionHandler(ActionFactory.BACK.getId(),
074: backAction);
075: actionBars.setGlobalActionHandler(
076: ActionFactory.FORWARD.getId(), forwardAction);
077: actionBars.setGlobalActionHandler(IWorkbenchActionConstants.UP,
078: upAction);
079: actionBars.setGlobalActionHandler(
080: IWorkbenchActionConstants.GO_TO_RESOURCE,
081: goToResourceAction);
082:
083: IToolBarManager toolBar = actionBars.getToolBarManager();
084: toolBar.add(backAction);
085: toolBar.add(forwardAction);
086: toolBar.add(upAction);
087: }
088:
089: protected void makeActions() {
090: FrameList frameList = navigator.getFrameList();
091: goIntoAction = new GoIntoAction(frameList);
092: backAction = new BackAction(frameList);
093: forwardAction = new ForwardAction(frameList);
094: upAction = new UpAction(frameList);
095: goToResourceAction = new GotoResourceAction(navigator,
096: ResourceNavigatorMessages.GoToResource_label);
097: }
098:
099: public void updateActionBars() {
100: ActionContext context = getContext();
101: boolean enable = false;
102:
103: // Fix for bug 26126. Resource change listener could call
104: // updateActionBars without a context being set.
105: // This should never happen because resource navigator sets
106: // context immediately after this group is created.
107: if (context != null) {
108: IStructuredSelection selection = (IStructuredSelection) context
109: .getSelection();
110:
111: if (selection.size() == 1) {
112: Object object = selection.getFirstElement();
113: if (object instanceof IProject) {
114: enable = ((IProject) object).isOpen();
115: } else if (object instanceof IFolder) {
116: enable = true;
117: }
118: }
119: }
120: goIntoAction.setEnabled(enable);
121: // the rest of the actions update by listening to frame list changes
122: }
123: }
|