]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2000, 2011 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 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 | @Override | |
49 | public void fillActionBars(IActionBars actionBars) { | |
50 | super.fillActionBars(actionBars); | |
51 | contributeToViewMenu(actionBars.getMenuManager()); | |
52 | } | |
53 | ||
54 | private void contributeToViewMenu(IMenuManager viewMenu) { | |
55 | viewMenu.add(new Separator(VIEWMENU_LAYOUT_GROUP)); | |
56 | ||
57 | // Create layout sub menu | |
58 | ||
59 | IMenuManager layoutSubMenu= new MenuManager(PackagesMessages.LayoutActionGroup_label); | |
60 | layoutSubMenu.add(fFlatLayoutAction); | |
61 | layoutSubMenu.add(fHierarchicalLayoutAction); | |
62 | ||
63 | viewMenu.add(layoutSubMenu); | |
64 | viewMenu.add(fShowLibrariesNode); | |
65 | } | |
66 | } | |
67 | ||
68 | class LayoutAction extends Action { | |
69 | ||
70 | private boolean fIsFlatLayout; | |
71 | private PackageExplorerPart fPackageExplorer; | |
72 | ||
73 | public LayoutAction(PackageExplorerPart packageExplorer, boolean flat) { | |
74 | super("", AS_RADIO_BUTTON); //$NON-NLS-1$ | |
75 | ||
76 | fIsFlatLayout= flat; | |
77 | fPackageExplorer= packageExplorer; | |
78 | if (fIsFlatLayout) { | |
79 | setText(PackagesMessages.LayoutActionGroup_flatLayoutAction_label); | |
80 | JavaPluginImages.setLocalImageDescriptors(this, "flatLayout.gif"); //$NON-NLS-1$ | |
81 | PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.LAYOUT_FLAT_ACTION); | |
82 | } else { | |
83 | setText(PackagesMessages.LayoutActionGroup_hierarchicalLayoutAction_label); | |
84 | JavaPluginImages.setLocalImageDescriptors(this, "hierarchicalLayout.gif"); //$NON-NLS-1$ | |
85 | PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.LAYOUT_HIERARCHICAL_ACTION); | |
86 | } | |
87 | setChecked(packageExplorer.isFlatLayout() == fIsFlatLayout); | |
88 | } | |
89 | ||
90 | /* | |
91 | * @see org.eclipse.jface.action.IAction#run() | |
92 | */ | |
93 | @Override | |
94 | public void run() { | |
95 | if (fPackageExplorer.isFlatLayout() != fIsFlatLayout) | |
96 | fPackageExplorer.setFlatLayout(fIsFlatLayout); | |
97 | } | |
98 | } | |
99 | ||
100 | class ShowLibrariesNodeAction extends Action { | |
101 | ||
102 | private PackageExplorerPart fPackageExplorer; | |
103 | ||
104 | public ShowLibrariesNodeAction(PackageExplorerPart packageExplorer) { | |
105 | super(PackagesMessages.LayoutActionGroup_show_libraries_in_group, AS_CHECK_BOX); | |
106 | fPackageExplorer= packageExplorer; | |
107 | setChecked(packageExplorer.isLibrariesNodeShown()); | |
108 | } | |
109 | ||
110 | /* | |
111 | * @see org.eclipse.jface.action.IAction#run() | |
112 | */ | |
113 | @Override | |
114 | public void run() { | |
115 | fPackageExplorer.setShowLibrariesNode(isChecked()); | |
116 | } | |
117 | } |