Reputation: 522
I want to test a command handler class of my Eclipse plugin. That's why I want to inject an instance of IWorkbenchWindow in the constructor of this handler class, because
PlatformUI.getWorkbench().getActiveWorkbenchWindow()
leaves me with a dependency on PlatformUI.
However I tried to do this
@Inject
public FindAndReplaceHandler(IWorkbenchWindow workbenchWindow) {
this.fWorkbenchWindow = workbenchWindow;
and then the framework throws an NoSuchMethodException complaining that the FindAndReplaceHandler class hasn't got a no-argument constructor.
My class FindAndReplaceHandler extends AbstractHandler and overrides
void execute(ExecutionEvent event)
(So I don't use the modern way with the annotations @Execute and @CanExecute)
My version of Eclipse is: Version: Mars.2 (4.5.2). I created my Eclipse plugin project with the setting Eclipse version = "3.5 or greater". However maybe I need to have the e4 tools installed and work with them? How to install them?
Any ideas how I can solve this problem are appreciated.
Upvotes: 1
Views: 316
Reputation: 111217
The @Inject style of command handler is only used when writing pure e4 style plugins (and these don't use IWorkbenchWindow
or PlatformUI
).
If you want to use IWorkbenchWindow
you are writing a 3.x compatibility mode plugin and can't use injection for the command handler (and most other things). You must have a no arguments constructor for the command handler.
Upvotes: 2