Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Activating a parts context after creation(So injecting domain objects with @Active will work)
Activating a parts context after creation [message #1699180] Mon, 22 June 2015 11:16 Go to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
Hello

I was looking for a way to inject stuff into a menu handler that depends on which part is currently active. I thought I might be able to inject this stuff with @Active to achieve this.

In the part I use context.set(MyDomainObject.class, stuff) to put the stuff in the context of the part. In the handler I have something like this:
@Execute
public boolean canExecute(@Optional @Active MyDomainObject stuff) {
	// perform some action
}

This works when I manualy select a part in the part stack by switching between tabs. Unfortunately it doesn't work right after I create a new part by code:
part = partService.createPart(myDescriptorId);
editorStack.getChildren().add(part);
partService.showPart(part, PartState.ACTIVATE);

Am I using EPartService correctly? Do I need to add an extra step to activate the part context?

Thanks!
Christoph
Re: Activating a parts context after creation [message #1699182 is a reply to message #1699180] Mon, 22 June 2015 11:24 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

Why do you need @Active?

Handlers of menu items are ALWAYS executed in the context of curently
active IEclipseContext which should be a MPart unless your application
does not show ANY part at all.

Back to your question @Active in your usecase should be the same as
simply putting MyDomainObject so you need to find out why on planet
earth partService.showPart() does not update the current active part.

For a short intro on @Active see
http://tomsondev.bestsolution.at/2013/01/30/active-in-e4/

Tom

On 22.06.15 13:16, Christoph Keimel wrote:
> Hello
>
> I was looking for a way to inject stuff into a menu handler that depends
> on which part is currently active. I thought I might be able to inject
> this stuff with @Active to achieve this.
>
> In the part I use context.set(MyDomainObject.class, stuff) to put the
> stuff in the context of the part. In the handler I have something like
> this:
> @Execute
> public boolean canExecute(@Optional @Active MyDomainObject stuff) {
> // perform some action
> }
> This works when I manualy select a part in the part stack by switching
> between tabs. Unfortunately it doesn't work right after I create a new
> part by code:
>
> part = partService.createPart(myDescriptorId);
> editorStack.getChildren().add(part);
> partService.showPart(part, PartState.ACTIVATE);
>
> Am I using EPartService correctly? Do I need to add an extra step to
> activate the part context?
>
> Thanks!
> Christoph
Re: Activating a parts context after creation [message #1699183 is a reply to message #1699180] Mon, 22 June 2015 11:33 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
Well ... I guess it depends on what one would expect from partService.showPart(part, PartState.ACTIVATE).
To activate the context it is possible to call part.getContext().activateBranch() right afterwards.
Re: Activating a parts context after creation [message #1699184 is a reply to message #1699183] Mon, 22 June 2015 11:35 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
@Tom: You are right of course Smile I've been refactoring some old code and I missed this possibility. Way better!
Re: Activating a parts context after creation [message #1699186 is a reply to message #1699183] Mon, 22 June 2015 11:40 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
No Active should really activate == push the input focus into the part
which would lead to @Focus called on your part which should lead to an
SWT.Activate in SWT (in JavaFX this is handled differently but the
result should be the same).

You need to track down why things go into different directions when
EPartService#showPart behaves in appropriately which might lead into a
bugzilla.

Tom

On 22.06.15 13:33, Christoph Keimel wrote:
> Well ... I guess it depends on what one would expect from
> partService.showPart(part, PartState.ACTIVATE).
> To activate the context it is possible to call
> part.getContext().activateBranch() right afterwards.
Re: Activating a parts context after creation [message #1699187 is a reply to message #1699186] Mon, 22 June 2015 11:42 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
On 22.06.15 13:40, Tom Schindl wrote:
> No Active should really activate == push the input focus into the part

meant PartState.ACTIVATE

Tom
Previous Topic:How integrate PyDev into RCP app
Next Topic:E4 UI - nested Tabbed Part container
Goto Forum:
  


Current Time: Thu Apr 25 05:20:26 GMT 2024

Powered by FUDForum. Page generated in 0.03366 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top