1 9 package org.eclipse.jdt.internal.ui.navigator; 10 11 import org.eclipse.jface.action.IMenuManager; 12 import org.eclipse.jface.preference.IPreferenceStore; 13 14 import org.eclipse.ui.IActionBars; 15 import org.eclipse.ui.IMemento; 16 import org.eclipse.ui.IViewPart; 17 import org.eclipse.ui.actions.ActionContext; 18 import org.eclipse.ui.navigator.CommonActionProvider; 19 import org.eclipse.ui.navigator.ICommonActionExtensionSite; 20 import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite; 21 import org.eclipse.ui.navigator.IExtensionStateModel; 22 23 import org.eclipse.jdt.ui.actions.CCPActionGroup; 24 import org.eclipse.jdt.ui.actions.GenerateActionGroup; 25 import org.eclipse.jdt.ui.actions.JavaSearchActionGroup; 26 import org.eclipse.jdt.ui.actions.OpenViewActionGroup; 27 import org.eclipse.jdt.ui.actions.RefactorActionGroup; 28 29 import org.eclipse.jdt.internal.ui.JavaPlugin; 30 import org.eclipse.jdt.internal.ui.navigator.IExtensionStateConstants.Values; 31 import org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage.GenerateBuildPathActionGroup; 32 33 public class PackageExplorerActionProvider extends CommonActionProvider { 34 35 private static final int HIERARCHICAL_LAYOUT = 0x1; 36 37 private static final int FLAT_LAYOUT = 0x2; 38 39 private static final String TAG_LAYOUT = "org.eclipse.jdt.internal.ui.navigator.layout"; 41 private CommonLayoutActionGroup fLayoutActionGroup; 42 43 private boolean fHasFilledViewMenu = false; 44 45 private IExtensionStateModel fStateModel; 46 47 private OpenViewActionGroup fOpenViewGroup; 48 49 private CCPActionGroup fCCPGroup; 50 51 private RefactorActionGroup fRefactorGroup; 52 53 private JavaSearchActionGroup fSearchGroup; 54 55 private GenerateBuildPathActionGroup fBuildPathGroup; 56 57 private GenerateActionGroup fGenerateGroup; 58 59 private boolean fInViewPart = false; 60 61 public void fillActionBars(IActionBars actionBars) { 62 if (!fHasFilledViewMenu) { 63 fLayoutActionGroup.fillActionBars(actionBars); 64 fHasFilledViewMenu = true; 65 } 66 if (fInViewPart) { 67 fOpenViewGroup.fillActionBars(actionBars); 68 fCCPGroup.fillActionBars(actionBars); 69 fBuildPathGroup.fillActionBars(actionBars); 70 fGenerateGroup.fillActionBars(actionBars); 71 fRefactorGroup.fillActionBars(actionBars); 72 fRefactorGroup.retargetFileMenuActions(actionBars); 73 fSearchGroup.fillActionBars(actionBars); 74 } 75 76 } 77 78 public void fillContextMenu(IMenuManager menu) { 79 80 if (fInViewPart) { 81 fOpenViewGroup.fillContextMenu(menu); 82 fCCPGroup.fillContextMenu(menu); 83 fBuildPathGroup.fillContextMenu(menu); 84 fGenerateGroup.fillContextMenu(menu); 85 fRefactorGroup.fillContextMenu(menu); 86 fSearchGroup.fillContextMenu(menu); 87 } 88 } 89 90 public void init(ICommonActionExtensionSite site) { 91 92 ICommonViewerWorkbenchSite workbenchSite = null; 93 if (site.getViewSite() instanceof ICommonViewerWorkbenchSite) 94 workbenchSite = (ICommonViewerWorkbenchSite) site.getViewSite(); 95 96 fStateModel = site.getExtensionStateModel(); 97 98 fLayoutActionGroup = new CommonLayoutActionGroup(site.getStructuredViewer(), fStateModel); 99 100 if (workbenchSite != null) { 101 if (workbenchSite.getPart() != null && workbenchSite.getPart() instanceof IViewPart) { 102 IViewPart viewPart = (IViewPart) workbenchSite.getPart(); 103 104 fOpenViewGroup = new OpenViewActionGroup(viewPart, site.getStructuredViewer()) { 105 protected boolean getShowProperties() { 106 return false; 107 } 108 }; 109 fCCPGroup = new CCPActionGroup(viewPart); 110 fRefactorGroup = new RefactorActionGroup(viewPart); 111 fGenerateGroup = new GenerateActionGroup(viewPart); 112 fSearchGroup = new JavaSearchActionGroup(viewPart); 113 fBuildPathGroup = new GenerateBuildPathActionGroup(viewPart); 114 115 fInViewPart = true; 116 } 117 118 } 119 120 } 121 122 public void setContext(ActionContext context) { 123 super.setContext(context); 124 if (fInViewPart) { 125 fOpenViewGroup.setContext(context); 126 fCCPGroup.setContext(context); 127 fRefactorGroup.setContext(context); 128 fGenerateGroup.setContext(context); 129 fSearchGroup.setContext(context); 130 fBuildPathGroup.setContext(context); 131 } 132 } 133 134 public void restoreState(IMemento memento) { 135 super.restoreState(memento); 136 restoreLayoutState(memento); 137 } 138 139 private void restoreLayoutState(IMemento memento) { 140 boolean isCurrentLayoutFlat = true; 141 Integer state = null; 142 if (memento != null) 143 state = memento.getInteger(TAG_LAYOUT); 144 145 if (state == null) { 147 IPreferenceStore store = JavaPlugin.getDefault().getPreferenceStore(); 148 state = new Integer (store.getInt(TAG_LAYOUT)); 149 } 150 151 if (state.intValue() == FLAT_LAYOUT) 152 isCurrentLayoutFlat = true; 153 else if (state.intValue() == HIERARCHICAL_LAYOUT) 154 isCurrentLayoutFlat = false; 155 156 fStateModel.setBooleanProperty(Values.IS_LAYOUT_FLAT, isCurrentLayoutFlat); 157 fLayoutActionGroup.setFlatLayout(isCurrentLayoutFlat); 158 } 159 160 public void saveState(IMemento aMemento) { 161 super.saveState(aMemento); 162 IPreferenceStore store = JavaPlugin.getDefault().getPreferenceStore(); 163 if (fStateModel.getBooleanProperty(Values.IS_LAYOUT_FLAT)) 164 store.setValue(TAG_LAYOUT, FLAT_LAYOUT); 165 else 166 store.setValue(TAG_LAYOUT, HIERARCHICAL_LAYOUT); 167 168 } 169 170 } 171 | Popular Tags |