Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 15:57 Go to next message
Eclipse UserFriend
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 #329929 is a reply to message #329922] Thu, 10 July 2008 18:03 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

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>
&lt;p&gt;Contains a core expression used by the
&lt;code&gt;IHandlerService&lt;/code&gt; to determine when this handler
is active.&lt;/p&gt;
</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 #329935 is a reply to message #329929] Thu, 10 July 2008 20:51 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: x_raajes.ugs.com

Thanks Paul. I'll try this out.


"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>
> &lt;p&gt;Contains a core expression used by the
> &lt;code&gt;IHandlerService&lt;/code&gt; to determine when this handler is
> active.&lt;/p&gt;
> </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 #329972 is a reply to message #329929] Fri, 11 July 2008 14:57 Go to previous messageGo to next message
Eclipse UserFriend
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>
> &lt;p&gt;Contains a core expression used by the
> &lt;code&gt;IHandlerService&lt;/code&gt; to determine when this handler is
> active.&lt;/p&gt;
> </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 14:18 Go to previous messageGo to next message
Eclipse UserFriend
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.
Re: How to use core expressions language in my own extension point [message #330423 is a reply to message #330329] Mon, 28 July 2008 16:08 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

In 3.3 you can ask the IHandlerService for the global application
context (getCurrentState()).

Selecting a variable is done using with:
<with variable="activePartId">
... whatever
</with>

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:TableViewer
Next Topic:bundle vs. plugin
Goto Forum:
  


Current Time: Fri Jul 19 12:16:38 GMT 2024

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

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

Back to the top