Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 320912 - [SWTGefBot] Add support for GEF-based views.
Summary: [SWTGefBot] Add support for GEF-based views.
Status: RESOLVED FIXED
Alias: None
Product: SWTBot
Classification: Technology
Component: GEFBot (show other bugs)
Version: 2.0.0-dev   Edit
Hardware: All All
: P3 critical (vote)
Target Milestone: ---   Edit
Assignee: Mariot Chauvin CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-26 10:52 EDT by Pascal Gélinas CLA
Modified: 2010-08-31 03:57 EDT (History)
1 user (show)

See Also:


Attachments
Proposed change (78.39 KB, patch)
2010-08-12 17:11 EDT, Pascal Gélinas CLA
mariot.chauvin: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Pascal Gélinas CLA 2010-07-26 10:52:00 EDT
Currently, the only way to make use of SWTGefBot (SWTBotGefEditPart and the like) is when you have an editor with a graphical viewer. It is impossible to access a view with a graphical viewer, since SWTBotGefEditor subclasses SWTBotEditor. We should probably find a better way then this, since there is no obvious reason why those GEF utilities should depend on IWorkbenchReference (be it an editor or a view).

I suggest something along these lines: instead of having a SWTBotGefEditor, let's have a SWTBotGefViewer. It doesn't subclass SWTBotEditor (nor SWTBotWorkbencPart), and it's constructor would be: SWTBotGefViewer(GraphicalViewer viewer, SWTGefBot bot). Everything else is exactly the same, except that you won't need to reimplement the isActive() and setFocus(), and the init method won't need to find the GraphicalViewer. I would also provide one factory method to create a SWTBotGefViewer, which would take a SWTBotWorkbenchPart as a parameter, it would look something like:

public SWTBotGefViewer foo(SWTBotWorkbenchPart part) {
  GraphicalViewer viewer = (GraphicalViewer) part.getAdapter(GraphicalViewer.class);
  return new SWTBotGefViewer(viewer, new SWTGefBot());
}

Of course, SWTBotWorkbenchPart#getAdapter(Class) would need to be abstract and implemented in both SWTBotEditor and SWTBotView to forward to their proper part.

What do you think?

On a (somewhat) unrelated note: why is SWTBotEditor#setFocus() implementation empty? Shouldn't we "pull up" the implementation of SWTBotGefEditor#setFocus()?
Comment 1 Pascal Gélinas CLA 2010-07-26 11:15:55 EDT
Hey, hey, I never stop improving:

public SWTBotGefViewer gefViewer(String partName){
  SWTBotWorkbenchPart part;
  // Search for views or editors that match partName and assign the result to part. Still haven't found how to do this magic though :P
  GraphicalViewer viewer = (GraphicalViewer) part.getAdapter(GraphicalViewer.class);
  return new SWTBotGefViewer(viewer, new SWTGefBot());
}

Then, you, as the user of this API, don't even need to care if it's an editor or a view, you only need to know its name.
Comment 2 Pascal Gélinas CLA 2010-08-12 17:11:53 EDT
Created attachment 176509 [details]
Proposed change

As no one complained, I thought I might as well do it ;)

So here it is. Main changes are that SWTBotGefEditor is now deprecated in profit of SWTBotGefViewer, which now works with a GraphicalViewer only, no IEditorReference required! All public method from SWTBotGefEditor now delegates to a SWTBotGefViewer.

I also changed the unit tests to use the new class instead of the old one. While I was doing this, I took the liberty to make some clean-up to the code and translated everything to JUnit 4 style. Everything's much clearer now! O, and all the tests still pass ;)

Enjoy!

p.s.: I did the patch using git diff. If there's a problem with it, let me now.
Comment 3 Mariot Chauvin CLA 2010-08-31 03:57:03 EDT
Thanks for the patch !
Committed with some minor modifications (I created a SWTBotGefView which is currently empty and wrap the viewer).
Revision 603.