Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Vogel2014-04-03 18:35:28 +0000
committerLars Vogel2014-04-05 09:54:47 +0000
commit5c65f3c751218e1b18b2481dc133cf9f41d1d765 (patch)
tree7989dc0cb005dc070451d27655155131452868cf
parente0c09f30121476543962345ea93f3812de09f6b3 (diff)
downloadeclipse.platform.ui-5c65f3c751218e1b18b2481dc133cf9f41d1d765.tar.gz
eclipse.platform.ui-5c65f3c751218e1b18b2481dc133cf9f41d1d765.tar.xz
eclipse.platform.ui-5c65f3c751218e1b18b2481dc133cf9f41d1d765.zip
Bug 426535 - [Trim] Allow to close toolbars via right click menu ->
Close Change-Id: Icd01bd93fe282519b71ee8425451119e19a33cd5 Signed-off-by: Lars Vogel <Lars.Vogel@gmail.com>
-rw-r--r--bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/Messages.java30
-rw-r--r--bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ToolBarManagerRenderer.java98
-rw-r--r--bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/messages.properties13
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java12
4 files changed, 149 insertions, 4 deletions
diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/Messages.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/Messages.java
new file mode 100644
index 00000000000..8d817566f1e
--- /dev/null
+++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/Messages.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2014 vogella GmbH 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:
+ * Lars Vogel <Lars.Vogel@gmail.com> - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.e4.ui.workbench.renderers.swt;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ */
+@SuppressWarnings("javadoc")
+public class Messages extends NLS {
+
+ public static String ToolBarManagerRenderer_MenuCloseText;
+ public static String ToolBarManagerRenderer_MenuRestoreText;
+
+ private static final String BUNDLE_NAME = "org.eclipse.e4.ui.workbench.renderers.swt.messages";//$NON-NLS-1$
+
+ static {
+ // load message values from bundle file
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+}
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 53d9af8ef68..45177a8a260 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
@@ -4,10 +4,11 @@
* 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
* Maxime Porhel <maxime.porhel@obeo.fr> Obeo - Bug 410426
+ * Lars Vogel <Lars.Vogel@gmail.com> - Bug 426535
*******************************************************************************/
package org.eclipse.e4.ui.workbench.renderers.swt;
@@ -39,6 +40,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.MWindow;
import org.eclipse.e4.ui.model.application.ui.menu.MDirectToolItem;
import org.eclipse.e4.ui.model.application.ui.menu.MHandledToolItem;
import org.eclipse.e4.ui.model.application.ui.menu.MToolBar;
@@ -52,6 +54,8 @@ import org.eclipse.e4.ui.workbench.IPresentationEngine;
import org.eclipse.e4.ui.workbench.Selector;
import org.eclipse.e4.ui.workbench.UIEvents;
import org.eclipse.e4.ui.workbench.UIEvents.ElementContainer;
+import org.eclipse.e4.ui.workbench.UIEvents.EventTags;
+import org.eclipse.e4.ui.workbench.modeling.EModelService;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.action.AbstractGroupMarker;
import org.eclipse.jface.action.ContributionItem;
@@ -67,6 +71,9 @@ import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
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;
@@ -90,6 +97,15 @@ public class ToolBarManagerRenderer extends SWTPartRenderer {
public static final String POST_PROCESSING_DISPOSE = "ToolBarManagerRenderer.postProcess.dispose"; //$NON-NLS-1$
public static final String UPDATE_VARS = "ToolBarManagerRenderer.updateVars"; //$NON-NLS-1$
+ /**
+ * This is a persistedState 'key' which can be used by the renderer
+ * implementation to decide that a user interface element has been hidden by
+ * the user
+ *
+ */
+ // TODO migrate to IPresentationEngine after the Luna release
+ public static final String HIDDEN_BY_USER = "HIDDEN_BY_USER"; //$NON-NLS-1$
+
private Map<MToolBar, ToolBarManager> modelToManager = new HashMap<MToolBar, ToolBarManager>();
private Map<ToolBarManager, MToolBar> managerToModel = new HashMap<ToolBarManager, MToolBar>();
@@ -102,6 +118,11 @@ public class ToolBarManagerRenderer extends SWTPartRenderer {
private ToolItemUpdater enablementUpdater = new ToolItemUpdater();
+ /**
+ * The context menu for this trim stack's items.
+ */
+ private Menu toolbarMenu;
+
// @Inject
// private Logger logger;
@@ -109,6 +130,9 @@ public class ToolBarManagerRenderer extends SWTPartRenderer {
private MApplication application;
@Inject
+ EModelService modelService;
+
+ @Inject
IEventBroker eventBroker;
private EventHandler itemUpdater = new EventHandler() {
@Override
@@ -287,6 +311,33 @@ public class ToolBarManagerRenderer extends SWTPartRenderer {
getUpdater().updateContributionItems(s);
}
+ @Inject
+ @Optional
+ private void subscribeTopicTagsChanged(
+ @UIEventTopic(UIEvents.ApplicationElement.TOPIC_TAGS) Event event) {
+
+ Object changedObj = event.getProperty(EventTags.ELEMENT);
+
+ if (!(changedObj instanceof MToolBar))
+ return;
+
+ final MUIElement changedElement = (MUIElement) changedObj;
+
+ if (UIEvents.isADD(event)) {
+ if (UIEvents.contains(event, UIEvents.EventTags.NEW_VALUE,
+ HIDDEN_BY_USER)) {
+ changedElement.setVisible(false);
+ changedElement.setToBeRendered(false);
+ }
+ } else if (UIEvents.isREMOVE(event)) {
+ if (UIEvents.contains(event, UIEvents.EventTags.OLD_VALUE,
+ HIDDEN_BY_USER)) {
+ changedElement.setVisible(true);
+ changedElement.setToBeRendered(true);
+ }
+ }
+ }
+
@PostConstruct
public void init() {
eventBroker.subscribe(UIEvents.UILabel.TOPIC_ALL, itemUpdater);
@@ -360,9 +411,35 @@ public class ToolBarManagerRenderer extends SWTPartRenderer {
}
}
+ createToolbarMenu(toolbarModel, renderedCtrl);
+
return renderedCtrl;
}
+ private void createToolbarMenu(final MToolBar toolbarModel,
+ Control renderedCtrl) {
+ toolbarMenu = new Menu(renderedCtrl);
+ MenuItem hideItem = new MenuItem(toolbarMenu, SWT.NONE);
+ hideItem.setText(Messages.ToolBarManagerRenderer_MenuCloseText);
+ hideItem.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(org.eclipse.swt.widgets.Event event) {
+ toolbarModel.getTags().add(HIDDEN_BY_USER);
+ }
+ });
+
+ new MenuItem(toolbarMenu, SWT.SEPARATOR);
+
+ MenuItem restoreHiddenItems = new MenuItem(toolbarMenu, SWT.NONE);
+ restoreHiddenItems
+ .setText(Messages.ToolBarManagerRenderer_MenuRestoreText);
+ restoreHiddenItems.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(org.eclipse.swt.widgets.Event event) {
+ removeHiddenByUserTags(toolbarModel);
+ }
+ });
+ renderedCtrl.setMenu(toolbarMenu);
+ }
+
/**
* @param toolbarModel
* @param elementId
@@ -484,6 +561,7 @@ public class ToolBarManagerRenderer extends SWTPartRenderer {
@Override
public void widgetDisposed(DisposeEvent e) {
cleanUp((MToolBar) element);
+ toolbarMenu = null;
}
});
return bar;
@@ -770,8 +848,7 @@ public class ToolBarManagerRenderer extends SWTPartRenderer {
linkModelToContribution(itemModel, ci);
}
- void processOpaqueItem(ToolBarManager parentManager,
- MToolItem itemModel) {
+ void processOpaqueItem(ToolBarManager parentManager, MToolItem itemModel) {
IContributionItem ici = getContribution(itemModel);
if (ici != null) {
return;
@@ -946,4 +1023,19 @@ public class ToolBarManagerRenderer extends SWTPartRenderer {
ToolItemUpdater getUpdater() {
return enablementUpdater;
}
+
+ /**
+ * Removes the IPresentationEngine.HIDDEN_BY_USER from the toolbars
+ *
+ * @param toolbarModel
+ */
+ private void removeHiddenByUserTags(MToolBar toolbarModel) {
+ MWindow mWindow = modelService.getTopLevelWindowFor(toolbarModel);
+ List<MToolBar> toolBars = modelService.findElements(mWindow, null,
+ MToolBar.class, null);
+ for (MToolBar mToolBar : toolBars) {
+ mToolBar.getTags().remove(HIDDEN_BY_USER);
+ }
+ }
+
}
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
new file mode 100644
index 00000000000..ad626023482
--- /dev/null
+++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/messages.properties
@@ -0,0 +1,13 @@
+################################################################################
+# Copyright (c) 2014 vogella GmbH 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:
+# Lars Vogel <Lars.Vogel@gmail.com> - initial API and implementation
+################################################################################
+
+ToolBarManagerRenderer_MenuCloseText = &Hide
+ToolBarManagerRenderer_MenuRestoreText = &Restore hidden toolbars
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 6834fdaf031..c9ff9aa1b1d 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
@@ -9,7 +9,7 @@
* IBM Corporation - initial API and implementation
* 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
+ * Lars Vogel <Lars.Vogel@gmail.com> - Bug 431340, 431348, Bug 426535
*******************************************************************************/
package org.eclipse.ui.internal;
@@ -64,6 +64,7 @@ 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.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;
@@ -3357,6 +3358,15 @@ public class WorkbenchPage extends CompatibleWorkbenchPage implements
tags.clear();
tags.addAll(dummyPerspective.getTags());
+ // remove HIDDEN_BY_USER tags from toolbar
+ // need to reset all window / perspective relevant elements if
+ // HIDDEN_BY_USER
+ // get implemented by more renderer
+ List<MToolBar> toolBars = modelService.findElements(window, null, MToolBar.class, null);
+ for (MToolBar mToolBar : toolBars) {
+ mToolBar.getTags().remove("HIDDEN_BY_USER"); //$NON-NLS-1$
+ }
+
partService.requestActivation();
// reset complete

Back to the top