Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 329074

Summary: Support expression language
Product: z_Archived Reporter: Konstantin Komissarchik <konstantin>
Component: SapphireAssignee: Konstantin Komissarchik <konstantin>
Status: CLOSED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: ling.hao, shenxue.zhou
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Konstantin Komissarchik CLA 2010-10-29 13:38:11 EDT
Currently, when you define a node, you can give it a fixed string static
label or a dynamic label that is tied to a value of a property. This works ok
in most situations, but more flexibility is sometimes necessary.

One thought is to allow embedding of scriptlets to specify how the label is
to be computed. The challenge with scriplets is handling label update
properly. Which properties do we need to listen for? This can be solved by
having the script work through a property manager that tracks property access
and sets up listeners on accessed properties.
Comment 1 Konstantin Komissarchik CLA 2010-11-18 00:42:26 EST
Expanding this scope of this enhancement to track creating a generic expression language to be used throughout model annotations and sdef UI files. 

I am currently investigating an approach based largely on JSP EL.
Comment 2 Konstantin Komissarchik CLA 2010-11-18 00:50:02 EST
Progress so far can be seen in org.eclipse.sapphire.modeling.el package.

The key class is Function, which can be implemented directly to provider custom functions in various contents. The EL package also has a variety of standard functions as specified by JSP EL language. The standard functions haven't been tested yet. The eventual goal is to have these be instantiated by the EL parser.
Comment 3 Konstantin Komissarchik CLA 2010-11-18 17:37:35 EST
The EL architecture is shaping up nicely. I have all operators from JSP EL spec implemented, along with type conversion rules. 

I have even converted the code that handles the dynamic-label feature for master details content outline node to use (manually-constructed) EL expression. In particular...

<dynamic-label>
  <property>Name</property>
  <null-value-text>[contact]</null-value-text>
</dynamic-lavel>

... is represented in code like so...

${ empty Name ? "[contact]" : Name }

The next step is to implement the parser so that expressions like the above one can be directly written in sdef files and models.

In terms of architecture, functions have a reference to FunctionContext, which supports retrieving properties and listening on their changes. Now that's a general concept of properties, not the specific concept of Sapphire model properties. FunctionContext is the base class. ModelElementFunctionContext is a subclass that wraps around an IModelElement and exposes that element's properties to functions. The function contexts can be extended arbitrarily by expression hosts.

Everything in the expression tree is a Function, including the key terminals Literal and PropertyReference. 

Functions are evaluated via push rather than pull model. That is, a function listens on its operands, when operands change the function is re-evaluated. If re-evaluation caused a value change, then the function notifies its listeners, etc. An expression host would listen on the expression to know when expression value has changed and trigger appropriate actions.
Comment 4 Konstantin Komissarchik CLA 2010-11-22 15:05:48 EST
Implemented expression language parser along with about 150 unit tests. Removed ILabelDef type added previously. The expression language is now integrated into the following contexts:

* master details content outline node label
* section label
* section description
Comment 5 Konstantin Komissarchik CLA 2010-11-22 15:09:39 EST
Note that a plain string parses as a literal expression. This makes it possible to integrate EL into any context that previously accepted only static strings without breaking existing usage. Here are some example expressions from the contacts sample:

Contacts
${ Name == null ? "&lt;contact&gt;" : Name }
Comment 6 Konstantin Komissarchik CLA 2010-11-22 20:02:08 EST
Added EL support to property enablement. All previous enablement usecases are now expressed via uniform @Enablement( expr = "..." } syntax.
Comment 7 Konstantin Komissarchik CLA 2010-11-22 20:37:56 EST
> Added EL support to property enablement. All previous enablement usecases 
> are now expressed via uniform @Enablement( expr = "..." } syntax.

Actually, @Enablement( service = SomeClass.class ) syntax is still supported. The new EL syntax replaces all other usecases.
Comment 8 Konstantin Komissarchik CLA 2010-11-22 20:38:48 EST
Added a section showing EL-based enablement functionality to the gallery sample.
Comment 9 Konstantin Komissarchik CLA 2010-11-26 22:55:20 EST
Added ability to register EL functions via Sapphire extension system.
Comment 10 Konstantin Komissarchik CLA 2010-12-06 12:33:17 EST
I have finished EL documentation (available under Sapphire Developer Guide). Calling this completed.
Comment 11 Ling Hao CLA 2010-12-15 20:05:19 EST
Verified in sample and documentation.