对象窗口由一下部分构成:
- 一个工具栏
- 一个表格
- 一组操作
- 一个适配器工厂
- 一组适配器
- 一个对象展示对话框
- 一个下拉菜单
实例图:
![](http://madz.vicp.net/images/attachicons/image.gif)
![](http://madz.vicp.net/attachments/forumid_8/1_gt6k1TCFV9gm.jpg)
![](http://madz.vicp.net/images/attachicons/image.gif)
![](http://madz.vicp.net/attachments/forumid_8/2_S2IoBmFX5mbt.jpg)
![](http://madz.vicp.net/images/attachicons/image.gif)
![](http://madz.vicp.net/attachments/forumid_8/3_knjY0ViINdxs.jpg)
![](http://madz.vicp.net/images/attachicons/image.gif)
![](http://madz.vicp.net/attachments/forumid_8/4_V9MRFfVZQgAa.jpg)
核心组件jar包
下图展示了对象窗口核心部分的类图:
![](http://madz.vicp.net/images/attachicons/image.gif)
![](http://madz.vicp.net/attachments/forumid_8/DataWindowCoreClassDiagram_O6IWc90KV2QI.gif)
对象窗口的创建对象窗口方法的时序图:
![](http://madz.vicp.net/images/attachicons/image.gif)
![](http://madz.vicp.net/attachments/forumid_8/DataWindowCoreSequanceDiagram_l9dw5g03oMuR.gif)
对象窗口核心组件使用方法
一、 继承AbstractDataWindow类
a) 实现public void setTableColumn()方法,为数据窗口添加列;
b) 实现public void setCheckboxTableViewerProviders()方法,为数据窗口添加各种适配器:标签适配器(必选)、内容适配器等(必选)、排序器(可选)、过滤器(可选)、编辑器(可选)、修改器(可选);
示例代码如下:
public class UserDataWindow extends AbstractDataWindow {
public UserDataWindow(Composite parent){
super(parent);
}
public void setTableColumn() {
// TODO Auto-generated method stub
final TableColumn userIDColumnTableColumn = new TableColumn(super.dataTable,SWT.CENTER);
userIDColumnTableColumn.setAlignment(SWT.CENTER);
userIDColumnTableColumn.setWidth(100);
userIDColumnTableColumn.setText("User ID");
final TableColumn userColumnTableColumn = new TableColumn(super.dataTable,
SWT.NONE);
userColumnTableColumn.setWidth(100);
userColumnTableColumn.setText("User Name");
final TableColumn userPasswordColumnTableColumn = new TableColumn(
super.dataTable, SWT.NONE);
userPasswordColumnTableColumn.setWidth(100);
userPasswordColumnTableColumn.setText("User Password");
}
public void setCheckboxTableViewerProviders() {
// TODO Auto-generated method stub
ctv.setContentProvider(new UserContentProvider());
ctv.setLabelProvider(new UserLabelProvider());
}
}
c) 实现内容器:
示例代码如下:
public class UserContentProvider implements IStructuredContentProvider {
public void dispose() {}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
public Object[] getElements(Object inputElement) {
if(inputElement instanceof List){
return ((List)inputElement).toArray();
}
else if(inputElement instanceof Collection){
return ((Collection)inputElement).toArray();
}else
return new Object[0];
}
}
d) 实现标签器:
示例代码如下:
public class UserLabelProvider implements ITableLabelProvider {
public Image getColumnImage(Object element, int columnIndex) { return null;}
public String getColumnText(Object element, int columnIndex) {
if(element instanceof UserTO){
UserTO uto = (UserTO)element;
if(columnIndex == 0)
return uto.getUserID();
else if(columnIndex == 1){
return uto.getUserName();
}
else
{
return uto.getUserPassword();
}
}
return "";
}
public void addListener(ILabelProviderListener listener) {}
public void dispose() {}
public boolean isLabelProperty(Object element, String property) {
return false;
}
public void removeListener(ILabelProviderListener listener) {}
}