Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Strange behaviour with SelectionService
Strange behaviour with SelectionService [message #989448] Thu, 06 December 2012 09:33 Go to next message
Gaetan Pitteloud is currently offline Gaetan PitteloudFriend
Messages: 17
Registered: September 2012
Junior Member
My use case: A part displays a tree, and when I double-click on a node, an editor opens for that node (just like eclipse-ide).

I have added a listener on the treeViewer, and when invoked, the current node is set in ESelectionService by invoking selectionService.setSelection(item). I have created a command and a handler that is invoked on the command. The handler receives the current selection in its @Execute method, thanks to @Named(IServiceConstants.ACTIVE_SELECTION) on the method parameter.
The handler is invoked from the listener thanks to ECommandService and EHandlerService. Here are the successive calls in my listener:
logger.debug("Double click on {}", selectedItem);
selectionService.setSelection(selectedItem);
logger.debug("Item {} set as global selected item", selectedItem);
ParameterizedCommand command = commandService.createCommand("my.command.id", null);
handlerService.executeHandler(command);
logger.debug("Handler invoked");

And here's the code of my handler:
@Inject private EPartService partService;
@Inject private EModelService modelService;
@Inject private MApplication app;

@Execute
public void openNode(@Named(IServiceConstants.ACTIVE_SELECTION) AbstractEntityDefinition<?> selectedItem) {
  logger.debug("Handler invoked with selected item {}", selectedItem);
  String partId = createEditorPartIdFor(selectedItem);
  MPart editorPart = partService.findPart(partId);
  if (editorPart == null) {
    logger.debug("No editor found with id={}", partId);
    editorPart = createEditorFor(selectedItem);
    MPartStack editorsStack = (MPartStack) modelService.find(Constants.EDITORS_STACK_NAME, app);
    editorsStack.getChildren().add(editorPart);
    logger.debug("Editor with id={} created and added to stack", partId);
  } else {
    logger.debug("Editor with id={} already exists", partId);
  }
  partService.activate(editorPart);
  logger.debug("Editor with id={} activated", partId);
}

Most of the time, but not always, the editor does not open when I double-click on a node. I added some logs, and discovered that the selected item set in the SelectionService in the listener is not always the item I get as a parameter in my handler.

Actually, I sometimes receive the previous node I selected before. In fact, if I wait some time (i.e. a few seconds, sometimes even more) between successive double-clicks, the correct selection is received in my handler, but sometimes not. If I set a debug breakpoint in the handler, I always get the correct selection in my handler (making it hard to debug). It looks like ESelectionService.setSelection() asynchronously sets the item and the handler is invoked before the new selection could be injected (I even tried to sleep for a while between the call to setSelection() and the invocation of the handler, but without success).

Am I doing something wrong ? Should I use another API to pass the selected item to my handler ? Any help would be appreciated.

Here are some logs about the issue:
1. Working correctly (first double-click)
[10:00:29,010] DEBUG TreePart Double click on FP_1001.PA_10 
[10:00:29,010] DEBUG TreePart Item FP_1001.PA_10 set as global selected item 
[10:00:29,010] DEBUG OpenTreeNodeHandler Handler invoked with selected item FP_1001.PA_10 
[10:00:29,010] DEBUG OpenTreeNodeHandler No editor found with id=editor.FP_1001.PA_10 
[10:00:29,011] DEBUG OpenTreeNodeHandler Editor with id=editor.FP_1001.PA_10 created and added to stack 
[10:00:29,027] DEBUG OpenTreeNodeHandler Editor with id=editor.FP_1001.PA_10 activated 
[10:00:29,027] DEBUG TreePart Handler invoked 

2. Not working correctly (double-click right after the previous successful one)
[10:00:30,493] DEBUG TreePart Double click on FP_1001.PA_16 
[10:00:30,493] DEBUG TreePart Item FP_1001.PA_16 set as global selected item 
[10:00:30,493] DEBUG OpenTreeNodeHandler Handler invoked with selected item FP_1001.PA_10 
[10:00:30,493] DEBUG OpenTreeNodeHandler Editor with id=editor.FP_1001.PA_10 already exists 
[10:00:30,493] DEBUG OpenTreeNodeHandler Editor with id=editor.FP_1001.PA_10 activated 
[10:00:30,494] DEBUG TreePart Handler invoked 

Line 3 in non-working log shows that the handler receives item from the previous selection.

[Update] I have tried the following 2 things:
1. In the handler, get the selection from the ESelectionService instead of getting it through injection --> same result
2. Before returning from the handler's execute method, set the selection to null --> I get null in the subsequent call to the handler.

[Updated on: Thu, 06 December 2012 09:43]

Report message to a moderator

Re: Strange behaviour with SelectionService [message #989451 is a reply to message #989448] Thu, 06 December 2012 09:46 Go to previous messageGo to next message
Eclipse UserFriend
If you could provide a minimal sample project to reproduce this it would be helpful to track down the issue.
Re: Strange behaviour with SelectionService [message #989682 is a reply to message #989451] Fri, 07 December 2012 09:51 Go to previous messageGo to next message
Gaetan Pitteloud is currently offline Gaetan PitteloudFriend
Messages: 17
Registered: September 2012
Junior Member
Here's a minimal e4 application that contains the problem.

os=win32, ws=win32, arch=x86_64
JRE=jdk1.6.0_26
eclipse build id = Juno SR1, 20121004-1855
launch arguments = -os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog
VM arguments = -Dosgi.requiredJavaVersion=1.5 -Dhelp.lucene.tokenizer=standard -Xms40m -Xmx512m

Selected plugins in run configuration |Start Level|Auto-Start|
Workspace | | |
* sample (1.0.0.qualifier) | default | default |
Target Platform|||||| | | |
* com.ibm.icu (4.4.2.v20110823) | default | default |
* javax.annotation (1.0.0.v20101115-0725) | default | default |
* javax.inject (1.0.0.v20091030) | default | default |
* javax.servlet (3.0.0.v201112011016) | default | default |
* javax.xml (1.3.4.v201005080400) | default | default |
* org.apache.batik.css (1.6.0.v201011041432) | default | default |
* org.apache.batik.util (1.6.0.v201011041432) | default | default |
* org.apache.batik.util.gui (1.6.0.v201011041432) | default | default |
* org.apache.commons.logging (1.0.4.v201101211617) | default | default |
* org.eclipse.ant.core (3.2.400.v20120523-1752) | default | default |
* org.eclipse.core.commands (3.6.1.v20120814-150512) | default | default |
* org.eclipse.core.contenttype (3.4.200.v20120523-2004) | default | default |
* org.eclipse.core.databinding (1.4.1.v20120521-2329) | default | default |
* org.eclipse.core.databinding.beans (1.2.200.v20120523-195 | default | default |
* org.eclipse.core.databinding.observable (1.4.1.v20120521- | default | default |
* org.eclipse.core.databinding.property (1.4.100.v20120523- | default | default |
* org.eclipse.core.expressions (3.4.401.v20120627-124442) | default | default |
* org.eclipse.core.filesystem (1.3.200.v20120522-2012) | default | default |
* org.eclipse.core.filesystem.win32.x86_64 (1.1.300.v201205 | default | false |
* org.eclipse.core.jobs (3.5.300.v20120622-204750) | default | default |
* org.eclipse.core.resources (3.8.1.v20120802-154922) | default | default |
* org.eclipse.core.runtime (3.8.0.v20120521-2346) | default | true |
* org.eclipse.core.runtime.compatibility.auth (3.2.300.v201 | default | default |
* org.eclipse.core.runtime.compatibility.registry (3.5.100. | default | false |
* org.eclipse.core.variables (3.2.600.v20120521-2012) | default | default |
* org.eclipse.e4.core.commands (0.10.1.v20120523-1955) | default | default |
* org.eclipse.e4.core.contexts (1.1.0.v20120828-170404) | default | default |
* org.eclipse.e4.core.di (1.1.0.v20120627-124443) | default | default |
* org.eclipse.e4.core.di.extensions (0.11.0.v20120523-2004) | default | default |
* org.eclipse.e4.core.services (1.0.0.v20120521-2346) | default | default |
* org.eclipse.e4.ui.bindings (0.10.1.v20120716-173435) | default | default |
* org.eclipse.e4.ui.css.core (0.10.2.v20120806-171245) | default | default |
* org.eclipse.e4.ui.css.swt (0.10.2.v20120821-165957) | default | default |
* org.eclipse.e4.ui.css.swt.theme (0.9.3.v20120806-170624) | default | default |
* org.eclipse.e4.ui.di (0.10.1.v20120523-1955) | default | default |
* org.eclipse.e4.ui.model.workbench (0.10.1.v20120523-1955) | default | default |
* org.eclipse.e4.ui.services (0.10.2.v20120726-172631) | default | default |
* org.eclipse.e4.ui.widgets (0.12.0.v20120905-175524) | default | default |
* org.eclipse.e4.ui.workbench (0.10.3.v20120822-140642) | default | default |
* org.eclipse.e4.ui.workbench.renderers.swt (0.10.2.v201208 | default | default |
* org.eclipse.e4.ui.workbench.swt (0.10.2.v20120802-184737) | default | default |
* org.eclipse.e4.ui.workbench3 (0.12.0.v20120521-2329) | default | default |
* org.eclipse.emf.common (2.8.0.v20120911-0500) | default | default |
* org.eclipse.emf.databinding (1.2.0.v20120917-0436) | default | default |
* org.eclipse.emf.ecore (2.8.1.v20120911-0500) | default | default |
* org.eclipse.emf.ecore.change (2.8.0.v20120911-0500) | default | default |
* org.eclipse.emf.ecore.xmi (2.8.0.v20120911-0500) | default | default |
* org.eclipse.equinox.app (1.3.100.v20120522-1841) | default | default |
* org.eclipse.equinox.common (3.6.100.v20120522-1841) | 2 | true |
* org.eclipse.equinox.concurrent (1.0.300.v20120522-2049) | default | default |
* org.eclipse.equinox.ds (1.4.0.v20120522-1841) | 1 | true |
* org.eclipse.equinox.event (1.2.200.v20120522-2049) | default | default |
* org.eclipse.equinox.preferences (3.5.0.v20120522-1841) | default | default |
* org.eclipse.equinox.registry (3.5.200.v20120522-1841) | default | default |
* org.eclipse.equinox.util (1.0.400.v20120522-2049) | default | default |
* org.eclipse.equinox.weaving.hook (1.0.200.I20120427-0800) | default | false |
* org.eclipse.jface (3.8.101.v20120817-083647) | default | default |
* org.eclipse.jface.databinding (1.6.0.v20120521-2329) | default | default |
* org.eclipse.osgi (3.8.1.v20120830-144521) | -1 | true |
* org.eclipse.osgi.services (3.3.100.v20120522-1822) | default | default |
* org.eclipse.swt (3.100.1.v4234e) | default | default |
* org.eclipse.swt.win32.win32.x86_64 (3.100.1.v4234e) | default | false |
* org.eclipse.team.core (3.6.100.v20120524-0627) | default | default |
* org.w3c.css.sac (1.3.1.v200903091627) | default | default |
* org.w3c.dom.smil (1.0.0.v200806040011) | default | default |
* org.w3c.dom.svg (1.1.0.v201011041433) | default | default |
(I did not choose them one by one, but just added the required ones, starting from a sample app).

Attached is the eclipse project source zip.

Click on File->Open or eclipse toolbar button. It will load a tree in the left part. When you double-click on a node, it opens an editor in editors parts stack, which name is suffixed with the node name (create it or find if already exists). The rest corresponds to the described behavior I mentioned in earlier post.

Many thanks in advance if you can spend some times on this issue. Please tell me if you need more info about my config.
  • Attachment: sample.zip
    (Size: 14.21KB, Downloaded 290 times)
Re: Strange behaviour with SelectionService [message #989747 is a reply to message #989682] Fri, 07 December 2012 13:56 Go to previous messageGo to next message
Lars Vogel is currently offline Lars VogelFriend
Messages: 1098
Registered: July 2009
Senior Member

Hi Gaetan,

nice example. Thanks!

Currently the @Focus method is required in the parts to make the services work correctly. If I implement these methods, the selection service works correctly. For details Bug report for missing @Focus causes Selection not propagated in conjunction with the Part service

Best regards, Lars
Re: Strange behaviour with SelectionService [message #989754 is a reply to message #989747] Fri, 07 December 2012 15:11 Go to previous messageGo to next message
Gaetan Pitteloud is currently offline Gaetan PitteloudFriend
Messages: 17
Registered: September 2012
Junior Member
It works as expected. Many thanks for your responsiveness !
--
Gaëtan
Re: Strange behaviour with SelectionService [message #989790 is a reply to message #989754] Fri, 07 December 2012 19:17 Go to previous message
Eclipse UserFriend
We should add a sticky post for this focus thing as people get constantly beaten up by this.
Previous Topic:Fancy Navigation?
Next Topic:PartDescriptors and Parts: dublicate data problem
Goto Forum:
  


Current Time: Sat Apr 20 12:50:18 GMT 2024

Powered by FUDForum. Page generated in 0.04475 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top