本文主要介绍JFace AbstractTableViewer 控件的分页,采用数据库分页,分页数据封装在一个Page<T>对象中,子类只需要实现抽象方法doSplitPageQuery,获取分页数据即可,伪代码如下:
/**
* 含分页的表格控件封装
*
* @author <a href="mailto:brofe.pan@gmail.com">brofe</a>
* @since 2010-12-19
* @version v 1.0
*/
@SuppressWarnings({"rawtypes", "unchecked"})
public abstract class SplitPageTableViewer<T> {
protected AbstractTableViewer tableViewer;
protected SplitPageUI<T> splitPageUI;
protected Composite parent;
protected Composite tableComposite;
protected Group tableGroup;
protected String title;
protected Page<T> page = new Page(Constants.DEFAULT_PAGE_SIZE);
protected double defaultFirstHeight = 0.88;
protected double defaultSecondHeigth = 0.12;
public SplitPageTableViewer(Composite parent, String title) {
this.parent = parent;
this.title = title;
this.draw();
}
public SplitPageTableViewer(Composite parent, String title, double defaultFirstHeight, double defaultSecondHeigth) {
this.parent = parent;
this.title = title;
this.defaultFirstHeight = defaultFirstHeight;
this.defaultSecondHeigth = defaultSecondHeigth;
this.draw();
}
private void draw() {
tableGroup = new Group(parent, SWT.FILL);
tableGroup.setLayout(new FillLayout());
tableGroup.setText(title);
Composite composite = new Composite(tableGroup, SWT.FILL);
composite.setLayout(new FillLayout());
SashForm sashForm = new SashForm(composite, SWT.FILL | SWT.VERTICAL);
sashForm.setLayout(new GridLayout(1, false));
sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
tableComposite = new Composite(sashForm, SWT.NONE | SWT.FILL);
tableComposite.setLayout(new FillLayout());
tableComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
splitPageUI = new SplitPageUI<T>() {
@Override
public void doPageQuery() {
doSplitPageQuery();
}
};
splitPageUI.createSplitPageUI(sashForm, page);
sashForm.setWeights(new int[] {
(int) (Constants.RECT.width * defaultFirstHeight),
(int) (Constants.RECT.width * defaultSecondHeigth)
});
sashForm.SASH_WIDTH = 0;
}
public void addTableViewer(AbstractTableViewer tableViewer) {
this.tableViewer = tableViewer;
this.layout();
}
protected void layout() {
tableComposite.layout();
}
public abstract void doSplitPageQuery();
public Composite getTableComposite() {
return tableComposite;
}
public Page<T> getPage() {
return page;
}
public void setPage(Page<T> page) {
this.page = page;
this.splitPageUI.setPage(page);
}
public SplitPageUI<T> getSplitPageUI() {
return splitPageUI;
}
public Group getTableGroup() {
return tableGroup;
}
}
// 使用方法如下:
final SplitPageTableViewer sptv = new SplitPageTableViewer<Bol>(mainComposite, "出库单") {
@Override
public void doSplitPageQuery() {
Page<Bol> page = DefaultCommonManager.getBusinessWarehouseManager().pageQueryBol(sptv.getPage(), null, bol);;
mainTableViewer.setInput(page.getResult());
sptv.getSplitPageUI().setPage(page);
}
};
// 初始化数据
Page<Bol> page = .............
BolTableViewer mainTableViewer = new BolTableViewer(this, sptv.getTableComposite(),
WarehouseApp.tableDigester.getTable(WHConstants.TEMPLATE_BOL), page.getResult());
sptv.addTableViewer(mainTableViewer);
sptv.setPage(page);
效果见截图。
- 大小: 172.6 KB
分享到:
相关推荐
swt/Jface用到的最基本的jar包
SWT/JFACE API,是关于SWT/JFACE开发所用的API
SWT/Jface API 3.4 SWT/Jface API 3.4 SWT/Jface API 3.4 SWT/Jface API 3.4
Eclipse SWT/JFace SWT JFace 实例 Eclipse SWT/JFace 书中 全部实例
Eclipse SWT/JFace 核心应用光盘源码下载,解压后即可使用
Eclipse SWT/JFace核心应用
本文档为swt/jface的api中文帮助文档。
SWT/Jface 开发入门指南 介绍以下方面的内容: ? 设定 swt 以及 JFace 的开发环境 ? swt 的一些简单部件(widget)介绍 ? JFace 的一些入门性介绍 ? swt 和 JFace 的事件模式 ? 通过一些简单的例子说明如何利用 swt ...
SWT/JFace开发实例
Eclipse SWT/JFace 核心应用 带书签 Eclipse SWT/JFace
eclipse swt/jface核心应用 这本书的源代码
eclipse swt/jface核心应用源代码 带视频,找了好久,希望可以帮到大家,跟书匹配
SWT/JFace 3.5 版本的 API,HTML格式,方便开发人员查阅。
swt/jface in action 中英文 pdf格式 + 源码下载,包含书中的所有源码,有需要的朋友可以下载,为正在学习swt、jface的朋友提供一些好资源。
基于 Java 桌面程序开发的图形库...本书主要讲解了如何使用 SWT 和 JFace 进行应用程序的开发,通过本书系统而全面的 SWT/JFace 知识学习,将帮助读者快 速开发出完美、实用的 GUI 程序,轻松完成繁琐的界面、菜单编程.
王占全,苏玲 著; ISBN:7-121-05152-4 学习 SWT/JFace 的好书!
Eclipse SWT/JFace 开发实战精解+完美书签+光盘源码完整版. pdf带书签 ,代码完整的光盘,赚点积分。
NULL 博文链接:https://niub.iteye.com/blog/1806580
《Eclipse SWT/Jface核心应用》全面介绍了SWT、JFace和RCP的相关知识。全书共分5篇,第1篇介绍了SWT产生的背景以及SWT的一些基本概念和基础知识。第2篇介绍了SWT基本控件的使用,以及事件处理、布局等SWT基本知识的...