1 11 package org.eclipse.ui.application; 12 13 import java.util.HashMap ; 14 import java.util.Iterator ; 15 import java.util.Map ; 16 17 import org.eclipse.core.runtime.Assert; 18 import org.eclipse.core.runtime.IStatus; 19 import org.eclipse.core.runtime.Status; 20 import org.eclipse.jface.action.IAction; 21 import org.eclipse.jface.action.ICoolBarManager; 22 import org.eclipse.jface.action.IMenuManager; 23 import org.eclipse.jface.action.IStatusLineManager; 24 import org.eclipse.ui.IMemento; 25 import org.eclipse.ui.IWorkbenchWindow; 26 import org.eclipse.ui.PlatformUI; 27 import org.eclipse.ui.actions.ActionFactory; 28 29 50 public class ActionBarAdvisor { 51 52 57 public static final int FILL_PROXY = 0x01; 58 59 64 public static final int FILL_MENU_BAR = 0x02; 65 66 71 public static final int FILL_COOL_BAR = 0x04; 72 73 78 public static final int FILL_STATUS_LINE = 0x08; 79 80 81 private IActionBarConfigurer actionBarConfigurer; 82 83 private Map actions = new HashMap (); 84 85 91 public ActionBarAdvisor(IActionBarConfigurer configurer) { 92 Assert.isNotNull(configurer); 93 actionBarConfigurer = configurer; 94 } 95 96 101 protected IActionBarConfigurer getActionBarConfigurer() { 102 return actionBarConfigurer; 103 } 104 105 145 public void fillActionBars(int flags) { 146 if ((flags & FILL_PROXY) == 0) { 147 makeActions(actionBarConfigurer.getWindowConfigurer().getWindow()); 148 } 149 if ((flags & FILL_MENU_BAR) != 0) { 150 fillMenuBar(actionBarConfigurer.getMenuManager()); 151 } 152 if ((flags & FILL_COOL_BAR) != 0) { 153 fillCoolBar(actionBarConfigurer.getCoolBarManager()); 154 } 155 if ((flags & FILL_STATUS_LINE) != 0) { 156 fillStatusLine(actionBarConfigurer.getStatusLineManager()); 157 } 158 } 159 160 167 protected void makeActions(IWorkbenchWindow window) { 168 } 170 171 187 protected void register(IAction action) { 188 String id = action.getId(); 189 Assert.isNotNull(id, "Action must not have null id"); getActionBarConfigurer().registerGlobalAction(action); 191 actions.put(id, action); 192 } 193 194 201 protected IAction getAction(String id) { 202 return (IAction) actions.get(id); 203 } 204 205 214 protected void fillMenuBar(IMenuManager menuBar) { 215 } 217 218 227 protected void fillCoolBar(ICoolBarManager coolBar) { 228 } 230 231 241 protected void fillStatusLine(IStatusLineManager statusLine) { 242 } 244 245 258 public boolean isApplicationMenu(String menuId) { 259 return false; 261 } 262 263 272 public void dispose() { 273 disposeActions(); 274 } 275 276 280 protected void disposeActions() { 281 for (Iterator i = actions.values().iterator(); i.hasNext();) { 282 IAction action = (IAction) i.next(); 283 disposeAction(action); 284 } 285 actions.clear(); 286 } 287 288 299 protected void disposeAction(IAction action) { 300 if (action instanceof ActionFactory.IWorkbenchAction) { 301 ((ActionFactory.IWorkbenchAction) action).dispose(); 302 } 303 } 304 305 317 public IStatus saveState(IMemento memento) { 318 return Status.OK_STATUS; 319 } 320 321 333 public IStatus restoreState(IMemento memento) { 334 return Status.OK_STATUS; 335 } 336 337 } 338 | Popular Tags |