Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » use Commands/Handlers in a non-Workbench window
use Commands/Handlers in a non-Workbench window [message #335338] Thu, 02 April 2009 11:51 Go to next message
Eclipse UserFriend
Hi,

I've got a kind of dialog window here where I'd like to have a toolbar and
re-use some of the actions from the workbench in this. I've tried to create
a coolbarmanager and use a menu service to populate it, but this crashes as
the dialog in question is not a workbench window. Is there another way to
have it populated from commands specified in the plugin.xml or do I have to
go the "hardcode your actions in java code" route?

Andreas
Re: use Commands/Handlers in a non-Workbench window [message #335356 is a reply to message #335338] Fri, 03 April 2009 12:07 Go to previous messageGo to next message
Eclipse UserFriend
You can use the IMenuService from the IWorkbench to populate a
contribution manager. Specifically, a ToolBarManager or MenuManager.
The code to populate a CoolBarManager (more or less) comes from
somewhere else.

It's unlikely you would be able to populate the main URIs (as described
in MenuUtil) but you should be able to define your own dialog-specific
URIs and use them.

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm
Re: use Commands/Handlers in a non-Workbench window [message #335394 is a reply to message #335356] Mon, 06 April 2009 07:04 Go to previous messageGo to next message
Eclipse UserFriend
Paul Webster wrote:

> You can use the IMenuService from the IWorkbench to populate a
> contribution manager. Specifically, a ToolBarManager or MenuManager.
> The code to populate a CoolBarManager (more or less) comes from
> somewhere else.
>
> It's unlikely you would be able to populate the main URIs (as described
> in MenuUtil) but you should be able to define your own dialog-specific
> URIs and use them.

I've found the relevant code that does this for the workbench window,
however using the same code in my dialog causes a null-pointer-exception
when trying to fetch the menu service:

IWorkbench workbench = PlatformUI.getWorkbench();
IServiceLocatorCreator slc = (IServiceLocatorCreator) workbench
.getService( IServiceLocatorCreator.class );
IServiceLocator serviceLocator = slc.createServiceLocator(
workbench, null,
new IDisposable() {
public void dispose()
{
final Shell shell = getShell();
if ( ( shell != null ) && !shell.isDisposed() ) {
close();
}
}
} );

IMenuService menuService = (IMenuService) serviceLocator.getService(
IMenuService.class );
menuService.populateContributionManager( "myid" );


java.lang.NullPointerException
at
org.eclipse.ui.internal.menus.MenuServiceFactory.create(Menu ServiceFactory.java:55)
at
org.eclipse.ui.internal.services.WorkbenchServiceRegistry.ge tService(WorkbenchServiceRegistry.java:102)
at
org.eclipse.ui.internal.services.ServiceLocator.getService(S erviceLocator.java:174)


Andreas
Re: use Commands/Handlers in a non-Workbench window [message #335400 is a reply to message #335394] Mon, 06 April 2009 10:00 Go to previous messageGo to next message
Eclipse UserFriend
In 3.4 (and so far in 3.5) you wouldn't create a new IServiceLocator ...
you would have to use the menu service from the IWorkbench, and then
release your ContributionManagers when your dialog goes away.

We will hopefully fix the NPEs in 3.5:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=267083

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm
Re: use Commands/Handlers in a non-Workbench window [message #335407 is a reply to message #335394] Mon, 06 April 2009 12:21 Go to previous messageGo to next message
Eclipse UserFriend
Andreas Pakulat wrote:

> Paul Webster wrote:
>
>> You can use the IMenuService from the IWorkbench to populate a
>> contribution manager. Specifically, a ToolBarManager or MenuManager.
>> The code to populate a CoolBarManager (more or less) comes from
>> somewhere else.
>>
>> It's unlikely you would be able to populate the main URIs (as described
>> in MenuUtil) but you should be able to define your own dialog-specific
>> URIs and use them.
>
> I've found the relevant code that does this for the workbench window,
> however using the same code in my dialog causes a null-pointer-exception
> when trying to fetch the menu service:
>
> IWorkbench workbench = PlatformUI.getWorkbench();
> IServiceLocatorCreator slc = (IServiceLocatorCreator) workbench
> .getService( IServiceLocatorCreator.class );
> IServiceLocator serviceLocator = slc.createServiceLocator(
> workbench, null,
> new IDisposable() {
> public void dispose()
> {
> final Shell shell = getShell();
> if ( ( shell != null ) && !shell.isDisposed() ) {
> close();
> }
> }
> } );
>
> IMenuService menuService = (IMenuService)
> serviceLocator.getService(
> IMenuService.class );
> menuService.populateContributionManager( "myid" );
>

I've finally made this work, I simply had to supply the workbenchwindow to
createServiceLocator instead of the workbench.

And indeed using a CoolbarManager/CoolBar doesn't seem to work - at least
there's no toolbar visible. However replacing "C" with "T" and using a
toolbar works like a charm.

Andreas
Re: use Commands/Handlers in a non-Workbench window [message #335416 is a reply to message #335400] Tue, 07 April 2009 04:03 Go to previous message
Eclipse UserFriend
Paul Webster wrote:

> In 3.4 (and so far in 3.5) you wouldn't create a new IServiceLocator ...
> you would have to use the menu service from the IWorkbench, and then
> release your ContributionManagers when your dialog goes away.

Ah, indeed that also works and allows me to avoid the usage of internal
classes.

One other minor thing is that I needed to provide the complete uri thats
used in the xml file, including the "toolbar:" prefix. And that wasn't
quite that easy to find out unfortunately ;)

Andreas
Previous Topic:how to create and install a feature patch
Next Topic:[Databinding] BigDecimal to TextField gets DefaultConverter on 3.4.2
Goto Forum:
  


Current Time: Tue Apr 29 00:12:47 EDT 2025

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

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

Back to the top