探索带选项卡的属性视图的使用问题
2008/5/13 21:56 一品凡心
首先添加 org.eclipse.ui.views.properties.tabbed 的三个扩展点
org.eclipse.ui.views.properties.tabbed.PropertyContributor
org.eclipse.ui.views.properties.tabbed.PropertyTabs
org.eclipse.ui.views.properties.tabbed.PropertySections
1. Property Contributor
1) 需要设定countributorId指定属性页countributor的唯一ID
2) 指定labelProvider 的标题Bar的标签的类,该类实现 org.eclipse.jface.viewers.ILabelProvider 接口
ILabelProvider接口的方法为:
public Image getImage(Object element);
public String getText(Object element);
3) 指定typeMapper这个用于实现类型映射器的类,该类实现org.eclipse.ui.views.properties.tabbed.ITypeMapper接口
ITypeMapper接口的方法为:
public Class mapType(Object object);
干什么用的尚不清楚
4) 添加propertyCategory一个或多个用于组织标签的种类属性.每个propertyCategory都指定唯一一个属性category
2. Property Tabs
需要指定countributorId以与相应的上面的propertyContributor相对应
依次添加propertyTab指定相应选项卡的信息,每个选项卡都有自己唯一的id
1) label,必须项,用于指定标签的label
2) category 必须项,用于指定其所属的PropertyContributor下的propertyCategory
3) id 必须项,指定唯一ID
4) afterTab,可选项,用于指定各个propertyTab在属性视图的先后关系,这里指定当前tab跟随在哪个tab后面
还有indented——是否消除锯齿,image——选项卡标签的背景图片
3. Perpoty Sections
需要指定countributorId,指明其所对应的Property Contributor
依次添加相应的propertySection, 需要进行如下设置:
1) tab, 指定对应哪一个选项卡标签
2) id,指定一个唯一ID
3) class, 指定实现该Section(即选项卡内的具体页面内容),需要继承实现org.eclipse.ui.views.properties.tabbed.AbstractPropertySection,该抽象类实现了ISection接口,该抽象类的内容如下:
/**
* 指定该Section左侧部分的标签默认长度
*/
public static final int STANDARD_LABEL_WIDTH = 85;
/**
* 该Section实现的表单页(SheetPage),这也限定了选项内页面的内容
*/
private TabbedPropertySheetPage tabbedPropertySheetPage;
/**
* 当前工作内的选择内容
*/
private ISelection selection;
/**
* 当前激活的工作区
*/
private IWorkbenchPart part;
public TabbedPropertySheetWidgetFactory getWidgetFactory() {
return tabbedPropertySheetPage.getWidgetFactory();
}
public ISelection getSelection() {
return selection;
}
public IWorkbenchPart getPart() {
return part;
}
public void createControls(Composite parent,
TabbedPropertySheetPage aTabbedPropertySheetPage) {
this.tabbedPropertySheetPage = aTabbedPropertySheetPage;
}
public void setInput(IWorkbenchPart part, ISelection selection) {
this.selection = selection;
this.part = part;
}
public void aboutToBeShown() {
/* empty default implementation */
}
public void aboutToBeHidden() {
/* empty default implementation */
}
public void dispose() {
/* empty default implementation */
}
public int getMinimumHeight() {
return SWT.DEFAULT;
}
public boolean shouldUseExtraSpace() {
return false;
}
public void refresh() {
/* empty default implementation */
}
4) filter, 指定显示该选项卡的过滤策略类,该类实现 org.eclipse.jface.viewers.IFilter接口,接口的内容如下:
public interface IFilter {
public boolean select(Object toTest);
}
5)在propertySection下还可以添加input,并指定属性type,在相应的tab会在这些指定的Input类型或接口被选中时激活。
<!ELEMENT propertySection (input*)>
<!ATTLIST propertySection
tab CDATA #REQUIRED
id CDATA #REQUIRED
class CDATA #REQUIRED
afterSection CDATA #IMPLIED
filter CDATA #IMPLIED
enablesFor CDATA #IMPLIED>
只要按照上面的规定在plugin.xml中进行相应的添加和设置,并在需要实现的接口和类中编写相应的代码,就可以完成带选项卡的属性视图的扩展功能。