001: /*******************************************************************************
002: * Copyright (c) 2003, 2007 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.internal.navigator;
011:
012: import org.eclipse.jface.action.IMenuManager;
013: import org.eclipse.jface.resource.ImageDescriptor;
014: import org.eclipse.ui.IActionBars;
015: import org.eclipse.ui.IWorkbenchActionConstants;
016: import org.eclipse.ui.actions.ActionGroup;
017: import org.eclipse.ui.internal.navigator.actions.CollapseAllAction;
018: import org.eclipse.ui.internal.navigator.actions.LinkEditorAction;
019: import org.eclipse.ui.internal.navigator.extensions.LinkHelperService;
020: import org.eclipse.ui.internal.navigator.filters.FilterActionGroup;
021: import org.eclipse.ui.navigator.CommonNavigator;
022: import org.eclipse.ui.navigator.CommonViewer;
023: import org.eclipse.ui.navigator.INavigatorViewerDescriptor;
024:
025: /**
026: *
027: *
028: * @since 3.2
029: */
030: public class CommonNavigatorActionGroup extends ActionGroup {
031:
032: private LinkEditorAction toggleLinkingAction;
033:
034: private CollapseAllAction collapseAllAction;
035:
036: private FilterActionGroup filterGroup;
037:
038: private final CommonViewer commonViewer;
039:
040: private CommonNavigator commonNavigator;
041:
042: private final LinkHelperService linkHelperService;
043:
044: /**
045: * Create a action group for Collapse All, Link with editor, and Select
046: * Filters.
047: *
048: * @param aNavigator
049: * The IViewPart for this action group
050: * @param aViewer
051: * The Viewer for this action group
052: * @param linkHelperService the link service helper
053: */
054: public CommonNavigatorActionGroup(CommonNavigator aNavigator,
055: CommonViewer aViewer, LinkHelperService linkHelperService) {
056: super ();
057: commonNavigator = aNavigator;
058: commonViewer = aViewer;
059: this .linkHelperService = linkHelperService;
060: makeActions();
061: }
062:
063: /**
064: * Returns the image descriptor with the given relative path.
065: */
066: protected final ImageDescriptor getImageDescriptor(
067: String relativePath) {
068: return NavigatorPlugin
069: .getImageDescriptor("icons/full/" + relativePath); //$NON-NLS-1$
070:
071: }
072:
073: /**
074: *
075: */
076: private void makeActions() {
077:
078: INavigatorViewerDescriptor viewerDescriptor = commonViewer
079: .getNavigatorContentService().getViewerDescriptor();
080: boolean hideLinkWithEditorAction = viewerDescriptor
081: .getBooleanConfigProperty(INavigatorViewerDescriptor.PROP_HIDE_LINK_WITH_EDITOR_ACTION);
082: if (!hideLinkWithEditorAction) {
083: toggleLinkingAction = new LinkEditorAction(commonNavigator,
084: commonViewer, linkHelperService);
085: ImageDescriptor syncIcon = getImageDescriptor("elcl16/synced.gif"); //$NON-NLS-1$
086: toggleLinkingAction.setImageDescriptor(syncIcon);
087: toggleLinkingAction.setHoverImageDescriptor(syncIcon);
088: }
089:
090: boolean hideCollapseAllAction = viewerDescriptor
091: .getBooleanConfigProperty(INavigatorViewerDescriptor.PROP_HIDE_COLLAPSE_ALL_ACTION);
092: if (!hideCollapseAllAction) {
093: collapseAllAction = new CollapseAllAction(commonViewer);
094: ImageDescriptor collapseAllIcon = getImageDescriptor("elcl16/collapseall.gif"); //$NON-NLS-1$
095: collapseAllAction.setImageDescriptor(collapseAllIcon);
096: collapseAllAction.setHoverImageDescriptor(collapseAllIcon);
097: }
098:
099: filterGroup = new FilterActionGroup(commonViewer);
100:
101: }
102:
103: /*
104: * (non-Javadoc)
105: *
106: * @see org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars)
107: */
108: public void fillActionBars(IActionBars theActionBars) {
109: IMenuManager menu = theActionBars.getMenuManager();
110:
111: filterGroup.fillActionBars(theActionBars);
112:
113: if (collapseAllAction != null) {
114: theActionBars.getToolBarManager().add(collapseAllAction);
115: }
116:
117: if (toggleLinkingAction != null) {
118: menu.insertAfter(IWorkbenchActionConstants.MB_ADDITIONS
119: + "-end", toggleLinkingAction); //$NON-NLS-1$
120:
121: theActionBars.getToolBarManager().add(toggleLinkingAction);
122: }
123:
124: theActionBars.updateActionBars();
125: }
126:
127: /*
128: * (non-Javadoc)
129: *
130: * @see org.eclipse.ui.actions.ActionGroup#dispose()
131: */
132: public void dispose() {
133: super.dispose();
134: if (toggleLinkingAction != null) {
135: toggleLinkingAction.dispose();
136: }
137: }
138:
139: }
|