读书人

RCP自定义扩充点的应用

发布时间: 2012-10-18 13:46:55 作者: rapoo

RCP自定义扩展点的应用

???????? 打开plugin.xml文件中Extension Points添加自定义扩展点的,定义相关元素的属性。此处仅仅定义一个可可扩展的Tab也实现一个自定义扩展。

???????? 操作完成之后,在项目中自动添加一个目录schema的目录。里面放着自定义的扩展点的schema描述。同时在plugin.xml中添加一句自定义扩展点的导入。

例如:

<extension-point id="com.easyway.tbs.commons.ext.tabs" name="tabPoint" schema="schema/com.easyway.tbs.commons.ext.tabs.exsd"/>
?

?

自定义的扩展点的xml如下:

?<extension
???????? point="com.easyway.tbs.commons.ext.tabs">
????? <tab
??????????? class="com.easyway.tbs.commons.ext.nebula.part.GridExampleTab"
??????????? name="Grid"/>
????? <tab
??????????? class="com.easyway.tbs.commons.ext.nebula.part.PGroupExampleTab"
??????????? name="PGroup"/>
????? <tab
??????????? class="com.easyway.tbs.commons.ext.nebula.part.CDateTimeExampleTab"
??????????? name="CDateTime"/>
????? <tab
??????????? class="com.easyway.tbs.commons.ext.nebula.part.GalleryExampleTab"
??????????? name="Gallery"/>
????? <tab
??????????? class="com.easyway.tbs.commons.ext.nebula.part.AnimationExampleTab"
??????????? name="Animation"/>
????? <tab
??????????? class="com.easyway.tbs.commons.ext.nebula.part.CollapsibleButtonsExampleTab"
??????????? name="CollapsibleButtons"/>
????? <tab
??????????? class="com.easyway.tbs.commons.ext.nebula.part.DateChooserExampleTab"
??????????? name="DateChooser">
????? </tab>
????? <tab
??????????? class="com.easyway.tbs.commons.ext.nebula.part.DateChooserComboExampleTab"
??????????? name="DateChooserCombo">
????? </tab>
????? <tab
??????????? class="com.easyway.tbs.commons.ext.nebula.part.RadioGroupExampleTab"
??????????? name="RadioGroup">
????? </tab>
????? <tab
??????????? class="com.easyway.tbs.commons.ext.nebula.part.TableComboExampleTab"
??????????? name="TableCombo">
????? </tab>
?? </extension>
??

?

获取之后设置为:

?

? public void createPartControl(Composite parent)
??? {
???????TabFolder ?tabFolder = new TabFolder(parent, 128);
??????? IConfigurationElement elements[] = Platform.getExtensionRegistry().getConfigurationElementsFor("com.easyway.tbs.commons.ext.tabs");
??????? for(int i = 0; i < elements.length; i++)
??????? {
??????????? IConfigurationElement element = elements[i];
??????????? TabItem item = new TabItem(tabFolder, 0);
??????????? item.setText(element.getAttribute("name"));
??????????? try
??????????? {
??????????????? AbstractExampleTab part = (AbstractExampleTab)element.createExecutableExtension("class");
??????????????? Composite client = new Composite(tabFolder, 0);
??????????????? part.create(client);
??????????????? item.setControl(client);
??????????? }
??????????? catch(CoreException e)
??????????? {
??????????????? e.printStackTrace();
??????????? }
??????? }
??????? tabFolder.setSelection(tabFolder.getItem(0));
??? }

读书人网 >软件架构设计

热点推荐