??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲精品天堂,在这里有精品,国产精品一卡http://www.aygfsteel.com/alanyzhang/Dengues Studio 开?用代码说?/description>zh-cnFri, 04 Jul 2025 06:15:41 GMTFri, 04 Jul 2025 06:15:41 GMT60[DENGUES]如何解决插g之间的@环依赖问?/title><link>http://www.aygfsteel.com/alanyzhang/archive/2007/11/20/157530.html</link><dc:creator>张飞刀(Dengues Studio)</dc:creator><author>张飞刀(Dengues Studio)</author><pubDate>Tue, 20 Nov 2007 05:19:00 GMT</pubDate><guid>http://www.aygfsteel.com/alanyzhang/archive/2007/11/20/157530.html</guid><wfw:comment>http://www.aygfsteel.com/alanyzhang/comments/157530.html</wfw:comment><comments>http://www.aygfsteel.com/alanyzhang/archive/2007/11/20/157530.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.aygfsteel.com/alanyzhang/comments/commentRss/157530.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/alanyzhang/services/trackbacks/157530.html</trackback:ping><description><![CDATA[<p>        如果两个插g出现双向的独立性关联就形成了@环依赖,Dengues利用Eclipse扩展Ҏ式解册个问题?br /> <br />         首先来介l一下原理。Eclipse在启动的时候会所有的扩展点实现加载到一个注册表里面Q这里注册的东西可以是一个类Q就像是我们通过扩展点的方式实现一个Viewer一P我们不仅要写入相应的iconq要写入相关的指定的cR?br />             <img alt="" src="http://www.aygfsteel.com/images/blogjava_net/alanyzhang/viewer_reg.jpg" border="0" /><br /> <br />             <img height="272" alt="" src="http://www.aygfsteel.com/images/blogjava_net/alanyzhang/viewer_desp.jpg" width="338" border="0" /><br />         同样道理Q如果我们可以定义一个扩展点Q在Eclipse启动的时候把实现了这个扩展点的类加蝲C个核心插仉。如果别的插件如果要用这个类的话Q直接加入对之个核心插g的依赖不可以了从而回避了对这个插件直接的依赖见下图:<br /> <br />         <img alt="" src="http://www.aygfsteel.com/images/blogjava_net/alanyzhang/plugin_struct.jpg" border="0" /><br />         在图1里A插g要引用B插g里的c,同样B插g也有需求要引用A插g里的c,q样造成了插件的循环依赖。现在利用扩展点Q在AQB插g里实C个定义于Core插g里的扩展点,在Eclispe启动的时候,实现了此扩展点的cd可以被加载到Core插g里。通过Core的桥梁作用A、B插g便可以实现类的相互引用。这里A、B插g只是对Core有一个单向的依赖关系Q通过core插g的帮助A与之间可以怺调,避免了直接的调用所以也׃会Ş成@环依赖了?br /> <br />         一、扩展点的定义:<br /> <br />         点击q入org.dengues.core插g的plugin.xml 文g,打开Extension Point标签Q点Add加入一个扩展点输入如下信息Q?br />         <img height="86" alt="" src="http://www.aygfsteel.com/images/blogjava_net/alanyzhang/extension01.jpg" width="334" border="0" /><br />         在Definition里加一个叫做Service的element,q加入两条use栏ؓreuqired的属性如下图所C:<br /> <br />         <img height="52" alt="" src="http://www.aygfsteel.com/images/blogjava_net/alanyzhang/extension02.jpg" width="231" border="0" /><br /> <br />         其中serviceClass的Type要选成java,q且在Implements里定义一个接口,q个接口规定了这个扩展点在实现的时候指定的cR这里ؓIDenguesService。其实接口里什么也没方法也没有定义Q只是一个申明而已?br />         <img height="234" alt="" src="http://www.aygfsteel.com/images/blogjava_net/alanyzhang/extension03.jpg" width="335" border="0" /><br /> <br />         </p> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><span style="color: #0000ff">package</span><span style="color: #000000"> org.dengues.core;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /> <img id="Codehighlighter1_60_241_Open_Image" onclick="this.style.display='none'; Codehighlighter1_60_241_Open_Text.style.display='none'; Codehighlighter1_60_241_Closed_Image.style.display='inline'; Codehighlighter1_60_241_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_60_241_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_60_241_Closed_Text.style.display='none'; Codehighlighter1_60_241_Open_Image.style.display='inline'; Codehighlighter1_60_241_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">interface</span><span style="color: #000000"> IDenguesService </span><span id="Codehighlighter1_60_241_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_60_241_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    String ID </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">org.dengues.commons.denguesService</span><span style="color: #000000">"</span><span style="color: #000000">; </span><span style="color: #008000">//</span><span style="color: #008000">$NON-NLS-1$</span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #000000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    String SERVICE_CLASS </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">serviceClass</span><span style="color: #000000">"</span><span style="color: #000000">; </span><span style="color: #008000">//</span><span style="color: #008000">$NON-NLS-1$</span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #000000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    String SERVICE_ID </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">serviceID</span><span style="color: #000000">"</span><span style="color: #000000">; </span><span style="color: #008000">//</span><span style="color: #008000">$NON-NLS-1$</span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" /></span><span style="color: #000000">}</span></span></div> <p><br />         <br />         二、实现扩展点。具体怎么用一个扩展点Q这里就不用多说了,只重点介l一下怎么实现IDenguesServicecR我们以Dengues里的org.dengues.design.core插gZ。在org.dengues.core里我们我Z个IDenguesService的子接口IDesignerCoreServiceQƈ写入我们要向其它plugin公开的方法?br />         </p> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img id="Codehighlighter1_62_831_Open_Image" onclick="this.style.display='none'; Codehighlighter1_62_831_Open_Text.style.display='none'; Codehighlighter1_62_831_Closed_Image.style.display='inline'; Codehighlighter1_62_831_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_62_831_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_62_831_Closed_Text.style.display='none'; Codehighlighter1_62_831_Open_Image.style.display='inline'; Codehighlighter1_62_831_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">interface</span><span style="color: #000000"> IDesignerCoreService </span><span style="color: #0000ff">extends</span><span style="color: #000000"> IDenguesService </span><span id="Codehighlighter1_62_831_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_62_831_Open_Text"><span style="color: #000000">{<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> IComponentsFactory getComponentsFactory();<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> IComponentFilesNaming getComponentFilesNaming();<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> initializeTemplates();<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> ICodeGenerator getCodeGenerator(ICompProcess process);<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> ICodeGenerator getCodeGenerator();<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> IJavaETLProcessor getJavaProcessor(ICompProcess process);<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> IJavaETLProcessor getJavaProcessor();<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #008000">//</span><span style="color: #008000"> public Action createStartHsqldbServer(String dbName);</span><span style="color: #008000"><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: #000000"><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> Action createStartHsqldbServer();<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">boolean</span><span style="color: #000000"> checkHsqldbConnection();<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> runSqlScript(IFile scriptFile);<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> DatabaseContainer getHsqlDatabase() </span><span style="color: #0000ff">throws</span><span style="color: #000000"> SQLException;<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> Connection getCurrentConnection() </span><span style="color: #0000ff">throws</span><span style="color: #000000"> SQLException, CoreException, ClassNotFoundException;<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div> <p><br />          以上q些Ҏ是org.dengues.designer.coreq个插g惌对其它插件公开的方法了Q它的实现自然会被写入到q个插g里了。这D代码很多,我们׃列在q里了,如果有兴的朋友可以到我们Dengues的google svn去check out代码。写好对IDesignerCoreService的实C后,我们可以把它加入到事先我们定义好的扩展炚w了,见下图:<br />         <br />         <img height="127" alt="" src="http://www.aygfsteel.com/images/blogjava_net/alanyzhang/extension04.jpg" width="762" border="0" /><br /> <br />         图中的DesignerCoreService是IDesingerCoreService的实现。好了,当Eclipse启动的时候它׃把这个类加蝲到注册表里了Q我们可以从q个注册里取到这个类了。那以后如果我们想从q个plugin里向外公开一些方法的话,可以通过向IDesignerCoreService写入相应的方法,在DesignerCoreService里写入相应的实现可以了?br /> <br />         三、从注册表里取出扩展点的cR?br /> <br />         在org.dengues.core里我们写了一个GlobalServiceFactory里面提供了相应的代码Q?br /> <br />             </p> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img id="Codehighlighter1_7_188_Open_Image" onclick="this.style.display='none'; Codehighlighter1_7_188_Open_Text.style.display='none'; Codehighlighter1_7_188_Closed_Image.style.display='inline'; Codehighlighter1_7_188_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_7_188_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_7_188_Closed_Text.style.display='none'; Codehighlighter1_7_188_Open_Image.style.display='inline'; Codehighlighter1_7_188_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span id="Codehighlighter1_7_188_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_7_188_Open_Text"><span style="color: #000000">{<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />        IExtensionRegistry registry </span><span style="color: #000000">=</span><span style="color: #000000"> Platform.getExtensionRegistry();<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />        configurationElements </span><span style="color: #000000">=</span><span style="color: #000000"> registry.getConfigurationElementsFor(IDenguesService.ID); </span><span style="color: #008000">//</span><span style="color: #008000">$NON-NLS-1$</span><span style="color: #008000"><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" /></span><span style="color: #000000">    }</span></span><span style="color: #000000"><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /><br /> <img id="Codehighlighter1_195_362_Open_Image" onclick="this.style.display='none'; Codehighlighter1_195_362_Open_Text.style.display='none'; Codehighlighter1_195_362_Closed_Image.style.display='inline'; Codehighlighter1_195_362_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_195_362_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_195_362_Closed_Text.style.display='none'; Codehighlighter1_195_362_Open_Image.style.display='inline'; Codehighlighter1_195_362_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />    </span><span id="Codehighlighter1_195_362_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff">/** */</span><span id="Codehighlighter1_195_362_Open_Text"><span style="color: #008000">/**</span><span style="color: #008000"><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />     * Comment method "getService".Gets the specific IService.<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />     * <br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />     * </span><span style="color: #808080">@param</span><span style="color: #008000"> klass the Service type you want to get<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />     * </span><span style="color: #808080">@return</span><span style="color: #008000"> IService IService<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />     </span><span style="color: #008000">*/</span></span><span style="color: #000000"><br /> <img id="Codehighlighter1_415_796_Open_Image" onclick="this.style.display='none'; Codehighlighter1_415_796_Open_Text.style.display='none'; Codehighlighter1_415_796_Closed_Image.style.display='inline'; Codehighlighter1_415_796_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_415_796_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_415_796_Closed_Text.style.display='none'; Codehighlighter1_415_796_Open_Image.style.display='inline'; Codehighlighter1_415_796_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> IDenguesService getService(Class klass) </span><span id="Codehighlighter1_415_796_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_415_796_Open_Text"><span style="color: #000000">{<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />        IDenguesService service </span><span style="color: #000000">=</span><span style="color: #000000"> services.get(klass);<br /> <img id="Codehighlighter1_501_766_Open_Image" onclick="this.style.display='none'; Codehighlighter1_501_766_Open_Text.style.display='none'; Codehighlighter1_501_766_Closed_Image.style.display='inline'; Codehighlighter1_501_766_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_501_766_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_501_766_Closed_Text.style.display='none'; Codehighlighter1_501_766_Open_Image.style.display='inline'; Codehighlighter1_501_766_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span style="color: #0000ff">if</span><span style="color: #000000"> (service </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000">) </span><span id="Codehighlighter1_501_766_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_501_766_Open_Text"><span style="color: #000000">{<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />            service </span><span style="color: #000000">=</span><span style="color: #000000"> findService(klass);<br /> <img id="Codehighlighter1_578_714_Open_Image" onclick="this.style.display='none'; Codehighlighter1_578_714_Open_Text.style.display='none'; Codehighlighter1_578_714_Closed_Image.style.display='inline'; Codehighlighter1_578_714_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_578_714_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_578_714_Closed_Text.style.display='none'; Codehighlighter1_578_714_Open_Image.style.display='inline'; Codehighlighter1_578_714_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (service </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000">) </span><span id="Codehighlighter1_578_714_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_578_714_Open_Text"><span style="color: #000000">{<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span><span style="color: #0000ff">throw</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> RuntimeException(</span><span style="color: #000000">"</span><span style="color: #000000">GlobalServiceRegister.ServiceNotRegistered</span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000">+</span><span style="color: #000000"> klass.getName()); </span><span style="color: #008000">//</span><span style="color: #008000">$NON-NLS-1$</span><span style="color: #008000"><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" /></span><span style="color: #000000">            }</span></span><span style="color: #000000"><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />            services.put(klass, service);<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span></span><span style="color: #000000"><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="color: #0000ff">return</span><span style="color: #000000"> service;<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />    }</span></span></div> <br /> <p><br />         如果我们要取刚才定义好的那个IDesignerCoreService的话Q我们可以按如下方式取到Q?br /> </p> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img id="Codehighlighter1_57_218_Open_Image" onclick="this.style.display='none'; Codehighlighter1_57_218_Open_Text.style.display='none'; Codehighlighter1_57_218_Closed_Image.style.display='inline'; Codehighlighter1_57_218_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_57_218_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_57_218_Closed_Text.style.display='none'; Codehighlighter1_57_218_Open_Image.style.display='inline'; Codehighlighter1_57_218_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /><span style="color: #000000">    </span><span style="color: #0000ff">public</span><span style="color: #000000"> IDesignerCoreService getDesignerCoreService() </span><span id="Codehighlighter1_57_218_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_57_218_Open_Text"><span style="color: #000000">{<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />        IDenguesService service </span><span style="color: #000000">=</span><span style="color: #000000"> GlobalServiceFactory.getDefault().getService(IDesignerCoreService.</span><span style="color: #0000ff">class</span><span style="color: #000000">);<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="color: #0000ff">return</span><span style="color: #000000"> (IDesignerCoreService) service;<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />    }</span></span></div> <p>        <br />         其实D代码是写在org.dengues.core插g里的CorePlugin里的Q也是说在M一个插仉只要加入了对org.dengues.core的依赖都可以通过CorePlguin.getDefault().getDesignerCoreService()来得到IDesignerCoreService的实例了?br />  <br />            <br />             <br />         <br />         <br /> <br /> </p> <img src ="http://www.aygfsteel.com/alanyzhang/aggbug/157530.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/alanyzhang/" target="_blank">张飞刀(Dengues Studio)</a> 2007-11-20 13:19 <a href="http://www.aygfsteel.com/alanyzhang/archive/2007/11/20/157530.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[DENGUES]怎样生成一个Eclipse的update website?/title><link>http://www.aygfsteel.com/alanyzhang/archive/2007/10/30/156980.html</link><dc:creator>张飞刀(Dengues Studio)</dc:creator><author>张飞刀(Dengues Studio)</author><pubDate>Tue, 30 Oct 2007 09:28:00 GMT</pubDate><guid>http://www.aygfsteel.com/alanyzhang/archive/2007/10/30/156980.html</guid><wfw:comment>http://www.aygfsteel.com/alanyzhang/comments/156980.html</wfw:comment><comments>http://www.aygfsteel.com/alanyzhang/archive/2007/10/30/156980.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.aygfsteel.com/alanyzhang/comments/commentRss/156980.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/alanyzhang/services/trackbacks/156980.html</trackback:ping><description><![CDATA[       <div align="center"><img src="http://www.aygfsteel.com/images/blogjava_net/alanyzhang/update01.jpg" alt="" border="0" height="619" width="622" /></div> <br /> <br />        Eclipse里有一功能就是通过update site直接插件从|上下蝲到自qIDE里,使用h方便省时Q^时只是这L别h的插Ӟ那如果自己开发了一个插Ӟ惌别h通过q种方式下蝲q用可以吗Q答案当然是肯定的?br /> <br />        首先要创Z个feature工程Q步骤如下:<br />        1Q在New Project Wizard选择Feature ProjectQ点一下步?br />        2Q写入feature工程的名字比?org.dengues.feature<br />        3Q在W二里保持ID为org.dengues.feature.名字改为Dengues Feature.<br />        4)选中要关联的插gQ在q里我选择了所有的dengues目插gQ如下:<br /> <br /> <div align="center"><img src="http://www.aygfsteel.com/images/blogjava_net/alanyzhang/update03.jpg" alt="" border="0" height="410" width="511" /></div>        <br />         点击finishq样创建好了一个feature插g了。这里简单的介绍一下feature有什么用Qfeature可以把其它的一个或者多个插件组合到一P以便于用户对插g的加载,理Q命名就像是对一个单元进行操作一栗当然也包括可以方便用于发布到网上?br /> <br />        做好feature插g以后Q就是要往里面写入相应的信息喽Q里面包括版权,可访问网站什么的东东Q填好以后就可以q入下一步创Z个update site project了?br /> <br />        创徏的步骤很单就不再详细说明了,工程名就叫org.dengues.update吧?br /> <br />        创徏完成之后Q在site map里加入一个category,q将我们刚才做好的feature加到q个category里面。就成了下面的样子:<br /> <br /> <div align="center"><img src="http://www.aygfsteel.com/images/blogjava_net/alanyzhang/update05.jpg" alt="" border="0" /></div> <br />        选中刚加入的feature选buildQ完成之后这个update site project的结构就变成了这栗?br /> <br />        <img src="http://www.aygfsteel.com/images/blogjava_net/alanyzhang/update06.jpg.jpg" alt="" border="0" /><br /> <br />        把这个工E下的所有文件直接拷到要发布的网|务器上就要以了,q样你就以通过Eclipse讉Kq个|站来更C的插件了不信你试Q简单吧Q?br />        <br /> <br /> <br /> <br /> <br /> <img src ="http://www.aygfsteel.com/alanyzhang/aggbug/156980.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/alanyzhang/" target="_blank">张飞刀(Dengues Studio)</a> 2007-10-30 17:28 <a href="http://www.aygfsteel.com/alanyzhang/archive/2007/10/30/156980.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[DENGUES]动态的hPalette里的内容http://www.aygfsteel.com/alanyzhang/archive/2007/10/26/155368.html张飞刀(Dengues Studio)张飞刀(Dengues Studio)Fri, 26 Oct 2007 05:32:00 GMThttp://www.aygfsteel.com/alanyzhang/archive/2007/10/26/155368.htmlhttp://www.aygfsteel.com/alanyzhang/comments/155368.htmlhttp://www.aygfsteel.com/alanyzhang/archive/2007/10/26/155368.html#Feedback0http://www.aygfsteel.com/alanyzhang/comments/commentRss/155368.htmlhttp://www.aygfsteel.com/alanyzhang/services/trackbacks/155368.html
       一开始还在怀疑这个能否实CQ不q后来看了看代码Q发现这是完全可行的Q且看我l细道来Q?br />
        先看GraphicalEditorWithFlyoutPalette里的splitterq个成员Q它把整个editor分成了两个部分一个就是大的用于GEFd的那部䆾Q另外一部分很明昑ְ是palette啦!说这么多Q看看它的createControlҎ全明白啦:
public void createPartControl(Composite parent) {
    splitter 
= new FlyoutPaletteComposite(parent, SWT.NONE, getSite().getPage(),
            getPaletteViewerProvider(), getPalettePreferences());
    
super.createPartControl(splitter);
    splitter.setGraphicalControl(getGraphicalControl());
    
if (page != null{
        splitter.setExternalViewer(page.getPaletteViewer());
        page 
= null;
    }

}

        其中的setExternalviewer是攄palette的viewerQ说到viewer我的W一个联惛_是SWT里的viewer其实不是q样的,q里的viewer其实与一个基于GEF的Graphcial ViewerQ也是_我们在一个graphical editor里看到的palette是通过drawer2DMMQ和我们qxGEF里的囑Ş没什么两栗?br />
/**
 * Returns the PaletteRoot for the palette viewer.
 * 
@return the palette root
 
*/

protected abstract PaletteRoot getPaletteRoot();
        再看q个getPaletteRootҎ它ؓpalette viewer提供一个root,那这个root到底是什么呢Q我们再l箋往下看。沿着palette root的承树往上找Q最后发Cq个Q?br />
        一看palette entry的文档就明白了,其实它就?palette的模型?br />
/**
 * Root class (statically) for the palette model.
 * 
 * 
@author Pratik Shah
 
*/

public class PaletteEntry {
        当然如果它是GEF的模型,那么必然他就会有listeners一查代码,果真是这L?br />
/**
 * A listener can only be added once.  Adding it more than once will do nothing.
 * 
@param listener the PropertyChangeListener that is to be notified of changes
 * 
@see java.beans.PropertyChangeSupport#addPropertyChangeListener(
 *                                                         java.beans.PropertyChangeListener)
 
*/

public void addPropertyChangeListener(PropertyChangeListener listener) {
    listeners.removePropertyChangeListener(listener);
    listeners.addPropertyChangeListener(listener);
}
        那么q个add listenerҎ被谁用呢Q想都不用想了,肯定是被它的edit part 喽,MVC嘛~~~不信看PaletteEditPart.java的activateҎQ?br />
/**
 * 
@see org.eclipse.gef.editparts.AbstractGraphicalEditPart#activate()
 
*/

public void activate() {
    
super.activate();
    PaletteEntry model 
= (PaletteEntry)getModel();
    model.addPropertyChangeListener(
this);
    traverseChildren(model, 
true);
}
        
        
        模型的修改必定会被通知?edit part 里,它再Ҏ具体的情况对viewerq行更新Q见下:
/**
 * 
@see java.beans.PropertyChangeListener#propertyChange(PropertyChangeEvent)
 
*/

public void propertyChange(PropertyChangeEvent evt) {
    String property 
= evt.getPropertyName();
    
if (property.equals(PaletteContainer.PROPERTY_CHILDREN)) {
        traverseChildren((List)evt.getOldValue(), 
false);
        refreshChildren();
        traverseChildren((List)evt.getNewValue(), 
true);
    }
 else if (property.equals(PaletteEntry.PROPERTY_LABEL)
            
|| property.equals(PaletteEntry.PROPERTY_SMALL_ICON)
            
|| property.equals(PaletteEntry.PROPERTY_LARGE_ICON)
            
|| property.equals(PaletteEntry.PROPERTY_DESCRIPTION))
        refreshVisuals();
}

        明白??说了那么多其实只要一名句话啦Q修改一下palette root里palette entry的内容GEF ׃自动的将palette里的表现更新了。在Dengues的项目里Q我在GEFComponentEditor.java里加入以下方法,便可以了Q?br />
    /**
     * Reset the content of the palette root will cause palette viewer be refreshed.
     * 
     * yzhang Comment method "refreshPalette".
     
*/
    
public void refreshPalette() {

        List
<PaletteContainer> containers = new ArrayList<PaletteContainer>(root.getChildren());

        
for (PaletteContainer element : containers) {
            
if (element instanceof PaletteGroup) {
                
continue;
            }
            root.remove(element);
        }

        CompEditorPaletteFactory.create(factory, root);

    }

       关于q个Ҏ是如何调用的Q这涉及到另外一个话题了Q见《如何解x件之间@环依赖的问题》?br />    
       K字好累。Han hanhan .....



]]>
վ֩ģ壺 | ɶ| ٲ| Զ| | | ͬ| | | ʹ| Ԫ| | | | | Ϫ| ɽ| Ӫɽ| ϳ| | ӥ̶| ͺ| Ͷ| ¤| ɽ| ϰ| ƽ| ϽϽ| ɽ| | | | | ɽ| | | | ɽ| | | |