Eclipse RCP:操作VS命令 [英] Eclipse RCP: Actions VS Commands

查看:247
本文介绍了Eclipse RCP:操作VS命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Eclipse RCP的上下文中,操作和命令之间有什么区别?我知道他们都有助于菜单项,但哪一个更好?为什么?



在我阅读的所有在线资源中,我无法确切了解两者之间的差异。



感谢

div class =h2_lin>解决方案

您阅读了日食wiki 详细说明差异



操作




  • UI和处理始终绑定

  • 虽然操作可以用于工作台的不同部分(弹出式菜单/工具栏),但所有这些都是不同的扩展点,所以你最终在多个地方复制XML。

  • 在多个地方指定操作是一个维护噩梦。如果您必须更改操作的图标,则需要在所有地方更改。

  • 在plugin.xml中复制操作的另一个问题是将在内存中创建相同操作的多个实例



命令涉及更多扩展点,但是:




  • 从命令。

  • 对所有处理程序的 activeWhen 进行求值,并返回true的处理程序声明
  • 选择最具体的条件。所有这些事情都是完成,甚至不会在内存中加载你的处理程序。即使没有加载插件
  • 定义参数是关于返回显示名称和地图的地图。 ids。

  • 定义一个IExecutionListener,它只是该命令的观察者


What are differences between Actions and Commands in the context of Eclipse RCP? I know that they both contribute to the menu entries, but which one is better? And why?

Of all the online resources I read, I could not get a firm understanding of the differences between both. I have not actually tried to use them, but just wanted to understand them to start with from higher level point of view.

Thanks

解决方案

Did you read the eclipse wiki FAQ What is the difference between a command and an action?

You probably already understand that Actions and Commands basically do the same thing: They cause a certain piece of code to be executed. They are triggered, mainly, from artificats within the user interface

The main concern with Actions is that the manifestation and the code is all stored in the Action.
Although there is some separation in Action Delegates, they are still connected to the underlying action. Selection events are passed to Actions so that they can change their enabled state (programmatically) based on the current selection. This is not very elegant. Also to place an action on a certain workbench part you have to use several extension points.

Commands pretty much solve all these issues. The basic idea is that the Command is just the abstract idea of some code to be executed. The actual handling of the code is done by, well, handlers. Handlers are activated by a certain state of the workbench. This state is queried by the platform core expressions. This means that we only need one global Save command which behaves differently based on which handler is currently active.

This article details the differences

Actions:

  • The UI and handling are always tied. There is no way you can separate each other
  • While Actions can be contributed to different parts of the workbench (popup menu/tool bar), all of them were different extension points and so you end up duplicating the XML in multiple places. The worst of it is that not all the extension points expect the same configuration.
  • Specifying Actions in multiple places is a maintenance nightmare. If you have to change the icon of an action, you need to change in all the places.
  • Another issue with duplicating Actions in plugin.xml is that multiple instance of the same Actions will be created in the memory.

Commands involve more extension points, but:

  • Handler can be declared separately from a Command. This enables for multiple handler declarations for the same command.
  • The activeWhen for all the handlers are evaluated and the one that returns true for the most specific condition is selected. All these things are done without even loading your handler in the memory. Even without loading your plugin!
  • Defining the parameters is all about returning a map of display names & the ids. The name would be displayed in the key bindings page and the id would be used to invoke the command when the key sequence is pressed.
  • Define an IExecutionListener, which is merely an observer of the command execution so it can neither veto on it nor make any changes to the event

这篇关于Eclipse RCP:操作VS命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆