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

Command Core Expressions/ko

코어 익스프레션은 org.eclipse.core.expresion 플러그인을 기반으로 하는 선언적 혹은 프로그래밍적인 표현식입니다.

익스프레션과 커맨드 프레임워크

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/>와 함께 이용됩니다. 또한 org.eclipse.common.expressions.PropertyTester와 함께 사용될 수도 있습니다. 3.3버전의 Action Set들은 org.eclipse.ui.actionSet를 부모로하는 문맥에 의해 미러링되어, 활성 문맥안에서 리스트 형태로 존재하게 됩니다.

3.2
activeActionSets IActionSetDescriptor[]

Note: 이것은 현재 내부 클래스를 가리키고, 그 타입이 언제라도 변경될 수 있으므로 지금은 사용되지 않는다

3.2
activeShell org.eclipse.swt.widgets.Shell

현재 활성화된 쉘, 다이얼로그나 워크벤치 윈도우 쉘이 될 수 있습니다.

3.2
activeWorkbenchWindowShell org.eclipse.swt.widgets.Shell

현재 활성화된 워크벤치 윈도우 쉘.

3.2
activeWorkbenchWindow org.eclipse.ui.IWorkbenchWindow

활성화된 워크밴치 윈도우.

3.2
activeWorkbenchWindow.isCoolbarVisible java.lang.Boolean

활성화된 워크밴치의 쿨바 가시성 여부.

3.3
activeWorkbenchWindow.isPerspectiveBarVisible java.lang.Boolean

현재 워크밴치 윈도우의 퍼스펙티브바 가시성 여부.

3.3
activeEditor org.eclipse.ui.IEditorPart

현재 활성화된 에디터. 에디터 파트가 아니라 뷰파트가 활성화되있더라도 마지막 에디터 파트가 기억됩니다.

3.2
activeEditorId java.lang.String

활성화된 에디터의 ID. 에디터의 타입을 평가하기 위해 사용할 수 있습니다.r expressions on the editor type.

3.2
activePart org.eclipse.ui.IWorkbenchPart

활성화된 Part.

3.2
activePartId java.lang.String

활성화된 Part의 ID.

3.2
activeSite org.eclipse.ui.IWorkbenchPartSite

활성화된 파트의 Site.

3.2
selection org.eclipse.jface.viewers.ISelection

전역 선택 목록. <test/>엘리먼트 안이나 프로그래밍적인 코어 익스프레션에서 org.eclipse.core.expressions.PropertyTester와 함께 이용될 수 있습니다. 3.3버전부터 <test/>와 함께 <iterate/> 와 <count/>도 함께 쓸 수 있습니다.

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

현재 보여지고 있는 문맥 메뉴의 ID리스트. #TextEditorRuler나 Part ID같은 예가 있을 수 있습니다. 대게 <iterate>, <count>와 함께 이용됩니다. <test>, org.eclipse.common.expressions.PropertyTester와 함께 이용할 수도 있습니다.

3.2
activeMenuSelection org.eclipse.jface.viewers.ISelection

팝업 메뉴가 보이는 동안 사용가능한 셀렉션입니다. 셀렉션 프로바이더에 등록된 팝업 메뉴의 셀렉션을 가리키며 보통 getSite().registerContextMenu(*)를 통해 등록됩니다. 이것은 대체로 selection 변수와 동일한 것 같지만 항상 그렇지는 않습니다. 좀더 레거시한 호환성을 보장합니다.

3.3
activeMenuEditorInput org.eclipse.jface.viewers.ISelection

에디터 영역에서 팝업 메뉴가 보이는 동안 사용가능한 셀렉션입니다. 이 셀렉션은 에디터 인풋으로 부터 가져옵니다. Selection보다 좀 더 Legacy한 호환성을 제공합니다.

3.3
activeFocusControl org.eclipse.swt.widgets.Control

IFocusService에 등록된 포커스를 획득한 Control객체 입니다.

3.3
activeFocusControlId java.lang.String

org.eclipse.ui.swt.IFocusService에 등록된 포커스를 획득한 Control의 ID를 가리킵니다.

3.3

프로퍼티 테스터

이클립스 SK는 코어 익스프레션에서 사용할 수 있는 몇개의 프로퍼티 테스터를 제공합니다. 익스프레션에서 프로퍼티 애트리뷰트를 지정하고, 테스터의 구현에 따라 아큐먼트의 조합을 가지게 됩니다. 프로퍼티 애트리뷰트는 네임스페이스와 프로퍼티 이름의 조합으로 이루어집니다. 예를 들어 IResouce의 name을 테스트하기 위해 프로퍼티 애트리뷰트는 org.eclipse.core.resources.name와 같이 나타내어야 합니다.

Namespace Type Implementation
org.eclipse.core.runtime

org.eclipse.core.runtime.Platform

PlatformPropertyTester.java

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

org.eclipse.core.resources.IResource

ResourcePropertyTester.java

Property Description

name

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

path

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

extension

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

readOnly

A property indicating whether the file is read only (value "readOnly").

projectNature

A property indicating the project nature (value "projectNature").

persistentProperty

A property indicating a persistent property on the selected resource (value "persistentProperty"). If two arguments are given, this treats the first as the property name, and the second as the expected property value. If only one argument (or just the expected value) is given, this treats it as the property name, and simply tests for existence of the property on the resource.

projectPersistentProperty

A property indicating a persistent property on the selected resource's project. (value "projectPersistentProperty"). If two arguments are given, this treats the first as the property name, and the second as the expected property value. If only one argument (or just the expected value) is given, this treats it as the property name, and simply tests for existence of the property on the resource.

sessionProperty

A property indicating a session property on the selected resource (value "sessionProperty"). If two arguments are given, this treats the first as the property name, and the second as the expected property value. If only one argument (or just the expected value) is given, this treats it as the property name, and simply tests for existence of the property on the resource.

projectSessionProperty

A property indicating a session property on the selected resource's project. (value "projectSessionProperty"). If two arguments are given, this treats the first as the property name, and the second as the expected property value. If only one argument (or just the expected value) is given, this treats it as the property name, and simply tests for existence of the property on the resource.

Namespace Type Implementation
org.eclipse.core.resources

org.eclipse.core.resources.IFile

FilePropertyTester.java

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

org.eclipse.core.resources.IProject

ProjectPropertyTester.java

Property Description

open

A property indicating whether the project is open (value "open").

Namespace Type Implementation
org.eclipse.core.resources

org.eclipse.core.resources.mapping.ResourceMapping

ResourceMappingPropertyTester.java

Property Description

projectPersistentProperty

A property indicating a persistent property on the selected resource's project. (value "projectPersistentProperty"). If two arguments are given, this treats the first as the property name, and the second as the expected property value. If only one argument (or just the expected value) is given, this treats it as the property name, and simply tests for existence of the property on the resource.

Namespace Type Implementation
org.eclipse.ui

org.eclipse.ui.IWorkbench

ActivityPropertyTester.java

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

org.eclipse.ui.IWorkbenchWindow

OpenPerspectivePropertyTester.java

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:

  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:

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

3.3 버전에서의 새로운 코어 익스프레션

3.3 버전에서 두개의 새로운 코어 익스프레션이 추가되었습니다.

count 와 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.

Back to the top