summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorWojciech Sudol2013-12-05 08:39:30 (EST)
committer Gerrit Code Review @ Eclipse.org2013-12-09 08:22:53 (EST)
commit642ec7b601902987e45846fb32929c9a44463993 (patch)
treee6b606210fa62b6d5a623ac742aa1503bb36dc5a
parent9d35505dbe80ad631a62f89ff02e2f4af663976e (diff)
downloadeclipse.platform.ui-642ec7b601902987e45846fb32929c9a44463993.zip
eclipse.platform.ui-642ec7b601902987e45846fb32929c9a44463993.tar.gz
eclipse.platform.ui-642ec7b601902987e45846fb32929c9a44463993.tar.bz2
Bug 412479 - ToolBarManagerRenderer doesn't care orientation changing ofrefs/changes/73/19373/11
MToolBar because of it's cache. Change-Id: If0db2864c6cc2151c555b8e214d9c3b767e93241 Signed-off-by: Wojciech Sudol <wojciech.sudol@pl.ibm.com>
-rw-r--r--bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ToolBarManagerRenderer.java11
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/action/ToolBarManager.java24
-rw-r--r--tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/action/AllTests.java3
-rw-r--r--tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/action/ToolBarManagerTest.java85
4 files changed, 116 insertions, 7 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 9c7d012..68e7298 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
@@ -362,11 +362,11 @@ public class ToolBarManagerRenderer extends SWTPartRenderer {
private ToolBar createToolbar(final MUIElement element, Composite parent) {
int orientation = getOrientation(element);
+ int style = orientation | SWT.WRAP | SWT.FLAT | SWT.RIGHT;
ToolBarManager manager = getManager((MToolBar) element);
if (manager == null) {
- manager = new ToolBarManager(orientation | SWT.WRAP | SWT.FLAT
- | SWT.RIGHT);
+ manager = new ToolBarManager(style);
IContributionManagerOverrides overrides = null;
MApplicationElement parentElement = element.getParent();
if (parentElement == null) {
@@ -382,6 +382,13 @@ public class ToolBarManagerRenderer extends SWTPartRenderer {
manager.setOverrides(overrides);
linkModelToManager((MToolBar) element, manager);
+ } else {
+ ToolBar toolBar = manager.getControl();
+ if (toolBar != null && !toolBar.isDisposed()
+ && (toolBar.getStyle() & orientation) == 0) {
+ toolBar.dispose();
+ }
+ manager.setStyle(style);
}
ToolBar bar = manager.createControl(parent);
bar.setData(manager);
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/action/ToolBarManager.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/action/ToolBarManager.java
index f8931f3..1f409f2 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/action/ToolBarManager.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/action/ToolBarManager.java
@@ -93,13 +93,29 @@ public class ToolBarManager extends ContributionManager implements
public ToolBarManager(ToolBar toolbar) {
this();
this.toolBar = toolbar;
+ if (toolBarExist()) {
+ this.itemStyle = toolBar.getStyle();
+ }
}
/**
- * Creates and returns this manager's tool bar control. Does not create a
- * new control if one already exists. Also create an {@link AccessibleListener}
- * for the {@link ToolBar}.
- *
+ * Sets SWT button style for new tool bar controls created
+ * in the {@code createControl(Composite)} method. It does not
+ * affect already existing tool bar control.
+ *
+ * @param style
+ * the tool bar item style
+ * @since 3.10
+ */
+ public void setStyle(int style) {
+ itemStyle = style;
+ }
+
+ /**
+ * Creates and returns this manager's tool bar control. Does not create
+ * a new control if one already exists and is not disposed.
+ * Also create an {@link AccessibleListener} for the {@link ToolBar}.
+ *
* @param parent
* the parent control
* @return the tool bar control
diff --git a/tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/action/AllTests.java b/tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/action/AllTests.java
index 213e6d9..e5535ef 100644
--- a/tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/action/AllTests.java
+++ b/tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/action/AllTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 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
@@ -25,6 +25,7 @@ public class AllTests extends TestSuite {
public AllTests() {
addTestSuite(ContributionItemTest.class);
+ addTestSuite(ToolBarManagerTest.class);
addTestSuite(CoolBarManagerTest.class);
addTestSuite(MenuManagerTest.class);
}
diff --git a/tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/action/ToolBarManagerTest.java b/tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/action/ToolBarManagerTest.java
new file mode 100644
index 0000000..b5f1b2c
--- /dev/null
+++ b/tests/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/action/ToolBarManagerTest.java
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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
+ ******************************************************************************/
+
+package org.eclipse.jface.tests.action;
+
+import org.eclipse.jface.action.ToolBarManager;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.ToolBar;
+
+public class ToolBarManagerTest extends JFaceActionTest {
+
+ private final static int DEFAULT_STYLE = SWT.WRAP | SWT.FLAT | SWT.RIGHT;
+
+ public ToolBarManagerTest(String name) {
+ super(name);
+ }
+
+ public void testSetStyleWhenToolBarDoesNotExist() {
+ Composite parent = createComposite();
+ ToolBarManager manager = new ToolBarManager(DEFAULT_STYLE | SWT.HORIZONTAL);
+
+ manager.setStyle( DEFAULT_STYLE | SWT.VERTICAL);
+ ToolBar toolBar = manager.createControl(parent);
+ assertFalse(toolBar.isDisposed());
+ verifyOrientation(toolBar, SWT.VERTICAL);
+ }
+
+ public void testSetStyleWhenToolBarExists() {
+ Composite parent = createComposite();
+ ToolBar toolBar = new ToolBar(parent, DEFAULT_STYLE | SWT.VERTICAL);
+ ToolBarManager manager = new ToolBarManager(toolBar);
+
+ manager.setStyle(DEFAULT_STYLE | SWT.HORIZONTAL);
+ assertSame(toolBar, manager.createControl(parent));
+ assertFalse(toolBar.isDisposed());
+
+ toolBar.dispose();
+ ToolBar newToolBar = manager.createControl(parent);
+ assertNotSame(toolBar, newToolBar);
+ assertFalse(newToolBar.isDisposed());
+ verifyOrientation(newToolBar, SWT.HORIZONTAL);
+ }
+
+ public void testCreateControlWhenParentNull() {
+ Composite parent = createComposite();
+ ToolBarManager manager = new ToolBarManager(DEFAULT_STYLE | SWT.VERTICAL);
+
+ assertNull(manager.createControl(null));
+
+ ToolBar toolBar = manager.createControl(parent);
+ assertNotNull(toolBar);
+ assertSame(toolBar, manager.createControl(null));
+ }
+
+ public void testDispose() {
+ Composite parent = createComposite();
+ ToolBar toolBar = new ToolBar(parent, DEFAULT_STYLE | SWT.VERTICAL);
+ ToolBarManager manager = new ToolBarManager(toolBar);
+
+ manager.dispose();
+ assertTrue(toolBar.isDisposed());
+ }
+
+
+ private Composite createComposite() {
+ return new Composite(getShell(), SWT.DEFAULT);
+ }
+
+ private void verifyOrientation(ToolBar toolBar, int expected) {
+ assertTrue((toolBar.getStyle() & expected) != 0);
+
+ int opposite = (expected & SWT.HORIZONTAL) != 0 ? SWT.VERTICAL : SWT.HORIZONTAL;
+ assertFalse((toolBar.getStyle() & opposite) != 0);
+ }
+
+}