Basic workbench extension points using commands

Workbench Core Expressions

The workbench uses core expressions (See org.eclipse.core.expressions.definitions for a description) for enabledWhen and activeWhen for handlers, programmatic activation of contexts, and for visibleWhen for menu contributions. Core expressions are also used as conditionals for certain property page contribution and object contribution expressions. In most cases, the workbench provides the IEvaluationContext that command core expressions are evaluate against.

The IEvaluationService provides methods that allow other clients and extension point builders to hook into the workbench core expressions.

Using Core Expressions in the Workbench

Core expressions are used declaratively in the plugin.xml files, and programmatically with some of the services provided in the workbench.

Note: Elements from workbench extension points that use core expressions, like enabledWhen, take one child core expression element. They do not and their elements together.

Declarative Expression Examples

  1. Basic IStructuredSelection
  2. IResources and the Package or Project Explorer
  3. Active Contexts
  4. Active Views and Editor
  5. ActionSets and Contexts

Basic IStructuredSelection

Most of the tree or table like viewers return an IStructuredSelection. For example, the Project Explorer and Package Explorer.

When using the default variable you must treat it as an java.util.Collection. That means using <count> or <iterate>. The expression below returns true if all of the selected items are Person.

This is equivalent to:

The behaviour of iterate is:

  • iterate ands the results of evaluating its child expressions for each element in the collection, unless you set the operator attribute.
  • iterate has the same semantics for its children as <and>
  • iterate with an operator of and returns true if the collection is empty, unless you set the ifEmpty attribute.

If you want to be enabled if only one Person is selected, you can include a count element.

The same expression using the default variable:

IResources and the Package or Project Explorer

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 org.eclipse.core.resources.IResource.
  3. Use one of the org.eclipse.core.resources property testers to test the org.eclipse.core.resources.IResource property.

When working with the current selection and property testers it does not always make sense to use adapt. In these situations it is a good practice to check that the object under test is a valid type for that property tester:

Active Contexts

If your handler should be enabled when your view or editor activates a context, you can use the activeContexts variable. Contexts are defined in the org.eclipse.ui.contexts extension point and activated programmatically using the org.eclipse.ui.contexts.IContextService.

Active Views and Editor

For handlers that are to be contributed to a specific view or editor, you can use activeEditorId and activePartId in the activeWhen clause. This is an example for a handler that should be active in text editors:

 

The following clause is for a handler that's active while in the Project Explorer:

 

ActionSets and Contexts

As of 3.3 all org.eclipse.ui.actionSets generate a context with a parent of org.eclipse.ui.contexts.actionSet. Contexts with href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.ui.preferencePages.Keys)")'> command link, Keys Preference Page General > Keys preference page.

Showing an actionSet activates the matching context. This allows contributed commands to "join" actionSets, like the debug launch actionSet.

Note: commands that are enabled or visible with actionSets are not currently displayed in the Customize Perspective Dialog.

Variables Provided in the Workbench

The IEvaluationService provides the global selection as the default variable (in a java.util.Collection) for expression evaluation. It can either be empty, have one entry (if the ISelection was something like an ITextSelection), or have the contents of an IStructuredSelection.

The workbench publishes variables in ISources that can be used in the <with/> element and can be retrieved from the IEvaluationContext. Some of the variables may not be set, depending on the current application context when they are evaluated. The following table explains some of the more commonly used ones:

NameTypeDescriptionSince
activeContextsA java.util.Collection of java.lang.String

This is a collection of the active context IDs as strings. Most commonly used with <iterate/>, <count/>, and <test/> with a combined org.eclipse.core.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.

3.2
activeShellorg.eclipse.swt.widgets.Shell

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

3.2
activeWorkbenchWindowShellorg.eclipse.swt.widgets.Shell

The active workbench window shell.

3.2
activeWorkbenchWindoworg.eclipse.ui.IWorkbenchWindow

The active workbench window.

3.2
activeWorkbenchWindow.isCoolbarVisiblejava.lang.Boolean

Reports coolbar visibility for the currently active workbench window.

3.3
activeWorkbenchWindow.isPerspectiveBarVisiblejava.lang.Boolean

Reports perspective bar visibility for the currently active workbench window.

3.3
activeWorkbenchWindow.activePerspectivejava.lang.String

Reports the name of the current perspective of the active workbench window.

3.4
activeEditororg.eclipse.ui.IEditorPart

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

3.2
activeEditorIdjava.lang.String

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

3.2
activeEditorInputorg.eclipse.ui.IEditorInput

The input of the currently active editor. This is useful for property testers.

3.5
activePartorg.eclipse.ui.IWorkbenchPart

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

3.2
activePartIdjava.lang.String

The ID of the currently active part.

3.2
activeSiteorg.eclipse.ui.IWorkbenchPartSite

The site of the currently active part.

3.2
selectionorg.eclipse.jface.viewers.ISelection

The current global selection. It is often used with <test/> elements with org.eclipse.core.expressions.PropertyTester, in programmatic core expressions, and in 3.3 with <iterate/> and <count/> elements.

3.2
activeMenuA 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/>, <count/>, and <test/> with a combined org.eclipse.core.expressions.PropertyTester.

3.2
activeMenuSelectionorg.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.

3.3
activeMenuEditorInputorg.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(*).

3.3
activeFocusControlorg.eclipse.swt.widgets.Control

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

3.3
activeFocusControlIdjava.lang.String

The ID of a control that has focus and has been registered with the IFocusService.

3.3
org.eclipse.core.runtime.Platformorg.eclipse.core.runtime.Platform

The runtime Platform class is available, for use with property testers like org.eclipse.core.runtime.isBundleInstalled and org.eclipse.core.runtime.product.

3.3

Property Testers Provided in the Workbench

The workbench 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.

NamespaceTypeImplementation
org.eclipse.core.runtime

org.eclipse.core.runtime.Platform

org.eclipse.core.internal.expressions.propertytester.PlatformPropertyTester
PropertyDescription

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.

 

NamespaceTypeImplementation
org.eclipse.core.resources

org.eclipse.core.resources.IResource

org.eclipse.core.internal.propertytester.ResourcePropertyTester
PropertyDescription

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.

 
NamespaceTypeImplementation
org.eclipse.core.resources

org.eclipse.core.resources.IFile

org.eclipse.core.internal.propertytester.FilePropertyTester
PropertyDescription

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.

 
NamespaceTypeImplementation
org.eclipse.core.resources

org.eclipse.core.resources.IProject

org.eclipse.core.internal.propertytester.ProjectPropertyTester
PropertyDescription

open

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

 
NamespaceTypeImplementation
org.eclipse.core.resources

org.eclipse.core.resources.mapping.ResourceMapping

org.eclipse.core.internal.propertytester.ResourceMappingPropertyTester
PropertyDescription

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.

 
NamespaceTypeImplementation
org.eclipse.ui

org.eclipse.ui.IWorkbench (not currently available)

org.eclipse.ui.internal.activities.ActivityPropertyTester
PropertyDescription

isActivityEnabled

Test if the activity in args is enabled.

isCategoryEnabled

Test if the category in args is enabled.

 
NamespaceTypeImplementation
org.eclipse.ui.workbenchWindow

org.eclipse.ui.IWorkbenchWindow

org.eclipse.ui.internal.OpenPerspectivePropertyTester
PropertyDescription

isPerspectiveOpen

Tests if any perspective is open.

备注:本文转载自:http://www.linuxtopia.org/online_books/eclipse_documentation/eclipse_platform_plug-in_developer_guide/topic/org.eclipse.platform.doc.isv/guide/eclipse_platform_plugin_workbench_cmd_expressions.htm

深度学习是机器学习的一个子领域,它基于人工神经网络的研究,特别是利用多层次的神经网络来进行学习和模式识别。深度学习模型能够学习数据的高层次特征,这些特征对于图像和语音识别、自然语言处理、医学图像分析等应用至关重要。以下是深度学习的一些关键概念和组成部分: 1. **神经网络(Neural Networks)**:深度学习的基础是人工神经网络,它是由多个层组成的网络结构,包括输入层、隐藏层和输出层。每个层由多个神经元组成,神经元之间通过权重连接。 2. **前馈神经网络(Feedforward Neural Networks)**:这是最常见的神经网络类型,信息从输入层流向隐藏层,最终到达输出层。 3. **卷积神经网络(Convolutional Neural Networks, CNNs)**:这种网络特别适合处理具有网格结构的数据,如图像。它们使用卷积层来提取图像的特征。 4. **循环神经网络(Recurrent Neural Networks, RNNs)**:这种网络能够处理序列数据,如时间序列或自然语言,因为它们具有记忆功能,能够捕捉数据中的时间依赖性。 5. **长短期记忆网络(Long Short-Term Memory, LSTM)**:LSTM 是一种特殊的 RNN,它能够学习长期依赖关系,非常适合复杂的序列预测任务。 6. **生成对抗网络(Generative Adversarial Networks, GANs)**:由两个网络组成,一个生成器和一个判别器,它们相互竞争,生成器生成数据,判别器评估数据的真实性。 7. **深度学习框架**:如 TensorFlow、Keras、PyTorch 等,这些框架提供了构建、训练和部署深度学习模型的工具和库。 8. **激活函数(Activation Functions)**:如 ReLU、Sigmoid、Tanh 等,它们在神经网络中用于添加非线性,使得网络能够学习复杂的函数。 9. **损失函数(Loss Functions)**:用于评估模型的预测与真实值之间的差异,常见的损失函数包括均方误差(MSE)、交叉熵(Cross-Entropy)等。 10. **优化算法(Optimization Algorithms)**:如梯度下降(Gradient Descent)、随机梯度下降(SGD)、Adam 等,用于更新网络权重,以最小化损失函数。 11. **正则化(Regularization)**:技术如 Dropout、L1/L2 正则化等,用于防止模型过拟合。 12. **迁移学习(Transfer Learning)**:利用在一个任务上训练好的模型来提高另一个相关任务的性能。 深度学习在许多领域都取得了显著的成就,但它也面临着一些挑战,如对大量数据的依赖、模型的解释性差、计算资源消耗大等。研究人员正在不断探索新的方法来解决这些问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值