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.
Command Core Expressions/ko
코어 익스프레션은 org.eclipse.core.expresion 플러그인을 기반으로 하는 선언적 혹은 프로그래밍적인 표현식입니다.
Contents
익스프레션과 커맨드 프레임워크
Platform Command Framework은 핸들러나 프로그래밍 문맥의 활성화 등을 위한 enabledWhen과 activeWhen, 그리고 메뉴의 가시성 여부 결정을 위한 visibleWhen에 코어 익스프레션을 이용합니다. 커멘드 프레임워크는 커맨드 코어 익스프레션들이 평가될 수 있는 IEvaluateContext를 제공합니다.
IEvaluationContext는 평가를 위한 기본 변수 및 다양한 변수 이름들을 제공합니다. 특별히 평가 대상을 지정하지 않는 경우, 기본 평가 대상 변수로 전역 선택 목록(Global Selection)이 java.util.Collection
로 제공합니다. (역자: 셀렉션 서비스를 생각하세요) 이 경우 평가 대상은 비어있을 수도 있고 오직 하나의 엔트리만을 가지고 있을 수도 있습니다. (만약 ISelection이 ITextSelection과 같은 것인 경우), 혹은 IStructuredSelection가 될 수도 있습니다.
<with/> 엘리먼트를 지정함으로서 자식(With의) 익스프레션 엘리먼트들이 평가를 수행할 대상을 명시적으로 지정할 수 있습니다.
변수와 커맨드 프레임 워크
커맨드 프레임워크의 평가에 사용되는 변수들은 ISources.java에 목록화 되어있습니다.
몇몇 변수들은 평가 시점의 어플리케이션 문맥에따라 세팅되지 않을 수도 있습니다.
변수명 | 타입 | 설명 | 지원 시작 버전 |
---|---|---|---|
activeContexts | java.lang.String 들로 구성된 java.util.Collection |
활성 문맥ID 들의 리스트입니다. 대체로 <iterate/> and <count/>와 함께 이용됩니다. 또한 |
3.2 |
activeActionSets | IActionSetDescriptor[] |
Note: 이것은 현재 내부 클래스를 가리키고, 그 타입이 언제라도 변경될 수 있으므로 지금은 사용되지 않는다 |
3.2 |
activeShell | org.eclipse.swt.widgets.Shell |
The currently active shell. It can be a dialog or workbench window shell. |
3.2 |
activeWorkbenchWindowShell | org.eclipse.swt.widgets.Shell |
The active workbench window shell. |
3.2 |
activeWorkbenchWindow | org.eclipse.ui.IWorkbenchWindow |
The active workbench window. |
3.2 |
activeWorkbenchWindow.isCoolbarVisible | java.lang.Boolean |
Reports coolbar visibility for the currently active workbench window. |
3.3 |
activeWorkbenchWindow.isPerspectiveBarVisible | java.lang.Boolean |
Reports perspective bar visibility for the currently active workbench window. |
3.3 |
activeEditor | org.eclipse.ui.IEditorPart |
The currently active editor. This is remembered even if the editor is not the currently active part. |
3.2 |
activeEditorId | java.lang.String |
The ID of the currently active editor. This can be used for expressions on the editor type. |
3.2 |
activePart | org.eclipse.ui.IWorkbenchPart |
The active part, which can be the same as the active editor. |
3.2 |
activePartId | java.lang.String |
The ID of the currently active part. |
3.2 |
activeSite | org.eclipse.ui.IWorkbenchPartSite |
The site of the currently active part. |
3.2 |
selection | org.eclipse.jface.viewers.ISelection |
The current global selection. It can be used in <test/> elements with |
3.2 |
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 |
3.2 |
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 |
3.3 |
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 |
3.3 |
activeFocusControl | org.eclipse.swt.widgets.Control |
A control that has focus and has been registered with the IFocusService. |
3.3 |
activeFocusControlId | java.lang.String |
The ID of a control that has focus and has been registered with the |
3.3 |
Property Testers
The Eclipse SDK provides a couple of property testers that can be used in core expressions. The expression defines a property attribute and then takes a combination of args and a value that is tester implementation dependent. The property attribute is the combination of the namespace and property name. For example, to test an IResource name the property would be org.eclipse.core.resources.name
.
Namespace | Type | Implementation |
---|---|---|
org.eclipse.core.runtime |
|
|
Property | Description | |
product |
Test the id of the currently active product. |
|
isBundleInstalled |
Test if a given bundle is installed in the running environment. Use the args attribute to pass in the bundle id. |
|
Namespace | Type | Implementation |
org.eclipse.core.resources |
|
|
Property | Description | |
name |
A property indicating the file name (value |
|
path |
A property indicating the file path (value |
|
extension |
A property indicating the file extension (value |
|
readOnly |
A property indicating whether the file is read only (value |
|
projectNature |
A property indicating the project nature (value |
|
persistentProperty |
A property indicating a persistent property on the selected resource (value |
|
projectPersistentProperty |
A property indicating a persistent property on the selected resource's project. (value |
|
sessionProperty |
A property indicating a session property on the selected resource (value |
|
projectSessionProperty |
A property indicating a session property on the selected resource's project. (value |
|
Namespace | Type | Implementation |
org.eclipse.core.resources |
|
|
Property | Description | |
contentTypeId |
A property indicating that we are looking to verify that the file matches the content type matching the given identifier. The identifier is provided as the expected value. |
|
Namespace | Type | Implementation |
org.eclipse.core.resources |
|
|
Property | Description | |
open |
A property indicating whether the project is open (value |
|
Namespace | Type | Implementation |
org.eclipse.core.resources |
|
|
Property | Description | |
projectPersistentProperty |
A property indicating a persistent property on the selected resource's project. (value |
|
Namespace | Type | Implementation |
org.eclipse.ui |
|
|
Property | Description | |
isActivityEnabled |
Test if the activity in args is enabled. |
|
isCategoryEnabled |
Test if the category in args is enabled. |
|
Namespace | Type | Implementation |
org.eclipse.ui.workbenchWindow |
|
|
Property | Description | |
isPerspectiveOpen |
Tests if any perspective is open. |
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
, org.eclipse.jdt.core.IJavaElement
and other classes. If you are trying to find all of the *.java files, you would need to:
- Iterate through the default variable
- adapt the selection elements to your class, in this case
IResource
- use one of the org.eclipse.core.resources property testers to test the IResource property
For example:
<activeWhen> <iterate> <adapt type="org.eclipse.core.resources.IResource"> <test property="org.eclipse.core.resources.name" value="*.java"/> </adapt> </iterate> </activeWhen>
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.
<activeWhen> <with variable="activeEditorId"> <equals value="org.eclipse.ui.DefaultTextEditor"/> </with> </activeWhen>
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
.
definitions
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"/> </with> </definition> </extension>
Then:
<activeWhen> <reference definitionId="org.eclipse.ui.examples.contributions.view.inView"/> </activeWhen>
The referenced expression will be evaluated at this point.