Skip to content

Commit c662c16

Browse files
committed
Don't remove parts from part stack on DnD drop
Currently when dropping elements onto a part stack MStackElements are removed if their element ids are equal. This leads to disappearing parts in case of - at least one part created using part descriptors allowing multiple instances is present in the part stack - another such part is dropped onto the part stack Following the comments/notes the intention is to remove place holder parts with the same element id as the element's id being dropped. This fix ensures that only instances of type MPlaceholder are removed from the part stack. Fixes #2771
1 parent 328646d commit c662c16

File tree

5 files changed

+483
-8
lines changed

5 files changed

+483
-8
lines changed

bundles/org.eclipse.e4.ui.workbench.addons.swt/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-SymbolicName: org.eclipse.e4.ui.workbench.addons.swt;singleton:=true
4-
Bundle-Version: 1.5.600.qualifier
4+
Bundle-Version: 1.5.700.qualifier
55
Bundle-Name: %pluginName
66
Bundle-Vendor: %providerName
77
Bundle-Localization: plugin

bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/StackDropAgent.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* Contributors:
1212
* IBM Corporation - initial API and implementation
1313
* Patrik Suzzi <[email protected]> - Bug 497348
14+
* Oliver Lins <[email protected]> - Issue 2771
1415
******************************************************************************/
1516

1617
package org.eclipse.e4.ui.workbench.addons.dndaddon;
@@ -21,6 +22,7 @@
2122
import java.util.stream.Stream;
2223
import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
2324
import org.eclipse.e4.ui.model.application.ui.MUIElement;
25+
import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
2426
import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
2527
import org.eclipse.e4.ui.model.application.ui.basic.MStackElement;
2628
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
@@ -260,13 +262,19 @@ private void dock(MUIElement dragElement, int dropIndex) {
260262
// Note 3: currently if we drag/drop parts, it looks like for editor parts we
261263
// always drop PartImpl instances, for views we drop PartStackImpl or
262264
// PlaceholderImpl instances. So one could use this for the check below too.
265+
// Note 4: b/c of parts allowing multiple instances with the same element id
266+
// it is necessary to also test for the instance type of the children of the
267+
// drop stack. If an instance is of type MPlaceholder and the element id is
268+
// equal to the drag element's element id the placeholder is removed.
263269
MStackElement viewWithSameId = null;
264270
if (elementIndex == -1 && !dragElement.getTags().contains("Editor")) { //$NON-NLS-1$
265271
for (MStackElement stackElement : dropChildren) {
266-
String id = stackElement.getElementId();
267-
if (id != null && id.equals(dragElement.getElementId())) {
268-
viewWithSameId = stackElement;
269-
break;
272+
if (stackElement instanceof MPlaceholder placeholder) {
273+
String id = placeholder.getElementId();
274+
if (id != null && id.equals(dragElement.getElementId())) {
275+
viewWithSameId = placeholder;
276+
break;
277+
}
270278
}
271279
}
272280
}

tests/org.eclipse.e4.ui.workbench.addons.swt.test/META-INF/MANIFEST.MF

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %pluginName
44
Bundle-SymbolicName: org.eclipse.e4.ui.workbench.addons.swt.test
5-
Bundle-Version: 1.5.0.qualifier
5+
Bundle-Version: 1.5.100.qualifier
66
Bundle-Localization: plugin
7-
Fragment-Host: org.eclipse.e4.ui.workbench.addons.swt;bundle-version="[1.1.0,2.0.0)"
7+
Fragment-Host: org.eclipse.e4.ui.workbench.addons.swt;bundle-version="[1.5.700,2.0.0)"
88
Bundle-RequiredExecutionEnvironment: JavaSE-17
99
Require-Bundle: org.junit;bundle-version="[4.12.0,5.0.0)",
1010
org.eclipse.e4.core.commands;bundle-version="[1.0.0,2.0.0)",
1111
org.eclipse.core.databinding.observable;bundle-version="[1.4.0,2.0.0)",
1212
org.eclipse.jface.databinding;bundle-version="[1.6.200,2.0.0)",
13-
org.eclipse.e4.ui.workbench.swt;bundle-version="[0.12.100,1.0.0)"
13+
org.eclipse.e4.ui.workbench.swt;bundle-version="[0.12.100,1.0.0)",
14+
org.mockito.mockito-core;bundle-version="5.15.2"
1415
Bundle-Vendor: %providerName
1516
Export-Package: org.eclipse.e4.ui.workbench.addons.minmax;x-internal:=true
1617
Automatic-Module-Name: org.eclipse.e4.ui.workbench.addons.swt.test

tests/org.eclipse.e4.ui.workbench.addons.swt.test/src/org/eclipse/e4/ui/workbench/addons/AllTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.eclipse.e4.ui.workbench.addons;
22

33
import org.eclipse.e4.ui.workbench.addons.cleanupaddon.CleanupAddonTest;
4+
import org.eclipse.e4.ui.workbench.addons.dndaddon.StackDropAgentTest;
45
import org.eclipse.e4.ui.workbench.addons.minmax.MaximizableChildrenTag;
56
import org.eclipse.e4.ui.workbench.addons.minmax.MaximizeBugTest;
67
import org.eclipse.e4.ui.workbench.addons.minmax.MaximizePartSashContainerPlaceholderTest;
@@ -14,6 +15,7 @@
1415
MaximizePartSashContainerPlaceholderTest.class, //
1516
MaximizableChildrenTag.class, //
1617
CleanupAddonTest.class, //
18+
StackDropAgentTest.class, //
1719
})
1820
public class AllTests {
1921

0 commit comments

Comments
 (0)