Difference between revisions of "Command Core Expressions"

From Eclipsepedia

Jump to: navigation, search
(Expressions and the Command Framework)
(selection)
Line 17: Line 17:
 
Here are some examples.  I'll pretend all of the examples are deciding when a handler is active.
 
Here are some examples.  I'll pretend all of the examples are deciding when a handler is active.
  
== selection ==
+
== Basic IStructuredSelection ==
 +
 
 +
A view provides a structured selection through its selection provider.  An example would be the InfoView in <b>org.eclipse.ui.examples.contributions<b>.  You can browse the [[plugin.xml|http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.ui.examples.contributions/plugin.xml?content-type=text%2Fplain&view=co]] and
 +
[[InfoView.java|http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.ui.examples.contributions/src/org/eclipse/ui/examples/contributions/view/InfoView.java?view=co]] files.  The InfoView provides an <code>IStructuredSelection</code> with 0 or more <code>org.eclipse.ui.examples.contributions.model.Person</code>.
 +
 
 +
When using the default variable, you must treat it as an <code>java.util.Collection</code>.  That means using &lt;count&gt; or &lt;iterate&gt;
 +
 
  
 
  <activeWhen>
 
  <activeWhen>
 +
    <iterate>
 +
      <instanceof value="org.eclipse.ui.examples.contributions.model.Person"/>
 +
    </iterate>
 
  </activeWhen>
 
  </activeWhen>
 +
 +
== Package Explorer IStructuredSelection ==
 +
 +
The Package Explorer is a mixture of <code>org.eclipse.core.resources.IResource</code> and

Revision as of 09:28, 12 June 2007

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

Contents

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

ISources provides the variables.

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<b>. You can browse the http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.ui.examples.contributions/plugin.xml?content-type=text%2Fplain&view=co and http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.ui.examples.contributions/src/org/eclipse/ui/examples/contributions/view/InfoView.java?view=co 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