Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » some commands "newbie" questions
some commands "newbie" questions [message #326965] Thu, 03 April 2008 17:43 Go to next message
Eclipse UserFriend
Originally posted by: tom.eiswind.de

HI I'm just getting started with commands, and I think I want to
refactor our app. But on the second glance I have some questions:

1) Toolbar on a form or section header. What would be a nice way to
contribute there ?

2) Guess I have some generic commands as add, remove edit that I want to
apply in different contexts on different objects.
2a) I have a generic handler that knows how to open entities from my
views from different plugins. Seems to me that this should be possible.
2b) Inside an editor i have different sections with add/edit/remove on
their section toolbar. how can I switch the contexts for the different
sections ?

Hope someone can poitn some things out to me :)
Regards Thomas
Re: some commands "newbie" questions [message #326967 is a reply to message #326965] Thu, 03 April 2008 18:14 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Thomas wrote:
> HI I'm just getting started with commands, and I think I want to
> refactor our app. But on the second glance I have some questions:
>
> 1) Toolbar on a form or section header. What would be a nice way to
> contribute there ?

If you want to contribute commands there, you can either simply add
CommandContributionItems or if you want extensibility then use
IMenuService to populate/release those contribution manager with some
well known, unique ID.

> 2) Guess I have some generic commands as add, remove edit that I want to
> apply in different contexts on different objects.

The command would be generic (your add command) and the contributed
handler would determine how it works in each part.

> 2a) I have a generic handler that knows how to open entities from my
> views from different plugins. Seems to me that this should be possible.

You can provide a default handler for a command, although I'm not sure
if that's what you are asking. A handler has access to the workbench
window selection using the ExecutionEvent application context (see
HandlerUtil for some helper methods).

> 2b) Inside an editor i have different sections with add/edit/remove on
> their section toolbar. how can I switch the contexts for the different
> sections ?

you can activate a handler-per-editor relatively easily using the
IHandlerService in your createPartControl(*) or equivalent method.
However you determine which section you are working on, you would have
to tell your handler which one to work on (or activate the appropriate
handler for that section).

Later,
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/help33/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


Re: some commands "newbie" questions [message #326994 is a reply to message #326967] Fri, 04 April 2008 06:23 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: tom.eiswind.de

Hello Paul,

thanks so far. See some more questions below :)

Paul Webster schrieb:
> Thomas wrote:
>> HI I'm just getting started with commands, and I think I want to
>> refactor our app. But on the second glance I have some questions:
>>
>> 1) Toolbar on a form or section header. What would be a nice way to
>> contribute there ?
>
> If you want to contribute commands there, you can either simply add
> CommandContributionItems or if you want extensibility then use
> IMenuService to populate/release those contribution manager with some
> well known, unique ID.

I guess that means I would have to create the toolbars in an appropriate
way. Can you give me an example how to do it and how the uri would have
to look like ?

Now I have sth like:
public void createSearchToolBar() {
IToolBarManager toolbarManager = searchPersonsForm.getToolBarManager();
toolbarManager.add(searchAction);
toolbarManager.update(true);
//
searchPersonsForm.setHeadClient(toolbarManager.createControl (searchPersonsForm.getHead()));
}
How can I give the toolbar an id ?

>
>> 2) Guess I have some generic commands as add, remove edit that I want
>> to apply in different contexts on different objects.
>
> The command would be generic (your add command) and the contributed
> handler would determine how it works in each part.

Thats what I want.
>
>> 2a) I have a generic handler that knows how to open entities from my
>> views from different plugins. Seems to me that this should be possible.
>
> You can provide a default handler for a command, although I'm not sure
> if that's what you are asking. A handler has access to the workbench
> window selection using the ExecutionEvent application context (see
> HandlerUtil for some helper methods).
>

So do I think. But I wonder how to do the following. I have a generic
handler in my core plugin. Another plugin extends the handler to know
handle its contributed types. it also has a view which gives a new
context that the handler should handle. can i somehow extend the handler
of my core plugin or do i have to dofine a new handler in my extending
plugin that points to the handler in core ?


>> 2b) Inside an editor i have different sections with add/edit/remove on
>> their section toolbar. how can I switch the contexts for the different
>> sections ?
>
> you can activate a handler-per-editor relatively easily using the
> IHandlerService in your createPartControl(*) or equivalent method.
> However you determine which section you are working on, you would have
> to tell your handler which one to work on (or activate the appropriate
> handler for that section).
>

so there is no way to set a fine grained context on the sections ? maybe
then i should have different commands and not use the generic ones there.

another thing that came to me:
Guess an editor opens some dialogs that have toolbars, can i have
extensibility there to the same way as mentioned above ?

I d like to use commands because of the ongoing discussion on
https://bugs.eclipse.org/bugs/show_bug.cgi?id=201052
this is what i really need in there. Its not so much about extending
everything, but controlling wehter the user can actually do something
based on his rights...

So long
Thomas


> Later,
> PW
>
Re: some commands "newbie" questions [message #327014 is a reply to message #326994] Fri, 04 April 2008 17:18 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Thomas wrote:
>
> I guess that means I would have to create the toolbars in an appropriate
> way. Can you give me an example how to do it and how the uri would have
> to look like ?
>
> Now I have sth like:
> public void createSearchToolBar() {
> IToolBarManager toolbarManager =
> searchPersonsForm.getToolBarManager();
> toolbarManager.add(searchAction);
> toolbarManager.update(true);
> //
> searchPersonsForm.setHeadClient(toolbarManager.createControl (searchPersonsForm.getHead()));
>
> }
> How can I give the toolbar an id ?

So using commands in that toolbar can be as simple as creating a
CommandContributionItem and adding it, similar to adding the searchAction.

If you want to be able to contribute to that toolbar using
org.eclipse.ui.menus (and allow others to do so) you would use something
like:

IMenuService ms
= (IMenuService) getSite().getService(IMenuService.class);
ms.populateContributionManager(toolbarManager,
"toolbar:my.editor.id.search.toolbar");

And when closing:
ms.releaseContributions(toolbarManager);


>
> So do I think. But I wonder how to do the following. I have a generic
> handler in my core plugin. Another plugin extends the handler to know
> handle its contributed types. it also has a view which gives a new
> context that the handler should handle. can i somehow extend the handler
> of my core plugin or do i have to dofine a new handler in my extending
> plugin that points to the handler in core ?

You have a couple of options (just an aside, a default handler tends to
be used for valid global behaviour: for example, the command that opens
the About dialog uses a default handler since that behaviour doesn't
change).

One option: provide an extendible handler as API. When another plugin
contributes a new view, they can extend your handler and activate it for
their view.

Another option: Provide a handler that is configurable using
IExecutableExtension ... then they can provide the handler in their
plugin.xml and configure it.


> so there is no way to set a fine grained context on the sections ? maybe
> then i should have different commands and not use the generic ones there.

You would probably activate/deactivate section handlers each time you
activate a different section within your editor. The other option is to
activate one handler for that command for the editor, and have it work
against the active section.

>
> another thing that came to me:
> Guess an editor opens some dialogs that have toolbars, can i have
> extensibility there to the same way as mentioned above ?

You can use the IMenuService there as well ... but you must be careful
to release the contribution manager when the dialog closes/is disposed.


> I d like to use commands because of the ongoing discussion on
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=201052
> this is what i really need in there. Its not so much about extending
> everything, but controlling wehter the user can actually do something
> based on his rights...

Later,
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/help33/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


Contribution on Form toolbar more questions [message #327022 is a reply to message #327014] Sat, 05 April 2008 07:22 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: tom.eiswind.de

Hi Paul et all,

I tried setting
toolbarManager = (ToolBarManager)searchForm.getToolBarManager();
IMenuService ms = (IMenuService)getSite().getService(IMenuService.class);
ms.populateContributionManager(toolbarManager,
"toolbar:de.eiswind.mango.client.searchview.toolbar");

and in plugin.xml:

<menuContribution
locationURI="toolbar:de.eiswind.mango.client.searchview.toolbar ">
<!--menuContribution
locationURI="toolbar:de.eiswind.mango.client.search.ui.Search "-->

<command
commandId="de.eiswind.mango.client.core.command.search"
icon="icons/search.gif"
id="de.eiswind.mango.client.search.search.toolbar"
tooltip="%searchTooltip">
</command>
</menuContribution>

in the view (commented out) it works but it doesnt show up in the form
toolbar. when i put actions in there i have to call update on the
toolbarmanager, can it be ?

And another question about the generic handler: Guess I have the edit
command with the genric handler. I want it to be enabled only when the
handler can handle the current selection (and if theres a selection) Can
How can I ask if theres a workbench selection and can I ask the handler
if he can handle it ?

So long
Thomas
Re: Contribution on Form toolbar more questions [message #327041 is a reply to message #327022] Mon, 07 April 2008 14:38 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Thomas wrote:
>
> in the view (commented out) it works but it doesnt show up in the form
> toolbar. when i put actions in there i have to call update on the
> toolbarmanager, can it be ?

There is needed a call to toolBarManager.update(true) after the call to
populateContributionManager(*).

> And another question about the generic handler: Guess I have the edit
> command with the genric handler. I want it to be enabled only when the
> handler can handle the current selection (and if theres a selection) Can
> How can I ask if theres a workbench selection and can I ask the handler
> if he can handle it ?

There can be 2 parts to this: an enabledWhen clause in the
org.eclipse.ui.handlers extension point. There you can use core
expressions to check the selection and see if it is valid (see some of
http://wiki.eclipse.org/Command_Core_Expressions and the examples from
http://wiki.eclipse.org/Menu_Contributions )

Later,
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/help33/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


Previous Topic:Why not common distro - All - for eclipse SDKs :
Next Topic:matching org.eclipse.ui.ide actions in activity
Goto Forum:
  


Current Time: Thu Jun 27 21:16:33 GMT 2024

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

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

Back to the top