`
lizhensan
  • 浏览: 378642 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

Part 1: Actions Vs Commands

 
阅读更多

源:http://blog.eclipse-tips.com/2009/01/commands-part-1-actions-vs-commands.html

 

eclipse 有两种方式创建Workbench的菜单。Actions and Commands

 

Commands 虽然是最新新更新的、强大的,可是我还是喜欢用Actions ,就是因为我习惯了Actions的用法。

 

 

现在我们就开始研究一下Command framework。

我深入的研究了下Command framework,我发现这东西确实好,我决定写一系列这方面的文章。

假如有哪些写的不对的。望大家多多指教。

 

 

我们用Action 可以去创建 toolbar  menu  downmenu  (popup)

我们可以在plugin.xml指定它们的一些细节,如 标签、提示、帮助、懒加载等。

用这种方式去实现的缺点在哪里呢?

 

1:ui与handler  总是系在一起,不可以彻底的分开。

2:不可以在不同的part中实现( toolbar  menu  downmenu  (popup)),还得必须在plugin.xml写重复的xml。

3:假如说有一个action需要更改,要更新所有重复的action配置。

4:另外就是在plugin中重复的action定义,在启动初始化的时候会被加载多个实例在内存中。

 

让我们看看Command framework是如何消除以上问题的。

 

 

Commands  是通过org.eclipse.ui.commands  扩展点定义的。

一个典型的command定义如下:

<command 
         id="com.eclipse-tips.commands.someCommand" 
         name="Some Command"> 
</command>


现在我们定义了一个command,假如想在某个地方创建  toolbar、menu等,需要通过org.eclipse.ui.menus

扩展点来创建,代码如下:

<menuContribution 
      locationURI="toolbar:org.eclipse.ui.main.toolbar"> 
   <toolbar 
         id="com.eclipse-tips.commands.toolbar1"> 
      <command 
            commandId="com.eclipse-tips.commands.someCommand" 
            id="com.eclipse-tips.commands.someCommandInToolBar"> 
      </command> 
   </toolbar> 
</menuContribution>

 

现在我们已经在创建中创建了一个toolbar,菜单的执行代码在哪里呢?这时候需要用到org.eclipse.ui.handlers扩展点来实现。代码如下:

<handler 
         class="com.eclipse_tips.commads.SomeCommandHandler" 
         commandId="com.eclipse-tips.commands.someCommand"> 
</handler> 

 

最后我们添加一个图标都command中,需要用org.eclipse.ui.commandImages扩展点来实现。

代码如下:

<image 
         commandId="com.eclipse-tips.commands.someCommand" 
         icon="icons/sample.gif"> 
</image>
 

 

现在让我们看看效果怎么样.


 

以前我们是通过一个扩展点搞定的东西。现在我们用了4个扩展点来实现。

 

 

 

 

  • 大小: 7.3 KB
分享到:
评论

相关推荐

    ISO 14229-1-2013.pdf

    ### ISO 14229-1:2013 – Road Vehicles – Unified Diagnostic Services (UDS) – Part 1: Specification and Requirements #### Overview ISO 14229-1:2013 is an international standard that defines the ...

    UG6.0快捷键大全

    MESSAGE Copies a feature so that it can be pasted either within the same part or to another. SYNONYMS duplicate, repeat HINT This command is available in history modeling mode. ACTIONS STANDARD ...

    Microsoft SharePoint 2010 Developer Reference

    - **Custom Actions:** Custom actions extend the SharePoint user interface by adding new commands or modifying existing ones. - **Ribbons:** Ribbons provide a customizable toolbar for SharePoint pages....

    Manning - Eclipse In Action.pdf

    **Chapter 1: Overview** - **Brief History of Eclipse**: The chapter begins with a brief history of Eclipse, highlighting its origins as an open-source project initiated by IBM. It evolved into a ...

    sed-awk-2nd-edition.chm

    After getting started by writing a few simple scripts, you'll learn other basic commands that parallel manual editing actions, as well as advanced commands that introduce simple programming ...

    Oracle Database 10g PL-SQL Programming

    #### 1. Introduction to PL/SQL PL/SQL (Procedural Language for SQL) is a procedural extension to SQL that provides a powerful way to manipulate data within the Oracle database environment. This ...

    Cours-VB-NET-2010-Developpez-com

    Instructions are single commands in VB.NET, such as assigning a value to a variable or displaying text on a label. ##### 2. Procedures Procedures are blocks of code that perform specific tasks. There...

    EurekaLog_7.5.0.0_Enterprise

    34)..Changed: EurekaLog 7 now can be installed over EurekaLog 6 automatically, with no additional actions/tools EurekaLog 7.4 (7.4.0.0), 26-January-2016 1)....Fixed: Performance issue in DLL exports...

    sed_awk.chm

    The basic commands are commands that parallel manual editing actions, while the advanced commands introduce simple programming capabilities. Among the advanced commands are those that manipulate the ...

    RCP学习资料.zip

    5. **工作流和命令**:在RCP中,工作流(Workbench Actions)和命令(Commands)系统负责处理用户操作。理解如何定义和关联命令,以及如何在不同视图和编辑器间传递命令,是构建交互性强的RCP应用的关键。 6. **...

    最新Ehlib 5.2.84(含完整源代码,支持delphi XE)

    panel at the top part of the grid. Then the panel is thisible it is allowed to form group levels by mouse. Drag title of the requaried column to the group panel and drop it onto panel. Font: ...

    R for beginner

    While loops are a fundamental part of programming, R emphasizes vectorized operations, which are more efficient and easier to read. For example, instead of using a loop to sum the elements of a vector...

    gvim常用插件及其配置文件配置(下载解压即可使用)

    customizing-menus.html latex-completion.html package-actions.html customizing-packages.html latex-folding.html part-compiling.html customizing-place-holders....

    2009 达内Unix学习笔记

    显示文件的权限、硬链接数(即包含文件数,普通文件是1,目录1+)、用户、组名、大小、修改日期、文件名。 ls -t (time)按修改时间排序,显示目录和文件。 ls -lt 是“-l”和“-t”的组合,按时间顺序显示列表。 ls...

    Turbo C 2.01[DISK]

    1. How to Get Help 2. Installation 3. Important Notes 4. Additional Notes 5. Notes for Turbo Prolog Users 6. Files on the Disks 1. HOW TO GET HELP ------------------- If you have any ...

    Turbo C 2.00[DISK]

    1. How to Get Help 2. Installation 3. Important Notes 4. Corrections to the Manuals 5. Additional Notes 6. Notes for Turbo Prolog Users 7. Files on the Disks 1. HOW TO GET HELP -------------...

    python3.6.5参考手册 chm

    Text Vs. Data Instead Of Unicode Vs. 8-bit Overview Of Syntax Changes New Syntax Changed Syntax Removed Syntax Changes Already Present In Python 2.6 Library Changes PEP 3101: A New Approach To ...

    Tornado Train Workshop

    and to synchronize the actions of different tasks. • Use timers for periodic code execution. • Differentiate between the standard I/O library, the formatted I/O library, and the basic I/O system. •...

    Universal-USB-Installer

    c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an ...

Global site tag (gtag.js) - Google Analytics