??xml version="1.0" encoding="utf-8" standalone="yes"?>www.91精品,欧美jizz18,亚洲欧美综合精品久久成人http://www.aygfsteel.com/jacky9881/archive/2010/07/09/keybind.html玩{Java玩{JavaFri, 09 Jul 2010 12:52:00 GMThttp://www.aygfsteel.com/jacky9881/archive/2010/07/09/keybind.htmlhttp://www.aygfsteel.com/jacky9881/comments/325681.htmlhttp://www.aygfsteel.com/jacky9881/archive/2010/07/09/keybind.html#Feedback0http://www.aygfsteel.com/jacky9881/comments/commentRss/325681.htmlhttp://www.aygfsteel.com/jacky9881/services/trackbacks/325681.html org.eclipse.ui.bindings
org.eclipse.ui.contexts

扩展点org.eclipse.ui.bindings是给command增加快捷键,l合Q介l二Q,l命令com.xxxx.test.command1增加快捷键,
CZ代码如下Q?br />
<extension
         
point="org.eclipse.ui.bindings">
      
<key
            
commandId="com.xxxx.test.command1"
            contextId
="org.eclipse.ui.contexts.window"
            schemeId
="org.eclipse.ui.defaultAcceleratorConfiguration"
            sequence
="M2+F7">
      
</key>  
</extension>

q样快捷键Shift+F7在Eclipse工作C都会(x)起作用,但是如果惌命o(h)的快捷键只对特定的视图或者编辑器起作用,那么可以通过org.eclipse.ui.contexts扩展Ҏ(gu)自定义上下文?br />
<extension
           
point="org.eclipse.ui.contexts">
        
<context
              
id="viewmenu.testcontext"
              name
="ViewContext"
              parentId
="org.eclipse.ui.contexts.window">
        
</context>
</extension>

扩展之后Q需要修改org.eclipse.ui.bindings扩展中的contextId属性ؓ(f)viewmenu.testcontext?/span>

另外q需要在需要增加该快捷键的~辑器或者视囑֯应类中增加如下代码(视图cd代码的createControlҎ(gu)Q编辑器cd代码的initҎ(gu)Q:(x)

IContextService contextService = 
(IContextService) getSite().getService(IContextService.
class);
contextService.activateContext(
"viewmenu.testcontext");


玩{Java 2010-07-09 20:52 发表评论
]]>
转蝲 Eclipse 插g开?-- 深入理解菜单QMenuQ功能及(qing)其扩展点http://www.aygfsteel.com/jacky9881/archive/2010/07/03/menu.html玩{Java玩{JavaSat, 03 Jul 2010 08:00:00 GMThttp://www.aygfsteel.com/jacky9881/archive/2010/07/03/menu.htmlhttp://www.aygfsteel.com/jacky9881/comments/325151.htmlhttp://www.aygfsteel.com/jacky9881/archive/2010/07/03/menu.html#Feedback0http://www.aygfsteel.com/jacky9881/comments/commentRss/325151.htmlhttp://www.aygfsteel.com/jacky9881/services/trackbacks/325151.html

菜单是各UY件及(qing)开发^C(x)提供的必备功能,Eclipse 也不例外Q提供了(jin)丰富的菜单,包括主菜单(Main MenuQ,视图 / ~辑器菜单(ViewPart/Editor MenuQ和上下文菜单(Context MenuQ。在 Eclipse 中,几乎所有的 Workbench Part 提供?jin)h性化的菜单,大大方便?jin)用L(fng)操作。因此,如何扩展 Eclipse 的菜单功能,q实现特定于我们自己插g的菜单,是插件开发者必L握的重要技能,同时QEclipse 提供?jin)丰富的扩展点供开发h员用。本文将首先介绍 Eclipse 中的菜单Q然后详l说明如何进行扩展,最后以一个实例的形式引导读者深入理?Eclipse 的菜单功能?/p>

  引言

  Eclipse h丰富的菜单功能,l开发h员提供了(jin)很好的用户体验。M而言QEclipse 菜单U类包括视图 / ~辑器菜单,主菜单(Main MenuQ,视图 / ~辑器菜单(ViewPart/EditorPart MenuQ和上下文菜单(Context MenuQ。插件开发h员通过灉|应用q些菜单Q可以给用户提供很好的体验。由于视囑֒~辑器菜单功能类|因此本文重点讲述视图菜单Q视图下拉菜单及(qing)其工h菜单Q,除此之外Q还讲qC菜单和上下文菜单?/p>

  如图 1 所CZؓ(f) Project Explorer 视图的菜单,包括视图下拉菜单和工h菜单Q折叠树(wi)节点Q。通常而言Q出现在视图工具栏的菜单都会(x)出现在视囄下拉菜单Q也是_(d)比较常用的视图菜单放在视囄工具栏?/p>

?1. Project Explorer 视图的菜?/p>

 

 

  如图 2 所CZؓ(f) Project Explorer 视图中的上下文菜单,只有当我们右键点?yn)L才会(x)出现。通常而言Q出现频率较高的菜单Ҏ(gu)?x)出现在菜单中。上下文菜单h很强的灵z项Q它可以随着我们点击的对象不同,弹出的菜单也?x)有相应的变化?/p>

?2. Project Explorer 视图中的上下文菜?/p>


  如图 3 所CZؓ(f) Eclipse 的主菜单Q包括最上面的主菜单(不可UdQ及(qing)其下面的工具栏菜单(可以UdQƈ?Eclipse 提供?jin)显C?/ 不显C些菜单的功能Q,Eclipse q不我们为每一个插仉d新的主菜单,q样Ҏ(gu)造成冗余Q而且不方便用h作。通常Q我们可以把菜单Ҏ(gu)加到 Eclipse 已有的菜单,如插件的查找功能可以d一个查找菜单项?Eclipse ?Search 主菜单上?/p>

?3. Eclipse 的主菜单


  前面讲到 Eclipse 的各U菜单,那么Q如何在开发插件或 RCP 应用E序的时候添加这些菜单?本文下面的篇q将详细介绍如何扩展 Eclipse 的菜单功能,使读者深入了(jin)?Eclipse 的菜单功能,q能够开发具有这些菜单的应用E序。因此,必须掌握三方面的内容Q菜单种c,菜单的扩展点Q菜单控Ӟ昄 / 隐藏或启?/ 用菜单)(j)。下面从概念上介l这三方面内容,下一节会(x)q行详细介绍?/p>

  菜单U类

  正如前面所讲到的,Eclipse 的菜单包括视图菜单,主菜单及(qing)上下文菜单三个种cR?/p>

  菜单的扩展?/p>

  Eclipse 提供?jin)两U扩展点供用h加菜单项到相应的位置。这两种扩展点ؓ(f) org.eclipse.ui.commandsQ本文简UCؓ(f) Commands 方式Q和 org.eclipse.ui.actionSetsQ本文简UCؓ(f) Actions 方式Q。Actions 方式为界面上不同区域的表现方式提供了(jin)相应的扩展点Qƈ且没有分d界面表现和内在实现。恰恰相反,Commands 方式通过三步有效的达到界面表现和内部实现的分:(x)首先Q通过 org.eclipse.ui.commands 扩展点创建命令和cdQCategoryQ,q且可以把某些命令放在一个类别(CategoryQ中Q然后,通过 org.eclipse.ui.menus 指定命o(h)出现在界面的哪个区域Q视图菜?/ 主菜?/ 上下文菜单)(j)Q最后通过 org.eclipse.ui.handlers 指定命o(h)的实现。因此,Eclipse 推荐新开发的插g使用 Commands 来创建?zhn)的界面菜单。当?dng)׃?Actions 在现有的插g中用得比较多Q如果我们需要扩展或Z之前的插件开发,也需要对其进行了(jin)解。除此之外,针对上下文菜单,虽然 Commands ?Actions 方式均可以创Z下文菜单Q但?Eclipse q提供了(jin)另外一U创Z下文菜单的扩展点 org.eclipse.ui.popupMenusQ本文简UCؓ(f) popupMenus 方式Q,本文就q三U扩展点做详l的介绍?/p>

  菜单控制

  菜单控制是一个非常常见的功能Q例如,随着选定的内Ҏ(gu)当前H口的不同,菜单中的菜单会(x)有相应的变化Q显C?/ 隐藏或启?/ 用菜单)(j)Q因此,如何控制菜单是插件开发h员必L握的知识。Eclipse 单控制提供了(jin)两种Ҏ(gu)Q一U是通过扩展点;另一U是通过 API 的方式编写程序控制?/p>

  Eclipse 菜单功能?qing)其扩展?/p>

  xQ我们对 Eclipse 菜单有了(jin)感观的认识。由上一节我们可知,要深入理?Eclipse 菜单功能Q我们需要从三个斚wL握:(x)菜单U类Q菜单的扩展点和菜单控制。下面将q行详细讲述?/p>

  菜单U类

  针对各种菜单QEclipse 提供?jin)相应的扩展点,因此Q开发h员可以通过q些扩展Ҏ(gu)菜单攑ֈ界面的不同区域,详细内容请参?2.2 节?/p>

  菜单的扩展点

  视图菜单的扩展点

  采用 Commands 方式创徏视图菜单Q需要引?org.eclipse.ui.menus 扩展点;?Actions 方式需要引?org.eclipse.ui.actionSets.

  1、视图菜单(Commands 方式Q:(x)

  MenuContribution locationURI = “[Scheme]:[id]?[argument-list]”

  其中QScheme 菜单出现的区域Qmenu 囄下拉菜单Qtoolbar 囄工具栏菜单;id 单区?IDQargument-list 菜单出现在指定菜单的位|?/p>

  例如Q在 ProbelmView 的下拉菜单加一个菜单项Q其 MenuContribution ?locationURI 应ؓ(f)Qmenu:org.eclipse.ui.views.ProblemView?after=additionsQ在 ProblemView 的工h菜单中加入一个菜单项Q其 locationURI 应ؓ(f)Qtoolbar:org.eclipse.ui.views.ProblemView?after=additions?/p>

  2、视图菜单(Actions 方式Q:(x)

  采用 Actions 方式创徏菜单Q需要引?org.eclipse.ui.actionSets 扩展点,q过讑֮ action ?menubarPath 指定下拉菜单 / 菜单出现的位置Q通过讑֮ action ?toolbarPath 讑֮工具栏菜?/ 菜单出现的位置?/p>

  例如Q添加一个下拉菜单项?Problems 视图中,?menubarPath 应ؓ(f)Q?/p>

  org.eclipse.ui.views.ProblemView/additions

  主菜单的扩展?/p>

  1、主菜单QCommands 方式Q?/p>

  通过 Commands 方式把菜单项dC菜单?qing)其工具栏上Q和视图菜单一P也是通过扩展?org.eclipse.ui.menus 实现Q需要设定其 menuContribution ?locationURI?/p>

  例如Q添加一个菜单(菜单可以包含若干个菜单项Q到主菜单一栏中Q其 locationURI 为:(x)

  menu:org.eclipse.ui.main.menu?after=additions

  d一个菜单到工具栏之中,?locationURI 为:(x)

  toolbar:org.eclipse.ui.main.toolbar?after=additions

  当然Q我们也可以把菜单项d到已l存在的菜单当中Q例如添加一个菜单项?Eclipse ?Search 主菜单当中,?locationURI 为:(x)

  menu:org.eclipse.search.menu?dialogGroup

  2、主菜单QActions 方式Q?/p>

  通过 Actions 方式把菜单项dC菜单?qing)其工具栏上Q和视图菜单一P也是通过扩展?org.eclipse.ui.actionSets 实现Q需要设?action ?menubarPath ?toolbarPath 实现?/p>

  例如Q添加一个菜单项?Eclipse ?Search 主菜单中Q其 menubarPath 应ؓ(f)Q?/p>

  org.eclipse.search.menu/dialogGroup

  注意Q如果采用上q方式添加一个菜单项?Search 主菜单,当我们运行时q没有出现添加的菜单,q时候需要换一?workspaceQ其原因?Eclipse ~存?jin)与其相关的某些信息?workspace 当中?/p>

  上下文菜单的扩展?/p>

  上下文菜单除?jin)通过 Commands ?Actions 方式dQ还可以使用扩展?org.eclipse.ui.popupMenus 方式dQ下面分别进行介l?/p>

  1、上下文菜单QCommands 方式Q?/p>

  Commands 方式与添加视图菜单和主菜单的方式一P通过讑֮?menuContribution ?locationURI 来实现?/p>

  例如Q添加一个上下文菜单?Problems 视图中,?locationURI 为:(x)

  popup:org.eclipse.ui.views.ProblemView?after=additions?/p>

  如果我们惌某个上下文菜单项出现在Q何区域,则可以用下面的 locationURIQ?/p>

  popup:org.eclipse.ui.popup.any?after=additions

  2、上下文菜单QActions 方式Q?/p>

  Actions 方式没有直接提供扩展Ҏ(gu)加上下文菜单Q但是我们可以通过~程的方式实玎ͼ如下代码清单 1 ?TreeViewer d上下文菜单,通过 IMenuManager ?add Ҏ(gu)d actions?/p>

清单 1. 通过 Actions 方式~程实现d上下文菜?/p>

 private void hookContextMenu() { 
  IMenuManager fMenuMgr = new MenuManager(“#PopupMenu”); 
  fMenuMgr.setRemoveAllWhenShown(true); 
  // d Actions 
  fMenuMgr.add(action … ) 
  fMenuMgr.createContextMenu(treeViewer.getControl()); 
  treeViewer.getControl().setMenu(fMenu); 
  getSite().registerContextMenu(fMenuMgr, treeViewer); 
 } 

  3、上下文菜单QpopupMenus 方式Q?/p>

  通过 popupMenus 扩展点实C下文菜单Q需要设?objectContribution ?objectClass 属性把上下文菜单添加到相应的区域?/p>

  例如Q如果我们想当用L(fng)?Eclipse 中的资源Ӟ弹出的上下文菜单包括某个菜单,我们可以讑֮ objectClass 属性ؓ(f)Q?/p>

  org.eclipse.core.resources.IResource

  通过 Commands 方式创徏菜单?/p>

  通过 Commands 方式创徏菜单,首先需要创?CommandQ通过扩展?org.eclipse.ui.commandsQ然后我们可以把q个 Command 攑ֈM区域Q上一节已经讲到Q通过 org.eclipse.ui.menus 扩展点确定菜单创建的区域Q最后通过扩展?org.eclipse.ui.handlers 定义q个 command 的具体行为?/p>

  在创?Command Ӟ我们可以先创Z?CategoryQƈ把相关的一些命令放到这?Category 中,q样有利于管理。代码清?2 创徏一?Command(“Show in Glossary Explorer”)Qƈ攑ֈ一?Category 中,然后把该 Command 攑ֈ BGSearchResultView 视图的上下文菜单中,最后通过扩展 org.eclipse.ui.handlers 定义?Command 的实现类?/p>

清单 2. 通过 Commands 方式d菜单?/p>

 <!-- d command --> 
 <extension 
   point="org.eclipse.ui.commands"> 
  <category 
   description="Business Glossary" 
   id="com.ibm.bg.ui.commands.category" 
   name="%category.BusinessGlossary.name"> 
  </category> 
  <command 
   categoryId="com.ibm.bg.ui.commands.category" 
   description="Show in Glossary Explorer" 
   id="com.ibm.bg.ui.commands.BGShowInBrowser" 
   name="%command.ShowInGE.name"> 
  </command> 
 </extension> 
 <!-- 把 Command 攑ֈ界面的对应区域 --> 
 <extension 
    point="org.eclipse.ui.menus"> 
  <menuContribution locationURI= 
  "popup:com.ibm.bg.internal.ui.search.BGSearchResultView?after=additions"> 
   <command 
      commandId="com.ibm.bg.ui.commands.BGShowInBrowser" 
      style="push" 
      tooltip="%command.ShowInGE.tooltip"> 
   </command> 
  </menuContribution> 
 </extension> 
 <!-- 定义 command 的实现类 --> 
 <extension 
   point="org.eclipse.ui.handlers"> 
  <handler 
     class="com.ibm.bg.internal.ui.handlers.BGShowInBrowser" 
     commandId="com.ibm.bg.ui.commands.BGShowInBrowser"> 
  </handler> 
 </extension> 

  通过 Actions 方式创徏菜单?/p>

  正如前面讲到QActions 方式没有分离界面的表现和内部实现Q因此,所有这些均通过 action 来完成。如下代码清?3 为添加一?Search 菜单到 Eclipse ?Search 主菜单(通过 action ?menubarPath 指定Q中Q其?class 对应的gؓ(f)?Action 的实现类Q该c需要实现接?IWorkbenchWindowActionDelegate?/p>

清单 3. 通过 Actions 方式d菜单?/p>

 <extension 
   point="org.eclipse.ui.actionSets"> 
  <actionSet 
     id="com.ibm.bg.ui.workbenchActionSet" 
     label="%category.name.0" 
     visible="true"> 
   <action 
      class="com.ibm.bg.internal.ui.handlers.BGSearchHandler" 
      definitionId="com.ibm.bg.ui.commands.BGSearch" 
      icon="icons/search.png" 
      id="com.ibm.bg.ui.commands.BGSearch" 
      label="%action.searchGlossayInMainMenu.label" 
      menubarPath="org.eclipse.search.menu/dialogGroup" 
      style="push"> 
   </action> 
  </actionSet> 
 </extension> 

  通过 popupMenus 方式创徏菜单?/p>

  popupMenus 方式创徏上下文菜单项也是通过 action 来实玎ͼ下面例子为添加一个菜单项到用户右?IGraphicalEditPart 对象时弹出的上下文菜单,通过 menubarPath 指定?Action 出现的区域,通过 class 指定?action 的实现类Q该c需要实现接?IObjectActionDelegate?/p>

清单 4. 通过 popupMenus 方式d菜单?/p>

 <extension 
   point="org.eclipse.ui.popupMenus"> 
  <objectContribution 
     adaptable="false" 
     id="com.ibm.bg.uml.objectContributions.BGAssignToGlossary" 
     objectClass="org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart"> 
   <action 
      class="com.ibm.bg.internal.uml.actions.BGAssignToGlossary" 
      enablesFor="+" 
      icon="icons/assign.png" 
      id="com.ibm.bg.internal.uml.actions.BGAssignToGlossary" 
      label="%BGAssignToGlossary.item" 
      menubarPath="com.ibm.bg.uml.popupMenuGroup"> 
   </action> 
  </objectContribution> 
 </extension> 

  菜单控制

  视图菜单的控制主要包括启?/ 用Q显C?/ 隐藏菜单?/p>

  通过 Command 方式创徏的菜单,可以通过 org.eclipse.ui.commands ?visibleWhen 属性控制菜单的隐藏和显C,通过 org.eclipse.ui.handlers ?activewhen ?enabledWhen 控制菜单的启用或用?/p>

  通过 Actions 方式创徏的菜单,可以通过 action ?enablement 属性控制菜单的启用 / 用?/p>

  通过 popupMenus 方式创徏的菜单,可以通过 objectContribution ?visibility ?enablement 来设|该 objectContribution 下的 action 的显C?/ 隐藏和启?/ 用Q我们也可以讄 action ?enablement 来控制该菜单的启?/ 用?/p>

  q里不详l讲q?enablementQvisibleWhen ?enabledWhen 的参数及(qing)如何讄Q读者可以参考第三节的例子和本文的参考文献?/p>

  ~程实践

  本文结合前两节讲到的知识,以例子的形式说明如何创徏q且控制菜单。首先创Z个视图(Menu ExampleQ,然后分别通过 CommandsQActions ?popupMenus 方式创徏若干个菜单,q添加相应的菜单控制炏V?/p>

  创徏 Menu Example 视图

  扩展 org.eclipse.views 创徏“Menu Example”视图Q如下代码清?5 为创囄 xml 代码?/p>

清单 5. 扩展 org.eclipse.ui.views 创徏视图

 <extension 
   point="org.eclipse.ui.views"> 
  <category 
     id="com.free.menu.category" 
     name="Menu Example View"> 
  </category> 
  <view 
     category="com.free.menu.category" 
     class="com.free.menu.view.MenuExplorer" 
     id="com.free.menu.view.MenuExplorer" 
     name="Menu Explorer" 
     restorable="true"> 
  </view> 
 </extension> 

  创徏 Commands

  采用 Command 方式创徏“Menu Example”主菜单(包含 AngryCommand ?JokeCommand 两个菜单)(j)Qƈ且基于这两个菜单创Z(jin) Menu Example 视图的下拉菜单和工具栏菜单,?qing)?TreeViewer 的上下文菜单?/p>

  如下代码清单 6 为扩?org.eclipse.ui.commands 创徏 Menu Example 命o(h)和类别,q且包含两个命o(h)QJoke Command ?Angry Command?/p>

清单 6. 扩展 org.eclipse.ui.commands 创徏命o(h)

 <extension 
   point="org.eclipse.ui.commands"> 
  <category 
     id="com.free.menu.category" 
     name="Menu Example"> 
  </category> 
  <command 
     categoryId="com.free.menu.category" 
     id="com.free.menu.commands.jokeCommand" 
     name="Joke Command"> 
  </command> 
  <command 
     categoryId="com.free.menu.category" 
     id="com.free.menu.commands.angryCommand" 
     name="Angry Command"> 
  </command> 
 </extension> 

  兌 Commands C菜单

  如下代码清单 7 为扩?org.eclipse.ui.menusQƈZ前面创徏?ComandsQ添加一个主菜单 Menu ExampleQƈ且包?Joke Command ?Angry Command 菜单V?/p>

清单 7. 创徏 Menu Example 主菜?/p>

 <menuContribution 
   locationURI="menu:org.eclipse.ui.main.menu?after=additions"> 
  <menu 
   id="com.free.menu.MenuExample" 
     label="Menu Example"> 
   <command 
      commandId="com.free.menu.commands.jokeCommand" 
      style="push"> 
   </command> 
   <command 
      commandId="com.free.menu.commands.angryCommand" 
      style="push"> 
   </command> 
  </menu> 
 </menuContribution> 

  Commands 的实现类

  如下代码清单 9 所C扩?org.eclipse.ui.handlers ?Joke Command ?Angry Command 创徏事g处理c,其中 Joke Command 通过 enabledWhen 属性控制该菜单Ҏ(gu)否启用,当我们同旉择?jin)两个对象?Joke Command 处于启用状态,否则为禁用?/p>

清单 9. 扩展 org.eclipse.ui.handlers ?Commands 创徏实现c?/p>

 <extension 
   point="org.eclipse.ui.handlers"> 
  <handler 
     class="com.free.menu.actions.JokeCommand" 
     commandId="com.free.menu.commands.jokeCommand"> 
   <enabledWhen> 
     <count 
        value="2"> 
     </count> 
   </enabledWhen> 
  </handler> 
  <handler 
     class="com.free.menu.actions.AngryCommand" 
     commandId="com.free.menu.commands.angryCommand"> 
  </handler> 
 </extension> 

  创徏 Action q关联到 Eclipse ?Search 主菜?/p>

  采用 Actions 方式?Eclipse 的主菜单 Search 中添加创单项 SmileAction。扩?org.eclipse.ui.actionSets ?Eclipse 的主菜单 Search 中添加一个菜单项 Smile Action。如下代码清?10 所C创 action q添加到 search 主菜单,只有当我们选择臛_一个对象时Q设|?enablesFor 属性ؓ(f)“+”Q,该菜单项才处于启用状态?/p>

清单 10. 通过 Actions 方式创徏菜单?/p>

 <extension 
   point="org.eclipse.ui.actionSets"> 
  <actionSet 
     id="com.free.menu.actionSet.MenuExample" 
     label="Menu Example" 
     visible="true"> 
   <action 
      class="com.free.menu.actions.SmileAction" 
      enablesFor="+" 
      icon="icons/searchres.gif" 
      id="com.free.menu.actions.smileAction" 
      label="Smile Action" 
      menubarPath="org.eclipse.search.menu/dialogGroup" 
      style="push"> 
   </action> 
  </actionSet> 
 </extension> 

  pupupMenus 方式创徏 Action q关联到 IResource 资源的上下文菜单

  扩展 org.eclipse.ui.popupMenus 创徏菜单“Menu Example”Q该菜单包含一个菜单项 HelloAction。当我们?Eclipse M区域叛_ org.eclipse.core.resources.IResource 资源时弹出的上下文菜单中?x)出?#8220;Menu Example”菜单。如下代码清?11 为创上下文菜单的 xml 代码?/p>

清单 11. popupMenus 方式创徏上下文菜?/p>

 <extension 
   point="org.eclipse.ui.popupMenus"> 
  <objectContribution 
     adaptable="true" 
     id="com.free.menu.popupMenu" 
     objectClass="org.eclipse.core.resources.IResource"> 
   <menu 
      label="Menu Example" 
      path="additions" 
      id="com.free.menu.popupSubMenu"> 
     <separator 
        name="additions"> 
     </separator> 
   </menu> 
   <action 
      label="Hello Action" 
      class="com.free.menu.popup.actions.HelloAction" 
      menubarPath="com.free.menu.popupSubMenu/additions" 
      enablesFor="1" 
      id="com.free.menu.newAction"> 
   </action> 
  </objectContribution> 
 </extension> 

  pupupMenus 方式创徏 Action q关联到 IResource 资源的上下文菜单

  扩展 org.eclipse.ui.popupMenus 创徏菜单?GreetAction ?CryActionQ当我们叛_ Menu Example 视图中的 TreeViewer 节点时弹出。如下代码清?12 所C扩?org.eclipse.ui.popupMenus ?Menu Example 视图创徏 GreetAction ?CryAction 上下文菜单项。?visiblity ?objectState 属性控制菜单项的可见状态,使用该属性要求其选择的对象实C(jin) org.eclipse.ui.IActionFilter 接口Q具体可参见 Person cȝ实现?/p>

清单 12. 扩展 org.eclipse.ui.popupMenus 创徏菜单

 <extension 
   point="org.eclipse.ui.popupMenus"> 
  <objectContribution 
     adaptable="false" 
     id="com.free.menu.views.popupMenu" 
     objectClass="com.free.menu.model.Person"> 
   <action 
      class="com.free.menu.actions.GreetAction" 
      enablesFor="+" 
      id="com.free.menu.actions.greetAction" 
      label="Greet Action" 
      menubarPath="additions"> 
   </action> 
   <visibility> 
     <objectState 
        name="firstName" 
        value="Dan"> 
     </objectState> 
   </visibility> 
  </objectContribution> 
 </extension> 
 <extension 
   point="org.eclipse.ui.popupMenus"> 
  <objectContribution 
     adaptable="false" 
     id="com.free.menu.views.popupMenu2" 
     objectClass="com.free.menu.model.Person"> 
   <action 
      class="com.free.menu.actions.CryAction" 
      enablesFor="+" 
      id="com.free.menu.actions.cryAction" 
      label="Cry Action" 
      menubarPath="additions"> 
     <enablement> 
      <objectState 
         name="firstName" 
         value="David"> 
      </objectState> 
     </enablement> 
   </action> 
   <visibility> 
     <objectState 
        name="lastName" 
        value="Rubel"> 
    </objectState> 
   </visibility> 
  </objectContribution> 
 </extension> 

  Menu Example 视图的代码实现类

  如下代码清单 13 所CZؓ(f) Menu Example 视图的代码,该视图中有一?TreeViewerQƈ通过函数 hookContextMenu 把上下文菜单兌?TreeViewer。其中函?viewMenuAction 用于更新菜单的状态,它首先获取视图菜单,然后调用 IMenuManager ?update Ҏ(gu)更新对应菜单的状态,从而达到控制菜单的目的?/p>

清单 13. Menu Example 视图代码

 public class MenuExplorer extends ViewPart { 
  private TreeViewer treeViewer; 
  private MenuManager fMenuMgr; 
  private Menu fMenu; 
  private static MenuExplorer fInstance = null; 
  public MenuExplorer() { 
    fInstance = this; 
  } 
  public static MenuExplorer getInstance(){ 
    return fInstance; 
  } 
  public void createPartControl(Composite parent) { 
    treeViewer = new TreeViewer (parent, SWT.MULTI); 
    treeViewer.setLabelProvider(new PersonListLabelProvider()); 
    treeViewer.setContentProvider(new PersonTreeContentProvider()); 
    treeViewer.setInput(Person.example()); 
    this.getSite().setSelectionProvider(treeViewer); 
    hookContextMenu(); 
    fInstance = this; 
     
  } 
  public void setViewMenuActionState(boolean state){     
    JokeCommand.setState(state); 
    viewMenuAction(); 
  } 
  private void viewMenuAction() { 
    IActionBars bars= getViewSite().getActionBars(); 
    final IMenuManager menu= bars.getMenuManager();   
     
    UIOperation.asyncExecCommand(new Runnable(){ 
      public void run() { 
        menu.update("com.free.menu.commands.jokeAction"); 
      }       
    });     
  } 
  private void hookContextMenu() { 
    fMenuMgr = new MenuManager("#PopupMenu"); 
    fMenuMgr.setRemoveAllWhenShown(true); 
    fMenuMgr.addMenuListener(new IMenuListener() { 
      public void menuAboutToShow(IMenuManager manager) {         
      } 
    }); 
    fMenu = fMenuMgr.createContextMenu(treeViewer.getControl()); 
 
    treeViewer.getControl().setMenu(fMenu); 
    getSite().registerContextMenu(fMenuMgr, treeViewer);        
  }   
  public void setFocus() { 
    treeViewer.getTree().setFocus(); 
 
  } 
 } 

  Person cȝ实现

  如下代码清单 14 ?Person cȝ实现Q用于表C?MenuExample 视图?TreeViewer 的一个节点,它实C(jin) IActionFilter 接口Q通过 testAttribute 来确定是否显C?/ 隐藏菜单Q其?target 表示用户选择的对象,name/value 对应?plugin.xml 文g?objectState ?name/valueQ?

清单 14. Person cd?/p>

 public class Person implements IActionFilter { 
 
  private String firstName = "John"; 
  private String lastName = "Doe"; 
  protected int age = 37; 
  public Person[] children = new Person[0]; 
  public Person parent = null; 
  public Person(String firstName, String lastName, int age) { 
    this.firstName = firstName; 
    this.lastName = lastName; 
    this.age = age; 
  } 
  public Person(String firstName, String lastName, int age, Person[] children) { 
    this(firstName, lastName, age); 
    this.children = children; 
    for (int i = 0; i < children.length; i++) { 
      children[i].parent = this; 
    } 
  } 
  public String getFirstName() { 
    return this.firstName; 
  } 
  public String getLastName() { 
    return this.lastName; 
  } 
  public static Person[] example() { 
    return new Person[] { 
        new Person("Dan", "Rubel", 38, new Person[] { 
            new Person("Beth", "Rubel", 8), 
            new Person("David", "Rubel", 3) }), 
        new Person("Eric", "Clayberg", 39, new Person[] { 
            new Person("Lauren", "Clayberg", 6), 
            new Person("Lee", "Clayberg", 4) }), 
        new Person("Mike", "Taylor", 52) }; 
  } 
  public String toString() { 
    return firstName + " " + lastName; 
  } 
  public boolean testAttribute(Object target, String name, String value) { 
 
    if (target instanceof Person) { 
      Person person = (Person) target; 
      if (name.equals("firstName") && value.equals(person.getFirstName())) { 
        return true; 
      } 
 
      if (name.equals("lastName") && value.equals(person.getLastName())) { 
        return true; 
      } 
    } 
    return false; 
  } 
 } 

  ȝ

  x为止Q已l把 Eclipse 菜单功能?qing)其扩展?gu)?qing)到的?/ 接口 /API q行?jin)详l的说明Q相信读者已l有清晰的认识了(jin)。对于前面提?popupMenus 方式创徏上下文菜单,要求选择的对象实?IActionFilter 接口Q但是,如果开发h员正在?gmf q行开发,那么我们可以不必要求选择的对象实?IActionFilterQ我们可以通过扩展 org.eclipse.gmf.runtime.common.ui.services.action.actionFilterProviders 对菜单项q行控制Q如下代码清?15 为扩展该 extension point ?xml 代码Q我们可以定义多个属性(<Attribute> … </AttributeQ,其中 Attribute ?name ?value 对应?visibility ?objectState 中的 name ?value?/p>

清单 15. 通过 actionFilterProviders 扩展点实现对菜单的控?/p>

 <extension 
 point="org.eclipse.gmf.runtime.common.ui.services.action.actionFilterProviders"> 
   <ActionFilterProvider 
      class="com.free.menu.PopupActionFilterProvider"> 
    <Priority 
       name="Medium"> 
    </Priority> 
    <Attribute 
       name="com.ibm.bg.uml.search.isSupportedType" 
       value="supported"> 
    </Attribute> 
   </ActionFilterProvider> 
 </extension> 

  如下代码清单 16 所C?PopupActionFilterProvider 的实玎ͼ它?AbstractActionFilterProviderQ只需要实现其中的 testAttribute ?provides Ҏ(gu)Q当 testAttribute q回 true Ӟ那么该菜单项被启用,否则用。其?target 对应于我们选择的对象,name ?value 参数对应?visiblity ?objectState ?name ?value 的指定?( 与前面提到的 Person cM?testAttribute Ҏ(gu)cM )?/p>


清单 16. actionFilterProviders 扩展点实现类

 public class PopupActionFilterProvider extends AbstractActionFilterProvider { 
 
 
  public PopupActionFilterProvider() { 
  } 
 
  public boolean testAttribute(Object target, String name, String value) { 
       
  } 
 
  public boolean provides(IOperation operation) { 
    return false; 
  } 
 
 }

 

 

 



玩{Java 2010-07-03 16:00 发表评论
]]>
Eclipse中一些扩展点介绍?/title><link>http://www.aygfsteel.com/jacky9881/archive/2010/07/03/menucommand.html</link><dc:creator>玩{Java</dc:creator><author>玩{Java</author><pubDate>Sat, 03 Jul 2010 07:55:00 GMT</pubDate><guid>http://www.aygfsteel.com/jacky9881/archive/2010/07/03/menucommand.html</guid><wfw:comment>http://www.aygfsteel.com/jacky9881/comments/325150.html</wfw:comment><comments>http://www.aygfsteel.com/jacky9881/archive/2010/07/03/menucommand.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/jacky9881/comments/commentRss/325150.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/jacky9881/services/trackbacks/325150.html</trackback:ping><description><![CDATA[扩展点:(x)<br /> <div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" /><span style="color: #000000">org.eclipse.ui.menusQ确定菜单创建的区域Q?br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" />org.eclipse.ui.commands<br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" />org.eclipse.ui.handlersQcommand的具体行为)(j)<br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" />org.eclipse.ui.commandImagesQcomand的图片)(j)<br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" /></span></div> <br /> 扩展点org.eclipse.ui.menus用来对菜单进行扩展,可以对主菜单Q工hQ上下文菜单q行扩展?br /> <br /> CZ代码如下Q?br /> <div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" /><span style="color: #0000ff"><</span><span style="color: #800000">extension<br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" />         </span><span style="color: #ff0000">point</span><span style="color: #0000ff">="org.eclipse.ui.menus"</span><span style="color: #0000ff">></span><span style="color: #000000"><br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" />      </span><span style="color: #0000ff"><</span><span style="color: #800000">menuContribution<br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" />            </span><span style="color: #ff0000">allPopups</span><span style="color: #0000ff">="false"</span><span style="color: #ff0000"><br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" />            locationURI</span><span style="color: #0000ff">="menu:org.eclipse.ui.main.menu?after=additions"</span><span style="color: #0000ff">></span><span style="color: #000000"><br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" />         </span><span style="color: #0000ff"><</span><span style="color: #800000">command<br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" />               </span><span style="color: #ff0000">commandId</span><span style="color: #0000ff">="com.xxxx.test.command1"</span><span style="color: #ff0000"><br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" />               style</span><span style="color: #0000ff">="push"</span><span style="color: #0000ff">></span><span style="color: #000000"><br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" />         </span><span style="color: #0000ff"></</span><span style="color: #800000">command</span><span style="color: #0000ff">></span><span style="color: #000000"><br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" />      </span><span style="color: #0000ff"></</span><span style="color: #800000">menuContribution</span><span style="color: #0000ff">></span><span style="color: #000000"><br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" /></span><span style="color: #0000ff"></</span><span style="color: #800000">extension</span><span style="color: #0000ff">></span><span style="color: #000000"><br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" /></span></div> <br /> 其中locationURI属性指定菜单扩展的位置Q上qC码是对主菜单q行扩展Q如果要对工h和上下文菜单q行扩展Q书写格式如下:(x)<br /> <br /> toolbar:org.eclipse.ui.main.toolbar?after=additions<br /> popup:org.eclipse.ui.popup.any?after=additions(上下文菜单在M位置出现)<br /> popup:org.eclipse.ui.views.ProblemView?after=additions(上下文菜单在问题视图中出?<br /> <br /> commandId属性指定该menu对应的commandQ一个menu可以对应多个command?br /> <br /> command可以通过扩展点org.eclipse.ui.commands扩展Q示例代码如下:(x)<br /> <br /> <div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" /><span style="color: #0000ff"><</span><span style="color: #800000">extension<br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" />         </span><span style="color: #ff0000">point</span><span style="color: #0000ff">="org.eclipse.ui.commands"</span><span style="color: #0000ff">></span><span style="color: #000000"><br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" /></span><span style="color: #0000ff"><</span><span style="color: #800000">category<br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" />            </span><span style="color: #ff0000">id</span><span style="color: #0000ff">="com.xxxx.test.category1"</span><span style="color: #ff0000"><br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" />            name</span><span style="color: #0000ff">="MenuTest"</span><span style="color: #0000ff">></span><span style="color: #000000"><br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" />      </span><span style="color: #0000ff"></</span><span style="color: #800000">category</span><span style="color: #0000ff">></span><span style="color: #000000"><br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" /><br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" />      </span><span style="color: #0000ff"><</span><span style="color: #800000">command<br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" /></span><span style="color: #ff0000">categoryId</span><span style="color: #0000ff">="="</span><span style="color: #ff0000">com.xxxx.test.category1"<br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" />            id</span><span style="color: #0000ff">="com.xxxx.test.command1"</span><span style="color: #ff0000"><br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" />            name</span><span style="color: #0000ff">="CommandA"</span><span style="color: #0000ff">></span><span style="color: #000000"><br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" />      </span><span style="color: #0000ff"></</span><span style="color: #800000">command</span><span style="color: #0000ff">></span><span style="color: #000000"><br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" /> </span><span style="color: #0000ff"></</span><span style="color: #800000">extension</span><span style="color: #0000ff">></span><span style="color: #000000"><br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" /></span></div> <br /> 至于Command具体要做什么,需要通过扩展点org.eclipse.ui.handlers来指定,CZ代码如下Q?br /> <br /> <div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" /><span style="color: #0000ff"><</span><span style="color: #800000">extension<br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" />         </span><span style="color: #ff0000">point</span><span style="color: #0000ff">="org.eclipse.ui.handlers"</span><span style="color: #0000ff">></span><span style="color: #000000"><br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" />      </span><span style="color: #0000ff"><</span><span style="color: #800000">handler<br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" />            </span><span style="color: #ff0000">class</span><span style="color: #0000ff">="com.xxxx.test.SampleHandler"</span><span style="color: #ff0000"><br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" />            commandId</span><span style="color: #0000ff">="com.xxxx.test.command1"</span><span style="color: #0000ff">></span><span style="color: #000000"><br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" />      </span><span style="color: #0000ff"></</span><span style="color: #800000">handler</span><span style="color: #0000ff">></span><span style="color: #000000"><br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" /> </span><span style="color: #0000ff"></</span><span style="color: #800000">extension</span><span style="color: #0000ff">></span><span style="color: #000000"><br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" /></span></div> <br /> q有扩展点org.eclipse.ui.commandImagesQ可以指定Command对应的图标?br /> <br /> <div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" /><span style="color: #000000"> </span><span style="color: #0000ff"><</span><span style="color: #800000">extension<br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" />         </span><span style="color: #ff0000">point</span><span style="color: #0000ff">="org.eclipse.ui.commandImages"</span><span style="color: #0000ff">></span><span style="color: #000000"><br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" />      </span><span style="color: #0000ff"><</span><span style="color: #800000">image<br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" />            </span><span style="color: #ff0000">commandId</span><span style="color: #0000ff">="com.xxxx.test.command1"</span><span style="color: #ff0000"><br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" />            icon</span><span style="color: #0000ff">="icons/sample.gif"</span><span style="color: #0000ff">></span><span style="color: #000000"><br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" />      </span><span style="color: #0000ff"></</span><span style="color: #800000">image</span><span style="color: #0000ff">></span><span style="color: #000000"><br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" />  </span><span style="color: #0000ff"></</span><span style="color: #800000">extension</span><span style="color: #0000ff">></span><span style="color: #000000"><br /> <img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" /></span></div> <br /> <img src ="http://www.aygfsteel.com/jacky9881/aggbug/325150.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/jacky9881/" target="_blank">玩{Java</a> 2010-07-03 15:55 <a href="http://www.aygfsteel.com/jacky9881/archive/2010/07/03/menucommand.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Eclipse中一些扩展点介绍一http://www.aygfsteel.com/jacky9881/archive/2010/07/03/orgeclipsecoreruntimepreferences.html玩{Java玩{JavaSat, 03 Jul 2010 07:22:00 GMThttp://www.aygfsteel.com/jacky9881/archive/2010/07/03/orgeclipsecoreruntimepreferences.htmlhttp://www.aygfsteel.com/jacky9881/comments/325148.htmlhttp://www.aygfsteel.com/jacky9881/archive/2010/07/03/orgeclipsecoreruntimepreferences.html#Feedback0http://www.aygfsteel.com/jacky9881/comments/commentRss/325148.htmlhttp://www.aygfsteel.com/jacky9881/services/trackbacks/325148.htmlorg.eclipse.core.runtime.preferences
功能Q该扩展点主要用来设|首选项的初始|

扩展点示例:(x)

<extension
         
point="org.eclipse.core.runtime.preferences">
      
<initializer
            
class="com.xxxx.test.AbstractPreferenceInitializer1">
      
</initializer>
</extension>

initializer指定讄首选项初始值的c,CZ代码如下Q?br />
public class AbstractPreferenceInitializer1 extends
        AbstractPreferenceInitializer 
{    
    @Override
    
public void initializeDefaultPreferences() {
        IPreferenceStore prefs 
= Activator.getDefault().getPreferenceStore();
        prefs.setDefault(
"MAX"1000);
    }

}


上述代码讄属性MAX的初始gؓ(f)1000Q这个属性就可以被首选项使用?jin)?br />
使用扩展?span style="font-family: 'Courier New'; color: black; font-size: 10pt; mso-fareast-font-family: 宋体; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA" lang="EN-US">org.eclipse.ui.preferencePages扩展首选项

扩展点示例:(x)

<extension
         
point="org.eclipse.ui.preferencePages">
      
<page
            
class="com.xxxx.test.WorkbenchPreferencePage1"
            id
="com.xxxx.test.page1"
            name
="testName">
      
</page>
</extension>

q样可以在WorkbenchPreferencePage1cM使用刚才定义的属性MAX?jin),CZ代码如下Q?br />
public class WorkbenchPreferencePage1 extends FieldEditorPreferencePage implements
        IWorkbenchPreferencePage 
{

    
public void init(IWorkbench workbench) {
        setPreferenceStore(Activator.getDefault().getPreferenceStore());        
    }

    @Override
    
protected void createFieldEditors() {
        
int max = getPreferenceStore().getDefaultInt("MAX");    
        System.out.println(
""+max);
    }
    
}




玩{Java 2010-07-03 15:22 发表评论
]]>
Eclipse的内存优化与内存不问题(转脓(chung))http://www.aygfsteel.com/jacky9881/archive/2010/06/26/Java_OutOfMemoryError.html玩{Java玩{JavaSat, 26 Jun 2010 13:37:00 GMThttp://www.aygfsteel.com/jacky9881/archive/2010/06/26/Java_OutOfMemoryError.htmlhttp://www.aygfsteel.com/jacky9881/comments/324572.htmlhttp://www.aygfsteel.com/jacky9881/archive/2010/06/26/Java_OutOfMemoryError.html#Feedback0http://www.aygfsteel.com/jacky9881/comments/commentRss/324572.htmlhttp://www.aygfsteel.com/jacky9881/services/trackbacks/324572.html原址地址Qhttp://hi.baidu.com/dangjun625/blog/item/a0732c0845181ddc63d98666.html

MyEclipse has detected that less than 5% of the 64MB of Perm
Gen (Non-heap memory) space remains. It is strongly recommended
that you exit and restart MyEclipse with new virtual machine memory
paramters to increase this memory.   Failure to do so can result in
data loss. The recommended Eclipse memory parameters are:
eclipse.exe -vmargs -Xms128M -Xmx512M -XX:PermSize=64M -XX:MaxPermSize=128M

eclipse根目录下面的 eclipse.ini 配置 从网上搜?jin)些资?/p>

-vmargsQ说明后面是VM的参?br /> -Xms128mQ虚拟机占用pȝ的最内?br /> -Xmx512mQ虚拟机占用pȝ的最大内存的5%?5.6MQ理Z要求-Xmx的数g-XX:MaxPermSize必须大于25.6M
-XX:PermSizeQ最堆大小。一般报内存不?都是说这个太? 堆空间剩余小?%׃(x)警告,把这个稍微设大一?不过要视自己机器内存大小来设|?br /> -XX:MaxPermSizeQ最大堆大小。这个也适当大些

把里面的参数改ؓ(f)
-vmargs  
-Xms128M  
-Xmx512M  
-XX:PermSize=128M  
-XX:MaxPermSize=256M
问题解决Q?/p>

从网上的资料看PermSize大一点肯定更好,而且最好是讄PermSize和MaxPermSize一样大。理由如下:(x)
PermSize 和MaxPermSize如果讄为相同还可以在一定程度上提高性能Q因为,PermSize在不断的变化中会(x)需要{Ud中的数据。如果固定了(jin)以后Q则可以减少每次扩大PermSize带来的性能损失?/p>

1、PermGen space?
  
  PermGen space的全U是Permanent Generation spaceQ是指内存的怹保存区域OutOfMemoryError: PermGen space从表面上看就是内存益出,解决Ҏ(gu)也一定是加大内存?
  
  说说Z么会(x)内存益出Q?
  Q?Q这一部分用于存放Class和Meta的信息,Class在被 Load的时候被攑օPermGen space区域Q它和和存放Instance的Heap区域不同?
  Q?Q?GC(Garbage Collection)不会(x)在主E序q行期对PermGen spaceq行清理Q所以如果你的APP?x)LOAD很多CLASS 的话,很可能出现PermGen space错误。这U错误常见在web服务器对JSPq行pre compile的时候?
  
  如果你的WEB APP下都用了(jin)大量的第三方jarQ其大小过?jin)jvm默认的大?4M)那么׃(x)产生此错误信息了(jin)?/p>

解决Ҏ(gu)Q?手动讄MaxPermSize大小
  
  修改TOMCAT_HOME/bin/catalina.batQ在echo "Using CATALINA_BASE: $CATALINA_BASE"上面加入以下行:(x)
   JAVA_OPTS="-server -XX:PermSize=64M -XX:MaxPermSize=128m
  Q将相同的第三方jar文gUȝ到tomcat/shared/lib目录下,q样可以减少jar 文重复占用内存

1。参数的含义

-vmargs -Xms128M -Xmx512M -XX:PermSize=64M -XX:MaxPermSize=128M

参数?vmargs的意思是讄JVM参数Q所以后面的其实都是JVM的参C(jin)Q我们首先了(jin)解一下JVM内存理的机Ӟ然后再解释每个参C表的含义?br /> ?Heap)和非?Non-heap)内存
按照官方的说法:(x)“Java 虚拟机具有一个堆Q堆是运行时数据区域Q所有类实例和数l的内存均从此处分配。堆是在 Java 虚拟机启动时创徏的?#8221;“在JVM中堆之外的内存称为非堆内?Non-heap memory)”。可以看出JVM主要理两种cd的内存:(x)堆和非堆。简单来说堆是Java代码可及(qing)的内存,是留l开发h员用的Q非堆就是JVM留给自己用的Q所以方法区、JVM内部处理或优化所需的内?如JIT~译后的代码~存)、每个类l构(如运行时常数池、字D和Ҏ(gu)数据)以及(qing)Ҏ(gu)和构造方法的代码都在非堆内存中?
堆内存分?br /> JVM初始分配的内存由-Xms指定Q默认是物理内存?/64Q?strong>JVM最大分配的内存?Xmx指定Q默认是物理内存?/4。默认空余堆内存于40%ӞJVM׃(x)增大堆直?Xmx的最大限ӞIZ堆内存大?0%ӞJVM?x)减堆直?Xms的最限制。因此服务器一般设|?Xms?Xmx相等以避免在每次GC 后调整堆的大?
非堆内存分配
JVM使用-XX:PermSize讄非堆内存初始?/strong>Q默认是物理内存?/64Q?strong>由XX:MaxPermSize讄最大非堆内存的大小Q默认是物理内存?/4?
JVM内存限制(最大?
首先JVM内存限制于实际的最大物理内存,假设物理内存无限大的话,JVM内存的最大D操作pȝ有很大的关系。简单的说就32位处理器虽然可控内存I间?GB,但是具体的操作系l会(x)l一个限Ӟq个限制一般是2GB-3GBQ一般来说Windowspȝ下ؓ(f)1.5G-2GQLinuxpȝ下ؓ(f)2G-3GQ,?4bit以上的处理器׃?x)有限制了(jin)?/p>

2. Z么有的机器我?Xmx?XX:MaxPermSize都设|ؓ(f)512M之后Eclipse可以启动Q而有些机器无法启动?

通过上面对JVM内存理的介l我们已l了(jin)解到JVM内存包含两种Q堆内存和非堆内存,另外JVM最大内存首先取决于实际的物理内存和操作pȝ。所以说讄VM参数DE序无法启动主要有以下几U原因:(x)
1) 参数?Xms的值大?XmxQ或?XX:PermSize的值大?XX:MaxPermSizeQ?br /> 2) -Xmx的值和-XX:MaxPermSize的d过?jin)JVM内存的最大限Ӟ比如当前操作pȝ最大内存限Ӟ或者实际的物理内存{等。说到实际物理内存这里需要说明一点的是,如果你的内存?024MBQ但实际pȝ中用到的q不可能?024MBQ因为有一部分被硬件占用了(jin)?/p>

3. Z上面的参数写入到eclipse.ini文gEclipse没有执行对应的设|?
那ؓ(f)什么同L(fng)参数在快h式或者命令行中有效而在eclipse.ini文g中是无效的呢Q这是因为我们没有遵守eclipse.ini文g的设|规则:(x)
参数形如“??#8221;q种形式Q中间有I格的需要换行书写,如果g有空格的需要用双引号包括v来。比如我们?vm C:\Java\jre1.6.0\bin\javaw.exe参数讄虚拟机,在eclipse.ini文g中要写成q样Q?br /> -vm
C:\Java\jre1.6.0\bin\javaw.exe
按照上面所说的Q最后参数在eclipse.ini中可以写成这个样子:(x)
-vmargs
-Xms128M
-Xmx512M
-XX:PermSize=64M
-XX:MaxPermSize=128M
实际q行的结果可以通过Eclipse?#8220;Help”-“About Eclipse SDK”H口里面?#8220;Configuration Details”按钮q行查看?br /> 另外需要说明的是,Eclipse压羃包中自带的eclipse.ini文g内容是这L(fng)Q?br /> -showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
-vmargs
-Xms40m
-Xmx256m
其中–launcher.XXMaxPermSizeQ注意最前面是两个连接线Q跟-XX:MaxPermSize参数的含义基本是一L(fng)Q我觉得唯一的区别就是前者是eclipse.exe启动的时候设|的参数Q而后者是eclipse所使用的JVM中的参数。其实二者设|一个就可以?jin),所以这里可以把–launcher.XXMaxPermSize和下一行?注释掉?/p>

3. 其他的启动参数?如果你有一个双核的CPUQ也许可以尝试这个参?



玩{Java 2010-06-26 21:37 发表评论
]]>
JVM terminated.Exit code=1.http://www.aygfsteel.com/jacky9881/archive/2008/07/27/217880.html玩{Java玩{JavaSun, 27 Jul 2008 13:22:00 GMThttp://www.aygfsteel.com/jacky9881/archive/2008/07/27/217880.htmlhttp://www.aygfsteel.com/jacky9881/comments/217880.htmlhttp://www.aygfsteel.com/jacky9881/archive/2008/07/27/217880.html#Feedback2http://www.aygfsteel.com/jacky9881/comments/commentRss/217880.htmlhttp://www.aygfsteel.com/jacky9881/services/trackbacks/217880.html JVM terminated.Exit code=1.
在网上找?jin)些资料Q找C(jin)解决Ҏ(gu)?br /> 只要修改eclipse.ini文g卛_。修改内容如下:(x)
-startup
plugins\org.eclipse.equinox.launcher_1.0.100.v20080509-1800.jar
--launcher.library
plugins\org.eclipse.equinox.launcher.win32.win32.x86_1.0.100.v20080509-1800
-showsplash
vm
D:\Java\jdk15011\bin\javaw.exe
org.eclipse.platform
--launcher.XXMaxPermSize
256m
-vmargs
-Xms40m
-Xmx256m
其中_体部分为新增内宏V?

玩{Java 2008-07-27 21:22 发表评论
]]>
Eclipse插g开发问题二http://www.aygfsteel.com/jacky9881/archive/2008/04/23/195233.html玩{Java玩{JavaWed, 23 Apr 2008 11:44:00 GMThttp://www.aygfsteel.com/jacky9881/archive/2008/04/23/195233.htmlhttp://www.aygfsteel.com/jacky9881/comments/195233.htmlhttp://www.aygfsteel.com/jacky9881/archive/2008/04/23/195233.html#Feedback0http://www.aygfsteel.com/jacky9881/comments/commentRss/195233.htmlhttp://www.aygfsteel.com/jacky9881/services/trackbacks/195233.html问题描述Q?/span>

最q在?/span>Eclipse插g开发的时候,在国际化的问题上遇到q样问题Q比如我?/span>plugin.xml文g中,通过%xxx来引?/span>plugin_zh.properties中对应键xxx的信息时Q在插gq行Ӟ相应的信息显CZ?jin),后来q过研究Q发现是׃?/span>MANIFEST.MF配|了(jin)一w成?/span>

Bundle-Localization: pluginQ?/span>

而这一w|我?/span>Overview标签上没有扑ֈ相应讄的地方,把这个在MANIFEST.MF加上Q插件在q行Ӟ可以显C?/span>plugin_zh.properties中定义的消息?jin)?/span>



玩{Java 2008-04-23 19:44 发表评论
]]>
Eclipse插g开发中的问题一http://www.aygfsteel.com/jacky9881/archive/2008/04/23/195232.html玩{Java玩{JavaWed, 23 Apr 2008 11:41:00 GMThttp://www.aygfsteel.com/jacky9881/archive/2008/04/23/195232.htmlhttp://www.aygfsteel.com/jacky9881/comments/195232.htmlhttp://www.aygfsteel.com/jacky9881/archive/2008/04/23/195232.html#Feedback1http://www.aygfsteel.com/jacky9881/comments/commentRss/195232.htmlhttp://www.aygfsteel.com/jacky9881/services/trackbacks/195232.html问题描述Q?/span>

最q在Eclipse插g开发中遇到q样的问题,我用如入扩展点

<extension
       
point="org.eclipse.debug.ui.launchConfigurationTabs">
    
<tab
          
class="com.example.launch.SqlDebugTab"
          group
="org.eclipse.jdt.debug.ui.launchConfigurationTabGroup.localJavaApplication"
          id
=" com.example.launchs.SqlDebugTab"
          name
="SqlDebugTab">
       
<associatedDelegate
             
delegate=" com.example.launch.SqlDebugLaunchDelegate">
       
</associatedDelegate>
    
</tab>
 
</extension>

<extension
          
point="org.eclipse.debug.core.launchDelegates">
       
<launchDelegate
             
delegate=" com.example.launch.SqlDebugLaunchDelegate"
             id
=" com.example.launch.SqlDebugLaunchDelegate"
             modes
="debug"
             type
="org.eclipse.jdt.launching.localJavaApplication">
       
</launchDelegate>
    
</extension>

 

也就是在调式Java Application的对话框中,增加一?/span>TabTab늚名字?/span>SqlDebugTabQ在q个Tab上增加几个复选框Q复选框要显C囄名称Q如果用户选择某个复选框Q点“Debug”后,显C指定的视图Q可是在com.example.launch.SqlDebugLaunchDelegatecM?/span>launchҎ(gu)中调?/span>PlatformUI.getWorkbench().getActiveWorkbenchWindow()Q得到的对象却ؓ(f)nullQ调试程序才发现Q运?/span>com.example.launch.SqlDebugLaunchDelegatecLQ走的是新线E,也就是说?#8220;Debug”按钮ӞEclipseq_启动的是新的U程Q非UIU程Q,而在新线E中是取不到ActiveWorkbenchWindow对象Qؓ(f)?jin)解册个问?/span>,p?jin)很多时_(d)最后终于找到解x?/span>,?/span>launchҎ(gu)通过如下E序来显C图,可以解决上面遇到的问题Q?/span>

PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
            
public void run() {
                IWorkbenchWindow window 
= PlatformUI.getWorkbench()
                        .getActiveWorkbenchWindow();
                
if (window != null){
                    window.getActivePage().showViewQ?/span>"……"Q;
}

}

}



玩{Java 2008-04-23 19:41 发表评论
]]>
程设计器开发十二(复制_脓(chung)部分Q?/title><link>http://www.aygfsteel.com/jacky9881/archive/2008/01/17/175815.html</link><dc:creator>玩{Java</dc:creator><author>玩{Java</author><pubDate>Thu, 17 Jan 2008 00:27:00 GMT</pubDate><guid>http://www.aygfsteel.com/jacky9881/archive/2008/01/17/175815.html</guid><wfw:comment>http://www.aygfsteel.com/jacky9881/comments/175815.html</wfw:comment><comments>http://www.aygfsteel.com/jacky9881/archive/2008/01/17/175815.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.aygfsteel.com/jacky9881/comments/commentRss/175815.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/jacky9881/services/trackbacks/175815.html</trackback:ping><description><![CDATA[要在~辑器中支持复制Q粘贴功能,首先Q要在编辑器中选择zd节点QEclipse工作台的菜单中复Ӟ_脓(chung)按钮处于Ȁzȝ态,要实现这功能Q我们还必须做些配置Q因为编辑器没有单独的菜单栏Q所有编辑器׃n一个菜单栏Q前面我们在定义~辑器扩展点Ӟ有一个属性contributorClass没有指定|它的值应该是一个实现IEditorActionBarContributor接口的类的全名,只有指定q个属性,菜单栏中的菜单项才能够对我们在编辑器中所做的操作q行相应Q?br /> 首先Q我们增加属性contributorClass对应的类Q?br /> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><span style="color: #0000ff">package</span><span style="color: #000000"> com.example.workflow.actions;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> org.eclipse.gef.ui.actions.ActionBarContributor;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> org.eclipse.ui.actions.ActionFactory;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /> <img id="Codehighlighter1_209_377_Open_Image" onclick="this.style.display='none'; Codehighlighter1_209_377_Open_Text.style.display='none'; Codehighlighter1_209_377_Closed_Image.style.display='inline'; Codehighlighter1_209_377_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_209_377_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_209_377_Closed_Text.style.display='none'; Codehighlighter1_209_377_Open_Image.style.display='inline'; Codehighlighter1_209_377_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> WorkflowActionContributor </span><span style="color: #0000ff">extends</span><span style="color: #000000"> ActionBarContributor </span><span id="Codehighlighter1_209_377_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_209_377_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    @Override<br /> <img id="Codehighlighter1_254_260_Open_Image" onclick="this.style.display='none'; Codehighlighter1_254_260_Open_Text.style.display='none'; Codehighlighter1_254_260_Closed_Image.style.display='inline'; Codehighlighter1_254_260_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_254_260_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_254_260_Closed_Text.style.display='none'; Codehighlighter1_254_260_Open_Image.style.display='inline'; Codehighlighter1_254_260_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">protected</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> buildActions() </span><span id="Codehighlighter1_254_260_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_254_260_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    @Override<br /> <img id="Codehighlighter1_317_373_Open_Image" onclick="this.style.display='none'; Codehighlighter1_317_373_Open_Text.style.display='none'; Codehighlighter1_317_373_Closed_Image.style.display='inline'; Codehighlighter1_317_373_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_317_373_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_317_373_Closed_Text.style.display='none'; Codehighlighter1_317_373_Open_Image.style.display='inline'; Codehighlighter1_317_373_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">protected</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> declareGlobalActionKeys() </span><span id="Codehighlighter1_317_373_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_317_373_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        addGlobalActionKey(ActionFactory.COPY.getId());<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000">    <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" />}</span></span></div> <p>在declareGlobalActionKeys增加对复制命令的xQ同时把属性contributorClass指定个类Q包含全路径。再定义复制动作CopyActionQ代码如下:(x)<br /> </p> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><span style="color: #0000ff">package</span><span style="color: #000000"> com.example.workflow.actions;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> org.eclipse.gef.ui.actions.SelectionAction;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> org.eclipse.ui.IWorkbenchPart;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> org.eclipse.ui.actions.ActionFactory;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /> <img id="Codehighlighter1_221_394_Open_Image" onclick="this.style.display='none'; Codehighlighter1_221_394_Open_Text.style.display='none'; Codehighlighter1_221_394_Closed_Image.style.display='inline'; Codehighlighter1_221_394_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_221_394_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_221_394_Closed_Text.style.display='none'; Codehighlighter1_221_394_Open_Image.style.display='inline'; Codehighlighter1_221_394_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> CopyAction </span><span style="color: #0000ff">extends</span><span style="color: #000000"> SelectionAction</span><span id="Codehighlighter1_221_394_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_221_394_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img id="Codehighlighter1_264_319_Open_Image" onclick="this.style.display='none'; Codehighlighter1_264_319_Open_Text.style.display='none'; Codehighlighter1_264_319_Closed_Image.style.display='inline'; Codehighlighter1_264_319_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_264_319_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_264_319_Closed_Text.style.display='none'; Codehighlighter1_264_319_Open_Image.style.display='inline'; Codehighlighter1_264_319_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> CopyAction(IWorkbenchPart part) </span><span id="Codehighlighter1_264_319_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_264_319_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        </span><span style="color: #0000ff">super</span><span style="color: #000000">(part);<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        setId(ActionFactory.COPY.getId());<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    @Override<br /> <img id="Codehighlighter1_371_391_Open_Image" onclick="this.style.display='none'; Codehighlighter1_371_391_Open_Text.style.display='none'; Codehighlighter1_371_391_Closed_Image.style.display='inline'; Codehighlighter1_371_391_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_371_391_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_371_391_Closed_Text.style.display='none'; Codehighlighter1_371_391_Open_Image.style.display='inline'; Codehighlighter1_371_391_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">protected</span><span style="color: #000000"> </span><span style="color: #0000ff">boolean</span><span style="color: #000000"> calculateEnabled() </span><span id="Codehighlighter1_371_391_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_371_391_Open_Text"><span style="color: #000000">{        <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">true</span><span style="color: #000000">;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" />}</span></span></div> <p> </p> <p><br /> 注意构造函C一定要把这个action的id讄为ActionFactory.COPY.getId()Q和前面l一hQ?/p> <p>到这儿还没有l束Q还必须在编辑器cM注册q个actionQ覆盖编辑器父类中的createActions()Ҏ(gu)Q?/p> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img id="Codehighlighter1_31_219_Open_Image" onclick="this.style.display='none'; Codehighlighter1_31_219_Open_Text.style.display='none'; Codehighlighter1_31_219_Closed_Image.style.display='inline'; Codehighlighter1_31_219_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_31_219_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_31_219_Closed_Text.style.display='none'; Codehighlighter1_31_219_Open_Image.style.display='inline'; Codehighlighter1_31_219_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /><span style="color: #0000ff">protected</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> createActions() </span><span id="Codehighlighter1_31_219_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_31_219_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">super</span><span style="color: #000000">.createActions();<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    CopyAction copyAction </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> CopyAction((IWorkbenchPart) </span><span style="color: #0000ff">this</span><span style="color: #000000">);<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    getActionRegistry().registerAction(copyAction);<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    getSelectionActions().add(copyAction.getId());<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" />}</span></span></div> 但是当我们在复制按钮可用情况Q点M后,我们希望把我们选择的对象,拯到剪切板上,q个在其他Y件中已经成功实现Q但要是在我们开发的程设计器中Q要实现q个功能Q我们还必须自己写代码来实现Q必重写C(j)opyAction父类中的runҎ(gu)Q把我们选择的对象放到剪切板上,代码如下Q?br /> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img id="Codehighlighter1_18_85_Open_Image" onclick="this.style.display='none'; Codehighlighter1_18_85_Open_Text.style.display='none'; Codehighlighter1_18_85_Closed_Image.style.display='inline'; Codehighlighter1_18_85_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_18_85_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_18_85_Closed_Text.style.display='none'; Codehighlighter1_18_85_Open_Image.style.display='inline'; Codehighlighter1_18_85_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> run() </span><span id="Codehighlighter1_18_85_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_18_85_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    Clipboard.getDefault().setContents(</span><span style="color: #0000ff">super</span><span style="color: #000000">.getSelectedObjects());<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" />}</span></span></div> <p>q样当我们点复制按钮之后Q流E设计器把我们选择的内Ҏ(gu)到剪切板上,下一步要做的是_脓(chung)?jin)?/p> <p>要ɾ_脓(chung)按钮可用Q所做的修改和复制类|在类WorkflowActionContributor 的方法declareGlobalActionKeys中增加addGlobalActionKey(ActionFactory.PASTE.getId())</p> <p>增加PasteActionc,代码如下Q?/p> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><span style="color: #0000ff">package</span><span style="color: #000000"> com.example.workflow.actions;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> org.eclipse.gef.ui.actions.Clipboard;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> org.eclipse.gef.ui.actions.SelectionAction;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> org.eclipse.ui.IWorkbenchPart;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> org.eclipse.ui.actions.ActionFactory;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /> <img id="Codehighlighter1_267_523_Open_Image" onclick="this.style.display='none'; Codehighlighter1_267_523_Open_Text.style.display='none'; Codehighlighter1_267_523_Closed_Image.style.display='inline'; Codehighlighter1_267_523_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_267_523_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_267_523_Closed_Text.style.display='none'; Codehighlighter1_267_523_Open_Image.style.display='inline'; Codehighlighter1_267_523_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> PasteAction </span><span style="color: #0000ff">extends</span><span style="color: #000000"> SelectionAction</span><span id="Codehighlighter1_267_523_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_267_523_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img id="Codehighlighter1_311_367_Open_Image" onclick="this.style.display='none'; Codehighlighter1_311_367_Open_Text.style.display='none'; Codehighlighter1_311_367_Closed_Image.style.display='inline'; Codehighlighter1_311_367_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_311_367_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_311_367_Closed_Text.style.display='none'; Codehighlighter1_311_367_Open_Image.style.display='inline'; Codehighlighter1_311_367_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> PasteAction(IWorkbenchPart part) </span><span id="Codehighlighter1_311_367_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_311_367_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        </span><span style="color: #0000ff">super</span><span style="color: #000000">(part);<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        setId(ActionFactory.PASTE.getId());<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    @Override<br /> <img id="Codehighlighter1_419_520_Open_Image" onclick="this.style.display='none'; Codehighlighter1_419_520_Open_Text.style.display='none'; Codehighlighter1_419_520_Closed_Image.style.display='inline'; Codehighlighter1_419_520_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_419_520_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_419_520_Closed_Text.style.display='none'; Codehighlighter1_419_520_Open_Image.style.display='inline'; Codehighlighter1_419_520_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">protected</span><span style="color: #000000"> </span><span style="color: #0000ff">boolean</span><span style="color: #000000"> calculateEnabled() </span><span id="Codehighlighter1_419_520_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_419_520_Open_Text"><span style="color: #000000">{        <br /> <img id="Codehighlighter1_471_491_Open_Image" onclick="this.style.display='none'; Codehighlighter1_471_491_Open_Text.style.display='none'; Codehighlighter1_471_491_Closed_Image.style.display='inline'; Codehighlighter1_471_491_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_471_491_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_471_491_Closed_Text.style.display='none'; Codehighlighter1_471_491_Open_Image.style.display='inline'; Codehighlighter1_471_491_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />        </span><span style="color: #0000ff">if</span><span style="color: #000000">(Clipboard.getDefault().getContents()</span><span style="color: #000000">!=</span><span style="color: #0000ff">null</span><span style="color: #000000">)</span><span id="Codehighlighter1_471_491_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_471_491_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">true</span><span style="color: #000000">;<br /> <img id="Codehighlighter1_496_517_Open_Image" onclick="this.style.display='none'; Codehighlighter1_496_517_Open_Text.style.display='none'; Codehighlighter1_496_517_Closed_Image.style.display='inline'; Codehighlighter1_496_517_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_496_517_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_496_517_Closed_Text.style.display='none'; Codehighlighter1_496_517_Open_Image.style.display='inline'; Codehighlighter1_496_517_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />        }</span></span><span style="color: #0000ff">else</span><span id="Codehighlighter1_496_517_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_496_517_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">false</span><span style="color: #000000">;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />        }</span></span><span style="color: #000000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" />}</span></span></div> <br /> q里对Paste菜单的可用性作?jin)判断,只有当剪切板中内容不为空Ӟ_脓(chung)按钮才可用,否则Z可用?br /> 态?br /> 另外q要在编辑器中对q个actionq行xQ?br /> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><span style="color: #000000">PasteAction pasteAction </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> PasteAction((IWorkbenchPart) </span><span style="color: #0000ff">this</span><span style="color: #000000">);<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" />getActionRegistry().registerAction(pasteAction);<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" />getSelectionActions().add(pasteAction.getId());</span></div> 到这里,当我们在~辑器中选择zdQ选择复制之后Q粘贴按钮可用,但点_脓(chung)按钮具体做什么,我们q没有定义,要实现这个做什么功能,q必覆盖PasteAction父类中的runҎ(gu)Q?br /> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img id="Codehighlighter1_18_559_Open_Image" onclick="this.style.display='none'; Codehighlighter1_18_559_Open_Text.style.display='none'; Codehighlighter1_18_559_Closed_Image.style.display='inline'; Codehighlighter1_18_559_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_18_559_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_18_559_Closed_Text.style.display='none'; Codehighlighter1_18_559_Open_Image.style.display='inline'; Codehighlighter1_18_559_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> run() </span><span id="Codehighlighter1_18_559_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_18_559_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        List list </span><span style="color: #000000">=</span><span style="color: #000000"> (List)Clipboard.getDefault().getContents();<br /> <img id="Codehighlighter1_110_556_Open_Image" onclick="this.style.display='none'; Codehighlighter1_110_556_Open_Text.style.display='none'; Codehighlighter1_110_556_Closed_Image.style.display='inline'; Codehighlighter1_110_556_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_110_556_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_110_556_Closed_Text.style.display='none'; Codehighlighter1_110_556_Open_Image.style.display='inline'; Codehighlighter1_110_556_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />        </span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000"> i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000"><</span><span style="color: #000000">list.size();i</span><span style="color: #000000">++</span><span style="color: #000000">)</span><span id="Codehighlighter1_110_556_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_110_556_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            AbstractActivityEditPart part </span><span style="color: #000000">=</span><span style="color: #000000"> (AbstractActivityEditPart)list.get(i);<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            AbstractActivity model </span><span style="color: #000000">=</span><span style="color: #000000"> (AbstractActivity)part.getModel();<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            WorkflowProcess parent </span><span style="color: #000000">=</span><span style="color: #000000"> (WorkflowProcess)part.getParent().getModel();<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            AbstractActivity clone </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> AbstractActivity();<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            clone.setName(</span><span style="color: #000000">"</span><span style="color: #000000">CloneActivity</span><span style="color: #000000">"</span><span style="color: #000000">);<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            clone.setLocation(model.getLocation());<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            clone.setSize(model.getSize());<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            clone.setFigure(model.getFigure());<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            parent.addChild(clone);<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />        }</span></span><span style="color: #000000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" />    }</span></span></div> <br /> q里只是做了(jin)一下简单处理,更复杂的逻辑用户可以Ҏ(gu)自己应用的需要,q里的run可以通过执行一个命令,以支持撤销Q重做功能,原理是q样的,另外剪切功能和这cMQ只是在复制基础上多?jin)个删除操作? <img src ="http://www.aygfsteel.com/jacky9881/aggbug/175815.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/jacky9881/" target="_blank">玩{Java</a> 2008-01-17 08:27 <a href="http://www.aygfsteel.com/jacky9881/archive/2008/01/17/175815.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>程设计器开发十一Q扩展点部分Q?/title><link>http://www.aygfsteel.com/jacky9881/archive/2008/01/16/175576.html</link><dc:creator>玩{Java</dc:creator><author>玩{Java</author><pubDate>Wed, 16 Jan 2008 00:42:00 GMT</pubDate><guid>http://www.aygfsteel.com/jacky9881/archive/2008/01/16/175576.html</guid><wfw:comment>http://www.aygfsteel.com/jacky9881/comments/175576.html</wfw:comment><comments>http://www.aygfsteel.com/jacky9881/archive/2008/01/16/175576.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.aygfsteel.com/jacky9881/comments/commentRss/175576.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/jacky9881/services/trackbacks/175576.html</trackback:ping><description><![CDATA[     摘要:   到目前ؓ(f)止,一个完整的程设计器已基本完成Qؓ(f)?jin)增加系l的可扩展性,比如目前zd的类型有三种Q假如以后我们要增加zd的类型,怎么办?按照目前的做法,我们只能修改代码Qؓ(f)?jin)ɾpȝ的扩展性更好,x们如果要增加zdcdQ只需要修攚w|文Ӟ而无M改现有系l的代码Qؓ(f)此,我们把活动类型定义一个扩展点Q用户以后要增加zdcdQ只需扩展q个扩展点就可以?jin)。(代码Q?在plugin.xml...  <a href='http://www.aygfsteel.com/jacky9881/archive/2008/01/16/175576.html'>阅读全文</a><img src ="http://www.aygfsteel.com/jacky9881/aggbug/175576.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/jacky9881/" target="_blank">玩{Java</a> 2008-01-16 08:42 <a href="http://www.aygfsteel.com/jacky9881/archive/2008/01/16/175576.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>程设计器开发十Q新建向导部分)(j)http://www.aygfsteel.com/jacky9881/archive/2008/01/15/175352.html玩{Java玩{JavaTue, 15 Jan 2008 00:45:00 GMThttp://www.aygfsteel.com/jacky9881/archive/2008/01/15/175352.htmlhttp://www.aygfsteel.com/jacky9881/comments/175352.htmlhttp://www.aygfsteel.com/jacky9881/archive/2008/01/15/175352.html#Feedback0http://www.aygfsteel.com/jacky9881/comments/commentRss/175352.htmlhttp://www.aygfsteel.com/jacky9881/services/trackbacks/175352.html阅读全文

玩{Java 2008-01-15 08:45 发表评论
]]>
程设计器开发九(ji)Q属性页部分Q?/title><link>http://www.aygfsteel.com/jacky9881/archive/2008/01/14/175062.html</link><dc:creator>玩{Java</dc:creator><author>玩{Java</author><pubDate>Mon, 14 Jan 2008 00:59:00 GMT</pubDate><guid>http://www.aygfsteel.com/jacky9881/archive/2008/01/14/175062.html</guid><wfw:comment>http://www.aygfsteel.com/jacky9881/comments/175062.html</wfw:comment><comments>http://www.aygfsteel.com/jacky9881/archive/2008/01/14/175062.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.aygfsteel.com/jacky9881/comments/commentRss/175062.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/jacky9881/services/trackbacks/175062.html</trackback:ping><description><![CDATA[     摘要: q一节主要介l如何给~辑器增加属性页Q属性页主要用来昄~辑器中选中对象的属性的Q比如在~辑器选中zdQ可以在属性页上显C活动的大小和位|等信息Q要实现q一功能Q首先要让模型实现IPropertySource接口Q我们让模型的基cModelElement实现q个接口Q基c要实现q接口中六个Ҏ(gu)Q这六个Ҏ(gu)如下Q? /** *//** An empty p...  <a href='http://www.aygfsteel.com/jacky9881/archive/2008/01/14/175062.html'>阅读全文</a><img src ="http://www.aygfsteel.com/jacky9881/aggbug/175062.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/jacky9881/" target="_blank">玩{Java</a> 2008-01-14 08:59 <a href="http://www.aygfsteel.com/jacky9881/archive/2008/01/14/175062.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>程设计器开发八Q大U视N分)(j)http://www.aygfsteel.com/jacky9881/archive/2008/01/11/174481.html玩{Java玩{JavaFri, 11 Jan 2008 00:44:00 GMThttp://www.aygfsteel.com/jacky9881/archive/2008/01/11/174481.htmlhttp://www.aygfsteel.com/jacky9881/comments/174481.htmlhttp://www.aygfsteel.com/jacky9881/archive/2008/01/11/174481.html#Feedback1http://www.aygfsteel.com/jacky9881/comments/commentRss/174481.htmlhttp://www.aygfsteel.com/jacky9881/services/trackbacks/174481.html阅读全文

玩{Java 2008-01-11 08:44 发表评论
]]>
程设计器开发七Q{UL炚w分)(j)http://www.aygfsteel.com/jacky9881/archive/2008/01/10/174184.html玩{Java玩{JavaThu, 10 Jan 2008 01:46:00 GMThttp://www.aygfsteel.com/jacky9881/archive/2008/01/10/174184.htmlhttp://www.aygfsteel.com/jacky9881/comments/174184.htmlhttp://www.aygfsteel.com/jacky9881/archive/2008/01/10/174184.html#Feedback2http://www.aygfsteel.com/jacky9881/comments/commentRss/174184.htmlhttp://www.aygfsteel.com/jacky9881/services/trackbacks/174184.html阅读全文

玩{Java 2008-01-10 09:46 发表评论
]]>
程设计器开发六Q{Ud立和删除Q?/title><link>http://www.aygfsteel.com/jacky9881/archive/2008/01/09/173935.html</link><dc:creator>玩{Java</dc:creator><author>玩{Java</author><pubDate>Wed, 09 Jan 2008 03:10:00 GMT</pubDate><guid>http://www.aygfsteel.com/jacky9881/archive/2008/01/09/173935.html</guid><wfw:comment>http://www.aygfsteel.com/jacky9881/comments/173935.html</wfw:comment><comments>http://www.aygfsteel.com/jacky9881/archive/2008/01/09/173935.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.aygfsteel.com/jacky9881/comments/commentRss/173935.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/jacky9881/services/trackbacks/173935.html</trackback:ping><description><![CDATA[     摘要:       哪个模型的控制器能接受在zd之间建立转移的请求呢Q只有活动模型的控制器了(jin)Q因为活动模型中l护着zd的输入和输出转移的列表,在活动控制器增加{略Q该控制器能接受徏立{UȝhQ代码如下:(x) protectedvoid createEditPolicies() {    &nbs...  <a href='http://www.aygfsteel.com/jacky9881/archive/2008/01/09/173935.html'>阅读全文</a><img src ="http://www.aygfsteel.com/jacky9881/aggbug/173935.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/jacky9881/" target="_blank">玩{Java</a> 2008-01-09 11:10 <a href="http://www.aygfsteel.com/jacky9881/archive/2008/01/09/173935.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>程设计器开发五Q移动和删除zd部分Q?/title><link>http://www.aygfsteel.com/jacky9881/archive/2008/01/07/173390.html</link><dc:creator>玩{Java</dc:creator><author>玩{Java</author><pubDate>Mon, 07 Jan 2008 09:16:00 GMT</pubDate><guid>http://www.aygfsteel.com/jacky9881/archive/2008/01/07/173390.html</guid><wfw:comment>http://www.aygfsteel.com/jacky9881/comments/173390.html</wfw:comment><comments>http://www.aygfsteel.com/jacky9881/archive/2008/01/07/173390.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/jacky9881/comments/commentRss/173390.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/jacky9881/services/trackbacks/173390.html</trackback:ping><description><![CDATA[     摘要:       q一节我们来介绍如何在编辑器中移动活动,改变?gu)zd的大和删除zdQ在程控制器中已经安装的策略WorkflowProcessXYLayoutEditPolicyQ可以接受移动活动和改变?gu)zd大小的请求,但不能接受删除活动的hQ要处理删除zd的请求,必须在活动控制器中安装策略?     &nb...  <a href='http://www.aygfsteel.com/jacky9881/archive/2008/01/07/173390.html'>阅读全文</a><img src ="http://www.aygfsteel.com/jacky9881/aggbug/173390.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/jacky9881/" target="_blank">玩{Java</a> 2008-01-07 17:16 <a href="http://www.aygfsteel.com/jacky9881/archive/2008/01/07/173390.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>程设计器开发四({略和命令部?http://www.aygfsteel.com/jacky9881/archive/2008/01/04/172635.html玩{Java玩{JavaFri, 04 Jan 2008 00:49:00 GMThttp://www.aygfsteel.com/jacky9881/archive/2008/01/04/172635.htmlhttp://www.aygfsteel.com/jacky9881/comments/172635.htmlhttp://www.aygfsteel.com/jacky9881/archive/2008/01/04/172635.html#Feedback0http://www.aygfsteel.com/jacky9881/comments/commentRss/172635.htmlhttp://www.aygfsteel.com/jacky9881/services/trackbacks/172635.html阅读全文

玩{Java 2008-01-04 08:49 发表评论
]]>
程设计器开发三(~辑器部?http://www.aygfsteel.com/jacky9881/archive/2008/01/03/172356.html玩{Java玩{JavaThu, 03 Jan 2008 00:54:00 GMThttp://www.aygfsteel.com/jacky9881/archive/2008/01/03/172356.htmlhttp://www.aygfsteel.com/jacky9881/comments/172356.htmlhttp://www.aygfsteel.com/jacky9881/archive/2008/01/03/172356.html#Feedback3http://www.aygfsteel.com/jacky9881/comments/commentRss/172356.htmlhttp://www.aygfsteel.com/jacky9881/services/trackbacks/172356.html阅读全文

玩{Java 2008-01-03 08:54 发表评论
]]>
程设计器开发二(控制器和视图部分)http://www.aygfsteel.com/jacky9881/archive/2008/01/02/172254.html玩{Java玩{JavaWed, 02 Jan 2008 08:51:00 GMThttp://www.aygfsteel.com/jacky9881/archive/2008/01/02/172254.htmlhttp://www.aygfsteel.com/jacky9881/comments/172254.htmlhttp://www.aygfsteel.com/jacky9881/archive/2008/01/02/172254.html#Feedback0http://www.aygfsteel.com/jacky9881/comments/commentRss/172254.htmlhttp://www.aygfsteel.com/jacky9881/services/trackbacks/172254.html阅读全文

玩{Java 2008-01-02 16:51 发表评论
]]>
程设计器开发一(模型部分)http://www.aygfsteel.com/jacky9881/archive/2008/01/02/172223.html玩{Java玩{JavaWed, 02 Jan 2008 07:32:00 GMThttp://www.aygfsteel.com/jacky9881/archive/2008/01/02/172223.htmlhttp://www.aygfsteel.com/jacky9881/comments/172223.htmlhttp://www.aygfsteel.com/jacky9881/archive/2008/01/02/172223.html#Feedback5http://www.aygfsteel.com/jacky9881/comments/commentRss/172223.htmlhttp://www.aygfsteel.com/jacky9881/services/trackbacks/172223.html阅读全文

玩{Java 2008-01-02 15:32 发表评论
]]>
վ֩ģ壺 | | Զ| ޳| ͨ| | ̫ԭ| | | | ɽ| ߰| | | | | ±| | | ½| | ɽ| | ƽ| | ϰ| | | | ¡Ң| | ֶ| | | | ӳ| | | ϲ| | ɽ|