1 11 package org.eclipse.jdt.internal.ui.navigator; 12 13 import java.util.Arrays ; 14 15 import org.eclipse.jface.preference.IPreferenceStore; 16 17 import org.eclipse.ui.IActionBars; 18 import org.eclipse.ui.IMemento; 19 import org.eclipse.ui.actions.ActionContext; 20 import org.eclipse.ui.navigator.CommonActionProvider; 21 import org.eclipse.ui.navigator.ICommonActionExtensionSite; 22 import org.eclipse.ui.navigator.IExtensionActivationListener; 23 import org.eclipse.ui.navigator.IExtensionStateModel; 24 import org.eclipse.ui.navigator.INavigatorActivationService; 25 26 import org.eclipse.jdt.internal.ui.JavaPlugin; 27 import org.eclipse.jdt.internal.ui.navigator.IExtensionStateConstants.Values; 28 29 37 public class JavaNavigatorViewActionProvider extends CommonActionProvider { 38 39 private static final int HIERARCHICAL_LAYOUT= 0x1; 40 41 private static final int FLAT_LAYOUT= 0x2; 42 43 private static final String TAG_LAYOUT= "org.eclipse.jdt.internal.ui.navigator.layout"; 45 private IExtensionStateModel fStateModel; 46 47 private CommonLayoutActionGroup fLayoutActionGroup; 48 49 private ICommonActionExtensionSite fExtensionSite; 50 51 private String fExtensionId; 52 53 private IActionBars fActionBars; 54 55 private boolean fEnabled= false; 56 57 private IExtensionActivationListener fMenuUpdater= new IExtensionActivationListener() { 58 59 public void onExtensionActivation(String viewerId, String [] theNavigatorExtensionIds, boolean isCurrentlyActive) { 60 61 if (fExtensionSite != null && fActionBars != null) { 62 63 int search= Arrays.binarySearch(theNavigatorExtensionIds, fExtensionId); 64 if (search > -1) { 65 if (isMyViewer(viewerId)) { 66 if (wasEnabled(isCurrentlyActive)) 67 fLayoutActionGroup.fillActionBars(fActionBars); 68 69 else 70 if (wasDisabled(isCurrentlyActive)) 71 fLayoutActionGroup.unfillActionBars(fActionBars); 72 } 74 fEnabled= isCurrentlyActive; 75 } 76 } 77 78 } 79 80 private boolean isMyViewer(String viewerId) { 81 String myViewerId= fExtensionSite.getViewSite().getId(); 82 return myViewerId != null && myViewerId.equals(viewerId); 83 } 84 85 private boolean wasDisabled(boolean isActive) { 86 return fEnabled && !isActive; 87 } 88 89 private boolean wasEnabled(boolean isActive) { 90 return !fEnabled && isActive; 91 } 92 }; 93 94 95 public void fillActionBars(IActionBars actionBars) { 96 fActionBars= actionBars; 97 fLayoutActionGroup.fillActionBars(actionBars); 98 } 99 100 public void init(ICommonActionExtensionSite site) { 101 102 fExtensionSite= site; 103 104 fStateModel= fExtensionSite.getExtensionStateModel(); 105 fLayoutActionGroup= new CommonLayoutActionGroup(fExtensionSite.getStructuredViewer(), fStateModel); 106 107 INavigatorActivationService activationService= fExtensionSite.getContentService().getActivationService(); 108 activationService.addExtensionActivationListener(fMenuUpdater); 109 110 fExtensionId= fExtensionSite.getExtensionId(); 111 112 fEnabled= true; 113 114 } 115 116 public void dispose() { 117 super.dispose(); 118 fExtensionSite.getContentService().getActivationService().removeExtensionActivationListener(fMenuUpdater); 119 } 120 121 public void setContext(ActionContext context) { 122 super.setContext(context); 123 } 124 125 public void restoreState(IMemento memento) { 126 boolean isCurrentLayoutFlat= true; 127 Integer state= null; 128 if (memento != null) 129 state= memento.getInteger(TAG_LAYOUT); 130 131 if (state == null) { 133 IPreferenceStore store= JavaPlugin.getDefault().getPreferenceStore(); 134 state= new Integer (store.getInt(TAG_LAYOUT)); 135 } 136 137 if (state.intValue() == FLAT_LAYOUT) 138 isCurrentLayoutFlat= true; 139 else 140 if (state.intValue() == HIERARCHICAL_LAYOUT) 141 isCurrentLayoutFlat= false; 142 143 fStateModel.setBooleanProperty(Values.IS_LAYOUT_FLAT, isCurrentLayoutFlat); 144 fLayoutActionGroup.setFlatLayout(isCurrentLayoutFlat); 145 } 146 147 public void saveState(IMemento aMemento) { 148 super.saveState(aMemento); 149 IPreferenceStore store= JavaPlugin.getDefault().getPreferenceStore(); 150 if (fStateModel.getBooleanProperty(Values.IS_LAYOUT_FLAT)) 151 store.setValue(TAG_LAYOUT, FLAT_LAYOUT); 152 else 153 store.setValue(TAG_LAYOUT, HIERARCHICAL_LAYOUT); 154 155 } 156 } 157 | Popular Tags |