- * <extension - * point="org.eclipse.ui.menus"> - * <menuContribution locationURI="toolbar:org.eclipse.debug.ui.VariableView?after=additions"> - * <command - * commandId="org.eclipse.debug.ui.pinViewToContextDropDown" - * icon="icons/full/elcl16/pin.gif" - * label="%PinViewToContextCommand.label" - * style="pulldown" - * tooltip="%PinViewToContextCommand.label"> - * </command> - * </menuContribution> - * <menuContribution - * locationURI="menu:org.eclipse.debug.ui.pinViewToContextDropDown"> - * <dynamic - * class="org.eclipse.debug.ui.contexts.PinViewToContextContribution" - * id="org.eclipse.debug.ui.pinToContextFactories"> - * </dynamic> - * </menuContribution> - * </extension> - * - * <extension point="org.eclipse.ui.commands"> - * <command - * id="org.eclipse.debug.ui.pinViewToContextDropDown" - * defaultHandler="org.eclipse.debug.ui.contexts.PinViewToContextDropDownHandler" - * name="%PinViewToContextCommand.label" - * description="%PinViewToContextCommand.description"/> - * </extension> - *- * - * @since 3.9 - * @noextend This class is not intended to be sub-classed by clients. - */ -public class PinViewToContextDynamicContribution extends CompoundContributionItem implements IWorkbenchContribution { - - private IServiceLocator fServiceLocator; - - private static IContributionItem[] NO_PIN_PROVIDERS_CONTRIBUTION_ITEMS = new IContributionItem[] { - new ContributionItem() { - public void fill(Menu menu, int index) { - MenuItem item = new MenuItem(menu, SWT.NONE); - item.setEnabled(false); - item.setText("No pinned context providers available"); //$NON-NLS-1$ - } - - public boolean isEnabled() { - return false; - } - } - }; - - /* (non-Javadoc) - * @see org.eclipse.ui.actions.CompoundContributionItem#getContributionItems() - */ - protected IContributionItem[] getContributionItems() { - IWorkbenchPart part = null; - IPartService partService = (IPartService)fServiceLocator.getService(IPartService.class); - if (partService != null) { - part = partService.getActivePart(); - } - - // If no part or selection, disable all. - if (!(part instanceof IPinnablePart)) { - return NO_PIN_PROVIDERS_CONTRIBUTION_ITEMS; - } - IPinnablePart pinnable = (IPinnablePart)part; - - // Get breakpoint toggle target IDs. - IDebugContextManager manager = DebugUITools.getDebugContextManager(); - IPinnedContextFactory[] factories = manager.getEnabledContextViewerFactories(pinnable, StructuredSelection.EMPTY); - - IContributionItem[] items = new IContributionItem[factories.length + 1]; - items[0] = makeActionContributionItem(new ClearPinnedContextAction(pinnable), 1); - for (int i = 0; i < factories.length; i++) { - Action action = new PinToContextAction(pinnable, factories[i]); - items[i + 1] = makeActionContributionItem(action, i + 2); - } - - return items; - } - - private IContributionItem makeActionContributionItem(Action action, int accelerator) { - if (accelerator < 10) { - StringBuffer label= new StringBuffer(); - //add the numerical accelerator - label.append('&'); - label.append(accelerator); - label.append(' '); - label.append(action.getText()); - action.setText(label.toString()); - } - return new ActionContributionItem(action); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.menus.IWorkbenchContribution#initialize(org.eclipse.ui.services.IServiceLocator) - */ - public void initialize(IServiceLocator serviceLocator) { - fServiceLocator = serviceLocator; - } -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/contexts/PinViewToContextHandler.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/contexts/PinViewToContextHandler.java deleted file mode 100644 index ebd95c8f4..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/contexts/PinViewToContextHandler.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 Wind River Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Wind River Systems - initial API and implementation - *******************************************************************************/ - -package org.eclipse.debug.ui.contexts; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.debug.ui.DebugUITools; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.handlers.HandlerUtil; - -/** - * Command handler that pins a view to a debug context. - *
- * The handler selects the pin-able context factory based on the active - * debug context provider and on the available factories. If a view is - * already pinned to a context, this handler will un-pin the view. - *
- *- * This handler can be used in conjunction with a dynamic contribution for - * a drop-down pin menu. See {@link PinViewToContextDynamicContribution} for - * details. - *
- * @noextend This class is not intended to be subclassed by clients. - * @since 3.9 - */ -public class PinViewToContextHandler extends AbstractHandler { - - public Object execute(ExecutionEvent event) throws ExecutionException { - IWorkbenchPart part = HandlerUtil.getActivePartChecked(event); - if (part instanceof IPinnablePart) { - IPinnablePart pinnable = (IPinnablePart)part; - if (!pinnable.isPinned()) { - pinnable.pin(getFactory(event)); - } else { - pinnable.clearPin(); - } - } - return null; - } - - private IPinnableDebugContextProvider getContextProvider(ExecutionEvent event) { - IDebugContextProvider provider = getContextService(event).getActiveProvider(); - if (provider instanceof IPinnableDebugContextProvider) { - return (IPinnableDebugContextProvider)provider; - } - return null; - } - - private IDebugContextService getContextService(ExecutionEvent event) { - IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); - if (window != null) { - return DebugUITools.getDebugContextManager().getContextService(window); - } - return null; - } - - private IPinnedContextFactory getFactory(ExecutionEvent event) { - IPinnableDebugContextProvider provider = getContextProvider(event); - if (provider != null) { - return DebugUITools.getDebugContextManager().getPinnedContextViewerFactory( provider.getFactoryId() ); - } - return null; - } -} \ No newline at end of file -- cgit v1.2.3