1 11 12 package org.eclipse.ui.internal.editors.text; 13 14 import com.ibm.icu.text.Collator; 15 import java.util.Iterator ; 16 import java.util.SortedSet ; 17 import java.util.TreeSet ; 18 19 import org.eclipse.swt.widgets.Control; 20 import org.eclipse.swt.widgets.Menu; 21 22 import org.eclipse.jface.action.Action; 23 import org.eclipse.jface.action.ActionContributionItem; 24 import org.eclipse.jface.action.IAction; 25 import org.eclipse.jface.action.IMenuCreator; 26 import org.eclipse.jface.preference.IPreferenceStore; 27 import org.eclipse.jface.viewers.ISelection; 28 29 import org.eclipse.ui.IWorkbenchWindow; 30 import org.eclipse.ui.IWorkbenchWindowPulldownDelegate2; 31 import org.eclipse.ui.texteditor.AnnotationPreference; 32 import org.eclipse.ui.texteditor.MarkerAnnotationPreferences; 33 34 39 public abstract class NextPreviousPulldownActionDelegate extends Action implements IMenuCreator, IWorkbenchWindowPulldownDelegate2 { 40 41 42 private Menu fMenu; 43 44 45 private IPreferenceStore fStore; 46 47 48 private static class NavigationEnablementAction extends Action implements Comparable { 49 50 51 private IPreferenceStore fStore; 52 53 54 private String fKey; 55 56 60 private String fName; 61 62 69 public NavigationEnablementAction(String name, IPreferenceStore store, String key) { 70 super(name, IAction.AS_CHECK_BOX); 71 fStore= store; 72 fKey= key; 73 fName= name; 74 setChecked(fStore.getBoolean(fKey)); 75 } 76 77 80 public void run() { 81 fStore.setValue(fKey, isChecked()); 82 } 83 84 88 public int compareTo(Object o) { 89 if (!(o instanceof NavigationEnablementAction)) 90 return -1; 91 92 String otherName= ((NavigationEnablementAction)o).fName; 93 94 return Collator.getInstance().compare(fName, otherName); 95 } 96 } 97 98 105 public abstract String getPreferenceKey(AnnotationPreference annotationPreference); 106 107 110 public Menu getMenu(Control parent) { 111 if (fMenu != null) 112 fMenu.dispose(); 113 114 fMenu= new Menu(parent); 115 fillMenu(fMenu); 116 117 return fMenu; 118 } 119 120 123 public NextPreviousPulldownActionDelegate() { 124 fStore= EditorsPlugin.getDefault().getPreferenceStore(); 125 } 126 127 130 public Menu getMenu(Menu parent) { 131 if (fMenu == null) { 132 fMenu= new Menu(parent); 133 fillMenu(fMenu); 134 } 135 136 return fMenu; 137 } 138 139 142 public void dispose() { 143 if (fMenu != null) { 144 fMenu.dispose(); 145 fMenu= null; 146 } 147 } 148 149 155 private void fillMenu(Menu menu) { 156 IAction[] actions= getActionsFromDescriptors(); 157 158 for (int i= 0; i < actions.length; i++) { 159 ActionContributionItem item= new ActionContributionItem(actions[i]); 160 item.fill(menu, -1); 161 } 162 } 163 164 170 private IAction[] getActionsFromDescriptors() { 171 MarkerAnnotationPreferences fMarkerAnnotationPreferences= EditorsPlugin.getDefault().getMarkerAnnotationPreferences(); 172 SortedSet containers= new TreeSet (); 173 174 Iterator iter= fMarkerAnnotationPreferences.getAnnotationPreferences().iterator(); 175 while (iter.hasNext()) { 176 AnnotationPreference preference= (AnnotationPreference)iter.next(); 177 String key= preference.getShowInNextPrevDropdownToolbarActionKey(); 178 if (key != null && fStore.getBoolean(key)) { 179 String preferenceKey= getPreferenceKey(preference); 180 181 187 preferenceKey= preference.getIsGoToNextNavigationTargetKey(); 188 189 if (preferenceKey != null) 190 containers.add(new NavigationEnablementAction(preference.getPreferenceLabel(), fStore, preferenceKey)); 191 } 192 } 193 194 return (IAction[]) containers.toArray(new Action[containers.size()]); 195 } 196 197 200 public void init(IWorkbenchWindow window) { 201 } 202 203 206 public void run(IAction action) { 207 } 208 209 212 public void selectionChanged(IAction action, ISelection selection) { 213 } 214 } 215 | Popular Tags |