Skip to main content
Jump to: navigation, search

Command Core Expressions

Revision as of 10:02, 14 June 2007 by (Talk | contribs) (Property Testers)

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

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

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. In 3.3 action sets are mirrored by contexts whose parent is org.eclipse.ui.actionSet, and the active action sets show up in the list of active contexts.

activeActionSets An IActionSetDescriptor[]

Note: This is currently not used as points to an internal class and the type might change in any released.

activeShell org.eclipse.swt.widgets.Shell

The currently active shell. It can be a dialog or workbench window shell.

activeWorkbenchWindowShell org.eclipse.swt.widgets.Shell

The active workbench window shell.

activeWorkbenchWindow org.eclipse.ui.IWorkbenchWindow

The active workbench window.

activeWorkbenchWindow.isCoolbarVisible java.lang.Boolean

Reports coolbar visibility for the currently active workbench window.

activeWorkbenchWindow.isPerspectiveBarVisible java.lang.Boolean

Reports perspective bar visibility for the currently active workbench window.

activeEditor org.eclipse.ui.IEditorPart

The currently active editor. This is remembered even if the editor is not the currently active part.

activeEditorId java.lang.String

The ID of the currently active editor. This can be used for expressions on the editor type.

activePart org.eclipse.ui.IWorkbenchPart

The active part, which can be the same as the active editor.

activePartId java.lang.String

The ID of the currently active part.

activeSite org.eclipse.ui.IWorkbenchPartSite

The site of the currently active part.

selection org.eclipse.jface.viewers.ISelection

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.

activeMenu A java.util.Collection of java.lang.String

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.

activeMenuSelection org.eclipse.jface.viewers.ISelection

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.

activeMenuEditorInput org.eclipse.jface.viewers.ISelection

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.

activeFocusControl org.eclipse.swt.widgets.Control

A control that has focus and has been registered with the IFocusService.

activeFocusControlId java.lang.String

The ID of a control that has focus and has been registered with the org.eclipse.ui.swt.IFocusService.


Property Testers

The Eclipse SDK provides a couple of property testers that can be used in core expressions.

Namespace Type Implementation


Property Description


Test the id of the currently active product.


Test if a given bundle is installed in the running environment. Use the args attribute to pass in the bundle id.

Namespace Type Implementation


Property Description


A property indicating the file name (value "name"). "*" and "?" wild cards are supported.










example info x

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 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>

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

Package Explorer IStructuredSelection

The Package Explorer is a mixture of org.eclipse.core.resources.IResource, org.eclipse.jdt.core.IJavaElement and other classes. If you are trying to find all of the *.java files, you would need to:

  1. Iterate through the default variable
  2. adapt the selection elements to your class, in this case IResource
  3. use one of the org.eclipse.core.resources property testers to test the IResource property

For example:

      <adapt type="org.eclipse.core.resources.IResource">
         <test property="" 

Active editor type

If you want your handler to be active for a specific type of editor, you can use activeEditorId to target your handler.

   <with variable="activeEditorId">
      <equals value="org.eclipse.ui.DefaultTextEditor"/>

New Core Expressions in 3.3

In 3.3 there were 2 additions to the core expressions framework.

count and iterate

Count and iterate have always worked against java.util.Collection. The <count/> and <iterate> elements can now be used on any variable that adapts to org.eclipse.core.expressions.ICountable and org.eclipse.core.expressions.IIterable or implements the interfaces directly. It wasn't possible to use the java 1.5 constructs for iterable.

The workbench provides an adapter for ISelection and IStructuredSelection.


The org.eclipse.core.expressions.definitions extension point was introduced. You can create core expression definitions, and then reference them from other core expressions.

<extension point="org.eclipse.core.expressions.definitions">
   <definition id="org.eclipse.ui.examples.contributions.view.inView">
      <with variable="activePartId">
         <equals value="org.eclipse.ui.examples.contributions.view"/>


   <reference definitionId="org.eclipse.ui.examples.contributions.view.inView"/>

The referenced expression will be evaluated at this point.

Back to the top