diff options
author | Rolf Theunissen | 2020-07-20 20:28:14 +0000 |
---|---|---|
committer | Rolf Theunissen | 2020-07-30 19:27:58 +0000 |
commit | 06c08046e77b6ca385a518ae4fd8168756012c53 (patch) | |
tree | b362e36c3f101185b0c3cae1d127f75805370a17 | |
parent | e6e2d3ca1ce40d79e41d656872ddc9ae320ecd2a (diff) | |
download | eclipse.platform.ui-06c08046e77b6ca385a518ae4fd8168756012c53.tar.gz eclipse.platform.ui-06c08046e77b6ca385a518ae4fd8168756012c53.tar.xz eclipse.platform.ui-06c08046e77b6ca385a518ae4fd8168756012c53.zip |
Bug 564561 - Buttons from hidden view are added to the visible view inY20200801-1200I20200801-1800I20200801-0010I20200731-2040I20200731-1800I20200731-0520I20200730-1800
same stack
Initially mark all toolbars of MParts invisible, they will become
visible when a parts get selected.
Also mark the toolbar of a part that is added to a (rendered) stack
invisible.
Change-Id: Id66e570dc1086f83ff8b7b12654693704fdf76d0
Signed-off-by: Rolf Theunissen <rolf.theunissen@gmail.com>
2 files changed, 101 insertions, 5 deletions
diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/LazyStackRenderer.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/LazyStackRenderer.java index 843d9b567a4..8211e829d13 100644 --- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/LazyStackRenderer.java +++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/LazyStackRenderer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2016 IBM Corporation and others. + * Copyright (c) 2008, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,6 +13,7 @@ * Lars Vogel <Lars.Vogel@vogella.com> - Bug 441150, 472654 * Fabio Zadrozny (fabiofz@gmail.com) - Bug 436763 * Dirk Fauth <dirk.fauth@googlemail.com> - Bug 457939 + * Rolf Theunissen <rolf.theunissen@gmail.com> - Bug 564561 *******************************************************************************/ package org.eclipse.e4.ui.workbench.renderers.swt; @@ -118,6 +119,16 @@ public abstract class LazyStackRenderer extends SWTPartRenderer { } } + @Override + public void childRendered(MElementContainer<MUIElement> parentElement, MUIElement element) { + super.childRendered(parentElement, element); + + if (parentElement.getSelectedElement() != element) { + // Make sure that everything is hidden + hideElementRecursive(element); + } + } + @Inject @Optional private void subscribePartTopicToolbar(@UIEventTopic(UIEvents.Part.TOPIC_TOOLBAR) Event event) { @@ -154,6 +165,9 @@ public abstract class LazyStackRenderer extends SWTPartRenderer { IPresentationEngine renderer = context.get(IPresentationEngine.class); for (MUIElement element : me.getChildren()) { + // Make sure that everything is hidden + hideElementRecursive(element); + if (!element.isToBeRendered() || !element.isVisible()) { continue; } @@ -203,7 +217,7 @@ public abstract class LazyStackRenderer extends SWTPartRenderer { } private void hideElementRecursive(MUIElement element) { - if (element == null || element.getWidget() == null) { + if (element == null) { return; } @@ -213,7 +227,7 @@ public abstract class LazyStackRenderer extends SWTPartRenderer { } // Hide any floating windows - if (element instanceof MWindow && element.getWidget() != null) { + if (element instanceof MWindow) { element.setVisible(false); } diff --git a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRendererTest.java b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRendererTest.java index 0ba7a0aa952..07e018bdad0 100644 --- a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRendererTest.java +++ b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRendererTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2019 IBM Corporation and others. + * Copyright (c) 2013, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -10,13 +10,15 @@ * * Contributors: * IBM Corporation - initial API and implementation - * Rolf Theunissen <rolf.theunissen@gmail.com> - Bug 546632 + * Rolf Theunissen <rolf.theunissen@gmail.com> - Bug 546632, 564561 ******************************************************************************/ package org.eclipse.e4.ui.workbench.renderers.swt; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; @@ -34,6 +36,7 @@ import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder; import org.eclipse.e4.ui.model.application.ui.basic.MPart; import org.eclipse.e4.ui.model.application.ui.basic.MPartStack; 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.services.IStylingEngine; import org.eclipse.e4.ui.services.internal.events.EventBroker; import org.eclipse.e4.ui.tests.rules.WorkbenchContextRule; @@ -220,4 +223,83 @@ public class StackRendererTest { assertEquals(ovrwriteIcon, descImage); } + @Test + public void testBug564561_ToolbarVisible_initial() { + MPart part1 = ems.createModelElement(MPart.class); + MPart part2 = ems.createModelElement(MPart.class); + + partStack.getChildren().add(part1); + partStack.getChildren().add(part2); + partStack.setSelectedElement(part1); + + MToolBar toolbar1 = ems.createModelElement(MToolBar.class); + toolbar1.setVisible(false); + part1.setToolbar(toolbar1); + + MToolBar toolbar2 = ems.createModelElement(MToolBar.class); + toolbar2.setVisible(true); + part2.setToolbar(toolbar2); + + contextRule.createAndRunWorkbench(window); + + assertTrue(toolbar1.isVisible()); + assertFalse(toolbar2.isVisible()); + + partStack.setSelectedElement(part2); + + assertFalse(toolbar1.isVisible()); + assertTrue(toolbar2.isVisible()); + } + + @Test + public void testBug564561_ToolbarVisible_added1() { + MPart part1 = ems.createModelElement(MPart.class); + + partStack.getChildren().add(part1); + partStack.setSelectedElement(part1); + + contextRule.createAndRunWorkbench(window); + + MPart part2 = ems.createModelElement(MPart.class); + MToolBar toolbar2 = ems.createModelElement(MToolBar.class); + toolbar2.setVisible(true); + part2.setToolbar(toolbar2); + + partStack.getChildren().add(part2); + + assertFalse(toolbar2.isVisible()); + } + + @Test + public void testBug564561_ToolbarVisible_added2() { + MPart part1 = ems.createModelElement(MPart.class); + MPart part2 = ems.createModelElement(MPart.class); + + partStack.getChildren().add(part1); + partStack.getChildren().add(part2); + partStack.setSelectedElement(part1); + + contextRule.createAndRunWorkbench(window); + + MToolBar toolbar1 = ems.createModelElement(MToolBar.class); + toolbar1.setVisible(false); + part1.setToolbar(toolbar1); + + MToolBar toolbar2 = ems.createModelElement(MToolBar.class); + toolbar2.setVisible(true); + part2.setToolbar(toolbar2); + + assertTrue(toolbar1.isVisible()); + assertFalse(toolbar2.isVisible()); + } + + // helper functions + + /* + * TODO tests: 1. switching tabs: are toolbars hidden, shown 2. add visible + * toolbar to hidden part, add invisible toolbar to shown part 3. shared part + * with visible toolbar on hidden part (do-render) (initial, and add tab after + * render) + */ + } |