Home » Eclipse Projects » Eclipse 4 » When are my (injected) POJO methods called?(dependency injection)
|
Re: When are my (injected) POJO methods called? [message #540494 is a reply to message #540492] |
Wed, 16 June 2010 12:03 |
|
1- how are you creating your "MyClass" object ?
If you are creating your object like this : new MyClass()
It won't work, because "the dependency injection engine won't be called". The @Inject means that the dependency injection engine should do the job so you should try :
IEclipseContext context = EclipseContextFactory.create();
MyClass myClass = ContextInjectionFactory.make(MyClass.class,context);
This time all your @Inject annotations should work. When the platform is creating your object (in the case of a part for example) I'm sure it's done this way.
2- Execute and CanExecute are annotations for Handlers only. For example, a "SaveHandler" class which save the content of the current active part could look like this :
@CanExecute
boolean canExecute(@Named(IServiceConstants.ACTIVE_PART) MPart part) {
return part.isDirty();
}
@Execute
void execute(EPartService partService, @Named(IServiceConstants.ACTIVE_PART) MPart part) {
partService.savePart(part, false);
}
|
|
| | | | | | | | | | | |
Re: When are my (injected) POJO methods called? [message #547675 is a reply to message #543666] |
Mon, 19 July 2010 10:41 |
Artur Kronenberg Messages: 159 Registered: August 2009 |
Senior Member |
|
|
Hi,
I had a little more time to dig into the problem and the equinox (both util and event) are started. That still didn't solve my problem.
However there is an exception to my problem.
Currently I am using a stack view with two viewparts in it. Viewpart B uses ViewPart A within and I am creating it like that:
(This is create control from viewPart B):
@Inject
public void createControl( final Composite parent ) {
Composite main = new Composite( parent, SWT.NONE );
main.setLayout( new FormLayout() );
canvas = new Canvas( main, SWT.BORDER | SWT.DOUBLE_BUFFERED);
FormData data = new FormData( COMPASS_RADIUS, COMPASS_RADIUS );
data.left = new FormAttachment( 0, 10 );
data.top = new FormAttachment( 0, 10 );
canvas.setLayoutData( data );
canvas.addPaintListener( this );
//Inserting the allready existing Robotview into this view to show additional information
//Need to create class like that to let Eclipse Injection now where to inject values
RobotView robotView = ContextInjectionFactory.make( RobotView.class, context );
}
As you can see the ContextInjectionFactory is used to create the seconds half of my view. The right composite gets injected in the RobotView so judging by the layout everything is fine (maybe at this point someone can explain to me how the InjectionFactory knows what composite to inject at what point - because I was expecting that the wrong Composite would have been injected there).
Now if I close my app and reopen it AND the ViewB was selected, so it's the one that is visible from the very beginning then everything works and the events in the injected RobotView that I created using the Factory get updated.
If however ViewA is visible and I switch tabs to ViewB in my stack the events don't get updated. However the initial event get injected ONCE when the Factory calls make and the Class gets created the first time.
It seems like the eventBus and and the Injection machanisms miss my created RobotView when I create it through the Factory.
I am sorry for the redundant information - I reread my earlier posts and realized that I did not really make myself too clear there. If there is any additional information needed I can provide it.
Sincerely,
Artur
|
|
|
Re: When are my (injected) POJO methods called? [message #547684 is a reply to message #547675] |
Mon, 19 July 2010 11:00 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
Hi,
Ideally you'd provide us a runnable snippet we can use to reproduce. If
you manage to get such a bundle, file a bugzilla so that we can take a look.
Am 19.07.10 12:41, schrieb Artur Kronenberg:
> Hi,
>
> I had a little more time to dig into the problem and the equinox (both
> util and event) are started. That still didn't solve my problem.
>
> However there is an exception to my problem.
>
> Currently I am using a stack view with two viewparts in it. Viewpart B
> uses ViewPart A within and I am creating it like that:
>
> (This is create control from viewPart B):
> @Inject
> public void createControl( final Composite parent ) {
> Composite main = new Composite( parent, SWT.NONE );
> main.setLayout( new FormLayout() );
> canvas = new Canvas( main, SWT.BORDER | SWT.DOUBLE_BUFFERED);
> FormData data = new FormData( COMPASS_RADIUS, COMPASS_RADIUS );
> data.left = new FormAttachment( 0, 10 );
> data.top = new FormAttachment( 0, 10 );
> canvas.setLayoutData( data );
> canvas.addPaintListener( this );
> //Inserting the allready existing Robotview into this view to show
> additional information
> //Need to create class like that to let Eclipse Injection now where
> to inject values
> RobotView robotView = ContextInjectionFactory.make( RobotView.class,
> context );
> }
>
> As you can see the ContextInjectionFactory is used to create the seconds
> half of my view. The right composite gets injected in the RobotView so
> judging by the layout everything is fine (maybe at this point someone
> can explain to me how the InjectionFactory knows what composite to
> inject at what point - because I was expecting that the wrong Composite
> would have been injected there).
Where's the context variable defined? It it is declared by
--------8<--------
@Inject
private IEclipseContext content;
--------8<--------
Then what you'll get as the Composite is the same you get in
--------8<--------
@Inject
public void createControl( final Composite parent ) {
}
--------8<--------
All in all I really have problems understanding what you are doing. Why
does ViewPartA use ViewPartB?
So please file a bug and provide a runnable example.
>
> Now if I close my app and reopen it AND the ViewB was selected, so it's
> the one that is visible from the very beginning then everything works
> and the events in the injected RobotView that I created using the
> Factory get updated.
> If however ViewA is visible and I switch tabs to ViewB in my stack the
> events don't get updated. However the initial event get injected ONCE
> when the Factory calls make and the Class gets created the first time.
>
> It seems like the eventBus and and the Injection machanisms miss my
> created RobotView when I create it through the Factory.
> I am sorry for the redundant information - I reread my earlier posts and
> realized that I did not really make myself too clear there. If there is
> any additional information needed I can provide it.
> Sincerely,
> Artur
|
|
| | |
Re: When are my (injected) POJO methods called? [message #577795 is a reply to message #540492] |
Wed, 16 June 2010 12:03 |
|
1- how are you creating your "MyClass" object ?
If you are creating your object like this : new MyClass()
It won't work, because "the dependency injection engine won't be called". The @Inject means that the dependency injection engine should do the job so you should try :
IEclipseContext context = EclipseContextFactory.create();
MyClass myClass = ContextInjectionFactory.make(MyClass.class,context);
This time all your @Inject annotations should work. When the platform is creating your object (in the case of a part for example) I'm sure it's done this way.
2- Execute and CanExecute are annotations for Handlers only. For example, a "SaveHandler" class which save the content of the current active part could look like this :
@CanExecute
boolean canExecute(@Named(IServiceConstants.ACTIVE_PART) MPart part) {
return part.isDirty();
}
@Execute
void execute(EPartService partService, @Named(IServiceConstants.ACTIVE_PART) MPart part) {
partService.savePart(part, false);
}
--
Stephane Begaudeau @ Obeo
|
|
| | | | | | | | | | | |
Re: When are my (injected) POJO methods called? [message #578854 is a reply to message #543666] |
Mon, 19 July 2010 10:41 |
Artur Kronenberg Messages: 159 Registered: August 2009 |
Senior Member |
|
|
Hi,
I had a little more time to dig into the problem and the equinox (both util and event) are started. That still didn't solve my problem.
However there is an exception to my problem.
Currently I am using a stack view with two viewparts in it. Viewpart B uses ViewPart A within and I am creating it like that:
(This is create control from viewPart B):
@Inject
public void createControl( final Composite parent ) {
Composite main = new Composite( parent, SWT.NONE );
main.setLayout( new FormLayout() );
canvas = new Canvas( main, SWT.BORDER | SWT.DOUBLE_BUFFERED);
FormData data = new FormData( COMPASS_RADIUS, COMPASS_RADIUS );
data.left = new FormAttachment( 0, 10 );
data.top = new FormAttachment( 0, 10 );
canvas.setLayoutData( data );
canvas.addPaintListener( this );
//Inserting the allready existing Robotview into this view to show additional information
//Need to create class like that to let Eclipse Injection now where to inject values
RobotView robotView = ContextInjectionFactory.make( RobotView.class, context );
}
As you can see the ContextInjectionFactory is used to create the seconds half of my view. The right composite gets injected in the RobotView so judging by the layout everything is fine (maybe at this point someone can explain to me how the InjectionFactory knows what composite to inject at what point - because I was expecting that the wrong Composite would have been injected there).
Now if I close my app and reopen it AND the ViewB was selected, so it's the one that is visible from the very beginning then everything works and the events in the injected RobotView that I created using the Factory get updated.
If however ViewA is visible and I switch tabs to ViewB in my stack the events don't get updated. However the initial event get injected ONCE when the Factory calls make and the Class gets created the first time.
It seems like the eventBus and and the Injection machanisms miss my created RobotView when I create it through the Factory.
I am sorry for the redundant information - I reread my earlier posts and realized that I did not really make myself too clear there. If there is any additional information needed I can provide it.
Sincerely,
Artur
|
|
|
Re: When are my (injected) POJO methods called? [message #578863 is a reply to message #578854] |
Mon, 19 July 2010 11:00 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
Hi,
Ideally you'd provide us a runnable snippet we can use to reproduce. If
you manage to get such a bundle, file a bugzilla so that we can take a look.
Am 19.07.10 12:41, schrieb Artur Kronenberg:
> Hi,
>
> I had a little more time to dig into the problem and the equinox (both
> util and event) are started. That still didn't solve my problem.
>
> However there is an exception to my problem.
>
> Currently I am using a stack view with two viewparts in it. Viewpart B
> uses ViewPart A within and I am creating it like that:
>
> (This is create control from viewPart B):
> @Inject
> public void createControl( final Composite parent ) {
> Composite main = new Composite( parent, SWT.NONE );
> main.setLayout( new FormLayout() );
> canvas = new Canvas( main, SWT.BORDER | SWT.DOUBLE_BUFFERED);
> FormData data = new FormData( COMPASS_RADIUS, COMPASS_RADIUS );
> data.left = new FormAttachment( 0, 10 );
> data.top = new FormAttachment( 0, 10 );
> canvas.setLayoutData( data );
> canvas.addPaintListener( this );
> //Inserting the allready existing Robotview into this view to show
> additional information
> //Need to create class like that to let Eclipse Injection now where
> to inject values
> RobotView robotView = ContextInjectionFactory.make( RobotView.class,
> context );
> }
>
> As you can see the ContextInjectionFactory is used to create the seconds
> half of my view. The right composite gets injected in the RobotView so
> judging by the layout everything is fine (maybe at this point someone
> can explain to me how the InjectionFactory knows what composite to
> inject at what point - because I was expecting that the wrong Composite
> would have been injected there).
Where's the context variable defined? It it is declared by
--------8<--------
@Inject
private IEclipseContext content;
--------8<--------
Then what you'll get as the Composite is the same you get in
--------8<--------
@Inject
public void createControl( final Composite parent ) {
}
--------8<--------
All in all I really have problems understanding what you are doing. Why
does ViewPartA use ViewPartB?
So please file a bug and provide a runnable example.
>
> Now if I close my app and reopen it AND the ViewB was selected, so it's
> the one that is visible from the very beginning then everything works
> and the events in the injected RobotView that I created using the
> Factory get updated.
> If however ViewA is visible and I switch tabs to ViewB in my stack the
> events don't get updated. However the initial event get injected ONCE
> when the Factory calls make and the Class gets created the first time.
>
> It seems like the eventBus and and the Injection machanisms miss my
> created RobotView when I create it through the Factory.
> I am sorry for the redundant information - I reread my earlier posts and
> realized that I did not really make myself too clear there. If there is
> any additional information needed I can provide it.
> Sincerely,
> Artur
|
|
| | |
Goto Forum:
Current Time: Tue Sep 24 13:23:44 GMT 2024
Powered by FUDForum. Page generated in 0.06566 seconds
|