KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > packageview > LayoutActionGroup


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.jdt.internal.ui.packageview;
12
13 import org.eclipse.jface.action.Action;
14 import org.eclipse.jface.action.IAction;
15 import org.eclipse.jface.action.IMenuManager;
16 import org.eclipse.jface.action.MenuManager;
17 import org.eclipse.jface.action.Separator;
18
19 import org.eclipse.ui.IActionBars;
20 import org.eclipse.ui.PlatformUI;
21 import org.eclipse.ui.actions.ActionGroup;
22
23 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
24 import org.eclipse.jdt.internal.ui.JavaPluginImages;
25
26 /**
27  * Adds view menus to switch between flat and hierarchical layout.
28  *
29  * @since 2.1
30  */

31 class LayoutActionGroup extends ActionGroup {
32
33     public static final String JavaDoc VIEWMENU_LAYOUT_GROUP= "layout"; //$NON-NLS-1$
34

35     private IAction fFlatLayoutAction;
36     private IAction fHierarchicalLayoutAction;
37     private IAction fShowLibrariesNode;
38     
39     LayoutActionGroup(PackageExplorerPart packageExplorer) {
40         fFlatLayoutAction= new LayoutAction(packageExplorer, true);
41         fHierarchicalLayoutAction= new LayoutAction(packageExplorer, false);
42         fShowLibrariesNode= new ShowLibrariesNodeAction(packageExplorer);
43     }
44
45     /* (non-Javadoc)
46      * @see ActionGroup#fillActionBars(IActionBars)
47      */

48     public void fillActionBars(IActionBars actionBars) {
49         super.fillActionBars(actionBars);
50         contributeToViewMenu(actionBars.getMenuManager());
51     }
52     
53     private void contributeToViewMenu(IMenuManager viewMenu) {
54         viewMenu.add(new Separator(VIEWMENU_LAYOUT_GROUP));
55
56         // Create layout sub menu
57

58         IMenuManager layoutSubMenu= new MenuManager(PackagesMessages.LayoutActionGroup_label);
59         layoutSubMenu.add(fFlatLayoutAction);
60         layoutSubMenu.add(fHierarchicalLayoutAction);
61         
62         viewMenu.add(layoutSubMenu);
63         viewMenu.add(fShowLibrariesNode);
64     }
65 }
66
67 class LayoutAction extends Action implements IAction {
68
69     private boolean fIsFlatLayout;
70     private PackageExplorerPart fPackageExplorer;
71
72     public LayoutAction(PackageExplorerPart packageExplorer, boolean flat) {
73         super("", AS_RADIO_BUTTON); //$NON-NLS-1$
74

75         fIsFlatLayout= flat;
76         fPackageExplorer= packageExplorer;
77         if (fIsFlatLayout) {
78             setText(PackagesMessages.LayoutActionGroup_flatLayoutAction_label);
79             JavaPluginImages.setLocalImageDescriptors(this, "flatLayout.gif"); //$NON-NLS-1$
80
PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.LAYOUT_FLAT_ACTION);
81         } else {
82             setText(PackagesMessages.LayoutActionGroup_hierarchicalLayoutAction_label);
83             JavaPluginImages.setLocalImageDescriptors(this, "hierarchicalLayout.gif"); //$NON-NLS-1$
84
PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.LAYOUT_HIERARCHICAL_ACTION);
85         }
86         setChecked(packageExplorer.isFlatLayout() == fIsFlatLayout);
87     }
88
89     /*
90      * @see org.eclipse.jface.action.IAction#run()
91      */

92     public void run() {
93         if (fPackageExplorer.isFlatLayout() != fIsFlatLayout)
94             fPackageExplorer.setFlatLayout(fIsFlatLayout);
95     }
96 }
97
98 class ShowLibrariesNodeAction extends Action implements IAction {
99
100     private PackageExplorerPart fPackageExplorer;
101
102     public ShowLibrariesNodeAction(PackageExplorerPart packageExplorer) {
103         super(PackagesMessages.LayoutActionGroup_show_libraries_in_group, AS_CHECK_BOX);
104         fPackageExplorer= packageExplorer;
105         setChecked(packageExplorer.isLibrariesNodeShown());
106     }
107
108     /*
109      * @see org.eclipse.jface.action.IAction#run()
110      */

111     public void run() {
112         fPackageExplorer.setShowLibrariesNode(isChecked());
113     }
114 }
115
Popular Tags