Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Query current activation state of handlers in plugin.xml
Query current activation state of handlers in plugin.xml [message #646673] Wed, 29 December 2010 14:04 Go to next message
ben Mising name is currently offline ben Mising name
Messages: 4
Registered: July 2009
Junior Member
Hi,

I would like to know whether there is any chance to evaluate the current activation state of a handler within the activeWhen statement in plugin.xml.

I need the state because the handler must keep its current state if another sub expression evaluates to false. An example:

<activeWhen>
<or>
<with
variable="perspectiveId">
<equals
value="somePerspective">
</equals>
<and>
<!-- further tests -->
</and>
</with>
<!-- if perspectiveId test fails keep old value here -->
</or>
</activeWhen>

The reason why I need the state is a self written source provider. This provider provides information on state changes of views (no matter whether active or not). This approach eliminates source providers for each view but requires some kind of conditional evaluation. Therefore the test for the perspective id and requirement to get the current activation state.

My solution is really ugly. To get the current activation state I am using a PropertyTester that queries the current command's handler state. Is there any other way to not drop the single source provider?
Re: Query current activation state of handlers in plugin.xml [message #647253 is a reply to message #646673] Wed, 05 January 2011 07:30 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Is it the activeWhen you need (which controls if the handler is active
and available to be used) or enabledWhen (which controls if the handler
will do anything)?


Where is the handler getting its state from? What is the cost of the
handler simply writing out that state at the end of its execute(*)
method (since it won't execute when it is not active)?

Core expressions are large "if" statements. They're not if (cond) {
statement; }

Why can your single source provider not simply provide data, and your
handler core expressions evaluate it?

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Query current activation state of handlers in plugin.xml [message #647835 is a reply to message #647253] Sun, 09 January 2011 13:24 Go to previous messageGo to next message
ben Mising name is currently offline ben Mising name
Messages: 4
Registered: July 2009
Junior Member
Thanks for your reply. It is the activeWhen i need.

What do you mean exactly with writing out the handler's state at the end of execute(*)?

Providing additional information via the the source provider certainly is an option. But i would prefer not mixing up information that actually do not belong together, because that might make future reuse difficult.

Unfortunately, expressions cannot be extended by client code. Otherwise one could extent the existing expressions (with, equals, iterate, test ...) and provide an if-statement.
Re: Query current activation state of handlers in plugin.xml [message #647928 is a reply to message #647835] Mon, 10 January 2011 08:46 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

On 01/09/2011 01:24 PM, ben wrote:
> Thanks for your reply. It is the activeWhen i need.
>
> What do you mean exactly with writing out the handler's state at the end
> of execute(*)?

That was me trying to understand what exactly needs "the state" and what
provides "the state".

A source provider provides one or more variables to the
IEvaluationService. It notifies the IEvaluationService that the
variable value has changed, and then the IEvaluationService takes care
of re-evaluating everybody that consumes that variable. Anything in the
system can provide state to a source provider (We update variables on
SWT events, in response to property listeners, and occasionally when
code programmatically sets information on a "Manager" provided by a
plugin activator).

The activeWhen expression determines if a given handler is active (by
consuming one or more variables from the IEvaluationService, + running
any property testers that are listed).

Your view can produce state, and presumably owns its runtime model (or
deals with the manager that does).

Handlers don't have state, they act on the state of the system. The
questions I was asking were to try and find out where your state is
coming from. Your view?

> Unfortunately, expressions cannot be extended by client code. Otherwise
> one could extent the existing expressions (with, equals, iterate, test
> ...) and provide an if-statement.

I'm not sure what you mean, exactly. The whole thing is an if statement:

if (evaluateActiveWhen(activeWhen)) { makeHandlerActive(handler); }

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Query current activation state of handlers in plugin.xml [message #648100 is a reply to message #647928] Tue, 11 January 2011 04:01 Go to previous message
ben Mising name is currently offline ben Mising name
Messages: 4
Registered: July 2009
Junior Member
To clarify, the views are extensions of ViewPart. Each view consists of two parts, a query part and a result display part. Query parts are used to select the data to display. The source provider provides a variable that changes if the query of any view changes and contains the view part and the query object. This information is used to determine the activation of handlers. Logically, this approach forces reevaluation of expressions every time a view's query has changed, no matter whether the handler is related to the changed view or not.

> I'm not sure what you mean, exactly. The whole thing is an if statement:
>
> if (evaluateActiveWhen(activeWhen)) { makeHandlerActive(handler); }

That was a missunderstanding. What i meen is an if-expression that can be used within the activeWhen statement. Something like:

if (someCondition == true) {
evaluateActiveWhen(activeWhen)
} else {
dontChangeAnything
}

whereas someCondition must be itself an expression.

All in all, i think i have to reconsider my implementation. Thanks for your efforts.
Previous Topic:Evaluating the VisibleWhen tag in menu contributions
Next Topic:Tree vs. jface.Text vs. ?
Goto Forum:
  


Current Time: Thu Aug 28 21:28:18 EDT 2014

Powered by FUDForum. Page generated in 0.02075 seconds