| 
| some commands "newbie" questions [message #326965] | Thu, 03 April 2008 13:43  |  | 
| Eclipse User  |  |  |  |  | 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 #326994 is a reply to message #326967] | Fri, 04 April 2008 02:23   |  | 
| Eclipse User  |  |  |  |  | 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 13:18   |  | 
| Eclipse User  |  |  |  |  | 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
 |  |  |  | 
|  | 
|  | 
Powered by 
FUDForum. Page generated in 0.04498 seconds