Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 416859 - Cannot click context menu item in text editors
Summary: Cannot click context menu item in text editors
Status: RESOLVED FIXED
Alias: None
Product: SWTBot
Classification: Technology
Component: EclipseBot (show other bugs)
Version: 2.1.1   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 2.2.0   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-09-09 12:29 EDT by Jan Koehnlein CLA
Modified: 2013-12-20 07:02 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Koehnlein CLA 2013-09-09 12:29:00 EDT
When I use 

SWTBotEclipseEditor editor = ...
editor.contextMenu("Rename Element").click();

I get a "Widget is disposed error". Same if I try to access the accelerator form the context menu item.
Comment 1 Mickael Istria CLA 2013-09-09 12:44:41 EDT
I had a look at source, and couldn't find a Unit-test for this use-case, so it might indeed be broken...
If you wish to contribute a test Case and a patch, you'd be very welcome ;) http://wiki.eclipse.org/SWTBot/Contributing
Comment 2 Jan Koehnlein CLA 2013-09-10 04:48:01 EDT
Workaround: Instead of calling 
  editor.contextMenu("Rename Element").click();
I call 
  new SWTBotMenu(ContextMenuHelper.contextMenu(editor.styledText, text)).click();

Maybe we should patch SWTBotEclipseEditor like 

  public SWTBotMenu contextMenu(String text) throws WidgetNotFoundException {
    return new SWTBotMenu(ContextMenuHelper.contextMenu(styledText, text));
  }
Comment 3 Mickael Istria CLA 2013-09-10 05:00:59 EDT
It seems to be a valid workaround, but it seems like this error is actually a consequence of a bug in AbstractSWTBot.contextMenu . It would be better to find the root cause, and fix it in the lowest layer possible.
Comment 4 Jan Koehnlein CLA 2013-09-10 05:03:02 EDT
The workaround was copied from SWTBotTreeItem.contextMenu(). Just for the record.
Comment 5 Jan Koehnlein CLA 2013-09-10 05:03:27 EDT
See also http://www.eclipse.org/forums/index.php/m/1105765/#msg_1105765
Comment 6 Mickael Istria CLA 2013-09-10 05:14:12 EDT
(In reply to Jan Koehnlein from comment #4)
> The workaround was copied from SWTBotTreeItem.contextMenu(). Just for the
> record.

Difference of implementation can be explained by the face that default AbstractSWTBot.contextMenu implementation should work on all SWT Control (including StyledText), whereas TreeItem and *Item in general are not Controls and need an alternative implementation.

But that's an interesting hint.
Comment 7 Lorenzo Bettini CLA 2013-10-01 15:52:02 EDT
This looks similar to https://bugs.eclipse.org/bugs/show_bug.cgi?id=384621 where ContextMenuHelper was introduced
Comment 8 Ingo Mohr CLA 2013-10-29 17:33:56 EDT
Pushed fix suggested above to gerrit.

https://git.eclipse.org/r/#/c/17862/
Comment 9 Mickael Istria CLA 2013-11-04 05:18:51 EST
Ingo's patch was tested successfully and merged. Thanks for this contribution!
Comment 10 Jan Koehnlein CLA 2013-11-04 12:20:36 EST
Just curious: Any reason why my patch has been accepted now? What removed your doubts?
Comment 11 Mickael Istria CLA 2013-11-04 12:28:00 EST
(In reply to Jan Koehnlein from comment #10)
> Just curious: Any reason why my patch has been accepted now? What removed
> your doubts?

There is no valid reason, and I still believe (but I'm not sure) that there is a better way to fix this bug.
However, the patch came as a Gerrit contribution, with some unit tests to highlight bug and efficiency of the fix, and Hudson validated it. So it is good enough to be merged. Refactorings and improvements on the same line of code are still welcome.
I guess if your patch was pushed to Gerrit with some unit tests, it would have been merged as well.