Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Is it the same Command?(How to reuse a Command in different contexts?)
Is it the same Command? [message #489749] Mon, 05 October 2009 18:53 Go to next message
Millard Ellingsworth is currently offline Millard Ellingsworth
Messages: 14
Registered: July 2009
Junior Member
Simple application. View with list of tasks, Editor to modify task properties. Editor uses a Scrolled/Managed/Form.

From the Task List View, I want to offer a popup menu choice to run the task (Task does not have to be open in an Editor to run it). From an open Editor for the task, I want to provide a Run command (so it is not necessary to go to the View, right-click, Run). Feels reasonable.

Using existing docs/examples (thanks, Lars), View side pretty easy to wire up and works fine. One command, one handler, one menu appearance. Handler enables when activeMenuSelection is a task item. Handler code uses selection and casts to appropriate object type. All good.

But I'm not quite following (and I can't find any examples or docs) about how to handle the Form/Editor side. For one thing, it feels like I need a different handler, yet isn't it one handler per command? The Editor handler would have different conditions for enabling the command (it at least wouldn't care about the activeMenuSelection). And it would need a different way to understand which task was to be executed since there may not be an active selection (and if there was, it might not match the active editor). [Thanks to folks here for help in figuring out how to wire declaratively into the Form's menu.]

My current approach, though I'm not certain it is reasonable or appropriate is to gum up the handler with an or condition that enables it from either possible angle (though I'm a little concerned about a false positive here). And then in the handler code, if casting against the exception doesn't work, look at the EditorInput of the currently active Editor (if one is open). But this has sort of a sad, hacky feel to it. I'm fumbling with an AbstractSourceProvider that can provide the editor input so that I can find the task object, but even when (if?) I get that working, it's still not clear I can successfully wire it all in.

Anyone done something like this? Any suggestions?

I guess I could do a RunTaskFromView and RunTaskFromEditor command/handler and just delegate the work to a common runner (probably simpler than where I'm headed now), but that also doesn't feel quite right.

Thanks...Millard
Re: Is it the same Command? [message #489811 is a reply to message #489749] Tue, 06 October 2009 05:52 Go to previous messageGo to next message
Prakash G.R. is currently offline Prakash G.R.
Messages: 621
Registered: July 2009
Senior Member
Millard Ellingsworth wrote:


> I need a different handler, yet isn't it one handler per command?

NO! The beauty of the command framework lies in multiple handlers per
command and the ability to select and enable them without even loading
the plugin:
http://blog.eclipse-tips.com/2009/01/commands-part-2-selecti on-and.html

> I'm fumbling with an AbstractSourceProvider that can provide the
> editor input

Why? Platform already has a ISourceProvider for the active editor input
(ISources.ACTIVE_EDITOR_INPUT_NAME) and it should be accessible from the
HandlerUtil.getVariable()

- Prakash

Platform UI Team, IBM
http://blog.eclipse-tips.com
Re: Is it the same Command? [message #489956 is a reply to message #489811] Tue, 06 October 2009 15:27 Go to previous message
Millard Ellingsworth is currently offline Millard Ellingsworth
Messages: 14
Registered: July 2009
Junior Member
Thanks for your comments, I'll see if that helps.

As to the "Why?" you asked regarding some of the struggling, this thread between Michael Scharf and Paul Webster seems to sum it up pretty well:

http://www.eclipse.org/forums/index.php?t=msg&goto=33647 5&S=eda6c784ceda983ed14a772178bed909

Michael Scharf wrote:
> How would I figure all this out without asking the
> newsgroup? I feel really stupid and I don't know
> how to figure out all the complexity of commands.

It's not you Smile

Right now, the resources on commands are the wiki included in my sig and
the (updated with Galileo out soon) stuff in the Help>Help
Contents>Platform Plug-in Developer Guide. But they're pretty slim.

I had hoped to create some more extensive docs on this along with
examples for each thing that people would like to do (for example,
checked state commands can now save their state so they reflect it
correctly on the next startup without activating their plugin). But
while 3.5 is ramping down, the work we need to put into e4 to be ready
at the end of July is consuming all of our time.


When you move beyond the simple, easily described stuff, I think "pretty slim" is a generous description of the documentation. I'm just a guy out here in the world trying to use Eclipse RCP as a tool to help my company (same one you and Paul work for) make money. At least around this topic, it has been impeding that effort.
Previous Topic:Create an "Application Desktop Toolbar" with RCP?
Next Topic:Loss of Mouse events and OBSCURED widgets
Goto Forum:
  


Current Time: Thu Oct 23 12:37:10 GMT 2014

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

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