﻿<?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-邋遢居-随笔分类-GEF</title><link>http://www.blogjava.net/JetGeng/category/11829.html</link><description>我的Java天堂</description><language>zh-cn</language><lastBuildDate>Tue, 27 Feb 2007 11:27:30 GMT</lastBuildDate><pubDate>Tue, 27 Feb 2007 11:27:30 GMT</pubDate><ttl>60</ttl><item><title>关于GEF中的Connection</title><link>http://www.blogjava.net/JetGeng/archive/2007/01/08/92407.html</link><dc:creator>Jet Geng</dc:creator><author>Jet Geng</author><pubDate>Mon, 08 Jan 2007 09:09:00 GMT</pubDate><guid>http://www.blogjava.net/JetGeng/archive/2007/01/08/92407.html</guid><wfw:comment>http://www.blogjava.net/JetGeng/comments/92407.html</wfw:comment><comments>http://www.blogjava.net/JetGeng/archive/2007/01/08/92407.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/JetGeng/comments/commentRss/92407.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/JetGeng/services/trackbacks/92407.html</trackback:ping><description><![CDATA[ 
<p style="margin-bottom: 0cm;" align="left" lang="zh-CN"><font face="宋体">在</font><font face="宋体">gef</font><font face="宋体">项目中连线一直扮演这个不可或缺的角色。碰巧前段时间有个机会好好的看了这个部分的内容。下面就把我的一点点认识和大家分享。</font></p><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"><font face="宋体">首先要在模型上支持，能够保存连接的信息。对于不同的项目有不同的要求。我们通过两个例子就可以看出这一点来。</font></p><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"><font face="Times New Roman, serif"><font face="宋体">1</font></font><font face="宋体">、</font><font face="Times New Roman, serif"><a href="http://www13.plala.or.jp/observe/GEF/"><font face="宋体">http://www13.plala.or.jp/observe/GEF/</font></a><font face="宋体"></font></font><font face="宋体">示例中的</font><font face="Times New Roman, serif"><font face="宋体">GEF6.zip </font></font><font face="宋体">（下面称这个例子为</font><font face="Times New Roman, serif"><font face="宋体">HelloWold</font></font><font face="宋体">）</font></p><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"><font face="宋体">运行的结果入下图所示：</font></p><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"><font face="宋体"><img src="http://www.blogjava.net/images/blogjava_net/jetgeng/Eclipse/gef/connection/hellwoui.jpg" alt="hellwoui.jpg" border="0" height="313" width="378" /></font></p><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"></p><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"><font face="宋体">它的模型可以使用如下的类图来表示：</font></p><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"><font face="宋体"><img src="http://www.blogjava.net/images/blogjava_net/jetgeng/Eclipse/gef/connection/LineConnectionModel-i.jpg" alt="LineConnectionModel-i.jpg" border="0" height="314" width="616" /></font></p><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"></p><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"><font face="宋体">用来描述</font><font face="宋体">Connection</font><font face="宋体">的分别是</font><font face="宋体">LineConnectionModel</font><font face="宋体">和</font><font face="宋体">ArrowConnectionModel</font><font face="宋体">这两个类。这两个类的父类和图形模型（</font><font face="宋体">HellowModel</font><font face="宋体">）相关。</font></p><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"><font face="宋体">2</font><font face="宋体">、</font><font face="宋体">IBM</font><font face="宋体">红皮书中的</font><font face="宋体">GEF</font><font face="宋体">范例</font><font face="宋体">(</font><font face="宋体">下面称这个例子为</font><font face="宋体">workflow)</font></p><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"><font face="宋体">运行效果如下图：</font></p><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"><font face="宋体"><img src="http://www.blogjava.net/images/blogjava_net/jetgeng/Eclipse/gef/connection/gefrun.jpg" alt="gefrun.jpg" border="0" height="234" width="368" /></font></p><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"></p><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"><font face="宋体">他的模型可用下面的类图描述：</font></p><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"><font face="宋体"><img src="http://www.blogjava.net/images/blogjava_net/jetgeng/Eclipse/gef/connection/gefredbook.jpg" alt="gefredbook.jpg" border="0" height="515" width="710" /></font></p><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"></p><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"><font face="宋体">其实连接的模型应该很简单，他只要能保存他的两端的对象就好了。图形模型（如</font><font face="宋体">HelloWold</font><font face="宋体">中的</font><font face="宋体">HelloModel</font><font face="宋体">）能够保持与他相关连的连接（</font><font face="宋体">HelloWold</font><font face="宋体">中的</font><font face="宋体">LineConnectionModel</font><font face="宋体">或</font><font face="宋体">ArrowConnectionModel</font><font face="宋体">）。</font></p><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"><font face="宋体">看完了</font><font face="宋体">Model</font><font face="宋体">，我们下面就可以看看</font><font face="宋体">EditPart</font><font face="宋体">部分了。</font></p><p style="margin-bottom: 0cm;" align="left"><font face="宋体"><span lang="zh-CN">要看</span></font><font face="宋体">EditPart</font><font face="宋体"><span lang="zh-CN">当然是要看最关键的了。也就是和连接直接关联的</span></font><font face="宋体">EditPart</font><font face="宋体"><span lang="zh-CN">了。分别察看了和连接相关的</span></font><font face="宋体">EditPart</font><font face="宋体"><span lang="zh-CN">，发现他们都会实现一个叫</span></font><font face="宋体"><font size="2"><font color="#000000">org.eclipse.gef.NodeEditPart</font></font></font><font face="宋体"><font size="2"><font color="#000000"><span lang="zh-CN">的接口。如下图所示：</span></font></font></font></p><img src="http://www.blogjava.net/images/blogjava_net/jetgeng/Eclipse/gef/connection/ShapeEditPart-a.jpg" alt="ShapeEditPart-a.jpg" border="0" height="269" width="611" /><br /><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"><font color="#000000"><font face="宋体"><font size="2">在</font></font><font face="宋体"><font size="2">nodeEditPart</font></font><font face="宋体"><font size="2">中有四个方法需要实现。通过这个四个方法的名字就可以看出他们和</font></font><font face="宋体"><font size="2">Anchor<sup>2</sup></font></font><font face="宋体"><font size="2">密切相关。下面就来看看这几个方法的具体功能：</font></font></font></p><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"><font color="#000000"><font face="宋体"><font size="2">ConnectionAnchor
getSourceConnectionAnchor(ConnectionEditPart connection);</font></font></font></p><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"><font color="#000000"><font face="宋体"><font size="2">当需要画连接的时候，通过这个方法获取连接的源锚点。不管这个锚点在什么位置，他取得以后直接就用它作为源点了。</font></font></font></p><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"><font color="#000000"><font face="宋体"><font size="2">ConnectionAnchor
getSourceConnectionAnchor(Request request);</font></font></font></p><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"><font color="#000000"><font face="宋体"><font size="2">当在准备创建连接的时候，通过</font></font><font face="宋体"><font size="2">Request</font></font><font face="宋体"><font size="2">来获取新连接的源锚点。</font></font></font></p><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"><font color="#000000"><font face="宋体"><font size="2">另外的两个就不再啰嗦了。是为了获得目标的锚点。</font></font></font></p><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"><br /></p><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"><font color="#000000"><font face="宋体"><font size="2">但是我们肯定看到了</font></font><font face="宋体"><font size="2">HelloWold</font></font><font face="宋体"><font size="2">和</font></font><font face="宋体"><font size="2">Workflow</font></font><font face="宋体"><font size="2">中的连接有点不一样。</font></font><font face="宋体"><font size="2">HelloWold</font></font><font face="宋体"><font size="2">中直接是图元上的，而</font></font><font face="宋体"><font size="2">workflow</font></font><font face="宋体"><font size="2">是通过连接基本图元上面的一个子图元而连接的。简单来说就是他们连接的</font></font><font face="宋体"><font size="2">anchor</font></font><font face="宋体"><font size="2">有点不一样，这样就会出现执行结果的不同。</font></font></font></p><p style="text-indent: 0.83cm; margin-bottom: 0cm;" align="left" lang="zh-CN"><font color="#000000"><font face="宋体"><font size="2">下面来看看他们到底是怎么实现的。根据上面提到的。锚点的获取是通过</font></font><font face="宋体"><font size="2">getSourceConnectionAnchor</font></font><font face="宋体"><font size="2">和</font></font><font face="宋体"><font size="2">getTargetConnectionAnchor</font></font><font face="宋体"><font size="2">方法来获取的。我们只需要好好比对一下他们这几个方法的不同就可以了。</font></font></font></p><p style="text-indent: 0.83cm; margin-bottom: 0cm;" align="left" lang="zh-CN"><font color="#000000"><font face="宋体"><font size="2">HelloWold</font></font><font face="宋体"><font size="2">中的</font></font><font face="宋体"><font size="2">getSourceConnectionAnchor</font></font></font></p><p style="text-indent: 0.83cm; margin-bottom: 0cm;" align="left" lang="zh-CN"><font color="#000000"><font face="宋体"><font size="2"><b><font color="#7f0055">public</font></b>
ConnectionAnchor getSourceConnectionAnchor(Request request) {</font></font></font></p><p style="margin-bottom: 0cm;" align="left"><font face="宋体"><font size="2"><font color="#000000"></font><b><font color="#7f0055">return</font></b><font color="#000000"></font><b><font color="#7f0055">new</font></b><font color="#000000">
ChopboxAnchor(getFigure());</font></font></font></p><p style="margin-bottom: 0cm;" align="left"><font color="#000000"><font face="宋体"><font size="2">	}</font></font></font></p><p style="margin-bottom: 0cm;" align="left"><font color="#000000"><font face="宋体"><font size="2"></font></font><font face="宋体"><font size="2"><span lang="zh-CN">这里就简单的创建一个
</span></font></font><font face="宋体"><font size="2">ChopboxAnchor
</font></font><font face="宋体"><font size="2"><span lang="zh-CN">就好了。这个就可以直接连到该</span></font></font><font face="宋体"><font size="2">Figure</font></font><font face="宋体"><font size="2"><span lang="zh-CN">上了。</span></font></font></font></p><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"><font color="#000000"><font face="宋体"><font size="2">在</font></font><font face="宋体"><font size="2">workflow</font></font><font face="宋体"><font size="2">中这个情况稍微有一点复杂了。先不说，还是看看他的
</font></font><font face="宋体"><font size="2">getSourceConnectionAnchor
</font></font><font face="宋体"><font size="2">是怎么实现的。</font></font></font></p><p style="margin-bottom: 0cm;" align="left"><font face="宋体"><font size="2"><font color="#000000"></font><b><font color="#7f0055">public</font></b><font color="#000000">
ConnectionAnchor getSourceConnectionAnchor(</font></font></font></p><p style="margin-bottom: 0cm;" align="left"><font color="#000000"><font face="宋体"><font size="2">ConnectionEditPart connection)
{</font></font></font></p><p style="margin-bottom: 0cm;" align="left"><font color="#000000"><font face="宋体"><font size="2">Connection edge = (Connection)
connection.getModel();</font></font></font></p><p style="margin-bottom: 0cm;" align="left"><font color="#000000"></font><font face="宋体"><font size="2"><b><font color="#7f0055">return</font></b><font color="#000000">
getNodeFigure().getConnectionAnchor(edge.getSource().getName());</font></font></font></p><p style="margin-bottom: 0cm;" align="left"><font color="#000000"><font face="宋体"><font size="2">}</font></font></font></p><p style="margin-bottom: 0cm;" align="left"><br /></p><p style="margin-bottom: 0cm;" align="left"><font color="#3f5fbf"><font face="宋体"><font size="2">/**</font></font></font></p><p style="margin-bottom: 0cm;" align="left"><font color="#000000"></font><font face="宋体"><font size="2"><font color="#3f5fbf">*</font><font color="#000000"></font><font color="#3f5fbf">returns</font><font color="#000000"></font><font color="#3f5fbf">an</font><font color="#000000"></font><font color="#3f5fbf">anchor</font><font color="#000000"></font><font color="#3f5fbf">given</font><font color="#000000"></font><font color="#3f5fbf">its</font><font color="#000000"></font><font color="#3f5fbf">name</font></font></font></p><p style="margin-bottom: 0cm;" align="left"><font color="#000000"></font><font face="宋体"><font size="2"><font color="#3f5fbf">*</font><font color="#000000"></font></font></font></p><p style="margin-bottom: 0cm;" align="left"><font color="#000000"></font><font face="宋体"><font size="2"><font color="#3f5fbf">*</font><font color="#000000"></font><b><font color="#7f9fbf">@param</font></b><font color="#000000"></font><font color="#3f5fbf">portName</font><font color="#000000"></font><font color="#3f5fbf">name</font><font color="#000000"></font><font color="#3f5fbf">of</font><font color="#000000"></font><font color="#3f5fbf">the</font><font color="#000000"></font><font color="#3f5fbf">anchor</font></font></font></p><p style="margin-bottom: 0cm;" align="left"><font color="#000000"></font><font face="宋体"><font size="2"><font color="#3f5fbf">*</font><font color="#000000"></font><b><font color="#7f9fbf">@return</font></b><font color="#000000"></font><font color="#3f5fbf">the</font><font color="#000000"></font><font color="#3f5fbf">anchor</font><font color="#000000"></font><font color="#3f5fbf">with</font><font color="#000000"></font><font color="#3f5fbf">the</font><font color="#000000"></font><font color="#3f5fbf">name</font><font color="#000000"></font><font color="#7f7f9f">&lt;code&gt;</font><font color="#3f5fbf">portName</font><font color="#7f7f9f">&lt;/code&gt;</font></font></font></p><p style="margin-bottom: 0cm;" align="left"><font color="#000000"></font><font face="宋体"><font size="2"><font color="#3f5fbf">*/</font></font></font></p><p style="margin-bottom: 0cm;" align="left"><font color="#000000"></font><font face="宋体"><font size="2"><b><font color="#7f0055">public</font></b><font color="#000000">
ConnectionAnchor getConnectionAnchor(String portName) {</font></font></font></p><p style="margin-bottom: 0cm;" align="left"><font color="#000000"></font><font face="宋体"><font size="2"><b><font color="#7f0055">return</font></b><font color="#000000">
(ConnectionAnchor)</font><font color="#0000c0">connectionAnchors</font><font color="#000000">.get(
portName );</font></font></font></p><p style="margin-bottom: 0cm;" align="left"><font color="#000000"><font face="宋体"><font size="2">}</font></font></font></p><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"><br /></p><p style="margin-bottom: 0cm;" align="left"><font face="宋体"><font size="2"><b><font color="#000000"></font><font color="#7f0055">protected</font></b><font color="#000000">
Hashtable </font><font color="#0000c0">connectionAnchors</font><font color="#000000">
= </font><b><font color="#7f0055">new</font></b><font color="#000000">
Hashtable(7);</font></font></font></p><p style="text-indent: 0.83cm; margin-bottom: 0cm;" align="left" lang="zh-CN"><br /></p><p style="text-indent: 0.83cm; margin-bottom: 0cm;" align="left" lang="zh-CN"><font color="#000000"><font face="宋体"><font size="2"><font color="#3f5fbf">/**</font></font></font></font></p><p style="margin-bottom: 0cm;" align="left"><font color="#000000"></font><font face="宋体"><font size="2"><font color="#3f5fbf">*</font><font color="#000000"></font><font color="#3f5fbf">Add</font><font color="#000000"></font><font color="#3f5fbf">an</font><font color="#000000"></font><font color="#3f5fbf">input</font><font color="#000000"></font><font color="#3f5fbf">port</font><font color="#000000"></font><font color="#3f5fbf">and</font><font color="#000000"></font><font color="#3f5fbf">its</font><font color="#000000"></font><font color="#3f5fbf">anchor</font></font></font></p><p style="margin-bottom: 0cm;" align="left"><font color="#000000"></font><font face="宋体"><font size="2"><font color="#3f5fbf">*</font><font color="#000000"></font></font></font></p><p style="margin-bottom: 0cm;" align="left"><font color="#000000"></font><font face="宋体"><font size="2"><font color="#3f5fbf">*</font><font color="#000000"></font><b><font color="#7f9fbf">@param</font></b><font color="#000000"></font><font color="#3f5fbf">portName</font></font></font></p><p style="margin-bottom: 0cm;" align="left"><font color="#000000"></font><font face="宋体"><font size="2"><font color="#3f5fbf">*</font><font color="#000000"></font><font color="#3f5fbf">unique</font><font color="#000000"></font><font color="#3f5fbf">name</font><font color="#000000"></font><font color="#3f5fbf">to</font><font color="#000000"></font><font color="#3f5fbf">refer</font><font color="#000000"></font><font color="#3f5fbf">to</font><font color="#000000"></font><font color="#3f5fbf">the</font><font color="#000000"></font><font color="#3f5fbf">port</font></font></font></p><p style="margin-bottom: 0cm;" align="left"><font color="#000000"></font><font face="宋体"><font size="2"><font color="#3f5fbf">*/</font></font></font></p><p style="margin-bottom: 0cm;" align="left"><font color="#000000"></font><font face="宋体"><font size="2"><b><font color="#7f0055">public</font></b><font color="#000000"></font><b><font color="#7f0055">void</font></b><font color="#000000">
addInput(String portName) {</font></font></font></p><p style="margin-bottom: 0cm;" align="left"><font color="#000000"><font face="宋体"><font size="2">InputPortFigure inputPort = </font><b><font color="#7f0055">new</font></b><font color="#000000">
InputPortFigure();</font></font></font></p><p style="margin-bottom: 0cm;" align="left"><font color="#000000"><font face="宋体"><font size="2">add(inputPort);</font></font></font></p><p style="margin-bottom: 0cm;" align="left"><br /></p><p style="margin-bottom: 0cm;" align="left"><font color="#000000"><font face="宋体"><font size="2">PortConnectionAnchor anchor = </font><b><font color="#7f0055">new</font></b><font color="#000000">
PortConnectionAnchor(inputPort);</font></font></font></p><p style="margin-bottom: 0cm;" align="left"><font color="#000000"><font face="宋体"><font size="2">getTargetConnectionAnchors().add(anchor);</font></font></font></p><p style="margin-bottom: 0cm;" align="left"><font color="#000000"></font><font face="宋体"><font size="2"><font color="#0000c0">connectionAnchors</font><font color="#000000">.put(portName,
anchor);</font></font></font></p><p style="margin-bottom: 0cm;" align="left"><font color="#000000"><font face="宋体"><font size="2">}</font></font></font></p><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"><br /></p><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"><font color="#000000"><font face="宋体"><font size="2"></font></font><font face="宋体"><font size="2">通过这几个方法可以看出它是在添加</font></font><font face="宋体"><font size="2">Input</font></font><font face="宋体"><font size="2">时候就创建好了一个和</font></font><font face="宋体"><font size="2">PortFigure
</font></font><font face="宋体"><font size="2">相关</font></font><font face="宋体"><font size="2">Anchor</font></font><font face="宋体"><font size="2">并把它保存起来。在要用的时候就把它取出来。这样就搞定了。</font></font></font></p><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"><font color="#000000"><font face="宋体"><font size="2"></font></font><font face="宋体"><font size="2">具体的可以参考这两个例子的代码。好了，打完收工。</font></font></font></p><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"><br /></p><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"><font face="宋体">参考文档</font></p><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"><font face="宋体">IBM
</font><font face="宋体">红皮书</font></p><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"><font face="Times New Roman, serif"><a href="../../reloadcn/archive/2006/10/09/gef5.html" name="Connection，Property"><font face="宋体">1</font></a></font><a href="../../reloadcn/archive/2006/10/09/gef5.html" name="Connection，Property"><font face="宋体"><span lang="zh-CN">、</span>荒野困兽</font><font face="Times New Roman, serif"><font face="宋体">(</font></font></a><a href="../../reloadcn/archive/2006/10/09/gef5.html" name="Connection，Property"><font face="宋体">老脸归来</font><font face="Times New Roman, serif"><font face="宋体">)’blog</font></font></a></p><p style="margin-bottom: 0cm;" align="left" lang="zh-CN"><font face="Times New Roman, serif"><a href="http://www.ibm.com/developerworks/cn/opensource/os-ecl-gef/part1/index.html" name="GEF 进阶，第一部分: Anchor" target="_blank"><font face="宋体">2</font></a></font><a href="http://www.ibm.com/developerworks/cn/opensource/os-ecl-gef/part1/index.html" name="GEF 进阶，第一部分: Anchor" target="_blank"><font face="宋体"><span lang="zh-CN">、</span></font><font face="Times New Roman, serif"><font face="宋体">GEF
</font></font></a><a href="http://www.ibm.com/developerworks/cn/opensource/os-ecl-gef/part1/index.html" name="GEF 进阶，第一部分: Anchor" target="_blank"><font face="宋体">进阶，第一部分</font><font face="Times New Roman, serif"><font face="宋体">:
Anchor</font></font></a></p><br /><img src ="http://www.blogjava.net/JetGeng/aggbug/92407.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/JetGeng/" target="_blank">Jet Geng</a> 2007-01-08 17:09 <a href="http://www.blogjava.net/JetGeng/archive/2007/01/08/92407.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>DragSourceEvent 中的坐标问题</title><link>http://www.blogjava.net/JetGeng/archive/2007/01/05/92104.html</link><dc:creator>Jet Geng</dc:creator><author>Jet Geng</author><pubDate>Fri, 05 Jan 2007 12:32:00 GMT</pubDate><guid>http://www.blogjava.net/JetGeng/archive/2007/01/05/92104.html</guid><wfw:comment>http://www.blogjava.net/JetGeng/comments/92104.html</wfw:comment><comments>http://www.blogjava.net/JetGeng/archive/2007/01/05/92104.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/JetGeng/comments/commentRss/92104.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/JetGeng/services/trackbacks/92104.html</trackback:ping><description><![CDATA[ 
<p style="MARGIN-BOTTOM: 0cm"><a name="_3196b2bfb616_HomePageDays_DaysList_ctl02_DayItem_DayList_ctl01_TitleUrl"></a><font face="宋体"><font color="#000000"><span lang="zh-CN">我想在我的</span></font></font><font face="Times New Roman, serif"><font face="宋体"><font color="#000000"><font size="2"><u>EditPartViewer</u></font></font></font></font><font face="宋体"><font color="#000000"><font size="2"><span lang="zh-CN"><span style="BACKGROUND: none transparent scroll repeat 0% 0%"><span style="TEXT-DECORATION: none">中获取一个图形元素把它拖放到一个</span></span></span></font></font></font><font face="Times New Roman, serif"><font face="宋体"><font color="#000000"><font size="2"><span style="BACKGROUND: none transparent scroll repeat 0% 0%"><span style="TEXT-DECORATION: none">swt</span></span></font></font></font></font><font face="宋体"><font color="#000000"><font size="2"><span lang="zh-CN"><span style="BACKGROUND: none transparent scroll repeat 0% 0%"><span style="TEXT-DECORATION: none">控件中。实现在</span></span></span></font></font></font><font face="Times New Roman, serif"><font face="宋体"><font color="#000000"><font size="2"><span style="BACKGROUND: none transparent scroll repeat 0% 0%"><span style="TEXT-DECORATION: none">&lt;&lt;</span></span></font></font></font></font><a href="/JetGeng/archive/2006/11/11/80604.html"><font face="宋体"><font color="#000000">图形编辑器中拖拽对象到</font></font><font face="Times New Roman, serif"><font face="宋体"><font color="#000000">swt</font></font></font></a><a href="/JetGeng/archive/2006/11/11/80604.html"><font face="宋体"><font color="#000000">控件</font></font><font face="Times New Roman, serif"><font face="宋体"><font color="#000000">&gt;&gt;</font></font></font></a><a href="/JetGeng/archive/2006/11/11/80604.html"><font face="宋体"><font color="#000000"><span lang="zh-CN"><span style="TEXT-DECORATION: none">一文有提到了。不过我在处理的时候，并不是按照他的那个方式来做的。我是根据当前点<span lang="zh-CN">（</span></span></span></font></font><font face="Times New Roman, serif"><font face="宋体"><font color="#000000"><span style="TEXT-DECORATION: none"><font size="2">DragSourceEvent</font></span></font></font></font></a><a href="/JetGeng/archive/2006/11/11/80604.html"><font face="宋体"><font color="#000000"><span lang="zh-CN"><span style="TEXT-DECORATION: none"><span lang="zh-CN">）</span>的位置来查找该点下的对象。看是否是我需要的对象，如果是就允许拖动。否则就不可以。</span></span></font></font></a></p><p lang="zh-CN" style="MARGIN-BOTTOM: 0cm"><font color="#000000"><font face="宋体"><span style="TEXT-DECORATION: none">问题在这里出来：当没有出现滚动条的时候一切都很正常，当一出现滚动条就死活没有办法拖动了。最后才发现</span></font><font face="宋体"><span style="TEXT-DECORATION: none">DragSourceEvent</span></font><font face="宋体"><span style="TEXT-DECORATION: none">中的坐标是按照屏幕来得，而</span></font><font face="宋体"><font size="2"><u>EditPartViewer </u></font></font><font face="宋体"><font size="2"><span style="TEXT-DECORATION: none">中的坐标是按照他的那个</span></font></font><font face="宋体"><font size="2"><span style="TEXT-DECORATION: none">viewer</span></font></font><font face="宋体"><font size="2"><span style="TEXT-DECORATION: none">来得。这个地方需要转换一下。</span></font></font></font></p><p lang="zh-CN" style="MARGIN-BOTTOM: 0cm; TEXT-DECORATION: none"><br /></p><p lang="zh-CN" style="MARGIN-BOTTOM: 0cm; TEXT-DECORATION: none"><br /></p><p style="MARGIN-BOTTOM: 0cm"><span lang="zh-CN">这个转换的动作发现在</span><font face="Times New Roman, serif">jfire</font><span lang="zh-CN">（</span><font face="Times New Roman, serif">org.nightlabs.editor2d.util.EditorUtil <a href="https://svn.jfire.org/svn/main/trunk/org.nightlabs.editor2d/src/org/nightlabs/editor2d/util/EditorUtil.java">https://svn.jfire.org/svn/main/trunk/org.nightlabs.editor2d/src/org/nightlabs/editor2d/util/EditorUtil.java</a></font>）中有现成的。不多说了，拿来用吧。</p><img src ="http://www.blogjava.net/JetGeng/aggbug/92104.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/JetGeng/" target="_blank">Jet Geng</a> 2007-01-05 20:32 <a href="http://www.blogjava.net/JetGeng/archive/2007/01/05/92104.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>图形编辑器中拖拽对象到swt控件</title><link>http://www.blogjava.net/JetGeng/archive/2006/11/11/80604.html</link><dc:creator>Jet Geng</dc:creator><author>Jet Geng</author><pubDate>Sat, 11 Nov 2006 11:56:00 GMT</pubDate><guid>http://www.blogjava.net/JetGeng/archive/2006/11/11/80604.html</guid><wfw:comment>http://www.blogjava.net/JetGeng/comments/80604.html</wfw:comment><comments>http://www.blogjava.net/JetGeng/archive/2006/11/11/80604.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/JetGeng/comments/commentRss/80604.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/JetGeng/services/trackbacks/80604.html</trackback:ping><description><![CDATA[    <span lang="zh-CN">前面一段时间有一个需求就是从</span><font face="Times New Roman, serif">swt</font><span lang="zh-CN">控件中拖拽对象到图形编辑器中（就是</span><font face="Times New Roman, serif"><b><span lang="zh-CN"><font size="3"><font face="System, sans-serif">class
org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor </font></font></span></b></font><b><font size="3"><font face="System, sans-serif">的儿子们</font></font></b><span lang="zh-CN">）编辑器。</span><p style="margin-bottom: 0cm;"><span lang="zh-CN">后来就<span lang="zh-CN">想假如</span>我需要从图形编辑器中拖拽对象到</span><font face="Times New Roman, serif">swt</font><span lang="zh-CN">控件中又该怎么做。<br />经过一段时间的探索，终于搞定了。</span></p><p style="margin-bottom: 0cm;" lang="zh-CN">记下如下过程，希望对需要的朋友有点帮助。</p><p style="margin-bottom: 0cm;" lang="zh-CN"></p><p style="margin-bottom: 0cm;"><span lang="zh-CN">首先<span lang="zh-CN">有了</span>《从</span><font face="Times New Roman, serif"><font face="Times New Roman, serif">SWT</font></font><span lang="zh-CN">控件中托拽对象到</span><font face="Times New Roman, serif"><font face="Times New Roman, serif">GEF</font></font><span lang="zh-CN">编辑器中》文中对</span><font face="Times New Roman, serif"><font size="3"><font face="宋体"><font color="#000000"><b>addDropTargetListener</b></font></font></font></font><font color="#000000"><span lang="zh-CN">方法使用的经历，很快就确定我需要对</span><font face="Times New Roman, serif"><font size="3"><font face="宋体">GraphicalViewer</font></font></font></font><font color="#000000"><span lang="zh-CN">添加一个</span><font face="Times New Roman, serif"><font size="2"><font face="Courier New, monospace">DragSourceListener</font></font></font></font><font color="#000000"><font size="2"><font face="Courier New, monospace"><span lang="zh-CN">。</span></font><span lang="zh-CN"><font face="宋体"><br /></font></span></font></font></p><p style="margin-bottom: 0cm;"><font color="#000000"><font size="2"><span lang="zh-CN"><font face="宋体">想着到这个地方我应该可以很快收工了。但是添加完了以后发现<span lang="zh-CN">原来的拖动功能都没有了</span>，这个怎么回事。谁在后面搞鬼。</font></span></font></font></p><p style="margin-bottom: 0cm;" lang="zh-CN">经过一段时间的狂搜滥索终于找到了问题的关键。因为<font face="Times New Roman, serif">GEF</font>不允许同时有两个活动
<font face="Times New Roman, serif">DragSource
</font>。</p><p style="margin-bottom: 0cm;" lang="zh-CN">它本身已经拥有一个<font face="Times New Roman, serif">DragSource</font>了（编辑器内部的托拽），我们这时候添加一个就会存在多</p><p style="margin-bottom: 0cm;" lang="zh-CN"><font face="Times New Roman, serif">DragSource</font>了。当我添加一个新的<font face="Times New Roman, serif">DragSource</font>时候我们新家的<font face="Times New Roman, serif">DragSource</font>就会被认为是默认的<font face="Times New Roman, serif">DragSource</font>。</p><p style="margin-bottom: 0cm;" lang="zh-CN">他以前的<font face="Times New Roman, serif">DragSource</font>就失效了。这不是我像看到的。</p><p style="margin-bottom: 0cm;" lang="zh-CN">怎么处理。看到了一个牛人的解决方案。</p><p style="margin-bottom: 0cm;" lang="zh-CN"><br /></p><pre lang="zh-CN">What I made to fix the problem was to only allow my DragSource to act under certain <br />conditions (in my application this happens when you click and drag the mouse AND<br /> the SHIFT key is pressed). So when the SHIFT key is not pressed my DragSource does <br />nothing and the editor's internal drag and drop works fine。<br /><br />public void dragStart(DragSourceEvent event) <br />{<br />  ...<br /><br />  if (!condition.isValid())<br />     event.doit = false;<br /><br />  ...<br />}<br /><br /><font face="宋体"><span lang="zh-CN">我尝试了一下这种状况，一下就搞定了。</span></font><br /><span lang="zh-CN">在我的项目中，由于还有一些数据需要转化。<font size="2"><font face="宋体"><font color="#000000">呵呵，感觉不错。<br /><br />参考文档：<br />http://dev.eclipse.org/newslists/news.eclipse.tools.gef/msg15754.html<br /></font></font></font></span></pre><img src ="http://www.blogjava.net/JetGeng/aggbug/80604.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/JetGeng/" target="_blank">Jet Geng</a> 2006-11-11 19:56 <a href="http://www.blogjava.net/JetGeng/archive/2006/11/11/80604.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>从SWT控件中托拽对象到GEF编辑器中</title><link>http://www.blogjava.net/JetGeng/archive/2006/09/12/69195.html</link><dc:creator>Jet Geng</dc:creator><author>Jet Geng</author><pubDate>Tue, 12 Sep 2006 09:16:00 GMT</pubDate><guid>http://www.blogjava.net/JetGeng/archive/2006/09/12/69195.html</guid><wfw:comment>http://www.blogjava.net/JetGeng/comments/69195.html</wfw:comment><comments>http://www.blogjava.net/JetGeng/archive/2006/09/12/69195.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.blogjava.net/JetGeng/comments/commentRss/69195.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/JetGeng/services/trackbacks/69195.html</trackback:ping><description><![CDATA[
		<p style="margin-bottom: 0cm;" align="center">从<font face="Times New Roman, serif">SWT</font>控件中托拽对象到<font face="Times New Roman, serif">GEF</font>编辑器中</p>
		<p style="margin-bottom: 0cm;" align="left">一般情况下<font face="Times New Roman, serif">GEF</font>程序都是采用如下的界面：</p>
		<br />
		<p style="margin-bottom: 0cm;" align="left">
				<img src="http://www.blogjava.net/images/blogjava_net/jetgeng/rcp/gef.jpg" alt="gef.jpg" border="0" height="354" width="462" />
		</p>
		<p style="margin-bottom: 0cm;" align="left">
		</p>
		<p style="margin-bottom: 0cm;" align="left">新建对象的操作时通过拖拽<font face="Times New Roman, serif">Palette</font>中元素到编辑而获得。但是有时候可能需要从<font face="Times New Roman, serif">SWT</font>，操作系统拖一些元素到<font face="Times New Roman, serif">GEF</font>编辑器中来。</p>
		<p style="margin-bottom: 0cm;" align="left">下面我就把创建这样的拖拽过程大概的描述一下：</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font face="Times New Roman, serif">1</font>、定义拖拽源（<font face="Times New Roman, serif"><font size="2"><font face="Courier New, monospace"><font color="#000000">DragSource</font></font></font></font>）。</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font face="Times New Roman, serif">2</font>、定义拖拽目标的监听（<font face="Times New Roman, serif"><font size="2"><font face="Courier New">DropTarget</font></font></font>）。</p>
		<p style="margin-bottom: 0cm;" align="left">到这里对于一般的拖拽其实是可以完工了。</p>
		<p style="margin-bottom: 0cm;" align="left">
				<a name="Header1_HeaderTitle">
				</a>
				<a name="viewpost1_TitleUrl">
				</a>
这个部分可以参考<font face="Times New Roman, serif"><a href="../../weidagang2046/">weidagang2046</a></font><a href="../../weidagang2046/">的专栏的《</a><font face="Times New Roman, serif"><a href="../../weidagang2046/articles/67707.html">DND</a></font><a href="../../weidagang2046/articles/67707.html">入门学习</a><a href="../../weidagang2046/">》</a></p>
		<p style="margin-bottom: 0cm;" align="left">但是要能让<font face="Times New Roman, serif"><font color="#000000"><font size="3"><font face="宋体">GraphicalViewer</font></font></font></font><font color="#000000"><font size="3"><font face="宋体">这个对象扮演起</font></font><font face="Times New Roman, serif"><font size="3"><font face="宋体">DropTarget</font></font></font></font><font color="#000000"><font size="3"><font face="宋体">我们还需要做点其他的工作。</font></font><font face="Times New Roman, serif"><font size="3"><font face="宋体">GraphicalViewer</font></font></font></font><font color="#000000"><font size="3"><font face="宋体">这个类本身提供了一个</font></font><font face="Times New Roman, serif"><font size="2"><font face="Courier New, monospace">addDropTargetListener</font></font><font size="3"><font face="宋体"></font></font></font></font><font color="#000000"><font size="3"><font face="宋体">方法。看到这个方法是不是一阵狂喜啊。如果有也是应该的，因为这个方法就是我们解决前面提出问题的关键。</font></font></font></p>
		<p style="margin-bottom: 0cm;" align="left">
				<font color="#000000">
						<font face="宋体">
								<font size="3">好了看看他的声明吧！</font>
						</font>
				</font>
		</p>
		<pre style="text-align: left;">
				<font color="#000000">
						<font face="宋体">
								<font size="3">public void <b>addDropTargetListener</b>(<a href="http://help.eclipse.org/help31/topic/org.eclipse.gef.doc.isv/reference/api/org/eclipse/gef/dnd/TransferDropTargetListener.html">TransferDropTargetListener</a> listener)</font>
						</font>
				</font>
		</pre>
		<p style="margin-bottom: 0cm;" align="left">
				<font color="#000000">
						<font face="宋体">
								<font size="3">他这个参数居然不是</font>
						</font>
						<font face="宋体">
								<font size="3">DropTargetListener</font>
						</font>
						<font face="宋体">
								<font size="3">。这个</font>
						</font>
						<font face="宋体">
								<font size="3">TransferDropTargetListener</font>
						</font>
						<font face="宋体">
								<font size="3">是一个什么玩意啊！</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font color="#000000">
						<font face="宋体">
								<font size="3">在</font>
						</font>
						<font face="宋体">
								<font size="3">help</font>
						</font>
						<font face="宋体">
								<font size="3">中查到：</font>
						</font>
				</font>
		</p>
		<dl>
				<dt style="text-align: left;">
						<font color="#000000">
								<font face="宋体">
										<font size="3">public
	interface <b>TransferDropTargetListener</b></font>
								</font>
						</font>
				</dt>
				<dt style="margin-bottom: 0.5cm;">
						<font face="Times New Roman, serif">extends
	<a href="http://help.eclipse.org/help31/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/jface/util/TransferDropTargetListener.html">TransferDropTargetListener</a></font>
				</dt>
		</dl>
		<p>
				<font face="Times New Roman, serif">A <code>DropTragetListener</code>
that handles one type of SWT <code><a href="http://help.eclipse.org/help31/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/dnd/Transfer.html">Transfer</a></code>.
The purpose of a TransferDropTargetListener is to: </font>
		</p>
		<ul>
				<li>
						<p style="margin-bottom: 0cm;">
								<font face="Times New Roman, serif">Determine
	enablement for a Drop operation. Enablement is often a function drop
	location, and/or criteria. </font>
						</p>
				</li>
				<li>
						<p style="margin-bottom: 0cm;">
								<font face="Times New Roman, serif">When
	enabled, optionally showing feedback on the DropTarget. </font>
						</p>
				</li>
				<li>
						<p>
								<font face="Times New Roman, serif">Performing the actualy
	Drop </font>
						</p>
				</li>
		</ul>
		<p>
				<font face="Times New Roman, serif">
						<code>
								<a href="http://help.eclipse.org/help31/topic/org.eclipse.gef.doc.isv/reference/api/org/eclipse/gef/dnd/DelegatingDropAdapter.html">DelegatingDropAdapter</a>
						</code>
allows these functions to be implemented separately for unrelated
types of Drags. DelegatingDropAdapter then combines the function of
each TransferDropTargetListener, while allowing them to be
implemented as if they were the only DragSourceListener. </font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font color="#000000">
						<font face="宋体">
								<font size="3">偷下懒，就不翻译了。</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font color="#000000">
						<font face="宋体">
								<font size="3">创建如下类来实现这个接口：</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font color="#000000">
						<font face="Courier New, monospace">
								<font size="2">
										<b>
												<font color="#7f0055">public</font>
										</b>
										<b>
												<font color="#7f0055">class</font>
										</b>
TreeNodeTransferDropTargetListener <b><font color="#7f0055">extends</font></b></font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font color="#000000">
						<font face="Courier New, monospace">
								<font size="2">		AbstractTransferDropTargetListener
{</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<br />
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font color="#000000">
						<font face="Courier New, monospace">
								<font size="2">
										<b>
												<font color="#7f0055">public</font>
										</b>
TreeNodeTransferDropTargetListener(EditPartViewer editPartViewer) {</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font color="#000000">
						<font face="Courier New, monospace">
								<font size="2">
								</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font face="Courier New, monospace">
						<font size="2">
								<b>
										<font color="#000000">
												<font face="宋体">//</font>
										</font>
								</b>
						</font>
				</font>
				<font face="Courier New, monospace">
						<font size="2">
								<b>
										<font color="#000000">
												<font face="宋体">改类默认是处理
</font>
										</font>
								</b>
						</font>
				</font>
				<font face="Courier New, monospace">
						<font size="2">
								<b>
										<font color="#000000">
												<font face="宋体">TextTransfer
</font>
										</font>
								</b>
						</font>
				</font>
				<font face="Courier New, monospace">
						<font size="2">
								<b>
										<font color="#000000">
												<font face="宋体">类型的拖拽事件</font>
										</font>
								</b>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font face="Courier New, monospace">
						<font size="2">
								<b>
										<font color="#000000">
										</font>
										<font color="#7f0055">super</font>
								</b>
								<font color="#000000">(editPartViewer,TextTransfer.<i>getInstance</i>());</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font face="Courier New, monospace">
						<font size="2">
								<font color="#000000">
								</font>
								<font color="#3f7f5f">//
</font>
								<b>
										<font color="#7f9fbf">TODO</font>
								</b>
								<font color="#3f7f5f">
Auto-generated constructor stub</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font color="#000000">
						<font face="Courier New, monospace">
								<font size="2">	}</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<br />
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font color="#000000">
						<font face="Courier New, monospace">
								<font size="2">
										<font color="#646464">@Override</font>
								</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font face="Courier New, monospace">
						<font size="2">
								<font color="#000000">
								</font>
								<b>
										<font color="#7f0055">protected</font>
								</b>
								<font color="#000000">
								</font>
								<b>
										<font color="#7f0055">void</font>
								</b>
								<font color="#000000">
updateTargetRequest() {</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font color="#000000">
						<font face="Courier New, monospace">
								<font size="2">
								</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font color="#000000">
						<font face="Courier New, monospace">
								<font size="2">	}</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<br />
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font color="#000000">
						<font face="Courier New, monospace">
								<font size="2">}</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font size="2">
						<font face="宋体">
								<font color="#000000">我们这个拖拽想是让他执行一个</font>
						</font>
				</font>
				<font face="Times New Roman, serif">
						<font size="2">
								<font face="Courier New, monospace">
										<font color="#000000">create</font>
								</font>
						</font>
				</font>
				<font size="2">
						<font face="宋体">
								<font color="#000000">命令。所以下面就是要重载他的</font>
						</font>
				</font>
				<font face="Times New Roman, serif">createTargetRequest()
</font>
				<font size="2">
						<font face="宋体">
								<font color="#000000">用来处理</font>
						</font>
				</font>
				<font face="Times New Roman, serif">
						<font size="2">
								<font face="Courier New, monospace">
										<font color="#000000">create</font>
								</font>
						</font>
				</font>
				<font size="2">
						<font face="宋体">
								<font color="#000000">对象的请求（</font>
						</font>
				</font>
				<font face="Times New Roman, serif">
						<font size="2">
								<font face="Courier New, monospace">
										<font color="#000000">CreateRequestion</font>
								</font>
						</font>
				</font>
				<font size="2">
						<font face="宋体">
								<font color="#000000">）。</font>
						</font>
				</font>
				<font face="Times New Roman, serif">
						<font size="2">
								<font face="Courier New, monospace">
										<font color="#000000">CreateRequetion</font>
								</font>
						</font>
				</font>
				<font size="2">
						<font face="宋体">
								<font color="#000000">需要使用到一个类，帮助我们创建对象的工厂类。</font>
						</font>
				</font>
				<font face="Times New Roman, serif">
						<font size="2">
								<font face="Courier New, monospace">
										<font color="#000000">GEF</font>
								</font>
						</font>
				</font>
				<font size="2">
						<font face="宋体">
								<font color="#000000">给了我们这样的一个接口</font>
						</font>
				</font>
				<font face="Times New Roman, serif">CreationFactory
</font>。下面我们取实现他就好了。</p>
		<p style="margin-bottom: 0cm;" align="left">
				<br />
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font face="Courier New, monospace">
						<font size="2">
								<b>
										<font color="#7f0055">package</font>
								</b>
								<font color="#000000">
org.eclipse.gef.examples.shapes.rcp.views;</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<br />
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font face="Courier New, monospace">
						<font size="2">
								<b>
										<font color="#7f0055">import</font>
								</b>
								<font color="#000000">
org.eclipse.gef.examples.shapes.model.EllipticalShape;</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font face="Courier New, monospace">
						<font size="2">
								<b>
										<font color="#7f0055">import</font>
								</b>
								<font color="#000000">
org.eclipse.gef.requests.CreationFactory;</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<br />
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font face="Courier New, monospace">
						<font size="2">
								<b>
										<font color="#7f0055">public</font>
								</b>
								<font color="#000000">
								</font>
								<b>
										<font color="#7f0055">class</font>
								</b>
								<font color="#000000">
TypeCreationFactory </font>
								<b>
										<font color="#7f0055">implements</font>
								</b>
								<font color="#000000">
 CreationFactory {</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<br />
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font color="#000000">
						<font face="Courier New, monospace">
								<font size="2">
								</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font face="Courier New, monospace">
						<font size="2">
								<font color="#000000">
								</font>
								<b>
										<font color="#7f0055">public</font>
								</b>
								<font color="#000000">
Object getNewObject() {</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font face="Courier New, monospace">
						<font size="2">
								<font color="#000000">
								</font>
								<font color="#3f7f5f">//
</font>
								<b>
										<font color="#7f9fbf">TODO</font>
								</b>
								<font color="#3f7f5f">
Auto-generated method stub</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font face="Courier New, monospace">
						<font size="2">
								<font color="#000000">		EllipticalShape
label = </font>
								<b>
										<font color="#7f0055">new</font>
								</b>
								<font color="#000000">
EllipticalShape();</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font face="Courier New, monospace">
						<font size="2">
								<font color="#000000">
								</font>
								<b>
										<font color="#7f0055">return</font>
								</b>
								<font color="#000000">
label;</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font color="#000000">
						<font face="Courier New, monospace">
								<font size="2">	}</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<br />
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font face="Courier New, monospace">
						<font size="2">
								<font color="#000000">
								</font>
								<b>
										<font color="#7f0055">public</font>
								</b>
								<font color="#000000">
Object getObjectType() {</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font face="Courier New, monospace">
						<font size="2">
								<font color="#000000">
								</font>
								<b>
										<font color="#7f0055">return</font>
								</b>
								<font color="#000000">
EllipticalShape.</font>
								<b>
										<font color="#7f0055">class</font>
								</b>
								<font color="#000000">;</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font color="#000000">
						<font face="Courier New, monospace">
								<font size="2">	}</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<br />
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font color="#000000">
						<font face="Courier New, monospace">
								<font size="2">}</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<br />
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font color="#000000">
						<font face="宋体">
								<font size="2">注意：这里的</font>
						</font>
						<font face="Courier New, monospace">
								<font size="2">getNewObject</font>
						</font>
						<font face="宋体">
								<font size="2">是返回要创建类的一个对象实例。</font>
						</font>
						<font face="Courier New, monospace">
								<font size="2">GetObjectType</font>
						</font>
						<font face="宋体">
								<font size="2">需要返回需要创建对象的类。这个可不要搞反了。</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font color="#000000">
						<font face="宋体">
								<font size="2">这样我们就可以把我们的
</font>
						</font>
						<font face="Courier New, monospace">
								<font size="2">TreeNodeTransferDropTargetListener
</font>
						</font>
						<font face="宋体">
								<font size="2">
										<font face="Courier New, monospace">类中的</font>
								</font>
						</font>
						<font face="Courier New, monospace">
								<font size="2">createTargetRequest</font>
						</font>
						<font face="宋体">
								<font size="2">
										<font face="Courier New, monospace">方法加上了。</font>
								</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<br />
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font color="#000000">
						<font face="Courier New, monospace">
								<font size="2">
										<b>
												<font color="#7f0055">private</font>
										</b>
TypeCreationFactory <font color="#0000c0">factory</font> = <b><font color="#7f0055">new</font></b>
TypeCreationFactory();</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font color="#000000">
						<font face="Courier New, monospace">
								<font size="2">
										<b>
												<font color="#7f0055">protected</font>
										</b>
Request createTargetRequest() {</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font face="Courier New, monospace">
						<font size="2">
								<font color="#000000">		CreateRequest
request = </font>
								<b>
										<font color="#7f0055">new</font>
								</b>
								<font color="#000000">
CreateRequest();</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font face="Courier New, monospace">
						<font size="2">
								<font color="#000000">		request.setFactory(</font>
								<font color="#0000c0">factory</font>
								<font color="#000000">);</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font face="Courier New, monospace">
						<font size="2">
								<font color="#000000">
								</font>
								<b>
										<font color="#7f0055">return</font>
								</b>
								<font color="#000000">
request;</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font color="#000000">
						<font face="Courier New, monospace">
								<font size="2">}</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<br />
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font color="#000000">
						<font face="宋体">
								<font size="2">好了这个时候不要客气了，加上</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font color="#000000">
						<font face="Courier New, monospace">
								<font size="2">
										<b>
												<font color="#7f0055">protected</font>
										</b>
										<b>
												<font color="#7f0055">void</font>
										</b> handleDragOver() {</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font face="Courier New, monospace">
						<font size="2">
								<font color="#000000">		getCurrentEvent().</font>
								<font color="#0000c0">detail</font>
								<font color="#000000">
= DND.</font>
								<i>
										<font color="#0000c0">DROP_MOVE</font>
								</i>
								<font color="#000000">|DND.</font>
								<i>
										<font color="#0000c0">DROP_COPY</font>
								</i>
								<font color="#000000">;</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font face="Courier New, monospace">
						<font size="2">
								<font color="#000000">
								</font>
								<b>
										<font color="#7f0055">super</font>
								</b>
								<font color="#000000">.handleDragOver();</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font color="#000000">
						<font face="Courier New, monospace">
								<font size="2">	}</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<br />
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font face="Courier New, monospace">
						<font size="2">
								<font color="#000000">
								</font>
								<font color="#646464">@Override</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font face="Courier New, monospace">
						<font size="2">
								<font color="#000000">
								</font>
								<b>
										<font color="#7f0055">protected</font>
								</b>
								<font color="#000000">
								</font>
								<b>
										<font color="#7f0055">void</font>
								</b>
								<font color="#000000">
handleDrop() {</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font face="Courier New, monospace">
						<font size="2">
								<font color="#000000">
								</font>
								<font color="#3f7f5f">//String
s = (String)getCurrentEvent().data;</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font face="Courier New, monospace">
						<font size="2">
								<font color="#000000">
								</font>
								<font color="#3f7f5f">//factory.setText(s);</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font face="Courier New, monospace">
						<font size="2">
								<font color="#000000">
								</font>
								<b>
										<font color="#7f0055">super</font>
								</b>
								<font color="#000000">.handleDrop();</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font color="#000000">
						<font face="Courier New, monospace">
								<font size="2">	}</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font color="#000000">
						<font face="宋体">
								<font size="2">这样的方法吧。</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font color="#000000">
						<font face="宋体">
								<font size="2">这样这个功能就完成了。</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<br />
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font color="#000000">
						<font face="宋体">
								<font size="2">参考文献：</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font color="#000000">
						<font face="Courier New, monospace">
								<font size="2">
										<a href="../../weidagang2046/archive/2006/09/05/67707.html">http://www.blogjava.net/weidagang2046/archive/2006/09/05/67707.html</a>
								</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font color="#000000">
						<font face="Courier New, monospace">
								<font size="2">http://www.eclipse.org/articles/Article-GEF-dnd/GEF-dnd.html</font>
						</font>
				</font>
		</p>
		<p style="margin-bottom: 0cm;" align="left">
				<font color="#000000">
						<font face="Courier New, monospace">
								<font size="2">
										<br />
								</font>
						</font>
				</font>
		</p>
<img src ="http://www.blogjava.net/JetGeng/aggbug/69195.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/JetGeng/" target="_blank">Jet Geng</a> 2006-09-12 17:16 <a href="http://www.blogjava.net/JetGeng/archive/2006/09/12/69195.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>