﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-rick-文章分类-eclipse插件开发</title><link>http://www.blogjava.net/rick/category/38903.html</link><description /><language>zh-cn</language><lastBuildDate>Thu, 09 Apr 2009 06:59:18 GMT</lastBuildDate><pubDate>Thu, 09 Apr 2009 06:59:18 GMT</pubDate><ttl>60</ttl><item><title>从一个command handler中获取当前的view</title><link>http://www.blogjava.net/rick/articles/264546.html</link><dc:creator>Rick Murphy</dc:creator><author>Rick Murphy</author><pubDate>Wed, 08 Apr 2009 15:21:00 GMT</pubDate><guid>http://www.blogjava.net/rick/articles/264546.html</guid><wfw:comment>http://www.blogjava.net/rick/comments/264546.html</wfw:comment><comments>http://www.blogjava.net/rick/articles/264546.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/rick/comments/commentRss/264546.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rick/services/trackbacks/264546.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp; handler执行的时候，eclipse会传入一个ExecutionEvent参数，通过调用该参数的getApplicationContext() 方法，可以获取一个上下文描述对象（Object）。如果这个上下文描述对象是 IEvaluationContext 的实例，则表示这是一个用 eclipse CoreExpression 描述的上下文对象（在command、handler架构中，按钮是通过 CoreExpression 绑定到view上的），在这个对象中，可以通过 getVariable(String name) 方法获取大量的信息，（可用的name列表可以在 org.eclipse.ui.ISource 中查到）例如：获取当前的view就用如下方法：<br />
Object o = getVariable(event, ISources.ACTIVE_PART_NAME)<br />
<br />
&nbsp;&nbsp;&nbsp; 不过这样通过名称调用还是比较晦涩，还好eclipse提供了 org.eclipse.ui.handlers.HandlerUtil 类，在这个工具类里，将常用的获取上下文的方法全部封装好了。<br />
<br />
&nbsp;&nbsp;&nbsp; 下面是个例子<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;Object&nbsp;execute(ExecutionEvent&nbsp;event)&nbsp;</span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);">&nbsp;ExecutionException&nbsp;{<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MessageDialog.openInformation(PlatformUI.getWorkbench()<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.getActiveWorkbenchWindow().getShell(),&nbsp;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">info</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">copy&nbsp;stack</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IWorkbenchPart&nbsp;view&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;HandlerUtil.getActivePart(event);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">&nbsp;(view&nbsp;</span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">)&nbsp;{<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(view.getTitle());<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
</span></div>
<br />
<img src ="http://www.blogjava.net/rick/aggbug/264546.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rick/" target="_blank">Rick Murphy</a> 2009-04-08 23:21 <a href="http://www.blogjava.net/rick/articles/264546.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>向View中添加一个右键菜单（采用commands架构）</title><link>http://www.blogjava.net/rick/articles/264544.html</link><dc:creator>Rick Murphy</dc:creator><author>Rick Murphy</author><pubDate>Wed, 08 Apr 2009 15:17:00 GMT</pubDate><guid>http://www.blogjava.net/rick/articles/264544.html</guid><wfw:comment>http://www.blogjava.net/rick/comments/264544.html</wfw:comment><comments>http://www.blogjava.net/rick/articles/264544.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/rick/comments/commentRss/264544.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rick/services/trackbacks/264544.html</trackback:ping><description><![CDATA[<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="ProgId" content="Word.Document" />
<meta name="Generator" content="Microsoft Word 11" />
<meta name="Originator" content="Microsoft Word 11" />
<link rel="File-List" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml" /><!--[if gte mso 9]><xml>
Normal
0
7.8 磅
0
2
false
false
false
MicrosoftInternetExplorer4
</xml><![endif]--><!--[if gte mso 9]><![endif]--><style>
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
{font-family:""@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
@page
{}
@page Section1
{size:595.3pt 841.9pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;
layout-grid:15.6pt;}
div.Section1
{page:Section1;}
/* List Definitions */
@list l0
{}
@list l0:level1
{
margin-left:21.0pt;
text-indent:-21.0pt;}
@list l1
{}
@list l1:level1
{
margin-left:21.0pt;
text-indent:-21.0pt;}
ol
{margin-bottom:0cm;}
ul
{margin-bottom:0cm;}
-->
</style><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{
mso-style-parent:"";
font-size:10.0pt;
font-family:"Times New Roman";}
</style>
<![endif]-->
<p style="text-indent: 21pt;"><span style="font-family: 宋体;">这两天学习了一下</span>commands<span style="font-family: 宋体;">架构，自己感觉和之前的</span>action set<span style="font-family: 宋体;">架构相比，有一点比较方便。即：针对同一个</span>command<span style="font-family: 宋体;">，可以存在多个</span>handler<span style="font-family: 宋体;">与之绑定，在运行时则自动选择</span>command<span style="font-family: 宋体;">指定的默认</span> handler<span style="font-family: 宋体;">或者由</span>core expression<span style="font-family: 宋体;">条件过滤出的</span>handler<span style="font-family: 宋体;">来执行。</span> <span style="font-family: 宋体;">这个亮点也是之所以</span>action set<span style="font-family: 宋体;">架构进化到</span>commands<span style="font-family: 宋体;">架构的原因。</span></p>
<p style="text-indent: 21pt;"><span style="font-family: 宋体;">最近给自己规划了一个插件任务：把选中的调试堆栈存储起来，并且可以选取若干个堆栈进行比较，采用直观的方式显示两个堆栈中的不同。有了这个插件，以后再调程序时就可以省去很多力气了，尤其是对我这样撂爪儿就忘的人更是帮助很大，我以前都是把堆栈拷贝到文本编辑器中比较的。而且，为了保持断点窗口的清洁，很多有价值的堆栈信息都删了，如果加上标注存起来，以后查找起来也会方便很多。</span></p>
<p style="text-indent: 21pt;"><span style="font-family: 宋体;">动手开始做的第一件事，就是解决如何向</span>Debug View<span style="font-family: 宋体;">中添加一个右键菜单，就像拷贝堆栈时用的那个&#8220;</span>copy stack<span style="font-family: 宋体;">&#8221;按钮一样，这个按钮为我们提供了一个拷贝堆栈的参考方法，但这不属于本文讨论的范围了。</span></p>
<p style="text-indent: 21pt;"><span style="font-family: 宋体;">有的文章在描述一个问题时，采用的方法只是把操作步骤列一下，然后配合几张图就</span>ok<span style="font-family: 宋体;">了，这种方式很像家用电器的操作手册，可以对于我们经常面对的复杂问题，只有这些显然不够，只有理解了为什么这样做，才会真正领会其要义，务必求其宗而非其法。</span></p>
<p style="text-indent: 21pt;"><span style="font-family: 宋体;">在这里我将操作步骤只是简要列一下，最主要的，还是要把解决问题过程中遇到的难点和解决办法整理出来。</span></p>
<p><span style="font-family: 宋体;">操作步骤：</span></p>
<p style="margin-left: 21pt; text-indent: -21pt;"><span><span>1.<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span></span><span style="font-family: 宋体;">添加</span>org.eclipse.ui.commands<span style="font-family: 宋体;">扩展，创建一个</span>command</p>
<p style="margin-left: 21pt; text-indent: -21pt;"><span><span>2.<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span></span><span style="font-family: 宋体;">添加</span>org.eclipse.ui.menus<span style="font-family: 宋体;">扩展，创建一个</span>menuContribution</p>
<p style="margin-left: 21pt; text-indent: -21pt;"><span><span>3.<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span></span><span style="font-family: 宋体;">添加</span>org.eclipse.ui.handlers<span style="font-family: 宋体;">扩展，创建一个</span>handler<span style="font-family: 宋体;">，</span>command id<span style="font-family: 宋体;">指向步骤</span>1<span style="font-family: 宋体;">中创建的</span>command<span style="font-family: 宋体;">，并为其编写实现类</span></p>
<p style="margin-left: 21pt; text-indent: -21pt;"><span><span>4.<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span></span><span style="font-family: 宋体;">为步骤</span>3<span style="font-family: 宋体;">中创建的</span>handler<span style="font-family: 宋体;">指定激活状态的表达式</span></p>
<p><span style="font-family: 宋体;">要点：</span></p>
<p style="margin-left: 21pt; text-indent: -21pt;"><span><span>1.<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span></span>&nbsp;</p>
<p>Q<span style="font-family: 宋体;">：新建</span>command<span style="font-family: 宋体;">时，是否需要为其指定</span>catagory<span style="font-family: 宋体;">属性？</span></p>
<p>A<span style="font-family: 宋体;">：看情况。我个人感觉</span>catagory<span style="font-family: 宋体;">就是用来进行菜单分组的。例如，一般一个插件会把自己提供的菜单指定一个统一的</span>catagory<span style="font-family: 宋体;">，这样在显示或处理时能放在一起</span></p>
<p style="margin-left: 21pt; text-indent: -21pt;"><span><span>2.<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span></span>&nbsp;</p>
<p>Q<span style="font-family: 宋体;">：新建</span>command<span style="font-family: 宋体;">时，是否需要为其指定</span>name<span style="font-family: 宋体;">属性？</span></p>
<p>A<span style="font-family: 宋体;">：</span>name<span style="font-family: 宋体;">属性是必填项，当然要指定了</span><span>
:-) </span><span style="font-family: 宋体;">当对应的</span>menu<span style="font-family: 宋体;">没有指定</span>label<span style="font-family: 宋体;">时，菜单中显示的就是这个</span>name<span style="font-family: 宋体;">了。</span></p>
<p style="margin-left: 21pt; text-indent: -21pt;"><span><span>3.<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span></span>&nbsp;</p>
<p>Q<span style="font-family: 宋体;">：</span>menu<span style="font-family: 宋体;">的</span>locationURI<span style="font-family: 宋体;">如何指定？</span></p>
<p>A<span style="font-family: 宋体;">：这是我碰到的第一个难题，因为</span>uri<span style="font-family: 宋体;">需要用一个描述脚本编写，那么如何编写脚本？编写脚本的规则是什么？</span>
<span style="font-family: 宋体;">答案就在</span>eclipse<span style="font-family: 宋体;">的帮助文档中</span><span>:
http://help.eclipse.org/stable/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/workbench_cmd_menus.htm</span></p>
<p style="text-indent: 21pt;"><span style="font-family: 宋体;">举例：</span>popup:org.eclipse.debug.ui.DebugView?after=additions</p>
<p style="text-indent: 21pt;"><span style="font-family: 宋体;">可以把这个示例</span>uri<span style="font-family: 宋体;">看成</span>3<span style="font-family: 宋体;">部分，第一部分是&#8220;</span>popup<span style="font-family: 宋体;">&#8221;，代表样式是右键弹出菜单；第二部分是</span> <span style="font-family: 宋体;">&#8220;</span>org.eclipse.debug.ui.DebugView<span style="font-family: 宋体;">&#8221;，含义是显示在哪个</span>view<span style="font-family: 宋体;">的弹出菜单中；第三部分是</span> <span style="font-family: 宋体;">&#8220;</span>after=additions<span style="font-family: 宋体;">&#8221;，含义是显示在弹出菜单的什么位置（弹出菜单中还有其他的菜单项）。</span></p>
<p style="text-indent: 21pt;"><span style="font-family: 宋体;">这个只是</span>uri<span style="font-family: 宋体;">众多写法的其中之一，还有向主菜单添加项目的，向工具栏添加项目的，具体情况请参考上面的帮助文档链接。</span></p>
<p style="text-indent: 21pt;"><span style="font-family: 宋体;">进行到这里，菜单应该已经可以在</span>debug<span style="font-family: 宋体;">窗口中显示出来了，但是这又引发了一个问题：每当点击这个菜单的时候，总是报告：</span>The chosen operation is not enabled<span style="font-family: 宋体;">。这是因为</span>handler<span style="font-family: 宋体;">的实现类直接实现了</span>IHandler<span style="font-family: 宋体;">接口，其</span>isHandled<span style="font-family: 宋体;">，</span>isEnabled<span style="font-family: 宋体;">方法由</span>eclipse<span style="font-family: 宋体;">自动生成的情况下全部是返回</span>false<span style="font-family: 宋体;">的，除非必要，否则一般情况下应采用继承</span>org.eclipse.core.commands.AbstractHandler<span style="font-family: 宋体;">的方式来编写</span>handler<span style="font-family: 宋体;">的实现类，可以省去不少麻烦。</span></p>
<p style="text-indent: 21pt;"><span style="font-family: 宋体;">其中要注意的是：在</span>plugin<span style="font-family: 宋体;">编辑器中，点击</span>handler<span style="font-family: 宋体;">的属性面板中的&#8220;</span>class<span style="font-family: 宋体;">&#8221;链接，会自动创建实现类，这个自动创建的实现类不是继承</span>AbstractHandler<span style="font-family: 宋体;">的，而是直接实现</span>IHandler<span style="font-family: 宋体;">，我就是这样被带到沟里去的。</span></p>
<p style="text-indent: 21pt;"><span style="font-family: 宋体;">报错的问题解决了，但是发现新增的菜单在有选中堆栈和没有选中堆栈的情况下都可以显示，这个有些不大合适，因为如果要复制堆栈信息，至少应该有一条被选中才可以。所以应该采取措施让这个菜单在没有选中任何堆栈信息时灰显，这也就引出了另一个很难理解的框架：</span>command core expression<span style="font-family: 宋体;">。</span></p>
<p style="text-indent: 21pt;">command core expression<span style="font-family: 宋体;">是一个脚本规则，</span>eclipse<span style="font-family: 宋体;">定义了许多变量、属性，通过</span>core expression<span style="font-family: 宋体;">可以对这些变量、属性进行诸如</span>instanceof<span style="font-family: 宋体;">，</span> equals<span style="font-family: 宋体;">等判定，从而得到一个</span>boolean<span style="font-family: 宋体;">值用来参与程序的逻辑。针对这个问题，我们只需要为</span>handler<span style="font-family: 宋体;">指定</span>enabledWhen<span style="font-family: 宋体;">的表达式（</span>core expression<span style="font-family: 宋体;">），让</span>handler<span style="font-family: 宋体;">只在选中已条堆栈信息时才被激活即可。</span></p>
<p style="text-indent: 21pt;">core expression<span style="font-family: 宋体;">的文档在：</span>http://wiki.eclipse.org/Command_Core_Expressions <span style="font-family: 宋体;">在</span> org.eclipse.ui.handlers <span style="font-family: 宋体;">扩展的声明文档中也有很多可以参考的信息。</span></p>
<p style="text-indent: 21pt;"><span style="font-family: 宋体;">在本例中我们通过对</span>selection<span style="font-family: 宋体;">变量的计数来判断是否有堆栈信息被选定。详细内容请参考本文后面的</span>plugin.xml<span style="font-family: 宋体;">文件的内容。</span></p>
<p style="text-indent: 21pt;"><span style="font-family: 宋体;">至此，添加菜单的过程就结束了，看似简单，其实牵涉了许多其他的应用技术，例如</span>core expression<span style="font-family: 宋体;">，</span> locationURI<span style="font-family: 宋体;">等。其他的问题其实也是一样，不断地遇到问题，不断地踩平它，不断地积累，慢慢地，一条路就会出现在脚下。</span><br />
</p>
<p style="text-indent: 21pt;">附件：<br />
plugin.xml文件的内容：<br />
</p>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 0, 255);">&lt;?</span><span style="color: rgb(255, 0, 255);">xml&nbsp;version="1.0"&nbsp;encoding="UTF-8"</span><span style="color: rgb(0, 0, 255);">?&gt;</span><span style="color: rgb(0, 0, 0);"><br />
<br />
</span><span style="color: rgb(0, 0, 255);">&lt;?</span><span style="color: rgb(255, 0, 255);">eclipse&nbsp;version="3.2"</span><span style="color: rgb(0, 0, 255);">?&gt;</span><span style="color: rgb(0, 0, 0);"><br />
<br />
</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">plugin</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
<br />
</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">extension<br />
<br />
</span><span style="color: rgb(255, 0, 0);">point</span><span style="color: rgb(0, 0, 255);">="org.eclipse.ui.commands"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
<br />
</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">command<br />
<br />
</span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="xxx.rick.stacker.cmd.copy"</span><span style="color: rgb(255, 0, 0);"><br />
<br />
name</span><span style="color: rgb(0, 0, 255);">="testcopy"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
<br />
</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">command</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
<br />
</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">extension</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
<br />
</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">extension<br />
<br />
</span><span style="color: rgb(255, 0, 0);">point</span><span style="color: rgb(0, 0, 255);">="org.eclipse.ui.menus"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
<br />
</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">menuContribution<br />
<br />
</span><span style="color: rgb(255, 0, 0);">locationURI</span><span style="color: rgb(0, 0, 255);">="popup:org.eclipse.debug.ui.DebugView?after=additions"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
<br />
</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">command<br />
<br />
</span><span style="color: rgb(255, 0, 0);">commandId</span><span style="color: rgb(0, 0, 255);">="xxx.rick.stacker.cmd.copy"</span><span style="color: rgb(255, 0, 0);"><br />
<br />
style</span><span style="color: rgb(0, 0, 255);">="push"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
<br />
</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">command</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
<br />
</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">menuContribution</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
<br />
</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">extension</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
<br />
</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">extension<br />
<br />
</span><span style="color: rgb(255, 0, 0);">point</span><span style="color: rgb(0, 0, 255);">="org.eclipse.ui.handlers"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
<br />
</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">handler<br />
<br />
</span><span style="color: rgb(255, 0, 0);">class</span><span style="color: rgb(0, 0, 255);">="xxx.rick.stacker.handler.CopyStack"</span><span style="color: rgb(255, 0, 0);"><br />
<br />
commandId</span><span style="color: rgb(0, 0, 255);">="xxx.rick.stacker.cmd.copy"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
<br />
</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">enabledWhen</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
<br />
</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">with<br />
<br />
</span><span style="color: rgb(255, 0, 0);">variable</span><span style="color: rgb(0, 0, 255);">="selection"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
<br />
</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">count<br />
<br />
</span><span style="color: rgb(255, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">="+"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
<br />
</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">count</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
<br />
</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">with</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
<br />
</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">enabledWhen</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
<br />
</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">handler</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
<br />
</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">extension</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />
<br />
<br />
<br />
</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">plugin</span><span style="color: rgb(0, 0, 255);">&gt;</span></div>
<img src ="http://www.blogjava.net/rick/aggbug/264544.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rick/" target="_blank">Rick Murphy</a> 2009-04-08 23:17 <a href="http://www.blogjava.net/rick/articles/264544.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>RCP应用中实现工作区的切换</title><link>http://www.blogjava.net/rick/articles/264543.html</link><dc:creator>Rick Murphy</dc:creator><author>Rick Murphy</author><pubDate>Wed, 08 Apr 2009 15:07:00 GMT</pubDate><guid>http://www.blogjava.net/rick/articles/264543.html</guid><wfw:comment>http://www.blogjava.net/rick/comments/264543.html</wfw:comment><comments>http://www.blogjava.net/rick/articles/264543.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/rick/comments/commentRss/264543.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rick/services/trackbacks/264543.html</trackback:ping><description><![CDATA[<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="ProgId" content="Word.Document" />
<meta name="Generator" content="Microsoft Word 11" />
<meta name="Originator" content="Microsoft Word 11" />
<link rel="File-List" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml" /><!--[if gte mso 9]><xml>
Normal
0
7.8 磅
0
2
false
false
false
MicrosoftInternetExplorer4
</xml><![endif]--><!--[if gte mso 9]><![endif]--><style>
<!--
/* Font Definitions */
@font-face
{font-family:Wingdings;
panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
{font-family:""@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
@page
{}
@page Section1
{size:595.3pt 841.9pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;
layout-grid:15.6pt;}
div.Section1
{page:Section1;}
/* List Definitions */
@list l0
{}
@list l0:level1
{
margin-left:21.0pt;
text-indent:-21.0pt;
font-family:Wingdings;}
@list l0:level2
{
margin-left:39.0pt;
text-indent:-18.0pt;}
ol
{margin-bottom:0cm;}
ul
{margin-bottom:0cm;}
-->
</style><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{
mso-style-parent:"";
font-size:10.0pt;
font-family:"Times New Roman";}
</style>
<![endif]-->
<p style="text-indent: 21pt;"><span style="font-family: 宋体;">一般在一个陌生领域开发时，动手之前都会找一些功能相同或近似的示例，通过观察示例学习一个实现的路径，而后再加些个性化的东西进去。</span></p>
<p style="text-indent: 21pt;"><span style="font-family: 宋体;">编写工作区切换这个功能，第一个想到的，肯定就是</span>Java IDE<span style="font-family: 宋体;">中的&#8220;</span>Switch Workspace<span style="font-family: 宋体;">&#8221;按钮。这个按钮对应的动作写在</span><span>
org.eclipse.ui.internal.ide.actions.OpenWorkspaceAction </span><span style="font-family: 宋体;">类中，位于</span>org.eclipse.ui.ide <span style="font-family: 宋体;">插件里。</span></p>
<p style="text-indent: 21pt;">eclipse<span style="font-family: 宋体;">中要实现工作区切换除了</span>OpenWorkspaceAction<span style="font-family: 宋体;">中的方法，应该还有两种方式可以尝试：</span></p>
<ul>
    <li><span style="font-family: Wingdings;"><span><span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"> </span></span></span><span style="font-family: 宋体;">在</span>PlatformUI.createAndRunWorkbench<span style="font-family: 宋体;">之前调用</span> Platform.getInstanceLocation().setURL<span style="font-family: 宋体;">方法，可以改变工作区，但如果要实现向指定工作目录转向，则需要通过某种方式（例如通过系统参数）将指定目录信息跨过重启的过程传递给启动方法。也是要重启一次。</span></li>
</ul>
<ul>
    <li><span style="font-family: Wingdings;"></span><span style="font-family: 宋体;">如果切换工作区的目的只是想改变一个</span>view<span style="font-family: 宋体;">的显示内容，则直接改这个</span>view<span style="font-family: 宋体;">的</span>contentProvider<span style="font-family: 宋体;">，而后执行以下刷新就可以。不过这只是一个想法，没有付诸实践，得空儿了得去试试。</span></li>
</ul>
<p style="text-indent: 21pt;"><span style="font-family: 宋体;">不过这里不讨论上面的两种情况，只来看看</span>OpenWorkspaceAction<span style="font-family: 宋体;">中的经典做法是如何实现的吧。</span></p>
<p style="margin-left: 39pt; text-indent: -18pt;">1、&nbsp;<span style="font-family: 宋体;">拼装一个启动命令，拿着这个命令你可以直接从命令行跑起一个</span>eclipse<span style="font-family: 宋体;">示例来</span></p>
<p style="margin-left: 39pt; text-indent: -18pt;">2、&nbsp;<span style="font-family: 宋体;">将这个启动命令存储在</span>System<span style="font-family: 宋体;">的</span>eclipse.exitdata<span style="font-family: 宋体;">属性中</span></p>
<p style="margin-left: 39pt; text-indent: -18pt;">3、&nbsp;<span style="font-family: 宋体;">将</span>System<span style="font-family: 宋体;">的</span>eclipse.exitcode<span style="font-family: 宋体;">属性设置为</span> 24<span style="font-family: 宋体;">（</span>relaunch<span style="font-family: 宋体;">）。</span>eclipse.exitcode<span style="font-family: 宋体;">可以有三种状态，在</span>IApplication<span style="font-family: 宋体;">中注册的，分别是</span> 0<span style="font-family: 宋体;">（</span>EXIT_OK<span style="font-family: 宋体;">），</span>23<span style="font-family: 宋体;">（</span>EXIT_RESTART<span style="font-family: 宋体;">）</span>, 24(EXIT_RELAUNCH), <span style="font-family: 宋体;">具体每个状态的含义可以参考</span>IApplication<span style="font-family: 宋体;">的帮助。</span></p>
<p style="margin-left: 39pt; text-indent: -18pt;">4、&nbsp;<span style="font-family: 宋体;">调用</span>window.getWorkbench().restart()<span style="font-family: 宋体;">方法重新启动。</span></p>
<p style="margin-left: 39pt; text-indent: -18pt;"><span style="font-family: 宋体;">下面是一个handler执行部分的实例代码：</span></p>
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;Object&nbsp;execute(ExecutionEvent&nbsp;event)&nbsp;</span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);">&nbsp;ExecutionException&nbsp;{<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;window&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;HandlerUtil.getActiveWorkbenchWindowChecked(event);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;show&nbsp;directory&nbsp;chooser</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.getProperties().list(System.out);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DirectoryDialog&nbsp;dlg&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">&nbsp;DirectoryDialog(window.getShell(),&nbsp;SWT.OPEN);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;result&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;dlg.open();<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;get&nbsp;relaunch&nbsp;command</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;cmd&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;buildCommandLine(result);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">&nbsp;(cmd&nbsp;</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">)<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.setProperty(PROP_EXIT_CODE,&nbsp;Integer.toString(</span><span style="color: rgb(0, 0, 0);">24</span><span style="color: rgb(0, 0, 0);">));<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.setProperty(PROP_EXIT_DATA,&nbsp;cmd);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MessageDialog.openConfirm(window.getShell(),&nbsp;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">alert</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">I&nbsp;am&nbsp;ready&nbsp;to&nbsp;go&nbsp;with:&nbsp;\n</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">&nbsp;cmd);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;Now&nbsp;ready&nbsp;to&nbsp;go</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;window.getWorkbench().restart();<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;}</span></div>
&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp; 除了目录选择窗口，其余部分都是从OpenWorkspaceAction中抄来的，包括buildCommandLine方法也是。<br />
&nbsp;&nbsp;&nbsp; 不过，有了这个方还不够，目前这个handler对应的按钮点完了重启后应该报错，报告eclipse.vm没有设置，这是因为在buildCommandLine 方法中用到了这个系统属性，但是在调试环境下这个从System取这个属性的值是取不出任何东西的，只有打包发布之后才可以。<br />
&nbsp;&nbsp;&nbsp; 打包发布，重启是可以了，但是重启后并没有切换到指定的目录，而是还停留在原工作区没动窝儿。这个陷阱是很容易踩到的，原因揪出来，就是出在Application.java 的 start方法中。至于具体为什么，把更改前和更改后的代码贴出来一看也就知道了：<br />
<br />
更改前：<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;Object&nbsp;start(IApplicationContext&nbsp;context)&nbsp;</span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);">&nbsp;Exception&nbsp;{<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Display&nbsp;display&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;PlatformUI.createDisplay();<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">try</span><span style="color: rgb(0, 0, 0);">&nbsp;{<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;returnCode&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;PlatformUI.createAndRunWorkbench(display,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">&nbsp;ApplicationWorkbenchAdvisor());<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">&nbsp;(returnCode&nbsp;</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);">&nbsp;PlatformUI.RETURN_RESTART)<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;IApplication.EXIT_RESTART;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"><br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;IApplication.EXIT_OK;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</span><span style="color: rgb(0, 0, 255);">finally</span><span style="color: rgb(0, 0, 0);">&nbsp;{<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;display.dispose();<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;}</span></div>
<br />
<br />
更改后：<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;Object&nbsp;start(IApplicationContext&nbsp;context)&nbsp;{<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Display&nbsp;display&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;PlatformUI.createDisplay();<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">try</span><span style="color: rgb(0, 0, 0);">&nbsp;{<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;returnCode&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;PlatformUI<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.createAndRunWorkbench(display,&nbsp;</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">&nbsp;ApplicationWorkbenchAdvisor());<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">&nbsp;(returnCode&nbsp;</span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);">&nbsp;PlatformUI.RETURN_RESTART)<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;EXIT_OK;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">&nbsp;(EXIT_RELAUNCH.equals(Integer.valueOf(System<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.getProperty(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">eclipse.exitcode</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">))))<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;EXIT_RELAUNCH;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"><br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;EXIT_RESTART;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</span><span style="color: rgb(0, 0, 255);">finally</span><span style="color: rgb(0, 0, 0);">&nbsp;{<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;display.dispose();<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;}</span></div>
<br />
<p style="margin-left: 39pt; text-indent: -18pt;">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="ProgId" content="Word.Document" />
<meta name="Generator" content="Microsoft Word 11" />
<meta name="Originator" content="Microsoft Word 11" />
<link rel="File-List" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml" /><!--[if gte mso 9]><xml>
Normal
0
7.8 磅
0
2
false
false
false
MicrosoftInternetExplorer4
</xml><![endif]--><!--[if gte mso 9]><![endif]--><style>
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
{font-family:""@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
@page
{}
@page Section1
{size:595.3pt 841.9pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;
layout-grid:15.6pt;}
div.Section1
{page:Section1;}
-->
</style><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{
mso-style-parent:"";
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";}
</style>
<![endif]--></p>
<p>&nbsp;</p>
<img src ="http://www.blogjava.net/rick/aggbug/264543.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rick/" target="_blank">Rick Murphy</a> 2009-04-08 23:07 <a href="http://www.blogjava.net/rick/articles/264543.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>