Bug 566184 - EModelService#move cannot move within the same container because of The 'no duplicates' constraint is violated
Summary: EModelService#move cannot move within the same container because of The 'no d...
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.14   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 4.19 M3   Edit
Assignee: Rolf Theunissen CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 576186
  Show dependency tree
 
Reported: 2020-08-19 04:13 EDT by Lars Vogel CLA
Modified: 2021-09-22 04:32 EDT (History)
2 users (show)

See Also:


Attachments
Screenshot (376.37 KB, image/png)
2021-09-21 08:10 EDT, Lars Vogel CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Lars Vogel CLA 2020-08-19 04:13:57 EDT
Trying to use EModelService leads to The 'no duplicates' constraint is violated if the element is already part of the container.


java.lang.IllegalArgumentException: The 'no duplicates' constraint is violated
	at org.eclipse.emf.common.util.AbstractEList.add(AbstractEList.java:337)
	at org.eclipse.e4.ui.internal.workbench.ModelServiceImpl.move(ModelServiceImpl.java:723)
	at org.eclipse.e4.ui.internal.workbench.ModelServiceImpl.move(ModelServiceImpl.java:709)
	at org.eclipse.e4.ui.tests.application.EModelServiceTest.moveWithInTheSameContainer(EModelServiceTest.java:287)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:542)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:770)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:464)
	at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.main(RemotePluginTestRunner.java:117)
	at org.eclipse.pde.internal.junit.runtime.PlatformUITestHarness.lambda$0(PlatformUITestHarness.java:45)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:40)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:185)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4988)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:4510)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1157)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1046)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:155)
	at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:644)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:551)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:153)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:150)
	at org.eclipse.pde.internal.junit.runtime.NonUIThreadTestApplication.runApp(NonUIThreadTestApplication.java:53)
	at org.eclipse.pde.internal.junit.runtime.UITestApplication.runApp(UITestApplication.java:47)
	at org.eclipse.pde.internal.junit.runtime.NonUIThreadTestApplication.start(NonUIThreadTestApplication.java:48)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:203)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:401)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:255)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:657)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:594)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1465)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1438)
Comment 1 Eclipse Genie CLA 2020-08-19 04:15:02 EDT
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.ui/+/167937
Comment 2 Eclipse Genie CLA 2020-08-20 15:36:33 EDT
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.ui/+/168031
Comment 3 Lars Vogel CLA 2020-11-18 08:31:53 EST
Mass change to 4.19 M1, please update the target if you have other plans.
Comment 4 Alexander Kurtakov CLA 2021-01-07 03:07:19 EST
Mass move 4.19 M1 bugs to M3
Comment 6 Lars Vogel CLA 2021-09-21 08:10:20 EDT
Created attachment 287176 [details]
Screenshot

The move method does not through an exception anymore but the UI does not get updated.

I don't think this is the correct behavior:

Method to move:

package atest.handlers;

import org.eclipse.e4.core.di.annotations.Execute;
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.workbench.modeling.EModelService;

public class MoveHandler {

	@Execute
	public void execute(MPart part, EModelService modelService, MWindow window) {
		MPartStack find = (MPartStack) modelService.find("atest.partstack.sample", window);
		modelService.move(part, find, 2);
	}
}


If I move the part manually then the UI gets updated.

	find.getChildren().remove(part);
		find.getChildren().add(2, part);
Comment 7 Lars Vogel CLA 2021-09-21 08:10:35 EDT
Rolf, WDTY?
Comment 8 Rolf Theunissen CLA 2021-09-22 03:03:23 EDT
(In reply to Lars Vogel from comment #7)
> Rolf, WDTY?

As a result of the ECollections.move an 'move' event is raise, instead of the 'remove'/'insert' when remove and add are used, see UIEvents.EventTypes.Move.
However, this event is not handled in any of the renderers. I had a patch that used this (I think in the when working on toolbar/menu renderer), but this was reverted.
Comment 9 Lars Vogel CLA 2021-09-22 04:32:48 EDT
(In reply to Rolf Theunissen from comment #8)
> (In reply to Lars Vogel from comment #7)
> > Rolf, WDTY?
> 
> As a result of the ECollections.move an 'move' event is raise, instead of
> the 'remove'/'insert' when remove and add are used, see
> UIEvents.EventTypes.Move.
> However, this event is not handled in any of the renderers. I had a patch
> that used this (I think in the when working on toolbar/menu renderer), but
> this was reverted.

Thanks Rolf, I opened Bug 576186 for considering this event in the stack renderer.