58,447
社区成员




// List inputObj = VisitInformationFactory.getInformations();
// tableViewer.setInput(inputObj);
public class TableViewerContentProvider implements IStructuredContentProvider {
public Object[] getElements(Object element) {
if(element instanceof List) {
return ((List) element).toArray();
} else {
return new Object[0];
}
}
public void dispose() {
// TODO 自动生成方法存根
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// TODO 自动生成方法存根
}
}
public class VisitClockView extends ViewPart {
private TableViewer tableViewer;
private Shell shell;
private Action reserveAction,rebesparkAction,clockAction,outAction,editAction,refreshAction,rightAction,deleteAction;
public static final int COMPANYNAME = 0;
public static final int VISITORNAME = 1;
public static final int VISITORCOUNT = 2;
public static final int BOOKTIME = 3;
public static final int NEEDTOSEE = 4;
public static final int VISITISSUE = 5;
public static final int BOOKBY = 6;
public static final int BOOKINGTIME = 7;
public static final int SHOWUPTIME = 8;
public static final int DEPOSITIDTYPE = 9;
public static final String ID = "com.dsrcom.ecq.dsreli_client.brucevisitmanager.views.VisitClockView"; //$NON-NLS-1$
/**
* Create contents of the view part
* @param parent
*/
@Override
public void createPartControl(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
container.setLayout(new FillLayout());
tableViewer = new TableViewer(container,SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
/**
* 通过TableViewer中的Table对其布局
*/
Table table = tableViewer.getTable();
table.setHeaderVisible(true); //显示表头
table.setLinesVisible(true); //显示表格线
TableLayout tLayout = new TableLayout();
table.setLayout(tLayout);
/**
* 建立TableViewer中的列
*/
tLayout.addColumnData(new ColumnWeightData(40));
TableColumn col0 = new TableColumn(table,SWT.NONE);
tableViewer.setSorter(new MyTableSort());
col0.setText("公司名称");
col0.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
((MyTableSort) tableViewer.getSorter()).doSort(COMPANYNAME);
tableViewer.refresh();
}
});
tLayout.addColumnData(new ColumnWeightData(40));
TableColumn col1 = new TableColumn(table,SWT.NONE);
col1.setText("访客");
col1.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
((MyTableSort) tableViewer.getSorter()).doSort(VISITORNAME);
tableViewer.refresh();
}
});
tLayout.addColumnData(new ColumnWeightData(20));
TableColumn col2 = new TableColumn(table,SWT.NONE);
col2.setText("来访人数");
col2.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
((MyTableSort) tableViewer.getSorter()).doSort(VISITORCOUNT);
tableViewer.refresh();
}
});
tLayout.addColumnData(new ColumnWeightData(50));
TableColumn col3 = new TableColumn(table,SWT.NONE);
col3.setText("预约会见时间");
col3.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
((MyTableSort) tableViewer.getSorter()).doSort(BOOKTIME);
tableViewer.refresh();
}
});
tLayout.addColumnData(new ColumnWeightData(20));
TableColumn col4 = new TableColumn(table,SWT.NONE);
col4.setText("来访对象");
col4.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
((MyTableSort) tableViewer.getSorter()).doSort(NEEDTOSEE);
tableViewer.refresh();
}
});
tLayout.addColumnData(new ColumnWeightData(40));
TableColumn col5 = new TableColumn(table,SWT.NONE);
col5.setText("来访事由");
col5.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
((MyTableSort) tableViewer.getSorter()).doSort(VISITISSUE);
tableViewer.refresh();
}
});
tLayout.addColumnData(new ColumnWeightData(20));
TableColumn col6 = new TableColumn(table,SWT.NONE);
col6.setText("预约人");
col6.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
((MyTableSort) tableViewer.getSorter()).doSort(BOOKBY);
tableViewer.refresh();
}
});
tLayout.addColumnData(new ColumnWeightData(40));
TableColumn col7 = new TableColumn(table,SWT.NONE);
col7.setText("输入时间");
col7.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
((MyTableSort) tableViewer.getSorter()).doSort(BOOKINGTIME);
tableViewer.refresh();
}
});
tLayout.addColumnData(new ColumnWeightData(40));
TableColumn col8 = new TableColumn(table,SWT.NONE);
col8.setText("到达时间");
col8.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
((MyTableSort) tableViewer.getSorter()).doSort(SHOWUPTIME);
tableViewer.refresh();
}
});
tLayout.addColumnData(new ColumnWeightData(50));
TableColumn col9 = new TableColumn(table,SWT.NONE);
col9.setText("访客暂存证件");
col9.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
((MyTableSort) tableViewer.getSorter()).doSort(DEPOSITIDTYPE);
tableViewer.refresh();
}
});
tableViewer.setContentProvider(new TableViewerContentProvider()); //内容器
tableViewer.setLabelProvider(new TableViewerLableProvider()); //标签器
// List inputObj = VisitInformationFactory.getInformations();
// tableViewer.setInput(inputObj);
/**
*
* 创建右键菜单和工具栏
*/
createActions();
hookContextMenu();
contributeToActionBars();
hookClickAction();
init();
}
}
public class TableViewerLableProvider implements ITableLabelProvider {
public void dispose() {
// TODO 自动生成方法存根
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// TODO 自动生成方法存根
}
public Image getColumnImage(Object element, int columnIndex) {
// TODO 自动生成方法存根
return null;
}
public String getColumnText(Object element, int columnIndex) {
VisitInformation visitInformation = (VisitInformation) element;
if (columnIndex == 0) {
if(visitInformation.getComanyName() == null) {
return "";
} else {
return visitInformation.getComanyName(); //公司名称
}
}
if (columnIndex == 1) {
return visitInformation.getVisitorName(); //访客对象
}
if (columnIndex == 2) {
return visitInformation.getVisitorCount().toString(); //来访人数
}
if (columnIndex == 3) {
/**
* DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
format.format(date);
textInputTime.setText(format.format(date).toString());
*/
DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
return format.format(visitInformation.getBookTime()).toString();
// return visitInformation.getBookTime().toString(); //预约会见时间
}
if (columnIndex == 4) {
return visitInformation.getNeedToSee(); //来访对象
}
if (columnIndex == 5) {
return visitInformation.getVisitIssue(); //来访事由
}
if (columnIndex == 6) {
return visitInformation.getBookBy(); //预约人
}
if (columnIndex == 7) {
DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
return format.format(visitInformation.getBookingTime()).toString(); //输入时间
}
if (columnIndex == 8) {
if(visitInformation.getShowUpTime() == null) {
return null;
} else {
DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
return format.format(visitInformation.getShowUpTime()).toString(); //到达时间
}
}
if (columnIndex == 9) {
if(visitInformation.getDepositIDType() == null) {
return "";
} else {
return visitInformation.getDepositIDType(); //访客暂存证件
}
}
return "";
}
public void addListener(ILabelProviderListener listener) {
}
public boolean isLabelProperty(Object element, String property) {
return false;
}
public void removeListener(ILabelProviderListener listener) {
}
}