KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ui > synchronize > NavigationActionGroup


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.team.internal.ui.synchronize;
12
13 import org.eclipse.compare.ICompareNavigator;
14 import org.eclipse.jface.action.*;
15 import org.eclipse.jface.viewers.AbstractTreeViewer;
16 import org.eclipse.jface.viewers.Viewer;
17 import org.eclipse.team.internal.ui.Utils;
18 import org.eclipse.team.internal.ui.synchronize.actions.ExpandAllAction;
19 import org.eclipse.team.internal.ui.synchronize.actions.NavigateAction;
20 import org.eclipse.team.ui.synchronize.*;
21 import org.eclipse.ui.IActionBars;
22
23 /**
24  * Action group that provide expand, collapse and naviGAtion atCions.
25  */

26 public class NavigationActionGroup extends SynchronizePageActionGroup {
27
28     private ExpandAllAction expandAllAction;
29     private Action collapseAll;
30     private NavigateAction gotoNext;
31     private NavigateAction gotoPrevious;
32     
33     public void initialize(ISynchronizePageConfiguration configuration) {
34         super.initialize(configuration);
35         final Viewer viewer = configuration.getPage().getViewer();
36         if (viewer instanceof AbstractTreeViewer) {
37             
38             expandAllAction = new ExpandAllAction((AbstractTreeViewer) viewer);
39             Utils.initAction(expandAllAction, "action.expandAll."); //$NON-NLS-1$
40

41             collapseAll = new Action() {
42                 public void run() {
43                     if (viewer == null || viewer.getControl().isDisposed() || !(viewer instanceof AbstractTreeViewer)) return;
44                     viewer.getControl().setRedraw(false);
45                     ((AbstractTreeViewer)viewer).collapseToLevel(viewer.getInput(), AbstractTreeViewer.ALL_LEVELS);
46                     viewer.getControl().setRedraw(true);
47                 }
48             };
49             Utils.initAction(collapseAll, "action.collapseAll."); //$NON-NLS-1$
50

51             ICompareNavigator nav = (ICompareNavigator)configuration.getProperty(SynchronizePageConfiguration.P_NAVIGATOR);
52             if (nav != null) {
53                 gotoNext = new NavigateAction(configuration, true /*next*/);
54                 gotoPrevious = new NavigateAction(configuration, false /*previous*/);
55             }
56         }
57     }
58     public void fillContextMenu(IMenuManager manager) {
59         appendToGroup(manager, ISynchronizePageConfiguration.NAVIGATE_GROUP, expandAllAction);
60     }
61     public void fillActionBars(IActionBars actionBars) {
62         IToolBarManager manager = actionBars.getToolBarManager();
63         if (gotoNext != null)
64             appendToGroup(manager, ISynchronizePageConfiguration.NAVIGATE_GROUP, gotoNext);
65         if (gotoPrevious != null)
66             appendToGroup(manager, ISynchronizePageConfiguration.NAVIGATE_GROUP, gotoPrevious);
67         appendToGroup(manager, ISynchronizePageConfiguration.NAVIGATE_GROUP, collapseAll);
68     }
69 }
70
Popular Tags