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]
 +
 +
Some of the variables may not be set, depending on the current application context when they are evaluated.
  
 
<table border="1">
 
<table border="1">
Line 25: Line 27:
 
<td>A <code>java.util.Collection</code> of <code>java.lang.String</code></td>
 
<td>A <code>java.util.Collection</code> of <code>java.lang.String</code></td>
 
<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>.
+
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>.</code>.
 
</td>
 
</td>
 
<td>3.2</td>
 
<td>3.2</td>
Line 43: Line 45:
 
<td><code>org.eclipse.swt.widgets.Shell</code></td>
 
<td><code>org.eclipse.swt.widgets.Shell</code></td>
 
<td>
 
<td>
 +
The currently active shell.  It can be a dialog or workbench window shell.
 
</td>
 
</td>
 
<td>3.2</td>
 
<td>3.2</td>
Line 51: Line 54:
 
<td><code>org.eclipse.swt.widgets.Shell</code></td>
 
<td><code>org.eclipse.swt.widgets.Shell</code></td>
 
<td>
 
<td>
 +
The active workbench window shell.
 
</td>
 
</td>
 
<td>3.2</td>
 
<td>3.2</td>
Line 59: Line 63:
 
<td><code>org.eclipse.ui.IWorkbenchWindow</code></td>
 
<td><code>org.eclipse.ui.IWorkbenchWindow</code></td>
 
<td>
 
<td>
 +
The active workbench window.
 
</td>
 
</td>
 
<td>3.2</td>
 
<td>3.2</td>
Line 67: Line 72:
 
<td><code>java.lang.Boolean</code></td>
 
<td><code>java.lang.Boolean</code></td>
 
<td>
 
<td>
 +
Reports coolbar visibility for the currently active workbench window.
 
</td>
 
</td>
 
<td>3.3</td>
 
<td>3.3</td>
Line 75: Line 81:
 
<td><code>java.lang.Boolean</code></td>
 
<td><code>java.lang.Boolean</code></td>
 
<td>
 
<td>
 +
Reports perspective bar visibility for the currently active workbench window.
 
</td>
 
</td>
 
<td>3.3</td>
 
<td>3.3</td>
Line 83: Line 90:
 
<td><code>org.eclipse.ui.IEditorPart</code></td>
 
<td><code>org.eclipse.ui.IEditorPart</code></td>
 
<td>
 
<td>
 +
The currently active editor.  This is remembered even if the editor is not the currently active part.
 
</td>
 
</td>
 
<td>3.2</td>
 
<td>3.2</td>
Line 91: Line 99:
 
<td><code>java.lang.String</code></td>
 
<td><code>java.lang.String</code></td>
 
<td>
 
<td>
 +
The ID of the currently active editor.  This can be used for expressions on the editor type.
 
</td>
 
</td>
 
<td>3.2</td>
 
<td>3.2</td>
Line 99: Line 108:
 
<td><code>org.eclipse.ui.IWorkbenchPart</code></td>
 
<td><code>org.eclipse.ui.IWorkbenchPart</code></td>
 
<td>
 
<td>
 +
The active part, which can be the same as the active editor.
 
</td>
 
</td>
 
<td>3.2</td>
 
<td>3.2</td>
Line 107: Line 117:
 
<td><code>java.lang.String</code></td>
 
<td><code>java.lang.String</code></td>
 
<td>
 
<td>
 +
The ID of the currently active part.
 
</td>
 
</td>
 
<td>3.2</td>
 
<td>3.2</td>
Line 115: Line 126:
 
<td><code>org.eclipse.ui.IWorkbenchPartSite</code></td>
 
<td><code>org.eclipse.ui.IWorkbenchPartSite</code></td>
 
<td>
 
<td>
 +
The site of the currently active part.
 
</td>
 
</td>
 
<td>3.2</td>
 
<td>3.2</td>
Line 123: Line 135:
 
<td><code>org.eclipse.jface.viewers.ISelection</code></td>
 
<td><code>org.eclipse.jface.viewers.ISelection</code></td>
 
<td>
 
<td>
 +
The current global selection.  It can be used in &lt;test/&gt; elements with <code>org.eclipse.core.expressions.PropertyTester</code>, in programmatic core expressions, and in '''3.3''' with &lt;iterate/&gt; and &lt;count/&lt; elements.
 
</td>
 
</td>
 
<td>3.2</td>
 
<td>3.2</td>
Line 131: Line 144:
 
<td>A <code>java.util.Collection</code> of <code>java.lang.String</code></td>
 
<td>A <code>java.util.Collection</code> of <code>java.lang.String</code></td>
 
<td>
 
<td>
 +
This is the list of IDs of the showing context menu.  Examples are like #TextEditorRuler or a part ID.  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>
 
</td>
 
<td>3.2</td>
 
<td>3.2</td>
Line 139: Line 153:
 
<td><code>org.eclipse.jface.viewers.ISelection</code></td>
 
<td><code>org.eclipse.jface.viewers.ISelection</code></td>
 
<td>
 
<td>
 +
This is a selection that is available while a context menu is showing.  It is the selection from the selection provider used to register the context menu, usually from <code>getSite().registerContextMenu(*)</code>.  It is usually the same as the <code>selection</code>variable, but not always.  This is more for legacy compatibility.
 
</td>
 
</td>
 
<td>3.3</td>
 
<td>3.3</td>
Line 147: Line 162:
 
<td><code>org.eclipse.jface.viewers.ISelection</code></td>
 
<td><code>org.eclipse.jface.viewers.ISelection</code></td>
 
<td>
 
<td>
 +
This is a selection that is available while a context menu is showing.  It is the selection from the editor input, usually if includeEditorInput was set to <code>true</code> during <code>getEditorSite().registerContextMenu(*)</code>.  This is more for legacy compatibility.
 
</td>
 
</td>
 
<td>3.3</td>
 
<td>3.3</td>

Revision as of 09:41, 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

Some of the variables may not be set, depending on the current application context when they are evaluated.

<td>3.2</td> <tr> <td>activeActionSets</td> <td>An IActionSetDescriptor[]</td> <td> Note: This is currently not used as points to an internal class and the type might change in any released. </td> <td>3.2</td> </tr> <tr> <td>activeShell</td> <td>org.eclipse.swt.widgets.Shell</td> <td> The currently active shell. It can be a dialog or workbench window shell. </td> <td>3.2</td> </tr> <tr> <td>activeWorkbenchWindowShell</td> <td>org.eclipse.swt.widgets.Shell</td> <td> The active workbench window shell. </td> <td>3.2</td> </tr> <tr> <td>activeWorkbenchWindow</td> <td>org.eclipse.ui.IWorkbenchWindow</td> <td> The active workbench window. </td> <td>3.2</td> </tr> <tr> <td>activeWorkbenchWindow.isCoolbarVisible</td> <td>java.lang.Boolean</td> <td> Reports coolbar visibility for the currently active workbench window. </td> <td>3.3</td> </tr> <tr> <td>activeWorkbenchWindow.isPerspectiveBarVisible</td> <td>java.lang.Boolean</td> <td> Reports perspective bar visibility for the currently active workbench window. </td> <td>3.3</td> </tr> <tr> <td>activeEditor</td> <td>org.eclipse.ui.IEditorPart</td> <td> The currently active editor. This is remembered even if the editor is not the currently active part. </td> <td>3.2</td> </tr> <tr> <td>activeEditorId</td> <td>java.lang.String</td> <td> The ID of the currently active editor. This can be used for expressions on the editor type. </td> <td>3.2</td> </tr> <tr> <td>activePart</td> <td>org.eclipse.ui.IWorkbenchPart</td> <td> The active part, which can be the same as the active editor. </td> <td>3.2</td> </tr> <tr> <td>activePartId</td> <td>java.lang.String</td> <td> The ID of the currently active part. </td> <td>3.2</td> </tr> <tr> <td>activeSite</td> <td>org.eclipse.ui.IWorkbenchPartSite</td> <td> The site of the currently active part. </td> <td>3.2</td> </tr> <tr> <td>selection</td> <td>org.eclipse.jface.viewers.ISelection</td> <td> The current global selection. It can be used in <test/> elements with org.eclipse.core.expressions.PropertyTester, in programmatic core expressions, and in 3.3 with <iterate/> and <count/< elements. </td> <td>3.2</td> </tr> <tr> <td>activeMenu</td> <td>A java.util.Collection of java.lang.String</td> <td> This is the list of IDs of the showing context menu. Examples are like #TextEditorRuler or a part ID. Most commonly used with <iterate> and <count>, and can also be used with <test> and a org.eclipse.common.expressions.PropertyTester. </td> <td>3.2</td> </tr> <tr> <td>activeMenuSelection</td> <td>org.eclipse.jface.viewers.ISelection</td> <td> This is a selection that is available while a context menu is showing. It is the selection from the selection provider used to register the context menu, usually from getSite().registerContextMenu(*). It is usually the same as the selectionvariable, but not always. This is more for legacy compatibility. </td> <td>3.3</td> </tr> <tr> <td>activeMenuEditorInput</td> <td>org.eclipse.jface.viewers.ISelection</td> <td> This is a selection that is available while a context menu is showing. It is the selection from the editor input, usually if includeEditorInput was set to true during getEditorSite().registerContextMenu(*). This is more for legacy compatibility. </td> <td>3.3</td> </tr> <tr> <td>activeFocusControl</td> <td>org.eclipse.swt.widgets.Control</td> <td> </td> <td>3.3</td> </tr> <tr> <td>activeFocusControlId</td> <td>java.lang.String</td> <td> </td> <td>3.3</td> </tr> </table>

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

Name Type Description Since
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.</code>.