Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Command Core Expressions"

(Variables and the Command Framework)
(Variables and the Command Framework)
Line 12: Line 12:
  
 
The variables used for command framework evaluation are listed in [http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.ui.workbench/Eclipse%20UI/org/eclipse/ui/ISources.java?view=co ISources.java]
 
The variables used for command framework evaluation are listed in [http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.ui.workbench/Eclipse%20UI/org/eclipse/ui/ISources.java?view=co ISources.java]
 +
 +
<table>
 +
<tr>
 +
<th>Name</th>
 +
<th>Type</th>
 +
<th>Description</th>
 +
</tr>
 +
 +
<tr>
 +
<td>activeContexts</td>
 +
<td>A <code>java.util.Collection</code> of <code>java.lang.String</code></td>
 +
<td>
 +
This is a collection of the active context IDs as strings.  Most commonly used with &lt;iterate&gt; and &lt;count&gt;, and can also be used with &lt;test&gt; and a <code>org.eclipse.common.expressions.PropertyTester</code>.
 +
</td>
 +
</tr>
 +
 +
</table>
  
 
= Expression examples =
 
= Expression examples =

Revision as of 10:06, 12 June 2007

Core expressions are declarative or programmatic expressions based on the org.eclipse.core.expressions plugin.

Expressions and the Command Framework

The Platform Command Framework uses core expressions for enabledWhen and activeWhen for handlers, programmatic activation of contexts, and for visibleWhen for menu contributions. The command framework provides the IEvaluationContext that command core expressions are evaluate against.

The IEvaluationContext provides a default variable for evaluations, and a number of named variables. In the command framework, we provide the global selection as a java.util.Collection as the default variable. It can either be empty, have one entry (if the ISelection was something like an ITextSelection), or have the contents of an IStructuredSelection.

The <with/> element can be used to change which variable the child expression elements are evaluating against.

Variables and the Command Framework

The variables used for command framework evaluation are listed in ISources.java

Name Type Description
activeContexts A java.util.Collection of java.lang.String

This is a collection of the active context IDs as strings. Most commonly used with <iterate> and <count>, and can also be used with <test> and a org.eclipse.common.expressions.PropertyTester.

Expression examples

Here are some examples. I'll pretend all of the examples are deciding when a handler is active.

Basic IStructuredSelection

A view provides a structured selection through its selection provider. An example would be the InfoView in org.eclipse.ui.examples.contributions. You can browse the plugin.xml and InfoView.java files. The InfoView provides an IStructuredSelection with 0 or more org.eclipse.ui.examples.contributions.model.Person.

When using the default variable, you must treat it as an java.util.Collection. That means using <count> or <iterate>


<activeWhen>
   <iterate>
      <instanceof value="org.eclipse.ui.examples.contributions.model.Person"/>
   </iterate>
</activeWhen>

Package Explorer IStructuredSelection

The Package Explorer is a mixture of org.eclipse.core.resources.IResource and

Back to the top