|
Lines 1-26
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/*************************************************************************************************** |
| 2 |
* Copyright (c) 2003, 2006 IBM Corporation and others. |
2 |
* Copyright (c) 2003, 2006 IBM Corporation and others. All rights reserved. This program and the |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* accompanying materials are made available under the terms of the Eclipse Public License v1.0 |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
|
|
| 5 |
* which accompanies this distribution, and is available at |
4 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
5 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
6 |
* |
| 8 |
* Contributors: |
7 |
* Contributors: IBM Corporation - initial API and implementation |
| 9 |
* IBM Corporation - initial API and implementation |
8 |
**************************************************************************************************/ |
| 10 |
*******************************************************************************/ |
|
|
| 11 |
package org.eclipse.jdt.internal.ui.navigator; |
9 |
package org.eclipse.jdt.internal.ui.navigator; |
| 12 |
|
10 |
|
| 13 |
import org.eclipse.jface.action.IAction; |
|
|
| 14 |
import org.eclipse.jface.action.IMenuManager; |
11 |
import org.eclipse.jface.action.IMenuManager; |
| 15 |
import org.eclipse.jface.preference.IPreferenceStore; |
12 |
import org.eclipse.jface.preference.IPreferenceStore; |
| 16 |
import org.eclipse.jface.viewers.TreeViewer; |
|
|
| 17 |
|
13 |
|
| 18 |
import org.eclipse.ui.IActionBars; |
14 |
import org.eclipse.ui.IActionBars; |
| 19 |
import org.eclipse.ui.IMemento; |
15 |
import org.eclipse.ui.IMemento; |
| 20 |
import org.eclipse.ui.IViewPart; |
16 |
import org.eclipse.ui.IViewPart; |
| 21 |
import org.eclipse.ui.actions.ActionContext; |
17 |
import org.eclipse.ui.actions.ActionContext; |
| 22 |
import org.eclipse.ui.navigator.CommonActionProvider; |
18 |
import org.eclipse.ui.navigator.CommonActionProvider; |
| 23 |
import org.eclipse.ui.navigator.ICommonActionConstants; |
|
|
| 24 |
import org.eclipse.ui.navigator.ICommonActionExtensionSite; |
19 |
import org.eclipse.ui.navigator.ICommonActionExtensionSite; |
| 25 |
import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite; |
20 |
import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite; |
| 26 |
import org.eclipse.ui.navigator.IExtensionStateModel; |
21 |
import org.eclipse.ui.navigator.IExtensionStateModel; |
|
Lines 28-140
Link Here
|
| 28 |
import org.eclipse.jdt.ui.actions.CCPActionGroup; |
23 |
import org.eclipse.jdt.ui.actions.CCPActionGroup; |
| 29 |
import org.eclipse.jdt.ui.actions.GenerateActionGroup; |
24 |
import org.eclipse.jdt.ui.actions.GenerateActionGroup; |
| 30 |
import org.eclipse.jdt.ui.actions.JavaSearchActionGroup; |
25 |
import org.eclipse.jdt.ui.actions.JavaSearchActionGroup; |
| 31 |
import org.eclipse.jdt.ui.actions.OpenAction; |
26 |
import org.eclipse.jdt.ui.actions.OpenViewActionGroup; |
| 32 |
import org.eclipse.jdt.ui.actions.OpenEditorActionGroup; |
|
|
| 33 |
import org.eclipse.jdt.ui.actions.RefactorActionGroup; |
27 |
import org.eclipse.jdt.ui.actions.RefactorActionGroup; |
| 34 |
|
28 |
|
| 35 |
import org.eclipse.jdt.internal.ui.JavaPlugin; |
29 |
import org.eclipse.jdt.internal.ui.JavaPlugin; |
| 36 |
import org.eclipse.jdt.internal.ui.navigator.IExtensionStateConstants.Values; |
30 |
import org.eclipse.jdt.internal.ui.navigator.IExtensionStateConstants.Values; |
| 37 |
import org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage.GenerateBuildPathActionGroup; |
31 |
import org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage.GenerateBuildPathActionGroup; |
| 38 |
|
32 |
|
| 39 |
public class PackageExplorerActionProvider extends CommonActionProvider { |
33 |
public class PackageExplorerActionProvider extends CommonActionProvider { |
| 40 |
|
34 |
|
| 41 |
private static final int HIERARCHICAL_LAYOUT = 0x1; |
35 |
private static final int HIERARCHICAL_LAYOUT = 0x1; |
| 42 |
|
36 |
|
| 43 |
private static final int FLAT_LAYOUT = 0x2; |
37 |
private static final int FLAT_LAYOUT = 0x2; |
| 44 |
|
38 |
|
| 45 |
private static final String TAG_LAYOUT = "layout"; //$NON-NLS-1$ |
39 |
private static final String TAG_LAYOUT = "layout"; //$NON-NLS-1$ |
| 46 |
|
40 |
|
| 47 |
private CommonLayoutActionGroup fLayoutActionGroup; |
41 |
private CommonLayoutActionGroup fLayoutActionGroup; |
| 48 |
|
42 |
|
| 49 |
private boolean fHasFilledViewMenu = false; |
43 |
private boolean fHasFilledViewMenu = false; |
| 50 |
|
44 |
|
| 51 |
private IExtensionStateModel fStateModel; |
45 |
private IExtensionStateModel fStateModel; |
| 52 |
|
46 |
|
| 53 |
private IAction fOpenAndExpand; |
47 |
private OpenViewActionGroup fOpenViewGroup; |
| 54 |
|
|
|
| 55 |
private OpenEditorActionGroup fOpenGroup; |
| 56 |
|
48 |
|
| 57 |
private CCPActionGroup fCCPGroup; |
49 |
private CCPActionGroup fCCPGroup; |
| 58 |
|
50 |
|
| 59 |
private RefactorActionGroup fRefactorGroup; |
51 |
private RefactorActionGroup fRefactorGroup; |
| 60 |
|
52 |
|
| 61 |
private JavaSearchActionGroup fSearchGroup; |
53 |
private JavaSearchActionGroup fSearchGroup; |
| 62 |
|
54 |
|
| 63 |
private GenerateBuildPathActionGroup fBuildPathGroup; |
55 |
private GenerateBuildPathActionGroup fBuildPathGroup; |
| 64 |
|
56 |
|
| 65 |
private GenerateActionGroup fGenerateGroup; |
57 |
private GenerateActionGroup fGenerateGroup; |
| 66 |
|
58 |
|
| 67 |
private boolean fInViewPart = false; |
59 |
private boolean fInViewPart = false; |
| 68 |
|
60 |
|
| 69 |
public void fillActionBars(IActionBars actionBars) { |
61 |
public void fillActionBars(IActionBars actionBars) { |
| 70 |
if (!fHasFilledViewMenu) { |
62 |
if (!fHasFilledViewMenu) { |
| 71 |
fLayoutActionGroup.fillActionBars(actionBars); |
63 |
fLayoutActionGroup.fillActionBars(actionBars); |
| 72 |
fHasFilledViewMenu = true; |
64 |
fHasFilledViewMenu = true; |
| 73 |
} |
65 |
} |
| 74 |
if(fInViewPart) { |
66 |
if (fInViewPart) { |
| 75 |
fOpenGroup.fillActionBars(actionBars); |
67 |
fOpenViewGroup.fillActionBars(actionBars); |
| 76 |
fCCPGroup.fillActionBars(actionBars); |
68 |
fCCPGroup.fillActionBars(actionBars); |
| 77 |
fBuildPathGroup.fillActionBars(actionBars); |
69 |
fBuildPathGroup.fillActionBars(actionBars); |
| 78 |
fGenerateGroup.fillActionBars(actionBars); |
70 |
fGenerateGroup.fillActionBars(actionBars); |
| 79 |
fRefactorGroup.fillActionBars(actionBars); |
71 |
fRefactorGroup.fillActionBars(actionBars); |
| 80 |
fRefactorGroup.retargetFileMenuActions(actionBars); |
72 |
fRefactorGroup.retargetFileMenuActions(actionBars); |
| 81 |
fSearchGroup.fillActionBars(actionBars); |
73 |
fSearchGroup.fillActionBars(actionBars); |
| 82 |
|
|
|
| 83 |
if(fOpenAndExpand == null && fOpenGroup.getOpenAction().isEnabled()) // TODO: is not updated! |
| 84 |
actionBars.setGlobalActionHandler(ICommonActionConstants.OPEN, fOpenGroup.getOpenAction()); |
| 85 |
else if(fOpenAndExpand.isEnabled()) |
| 86 |
actionBars.setGlobalActionHandler(ICommonActionConstants.OPEN, fOpenAndExpand); |
| 87 |
} |
74 |
} |
| 88 |
|
75 |
|
| 89 |
} |
76 |
} |
| 90 |
|
77 |
|
| 91 |
public void fillContextMenu(IMenuManager menu) { |
78 |
public void fillContextMenu(IMenuManager menu) { |
| 92 |
|
79 |
|
| 93 |
if(fInViewPart) { |
80 |
if (fInViewPart) { |
| 94 |
fCCPGroup.fillContextMenu(menu); |
81 |
fOpenViewGroup.fillContextMenu(menu); |
|
|
82 |
fCCPGroup.fillContextMenu(menu); |
| 95 |
fBuildPathGroup.fillContextMenu(menu); |
83 |
fBuildPathGroup.fillContextMenu(menu); |
| 96 |
fGenerateGroup.fillContextMenu(menu); |
84 |
fGenerateGroup.fillContextMenu(menu); |
| 97 |
fRefactorGroup.fillContextMenu(menu); |
85 |
fRefactorGroup.fillContextMenu(menu); |
| 98 |
fSearchGroup.fillContextMenu(menu); |
86 |
fSearchGroup.fillContextMenu(menu); |
| 99 |
} |
87 |
} |
| 100 |
} |
88 |
} |
| 101 |
|
89 |
|
| 102 |
public void init(ICommonActionExtensionSite site) { |
90 |
public void init(ICommonActionExtensionSite site) { |
| 103 |
|
91 |
|
| 104 |
ICommonViewerWorkbenchSite workbenchSite = null; |
92 |
ICommonViewerWorkbenchSite workbenchSite = null; |
| 105 |
if (site.getViewSite() instanceof ICommonViewerWorkbenchSite) |
93 |
if (site.getViewSite() instanceof ICommonViewerWorkbenchSite) |
| 106 |
workbenchSite = (ICommonViewerWorkbenchSite) site.getViewSite(); |
94 |
workbenchSite = (ICommonViewerWorkbenchSite) site.getViewSite(); |
| 107 |
|
95 |
|
| 108 |
fStateModel = site.getExtensionStateModel(); |
96 |
fStateModel = site.getExtensionStateModel(); |
| 109 |
|
97 |
|
| 110 |
fLayoutActionGroup = new CommonLayoutActionGroup(site |
98 |
fLayoutActionGroup = new CommonLayoutActionGroup(site.getStructuredViewer(), fStateModel); |
| 111 |
.getStructuredViewer(), fStateModel); |
|
|
| 112 |
|
99 |
|
| 113 |
if (workbenchSite != null) { |
100 |
if (workbenchSite != null) { |
| 114 |
if (workbenchSite.getPart() != null |
101 |
if (workbenchSite.getPart() != null && workbenchSite.getPart() instanceof IViewPart) { |
| 115 |
&& workbenchSite.getPart() instanceof IViewPart) { |
|
|
| 116 |
IViewPart viewPart = (IViewPart) workbenchSite.getPart(); |
102 |
IViewPart viewPart = (IViewPart) workbenchSite.getPart(); |
| 117 |
|
103 |
|
| 118 |
fOpenGroup = new OpenEditorActionGroup(viewPart); |
104 |
fOpenViewGroup = new OpenViewActionGroup(viewPart, site.getStructuredViewer(), false); |
| 119 |
fCCPGroup = new CCPActionGroup(viewPart); |
105 |
fCCPGroup = new CCPActionGroup(viewPart); |
| 120 |
fRefactorGroup = new RefactorActionGroup(viewPart); |
106 |
fRefactorGroup = new RefactorActionGroup(viewPart); |
| 121 |
fGenerateGroup = new GenerateActionGroup(viewPart); |
107 |
fGenerateGroup = new GenerateActionGroup(viewPart); |
| 122 |
fSearchGroup = new JavaSearchActionGroup(viewPart); |
108 |
fSearchGroup = new JavaSearchActionGroup(viewPart); |
| 123 |
fBuildPathGroup = new GenerateBuildPathActionGroup(viewPart); |
109 |
fBuildPathGroup = new GenerateBuildPathActionGroup(viewPart); |
| 124 |
|
110 |
|
| 125 |
if(site.getStructuredViewer() instanceof TreeViewer) |
|
|
| 126 |
fOpenAndExpand = new OpenAndExpand(workbenchSite.getSite(), (OpenAction) fOpenGroup.getOpenAction(), (TreeViewer)site.getStructuredViewer()); |
| 127 |
fInViewPart = true; |
111 |
fInViewPart = true; |
| 128 |
} |
112 |
} |
| 129 |
|
113 |
|
| 130 |
} |
114 |
} |
| 131 |
|
115 |
|
| 132 |
} |
116 |
} |
| 133 |
|
117 |
|
| 134 |
public void setContext(ActionContext context) { |
118 |
public void setContext(ActionContext context) { |
| 135 |
super.setContext(context); |
119 |
super.setContext(context); |
| 136 |
if(fInViewPart) { |
120 |
if (fInViewPart) { |
| 137 |
fOpenGroup.setContext(context); |
121 |
fOpenViewGroup.setContext(context); |
| 138 |
fCCPGroup.setContext(context); |
122 |
fCCPGroup.setContext(context); |
| 139 |
fRefactorGroup.setContext(context); |
123 |
fRefactorGroup.setContext(context); |
| 140 |
fGenerateGroup.setContext(context); |
124 |
fGenerateGroup.setContext(context); |
|
Lines 156-163
Link Here
|
| 156 |
|
140 |
|
| 157 |
// If no memento try an restore from preference store |
141 |
// If no memento try an restore from preference store |
| 158 |
if (state == null) { |
142 |
if (state == null) { |
| 159 |
IPreferenceStore store = JavaPlugin.getDefault() |
143 |
IPreferenceStore store = JavaPlugin.getDefault().getPreferenceStore(); |
| 160 |
.getPreferenceStore(); |
|
|
| 161 |
state = new Integer(store.getInt(TAG_LAYOUT)); |
144 |
state = new Integer(store.getInt(TAG_LAYOUT)); |
| 162 |
} |
145 |
} |
| 163 |
|
146 |
|
|
Lines 166-174
Link Here
|
| 166 |
else if (state.intValue() == HIERARCHICAL_LAYOUT) |
149 |
else if (state.intValue() == HIERARCHICAL_LAYOUT) |
| 167 |
isCurrentLayoutFlat = false; |
150 |
isCurrentLayoutFlat = false; |
| 168 |
|
151 |
|
| 169 |
fStateModel.setBooleanProperty(Values.IS_LAYOUT_FLAT, |
152 |
fStateModel.setBooleanProperty(Values.IS_LAYOUT_FLAT, isCurrentLayoutFlat); |
| 170 |
isCurrentLayoutFlat); |
|
|
| 171 |
fLayoutActionGroup.setFlatLayout(isCurrentLayoutFlat); |
153 |
fLayoutActionGroup.setFlatLayout(isCurrentLayoutFlat); |
| 172 |
} |
154 |
} |
| 173 |
|
155 |
|
|
|
156 |
public void saveState(IMemento aMemento) { |
| 157 |
super.saveState(aMemento); |
| 158 |
IPreferenceStore store = JavaPlugin.getDefault().getPreferenceStore(); |
| 159 |
if (fStateModel.getBooleanProperty(Values.IS_LAYOUT_FLAT)) |
| 160 |
store.setValue(TAG_LAYOUT, FLAT_LAYOUT); |
| 161 |
else |
| 162 |
store.setValue(TAG_LAYOUT, HIERARCHICAL_LAYOUT); |
| 163 |
|
| 164 |
} |
| 165 |
|
| 174 |
} |
166 |
} |