Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-ui-dev] Extending core expressions with java and javascript

While working on bug 248140 [1] I began fooling around with extending
core expressions to support other syntaxes than XML.  The core
expressions plugin supports plugging in a number of different
Expression generators, and it turned into comment#3 [2].

Specifying <expression script="java"
expressionClass="z.ex.label.untouchable.MyExpression"/> and providing
a subclass of org.eclipse.core.expressions.Expression was easy to do.
Existing OSGi support (Bundle-ActivationPolicy: lazy;
exclude:="z.ex.label.untouchable") can be used to insure that this
class doesn't cause plugin loading, although care has to be taking
that it doesn't reference any other classes in the bundle.  I'm not
sure what a best practice would be while coding, but you at least get
JDT support while writing the expression.

Plugging in something like javascript was a little harder (in the
setup) but still relatively easy:
<enabledWhen>
  <expression script="js">
<![CDATA[
function uses(info) {
  info.addVariableNameAccess("activeContexts");
}

function evaluate(context) {
  var result = context.activeContexts.contains("z.ex.menu.actionSet1")
    || context.activeContexts.contains("z.ex.menu.actionSet2")
  return result;
}
]]>
  </expression>
</enabledWhen>

I find this interesting especially if the script syntax could easily
specify a bundle .js file to load, since that would allow JS tools to
be used for writing the expressions in the .js file.  It would be cool
to see the performance impact.

This was an interesting experiment, but aside from the coolness of
including JavaScript or my own personal preference for Java core
expressions over declarative XML, I'm not sure how much benefit
something like this could add to 3.x.  We might discuss it at our next
UI call.


We're still investigating how JavaScript (and other languages) will be
used in e4, and what their place will be.

----
[1]  https://bugs.eclipse.org/bugs/show_bug.cgi?id=248140
      [Commands] resolve can use org.eclipse.core.variables.dynamicVariables
[2] https://bugs.eclipse.org/bugs/show_bug.cgi?id=248140#c3

-- 
Paul Webster
Hi floor.  Make me a sammich! - GIR


Back to the top