﻿<?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-eroself-随笔分类-GEF&amp;EMF&amp;GMF</title><link>http://www.blogjava.net/eroself/category/27851.html</link><description>关于人生的程式，在这里谱写......</description><language>zh-cn</language><lastBuildDate>Mon, 07 Jan 2008 11:05:50 GMT</lastBuildDate><pubDate>Mon, 07 Jan 2008 11:05:50 GMT</pubDate><ttl>60</ttl><item><title>把GEF editor集成到Multi-page editor中</title><link>http://www.blogjava.net/eroself/archive/2008/01/07/173292.html</link><dc:creator>鬼谷子</dc:creator><author>鬼谷子</author><pubDate>Mon, 07 Jan 2008 04:10:00 GMT</pubDate><guid>http://www.blogjava.net/eroself/archive/2008/01/07/173292.html</guid><wfw:comment>http://www.blogjava.net/eroself/comments/173292.html</wfw:comment><comments>http://www.blogjava.net/eroself/archive/2008/01/07/173292.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/eroself/comments/commentRss/173292.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/eroself/services/trackbacks/173292.html</trackback:ping><description><![CDATA[<p>转自：http://superinfinite.spaces.live.com/blog/cns!59C5F00DCFF3DBDB!221.entry<br />
<br />
</p>
<div><font face="Courier New">由于一个需求是要在GEF的一个画布外，再提供一个view显示JSP的流程（其实这个功能没大必要，但实现起来却不容易）。</font></div>
<div><font face="Courier New">&nbsp;</font></div>
<div><font face="Courier New">不管怎么说，还是要照着需求去做滴。</font></div>
<div><font face="Courier New">&nbsp;</font></div>
<div><font face="Courier New">其实，在看了需求后，我就意识到了可能要做成一个Multi-page。 由于时间不多，没来的及仔细考虑，</font></div>
<div><font face="Courier New">一开始还是做成普通的GEF编辑器，在把application flow基本上搞定之后，再次回到这个问题上。</font></div>
<div><font face="Courier New">&nbsp;</font></div>
<div><font face="Courier New">没办法，继续看别人的代码（反编译的），myeclipse中的web-designer，就象dreamweaver一样有3种视图，虽然这是我以后要做的，但却没有采用它的做法。</font></div>
<div><font face="Courier New">&nbsp;</font></div>
<div><font face="Courier New">记的struts-box的struts-config editor有个visualizer的页面（真巧，和我现在写的plugin名字一样），它是一个GraphicalViewer ，做法其实挺简单的。</font></div>
<div><font face="Courier New">&nbsp;</font></div>
<div><font face="Courier New">构建一个Multi-page editor的框架。</font></div>
<div><font face="Courier New">&nbsp;</font></div>
<div><font face="Courier New">把一个视图作为一个page放到这个Multi-page editor中。</font></div>
<div><font face="Courier New">&nbsp;</font></div>
<div><font face="Courier New">为这个page写一个Section,</font></div>
<div><font face="Courier New">&nbsp;</font></div>
<div><font face="Courier New">protected void createClient(Section section, FormToolkit toolkit) {<br />
&nbsp;&nbsp;Composite container = toolkit.createComposite(section);<br />
&nbsp;&nbsp;FillLayout layout = new FillLayout();<br />
&nbsp;&nbsp;container.setLayout(layout);<br />
&nbsp;&nbsp;GraphicalViewer viewer = ((VisualizerEditor)editor).createGraphicalViewer(container);</font></div>
<div><font face="Courier New">&nbsp;section.setClient(container);</font></div>
<div><font face="Courier New">}</font></div>
<div><font face="Courier New">&nbsp;</font></div>
<div><font face="Courier New">这个viewer呢 ，当然是原来那个GEF editor中的viewer了。</font></div>
<div><font face="Courier New">&nbsp;</font></div>
<div><font face="Courier New">这时候那个新建的Multi-page当然也要改了，addPage()就不说了，</font></div>
<div><font face="Courier New">&nbsp;</font></div>
<div><font face="Courier New">以后是要用这个Multi-page editor打开的，所以原来那个GEF 的editor中的几个方法是调用不到的。</font></div>
<div><font face="Courier New">&nbsp;</font></div>
<div><font face="Courier New">public void init(IEditorSite site, IEditorInput input)<br />
&nbsp;&nbsp;&nbsp;throws PartInitException {<br />
&nbsp;&nbsp;super.init(site,input);<br />
&nbsp;&nbsp;appFlowVisualEditor.init(site, input);<br />
&nbsp;&nbsp;this.visualizer = appFlowVisualEditor.getVisualizer();<br />
&nbsp;&nbsp;appFlowVisualEditor.setVisualizerEditor(this);<br />
&nbsp;}</font></div>
<div><font face="Courier New">&nbsp;</font></div>
<div><font face="Courier New">这是一个，其它的就缺什么补什么，debug的时候可以看出来的。</font></div>
<div><font face="Courier New">&nbsp;</font></div>
<div><font face="Courier New">还有一点，就是如果没在section中另外加listener 的话，你在page中编辑GEF的元素，编辑器是不会标志dirty的，所以在section中为CommandStack加一个listener：</font></div>
<div><font face="Courier New">viewer.getEditDomain().getCommandStack().addCommandStackEventListener(new CommandStackEventListener(){</font></div>
<div><font face="Courier New">&nbsp;&nbsp;&nbsp;public void stackChanged(CommandStackEvent arg0) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;markDirty();<br />
&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;});</font></div>
<div><font face="Courier New"></font>&nbsp;</div>
<div><font face="Courier New"></font>&nbsp;</div>
<div><font face="Courier New" color="#ff0000">在editor <em>init()</em>的时候 getCommandStack().addCommandStackListener(this) (editor实现CommandStackListener) Section中就不需要加了。</font></div>
<div><font face="Courier New" color="#ff0000"></font>&nbsp;</div>
<div><font face="Courier New" color="#ff0000">要覆盖FormEditor的<em>isDirty()</em>方法</font></div>
<div><font face="Courier New">&nbsp;</font></div>
<div><font face="Courier New">这样编辑器会在你对GEF元素进行操作后会给title标上一个*号。今天试了一下，却发现无论怎么保存，那个星号还在，仔细一看，原来忘加了个comit的方法：</font></div>
<div><font face="Courier New">&nbsp;</font></div>
<div><font face="Courier New">private void commitFormPages(boolean b) {<br />
&nbsp;&nbsp;IFormPage[] pages = getPages();<br />
&nbsp;&nbsp;for (int i = 0; i &lt; pages.length; i++) {<br />
&nbsp;&nbsp;&nbsp;IFormPage page = pages[i];<br />
&nbsp;&nbsp;&nbsp;IManagedForm mform = page.getManagedForm();<br />
&nbsp;&nbsp;&nbsp;if (mform != null &amp;&amp; mform.isDirty())<br />
&nbsp;&nbsp;&nbsp;&nbsp;mform.commit(true);<br />
&nbsp;&nbsp;}</font></div>
<div><font face="Courier New">&nbsp;}<br />
&nbsp;<br />
&nbsp;protected IFormPage[] getPages() {<br />
&nbsp;&nbsp;List formPages = new ArrayList();<br />
&nbsp;&nbsp;for (int i = 0; i &lt; pages.size(); i++) {<br />
&nbsp;&nbsp;&nbsp;Object page = pages.get(i);<br />
&nbsp;&nbsp;&nbsp;if (page instanceof IFormPage)<br />
&nbsp;&nbsp;&nbsp;&nbsp;formPages.add(page);<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;return (IFormPage[]) formPages.toArray(new IFormPage[formPages.size()]);<br />
&nbsp;}</font></div>
<div><font face="Courier New">&nbsp;</font></div>
<div><font face="Courier New">呵呵，以后不会忘了吧。</font></div>
<img src ="http://www.blogjava.net/eroself/aggbug/173292.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/eroself/" target="_blank">鬼谷子</a> 2008-01-07 12:10 <a href="http://www.blogjava.net/eroself/archive/2008/01/07/173292.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>