i'm taking new eclipse rcp framework , have questions handlers. in rcp 3.x handler class needed implement interface, methods given. in rcp 4 handler class doesn't need implement interface. instead annotate methods. e.g. if have exithandler
in vogellas tutorial have @execute
annotation. can see, there's iworkbench
parameter passed.
package com.example.e4.rcp.todo.handler; import org.eclipse.e4.core.di.annotations.execute; import org.eclipse.e4.ui.workbench.iworkbench; public class exithandler { @execute public void execute(iworkbench workbench) { workbench.close(); } }
my question is: how know parameters passed when using annotations? how know in case iworkbench
object , not window object or something? in fact can annotate method without parameter , still executed.
is there documentation somewhere? eclipse e4 tools don't seem support me there either...
the annotation @execute
doesn't determine type injected, method declaration does.
as behavior annotation, @execute
marks method should called when handler executed. type of object injected determined method's arguments. inject object type, change method's argument, e.g.
@execute public void execute(mwindow window) { // method body }
to inject mwindow
active context.
the @execute
annotation contains @inject
annotation, when event triggered , handler going executed following happens:
- the framework looks method marked
@execute
annotation - the e4 context searched object of method's argument type (e.g.
iworkbench
) - the object gets injected , method executed
unless @optional
annotation set, exception thrown if no object found in context.
for further reading , more thorough explanations see eclipse 4 (e4) tutorial part 4- dependency injection basics , eclipse 4 (e4) tutorial part 6: behavior annotations.
an overview of eclipse 4 annotations can found @ eclipse 4 wiki.
Comments
Post a Comment