1 11 12 package org.eclipse.ui.internal.handlers; 13 14 import java.util.HashMap ; 15 import java.util.Map ; 16 17 import org.eclipse.core.commands.AbstractHandler; 18 import org.eclipse.core.commands.ExecutionEvent; 19 import org.eclipse.core.commands.ExecutionException; 20 import org.eclipse.ui.IWorkbenchWindow; 21 import org.eclipse.ui.commands.ICommandService; 22 import org.eclipse.ui.commands.IElementUpdater; 23 import org.eclipse.ui.handlers.HandlerUtil; 24 import org.eclipse.ui.internal.WorkbenchMessages; 25 import org.eclipse.ui.internal.WorkbenchWindow; 26 import org.eclipse.ui.menus.UIElement; 27 import org.eclipse.ui.services.IServiceScopes; 28 29 34 public class ToggleCoolbarHandler extends AbstractHandler implements 35 IElementUpdater { 36 37 42 public Object execute(ExecutionEvent event) throws ExecutionException { 43 final IWorkbenchWindow activeWorkbenchWindow = HandlerUtil 44 .getActiveWorkbenchWindowChecked(event); 45 if (activeWorkbenchWindow instanceof WorkbenchWindow) { 46 WorkbenchWindow window = (WorkbenchWindow) activeWorkbenchWindow; 47 window.toggleToolbarVisibility(); 48 ICommandService commandService = (ICommandService) activeWorkbenchWindow 49 .getService(ICommandService.class); 50 Map filter = new HashMap (); 51 filter.put(IServiceScopes.WINDOW_SCOPE, window); 52 commandService.refreshElements(event.getCommand().getId(), filter); 53 } 54 55 return null; 56 } 57 58 64 public void updateElement(UIElement element, Map parameters) { 65 IWorkbenchWindow window = (IWorkbenchWindow) element 66 .getServiceLocator().getService(IWorkbenchWindow.class); 67 if (window == null || !(window instanceof WorkbenchWindow)) 68 return; 69 element 70 .setText(isCoolbarVisible((WorkbenchWindow) window) ? WorkbenchMessages.ToggleCoolbarVisibilityAction_hide_text 71 : WorkbenchMessages.ToggleCoolbarVisibilityAction_show_text); 72 } 73 74 81 private boolean isCoolbarVisible(WorkbenchWindow window) { 82 return window.getCoolBarVisible() || window.getPerspectiveBarVisible(); 83 } 84 } 85 | Popular Tags |