diff options
author | Sopot Cela | 2014-04-08 16:23:31 +0000 |
---|---|---|
committer | Lars Vogel | 2014-04-23 10:16:01 +0000 |
commit | 032f14076a4bc91d903adcd8008f8056eb1155a8 (patch) | |
tree | 29e77f86578ec73e543da6f55cfee6147434cfc4 | |
parent | c39657e9283a347923dd161606620410ebbb6b5e (diff) | |
download | eclipse.platform.ui-032f14076a4bc91d903adcd8008f8056eb1155a8.tar.gz eclipse.platform.ui-032f14076a4bc91d903adcd8008f8056eb1155a8.tar.xz eclipse.platform.ui-032f14076a4bc91d903adcd8008f8056eb1155a8.zip |
Bug 431868 - [Trim] Allow to hide ToolControl via right click menu
Migrated to IPresentationEngine.HIDDEN_EXPLICIT and aligns the reset of
the trimbar entries.
Change-Id: I327dcfb8702aa2395f63a40f0b022fe23f08bd04
Signed-off-by: Sopot Cela <sopotcela@gmail.com>
Signed-off-by: Lars Vogel <Lars.Vogel@gmail.com>
4 files changed, 127 insertions, 14 deletions
diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ToolBarManagerRenderer.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ToolBarManagerRenderer.java index 77ef82b0123..86a42496ba9 100644 --- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ToolBarManagerRenderer.java +++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ToolBarManagerRenderer.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Maxime Porhel <maxime.porhel@obeo.fr> Obeo - Bug 410426 - * Lars Vogel <Lars.Vogel@gmail.com> - Bug 426535, 433234 + * Lars Vogel <Lars.Vogel@gmail.com> - Bug 426535, 433234, 431868 * Maxime Porhel <maxime.porhel@obeo.fr> Obeo - Bug 431778 *******************************************************************************/ package org.eclipse.e4.ui.workbench.renderers.swt; @@ -41,6 +41,7 @@ import org.eclipse.e4.ui.model.application.ui.MElementContainer; import org.eclipse.e4.ui.model.application.ui.MUIElement; import org.eclipse.e4.ui.model.application.ui.SideValue; import org.eclipse.e4.ui.model.application.ui.basic.MTrimBar; +import org.eclipse.e4.ui.model.application.ui.basic.MTrimElement; import org.eclipse.e4.ui.model.application.ui.basic.MWindow; import org.eclipse.e4.ui.model.application.ui.menu.MDirectToolItem; import org.eclipse.e4.ui.model.application.ui.menu.MHandledToolItem; @@ -1053,16 +1054,18 @@ public class ToolBarManagerRenderer extends SWTPartRenderer { } /** - * Removes the IPresentationEngine.HIDDEN_EXPLICITLY from the toolbar entres + * Removes the IPresentationEngine.HIDDEN_EXPLICITLY from the trimbar + * entries. Having a separate logic for toolbars and toolcontrols would be + * confusing for the user, hence we remove this tag for both these types * * @param toolbarModel */ private void removeHiddenTags(MToolBar toolbarModel) { MWindow mWindow = modelService.getTopLevelWindowFor(toolbarModel); - List<MToolBar> toolBars = modelService.findElements(mWindow, null, - MToolBar.class, null); - for (MToolBar mToolBar : toolBars) { - mToolBar.getTags().remove(IPresentationEngine.HIDDEN_EXPLICITLY); + List<MTrimElement> trimElements = modelService.findElements(mWindow, + null, MTrimElement.class, null); + for (MTrimElement trimElement : trimElements) { + trimElement.getTags().remove(IPresentationEngine.HIDDEN_EXPLICITLY); } } diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ToolControlRenderer.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ToolControlRenderer.java index 279c5119a95..76af05c72e8 100644 --- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ToolControlRenderer.java +++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ToolControlRenderer.java @@ -1,38 +1,61 @@ /******************************************************************************* - * Copyright (c) 2010, 2012 IBM Corporation and others. + * Copyright (c) 2010, 2014 IBM Corporation 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: * IBM Corporation - initial API and implementation + * Sopot Cela <sopotcela@gmail.com> - Bug 431868 + * Lars Vogel <Lars.Vogel@gmail.com> - Bug 431868 *******************************************************************************/ package org.eclipse.e4.ui.workbench.renderers.swt; +import java.util.List; +import javax.inject.Inject; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; import org.eclipse.e4.core.services.contributions.IContributionFactory; +import org.eclipse.e4.ui.di.UIEventTopic; import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer; import org.eclipse.e4.ui.internal.workbench.swt.CSSRenderingUtils; +import org.eclipse.e4.ui.model.application.MApplication; import org.eclipse.e4.ui.model.application.ui.MUIElement; import org.eclipse.e4.ui.model.application.ui.SideValue; import org.eclipse.e4.ui.model.application.ui.basic.MTrimBar; +import org.eclipse.e4.ui.model.application.ui.basic.MTrimElement; +import org.eclipse.e4.ui.model.application.ui.basic.MWindow; import org.eclipse.e4.ui.model.application.ui.menu.MToolBar; import org.eclipse.e4.ui.model.application.ui.menu.MToolControl; +import org.eclipse.e4.ui.workbench.IPresentationEngine; +import org.eclipse.e4.ui.workbench.UIEvents; +import org.eclipse.e4.ui.workbench.UIEvents.EventTags; import org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.ToolBar; import org.eclipse.swt.widgets.ToolItem; import org.eclipse.swt.widgets.Widget; +import org.osgi.service.event.Event; /** * Create a contribute part. */ public class ToolControlRenderer extends SWTPartRenderer { + @Inject + private MApplication application; + /** + * The context menu for this trim stack's items. + */ + private Menu toolControlMenu; + @Override public Object createWidget(final MUIElement element, Object parent) { if (!(element instanceof MToolControl) @@ -104,7 +127,92 @@ public class ToolControlRenderer extends SWTPartRenderer { } CSSRenderingUtils cssUtils = parentContext.get(CSSRenderingUtils.class); newCtrl = cssUtils.frameMeIfPossible(newCtrl, null, vertical, true); + createToolControlMenu(toolControl, newCtrl); return newCtrl; } + @Inject + @Optional + private void subscribeTopicTagsChanged( + @UIEventTopic(UIEvents.ApplicationElement.TOPIC_TAGS) Event event) { + + Object changedObj = event.getProperty(EventTags.ELEMENT); + + if (!(changedObj instanceof MToolControl)) + return; + + final MUIElement changedElement = (MUIElement) changedObj; + + if (UIEvents.isADD(event)) { + if (UIEvents.contains(event, UIEvents.EventTags.NEW_VALUE, + IPresentationEngine.HIDDEN_EXPLICITLY)) { + changedElement.setVisible(false); + changedElement.setToBeRendered(false); + } + } else if (UIEvents.isREMOVE(event)) { + if (UIEvents.contains(event, UIEvents.EventTags.OLD_VALUE, + IPresentationEngine.HIDDEN_EXPLICITLY)) { + changedElement.setVisible(true); + changedElement.setToBeRendered(true); + } + } + } + + @Inject + @Optional + private void subscribeTopicAppStartup( + @UIEventTopic(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE) Event event) { + List<MToolControl> toolControls = modelService.findElements( + application, null, MToolControl.class, null); + for (MToolControl toolControl : toolControls) { + if (toolControl.getTags().contains( + IPresentationEngine.HIDDEN_EXPLICITLY)) { + toolControl.setVisible(false); + toolControl.setToBeRendered(false); + } + } + } + + private void createToolControlMenu(final MToolControl toolControl, + Control renderedCtrl) { + toolControlMenu = new Menu(renderedCtrl); + MenuItem hideItem = new MenuItem(toolControlMenu, SWT.NONE); + hideItem.setText(Messages.ToolBarManagerRenderer_MenuCloseText); + hideItem.addListener(SWT.Selection, new Listener() { + public void handleEvent(org.eclipse.swt.widgets.Event event) { + toolControl.getTags() + .add(IPresentationEngine.HIDDEN_EXPLICITLY); + } + }); + + new MenuItem(toolControlMenu, SWT.SEPARATOR); + + MenuItem restoreHiddenItems = new MenuItem(toolControlMenu, SWT.NONE); + restoreHiddenItems + .setText(Messages.ToolBarManagerRenderer_MenuRestoreText); + restoreHiddenItems.addListener(SWT.Selection, new Listener() { + public void handleEvent(org.eclipse.swt.widgets.Event event) { + removeHiddenTags(toolControl); + } + }); + renderedCtrl.setMenu(toolControlMenu); + + } + + /** + * Removes the IPresentationEngine.HIDDEN_EXPLICITLY from the trimbar + * entries. Having a separate logic for toolbars and toolcontrols would be + * confusing for the user, hence we remove this tag for both these types + * + * @param toolbarModel + */ + private void removeHiddenTags(MToolControl toolControl) { + MWindow mWindow = modelService.getTopLevelWindowFor(toolControl); + List<MTrimElement> trimElements = modelService.findElements(mWindow, + null, MTrimElement.class, null); + for (MTrimElement trimElement : trimElements) { + trimElement.getTags().remove(IPresentationEngine.HIDDEN_EXPLICITLY); + } + } + } diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/messages.properties b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/messages.properties index ecca451a4bd..23ccf7a9e96 100644 --- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/messages.properties +++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/messages.properties @@ -10,4 +10,4 @@ ################################################################################ ToolBarManagerRenderer_MenuCloseText = &Hide -ToolBarManagerRenderer_MenuRestoreText = &Restore Hidden Toolbars +ToolBarManagerRenderer_MenuRestoreText = &Restore Hidden Trimbar Entries diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java index 656c7f66c17..c3c982f8932 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java @@ -10,6 +10,7 @@ * Christian Janz - <christian.janz@gmail.com> Fix for Bug 385592 * Marc-Andre Laperle (Ericsson) - Fix for Bug 413590 * Lars Vogel <Lars.Vogel@gmail.com> - Bug 431340, 431348, 426535, 433234 + * Lars Vogel <Lars.Vogel@gmail.com> - Bug 431868 *******************************************************************************/ package org.eclipse.ui.internal; @@ -62,9 +63,9 @@ import org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainer; import org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainerElement; import org.eclipse.e4.ui.model.application.ui.basic.MPartStack; import org.eclipse.e4.ui.model.application.ui.basic.MStackElement; +import org.eclipse.e4.ui.model.application.ui.basic.MTrimElement; import org.eclipse.e4.ui.model.application.ui.basic.MWindow; import org.eclipse.e4.ui.model.application.ui.basic.MWindowElement; -import org.eclipse.e4.ui.model.application.ui.menu.MToolBar; import org.eclipse.e4.ui.workbench.IPresentationEngine; import org.eclipse.e4.ui.workbench.UIEvents; import org.eclipse.e4.ui.workbench.modeling.EModelService; @@ -3375,10 +3376,11 @@ public class WorkbenchPage extends CompatibleWorkbenchPage implements tags.clear(); tags.addAll(dummyPerspective.getTags()); - // remove HIDDEN_EXPLICITLY tag from toolbar - List<MToolBar> toolBars = modelService.findElements(window, null, MToolBar.class, null); - for (MToolBar mToolBar : toolBars) { - mToolBar.getTags().remove(IPresentationEngine.HIDDEN_EXPLICITLY); + // remove HIDDEN_EXPLICITLY tag from trim elements + List<MTrimElement> trimElements = modelService.findElements(window, null, + MTrimElement.class, null); + for (MTrimElement mTrimElement : trimElements) { + mTrimElement.getTags().remove(IPresentationEngine.HIDDEN_EXPLICITLY); } partService.requestActivation(); |