Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Button - Action - Job
Button - Action - Job [message #462537] Tue, 30 January 2007 11:09 Go to next message
Eclipse UserFriend
Originally posted by: kristof.taveirne.intec.ugent.be

Hi,

I have this Job that needs to be executed. The Job reads content from a
smartcard and then does a webservice call, so it can take a while until
it is finished.

The user should be able to execute this from the menu, a shortcut and a
button on some view.

By defining an actionSet i've got a menu-item linked to an
IWorkbenchActionDelegate, so I guess i can schedule the Job in the run
method there.
I've added a org.eclipse.ui.commands extension and via the definitionId
in Action i now have a shortcute that executes the action.
The problem is when I want to use the button.

I've added a SelectionListener to the button and in the
widgetSelected(..) method I've created a new actionDelegate Object and
passed 'new Action(){}' to its run method.
The execution of this action works as long as I don't access
IWorkbenchWindow reference in my actionDelegate implementation. this
ofcourse is a null reference here because the init-method wasn't called.

Is there a way I can access the object that's already initiated so I can
easily provide the window as a parent shell for a message dialog? Or
should I get a reference to the current IWorkbenchWindow in some other way?

Thanks,
kristof.
Re: Button - Action - Job [message #462579 is a reply to message #462537] Tue, 30 January 2007 19:46 Go to previous messageGo to next message
Snjezana Peco is currently offline Snjezana PecoFriend
Messages: 789
Registered: July 2009
Senior Member
You can get a reference to the current IWorkbenchWindow using the
following method:
PlatformUI.getWorkbench().getActiveWorkbenchWindow()

Snjeza

Kristof Taveirne wrote:
> Hi,
>
> I have this Job that needs to be executed. The Job reads content from a
> smartcard and then does a webservice call, so it can take a while until
> it is finished.
>
> The user should be able to execute this from the menu, a shortcut and a
> button on some view.
>
> By defining an actionSet i've got a menu-item linked to an
> IWorkbenchActionDelegate, so I guess i can schedule the Job in the run
> method there.
> I've added a org.eclipse.ui.commands extension and via the definitionId
> in Action i now have a shortcute that executes the action.
> The problem is when I want to use the button.
>
> I've added a SelectionListener to the button and in the
> widgetSelected(..) method I've created a new actionDelegate Object and
> passed 'new Action(){}' to its run method.
> The execution of this action works as long as I don't access
> IWorkbenchWindow reference in my actionDelegate implementation. this
> ofcourse is a null reference here because the init-method wasn't called.
>
> Is there a way I can access the object that's already initiated so I can
> easily provide the window as a parent shell for a message dialog? Or
> should I get a reference to the current IWorkbenchWindow in some other way?
>
> Thanks,
> kristof.
Re: Button - Action - Job [message #462863 is a reply to message #462579] Thu, 01 February 2007 15:11 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: kristof.taveirne.intec.ugent.be

Snjezana Peco schreef:
> You can get a reference to the current IWorkbenchWindow using the
> following method:
> PlatformUI.getWorkbench().getActiveWorkbenchWindow()

Thanks! works great.

>
> Snjeza
>
> Kristof Taveirne wrote:
>
>> Hi,
>>
>> I have this Job that needs to be executed. The Job reads content from
>> a smartcard and then does a webservice call, so it can take a while
>> until it is finished.
>>
>> The user should be able to execute this from the menu, a shortcut and
>> a button on some view.
>>
>> By defining an actionSet i've got a menu-item linked to an
>> IWorkbenchActionDelegate, so I guess i can schedule the Job in the run
>> method there.
>> I've added a org.eclipse.ui.commands extension and via the
>> definitionId in Action i now have a shortcute that executes the action.
>> The problem is when I want to use the button.
>>
>> I've added a SelectionListener to the button and in the
>> widgetSelected(..) method I've created a new actionDelegate Object and
>> passed 'new Action(){}' to its run method.
>> The execution of this action works as long as I don't access
>> IWorkbenchWindow reference in my actionDelegate implementation. this
>> ofcourse is a null reference here because the init-method wasn't called.
>>
>> Is there a way I can access the object that's already initiated so I
>> can easily provide the window as a parent shell for a message dialog?
>> Or should I get a reference to the current IWorkbenchWindow in some
>> other way?
>>
>> Thanks,
>> kristof.
Re: Button - Action - Job [message #463057 is a reply to message #462537] Mon, 05 February 2007 18:10 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

1. you can use org.eclipse.ui.actionSets to add it to the main toolbar,
or org.eclipse.ui.viewActions to add it to the view toolbar.

2. If you've bound your action to a command using the definitionId, you
can call that command from the handler service ... no need to
instantiate another action:

IHandlerService service = (IHandlerService)
getSite().getService(IHandlerService.class);
service.executeCommand(definitionId, null);

You could put that in your widgetSelected(*) method.

3. you could give up on your action, and write it in a handler instead.
Then your keybinding and command work the same way. The only
difference is you would put that service.executeCommand(*) code in your
IActionDelevate#run(*) method.

Later,
PW


Previous Topic:Are nested views possible within Eclipse RCP
Next Topic:Focus lost between Editor and Shell
Goto Forum:
  


Current Time: Wed Jan 15 07:59:26 GMT 2025

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

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

Back to the top