KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > navigator > CommonNavigatorActionGroup


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.ui.internal.navigator;
12
13 import org.eclipse.jface.action.IMenuManager;
14 import org.eclipse.jface.resource.ImageDescriptor;
15 import org.eclipse.ui.IActionBars;
16 import org.eclipse.ui.IWorkbenchActionConstants;
17 import org.eclipse.ui.actions.ActionGroup;
18 import org.eclipse.ui.internal.navigator.actions.CollapseAllAction;
19 import org.eclipse.ui.internal.navigator.actions.LinkEditorAction;
20 import org.eclipse.ui.internal.navigator.extensions.LinkHelperService;
21 import org.eclipse.ui.internal.navigator.filters.FilterActionGroup;
22 import org.eclipse.ui.navigator.CommonNavigator;
23 import org.eclipse.ui.navigator.CommonViewer;
24 import org.eclipse.ui.navigator.INavigatorViewerDescriptor;
25
26 /**
27  *
28  *
29  * @since 3.2
30  */

31 public class CommonNavigatorActionGroup extends ActionGroup {
32
33     private LinkEditorAction toggleLinkingAction;
34
35     private CollapseAllAction collapseAllAction;
36
37     private FilterActionGroup filterGroup;
38
39     private final CommonViewer commonViewer;
40
41     private CommonNavigator commonNavigator;
42
43     private final LinkHelperService linkHelperService;
44
45     /**
46      * Create a action group for Collapse All, Link with editor, and Select
47      * Filters.
48      *
49      * @param aNavigator
50      * The IViewPart for this action group
51      * @param aViewer
52      * The Viewer for this action group
53      * @param linkHelperService the link service helper
54      */

55     public CommonNavigatorActionGroup(CommonNavigator aNavigator,
56             CommonViewer aViewer, LinkHelperService linkHelperService) {
57         super();
58         commonNavigator = aNavigator;
59         commonViewer = aViewer;
60         this.linkHelperService = linkHelperService;
61         makeActions();
62     }
63
64     /**
65      * Returns the image descriptor with the given relative path.
66      */

67     protected final ImageDescriptor getImageDescriptor(String JavaDoc relativePath) {
68         return NavigatorPlugin.getImageDescriptor("icons/full/" + relativePath); //$NON-NLS-1$
69

70     }
71
72     /**
73      *
74      */

75     private void makeActions() {
76
77         INavigatorViewerDescriptor viewerDescriptor = commonViewer
78                 .getNavigatorContentService().getViewerDescriptor();
79         boolean hideLinkWithEditorAction = viewerDescriptor
80                 .getBooleanConfigProperty(INavigatorViewerDescriptor.PROP_HIDE_LINK_WITH_EDITOR_ACTION);
81         if (!hideLinkWithEditorAction) {
82             toggleLinkingAction = new LinkEditorAction(commonNavigator,
83                     commonViewer, linkHelperService);
84             ImageDescriptor syncIcon = getImageDescriptor("elcl16/synced.gif"); //$NON-NLS-1$
85
toggleLinkingAction.setImageDescriptor(syncIcon);
86             toggleLinkingAction.setHoverImageDescriptor(syncIcon);
87         }
88
89         boolean hideCollapseAllAction = viewerDescriptor
90                 .getBooleanConfigProperty(INavigatorViewerDescriptor.PROP_HIDE_COLLAPSE_ALL_ACTION);
91         if (!hideCollapseAllAction) {
92             collapseAllAction = new CollapseAllAction(commonViewer);
93             ImageDescriptor collapseAllIcon = getImageDescriptor("elcl16/collapseall.gif"); //$NON-NLS-1$
94
collapseAllAction.setImageDescriptor(collapseAllIcon);
95             collapseAllAction.setHoverImageDescriptor(collapseAllIcon);
96         }
97
98         filterGroup = new FilterActionGroup(commonViewer);
99
100     }
101
102     /*
103      * (non-Javadoc)
104      *
105      * @see org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars)
106      */

107     public void fillActionBars(IActionBars theActionBars) {
108         IMenuManager menu = theActionBars.getMenuManager();
109
110         filterGroup.fillActionBars(theActionBars);
111
112         if (collapseAllAction != null) {
113             theActionBars.getToolBarManager().add(collapseAllAction);
114         }
115
116         if (toggleLinkingAction != null) {
117             menu
118                     .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 }
140
Popular Tags