Bug 551587 ControlContribution does not set itself inside ToolItem data
Change-Id: Ib85aff73faccf83725d473fc74903b399f51263d
Signed-off-by: laeubi <laeubi@laeubi-soft.de>
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/action/ControlContribution.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/action/ControlContribution.java
index 8f20523..ebe2ade 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/action/ControlContribution.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/action/ControlContribution.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2015 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -10,6 +10,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Christoph Läubrich - Bug 551587
*******************************************************************************/
package org.eclipse.jface.action;
@@ -110,6 +111,7 @@
ToolItem ti = new ToolItem(parent, SWT.SEPARATOR, index);
ti.setControl(control);
ti.setWidth(computeWidth(control));
+ ti.setData(this);
}
}
}
diff --git a/tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/action/ToolBarManagerTest.java b/tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/action/ToolBarManagerTest.java
index e5f804c..6c32a20 100644
--- a/tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/action/ToolBarManagerTest.java
+++ b/tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/action/ToolBarManagerTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013 IBM Corporation and others.
+ * Copyright (c) 2013, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -10,14 +10,19 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Christoph Läubrich - add testcase for Bug #551587
******************************************************************************/
package org.eclipse.jface.tests.action;
+import org.eclipse.jface.action.ControlContribution;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ToolBar;
+import org.eclipse.swt.widgets.ToolItem;
public class ToolBarManagerTest extends JFaceActionTest {
@@ -73,6 +78,24 @@
assertTrue(toolBar.isDisposed());
}
+ public void testControlContributionIsSet() {
+ ToolBarManager manager = new ToolBarManager();
+ manager.add(new ControlContribution("test") {
+
+ @Override
+ protected Control createControl(Composite parent) {
+
+ return new Label(parent, SWT.NONE);
+ }
+ });
+ ToolBar toolBar = manager.createControl(createComposite());
+ for (ToolItem item : toolBar.getItems()) {
+ if (!(item.getData() instanceof ControlContribution)) {
+ fail("ToolItem data is not set to ControlContribution");
+ }
+ }
+ }
+
private Composite createComposite() {
return new Composite(getShell(), SWT.DEFAULT);
}