-
Notifications
You must be signed in to change notification settings - Fork 231
StackRenderer updates correctly when part is moved #3705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
vogella
merged 4 commits into
eclipse-platform:master
from
vogella:test-stack-renderer-reordering
Jan 30, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
53d2c12
Fix(workbench): StackRenderer updates correctly when part is moved
vogella 9351f65
Add test case for StackRenderer part reordering
vogella c450202
Fix(workbench): StackRenderer duplication of tabs on move
vogella 9a9b102
Fix tab selection on move and enhance test coverage
vogella File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
...ipse.e4.ui.tests/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRendererMoveTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| package org.eclipse.e4.ui.workbench.renderers.swt; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertNotSame; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import jakarta.inject.Inject; | ||
| import java.util.List; | ||
| import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer; | ||
| import org.eclipse.e4.ui.model.application.MApplication; | ||
| 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.tests.rules.WorkbenchContextExtension; | ||
| import org.eclipse.e4.ui.workbench.modeling.EModelService; | ||
| import org.eclipse.swt.custom.CTabFolder; | ||
| import org.eclipse.swt.custom.CTabItem; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
|
||
| public class StackRendererMoveTest { | ||
|
|
||
| @RegisterExtension | ||
| public WorkbenchContextExtension contextRule = new WorkbenchContextExtension(); | ||
|
|
||
| @Inject | ||
| private EModelService ems; | ||
|
|
||
| @Inject | ||
| private MApplication application; | ||
|
|
||
| private MWindow window; | ||
| private MPartStack partStack; | ||
|
|
||
| @BeforeEach | ||
| public void setUp() throws Exception { | ||
| window = ems.createModelElement(MWindow.class); | ||
| application.getChildren().add(window); | ||
| application.setSelectedElement(window); | ||
|
|
||
| partStack = ems.createModelElement(MPartStack.class); | ||
| window.getChildren().add(partStack); | ||
| } | ||
|
|
||
| @Test | ||
| public void testPartMoveUpdatesWidget() throws Exception { | ||
| // Create two parts | ||
| MPart part1 = ems.createModelElement(MPart.class); | ||
| part1.setLabel("Part 1"); | ||
| partStack.getChildren().add(part1); | ||
|
|
||
| MPart part2 = ems.createModelElement(MPart.class); | ||
| part2.setLabel("Part 2"); | ||
| partStack.getChildren().add(part2); | ||
|
|
||
| // Render the window (and thus the stack and parts) | ||
| contextRule.createAndRunWorkbench(window); | ||
|
|
||
| CTabFolder tabFolder = (CTabFolder) partStack.getWidget(); | ||
| assertEquals(2, tabFolder.getItemCount()); | ||
|
|
||
| CTabItem item1 = tabFolder.getItem(0); | ||
| CTabItem item2 = tabFolder.getItem(1); | ||
|
|
||
| assertEquals(part1, item1.getData(AbstractPartRenderer.OWNING_ME)); | ||
| assertEquals(part2, item2.getData(AbstractPartRenderer.OWNING_ME)); | ||
| assertEquals(item1.getControl(), part1.getWidget()); | ||
| assertEquals(item2.getControl(), part2.getWidget()); | ||
|
|
||
| // Move part1 to the end (index 1) | ||
| // We use model service to move to ensure events are fired | ||
| ems.move(part1, partStack, 1); | ||
|
|
||
| // Verify model update | ||
| List<org.eclipse.e4.ui.model.application.ui.basic.MStackElement> children = partStack.getChildren(); | ||
| assertEquals(part2, children.get(0)); | ||
| assertEquals(part1, children.get(1)); | ||
|
|
||
| // Verify UI update | ||
| assertEquals(2, tabFolder.getItemCount()); | ||
| CTabItem newItem1 = tabFolder.getItem(1); | ||
| CTabItem newItem2 = tabFolder.getItem(0); | ||
|
|
||
| // The old item1 should be disposed | ||
| assertTrue(item1.isDisposed(), "Old item for part1 should be disposed"); | ||
| assertFalse(item2.isDisposed(), "Item2 should not be disposed"); | ||
|
|
||
| // part1 should have a NEW widget item, but the part's widget (content) should be preserved | ||
| assertNotSame(item1, newItem1); | ||
| assertEquals(part1, newItem1.getData(AbstractPartRenderer.OWNING_ME), "New item should have OWNING_ME set"); | ||
| assertEquals(part1.getWidget(), newItem1.getControl(), "Part1 widget should be the control of the new item"); | ||
|
|
||
| // part2 should still be valid and same widget | ||
| assertEquals(item2, newItem2); | ||
| assertEquals(part2, newItem2.getData(AbstractPartRenderer.OWNING_ME)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the currently selected tab is moved, the selection is not preserved. I should try to save it
java boolean wasSelected = tabFolder.getSelection() == item;
// ... dispose and recreate ...
if (wasSelected) {
tabFolder.setSelection(newItem);
}