Home » Eclipse Projects » Eclipse Platform » How to use core expressions language in my own extension point
How to use core expressions language in my own extension point [message #329922] |
Thu, 10 July 2008 11:57  |
Eclipse User |
|
|
|
Originally posted by: x_raajes.ugs.com
I need to write an extension point for a TreeViewer that delegates to
different content providers. To make it extensible and usable in different
ways, I would need to use the expressions language (like instanceof, adapt,
test, and, or, not, with etc.) to allow for conditions to be specified. So
when a consumer of this extension point creates an extension, they would
specify a content provider class, and specify the conditions under which
this content provider should be picked up for the object that is being
expanded in the TreeViewer. As such, the condition could be something like -
if the object is adaptable to xyz, and not an instanceof abc... etc.
I know that the CNF does something similar using "triggerPoints", and for
various reasons, we cannot use the CNF itself. I am sure the expressions
language is re-usable in our extension point definitions, but I have no idea
how and where to start. It would be helpful if anyone has pointers, or
better still, an example of how to do this. Specifically, I am looking for
the following:
1) How do I define these conditions in my extension point definition?
2) Once defined, how do I evaluate the conditions? Do I have to evaluate
each condition myself, or is there built-in support for the simple
conditions I need in my case?
I am trying to evaluate if I would end up writing a lot of code to do this.
Any inputs will be helpful.
Thanks.
|
|
| | |
Re: How to use core expressions language in my own extension point [message #329972 is a reply to message #329929] |
Fri, 11 July 2008 10:57   |
Eclipse User |
|
|
|
Originally posted by: x_raajes.ugs.com
Paul - Thanks to your examples below, I was able to implement these in my
extension point yesterday.
"Paul Webster" <pwebster@ca.ibm.com> wrote in message
news:g55j56$qb0$1@build.eclipse.org...
> Raajesh B.Kashyap wrote:
>> 1) How do I define these conditions in my extension point definition?
>> 2) Once defined, how do I evaluate the conditions? Do I have to evaluate
>> each condition myself, or is there built-in support for the simple
>> conditions I need in my case?
>>
>> I am trying to evaluate if I would end up writing a lot of code to do
>> this. Any inputs will be helpful.
>
> To use core expressions in your own extension point involves 4 steps.
>
> 1) include the core expressions schema in your exsd (examples from
> org.eclipse.ui/schema/handlers.exsd):
>
> <include
> schemaLocation=" schema://org.eclipse.core.expressions/schema/expressionLangu age.exsd"/>
> [/xml]
>
> 2) define your own element that contains the core expression elements. You
> can use <enablement> if you want (although that has caused us some
> conflicts):
>
> <element name="activeWhen">
> <annotation>
> <documentation>
> <p>Contains a core expression used by the
> <code>IHandlerService</code> to determine when this handler is
> active.</p>
> </documentation>
> </annotation>
> <complexType>
> <choice>
> <element ref="not"/>
> <element ref="and"/>
> <element ref="or"/>
> <element ref="instanceof"/>
> <element ref="test"/>
> <element ref="systemTest"/>
> <element ref="equals"/>
> <element ref="count"/>
> <element ref="with"/>
> <element ref="resolve"/>
> <element ref="adapt"/>
> <element ref="iterate"/>
> <element ref="reference"/>
> </choice>
> </complexType>
> </element>
> [/xml]
>
>
> 3) when you read your extension create the core expression. Check out
> org.eclipse.ui.internal.services.RegistryPersistence.readWhe nElement(IConfigurationElement,
> String, String, List) for a complex example, but basically:
>
> IConfigurationElement activeWhenChild = ...;
> final ElementHandler elementHandler = ElementHandler.getDefault();
> final ExpressionConverter converter = ExpressionConverter.getDefault();
> whenExpression = elementHandler.create(converter, activeWhenChild);
>
> 4) when you need to evaluate your expression, for example:
> org.eclipse.ui.internal.dialogs.RegistryPageContributor.fail sEnablement(Object)
> basically creating an EvaluationContext for your expression to work
> against.
>
>
> In 3.4 the IEvaluationService allows anybody (including other extension
> points) to hook provided core expressions into the main workbench
> evaluation strategy (i.e. your extension point can hook a listener to the
> workbench state that will be notified when a core expression is updated
> ... this is how the org.eclipse.ui.internal.handlers.HandlerProxy uses
> IEvaluationService to control its enabledWhen core expression).
>
> 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: How to use core expressions language in my own extension point [message #330329 is a reply to message #329929] |
Fri, 25 July 2008 10:18   |
Eclipse User |
|
|
|
Originally posted by: x_raajes.ugs.com
I have a related question here on the evaluation contexts. In this extension
point that I have written, is it possible that I make use of the
"activePartId" and such other variables in the "with" element, such as are
provided for the menus/handlers? Maybe I am missing something, but I am not
clear about how a consumer of my extension point would be able to put in
such a condition, say, to do something when the activePartId is something.
Looking at the Eclipse documentation, it says that the plug-in making use of
the variables is responsible for setting them up, but I didn't find an
example of how to setup a variable, and if/how I can make use of existing
variables. Again, I am on Eclipse 3.3, so if there is anything available to
do this, please let me know.
Thanks.
|
|
| |
Goto Forum:
Current Time: Wed Apr 30 21:45:21 EDT 2025
Powered by FUDForum. Page generated in 0.07709 seconds
|