1 6 package com.nightlabs.rcp.table; 7 8 import org.eclipse.jface.viewers.TableLayout; 9 import org.eclipse.jface.viewers.TableViewer; 10 import org.eclipse.swt.SWT; 11 import org.eclipse.swt.layout.GridData; 12 import org.eclipse.swt.layout.GridLayout; 13 import org.eclipse.swt.widgets.Composite; 14 import org.eclipse.swt.widgets.Table; 15 ; 16 17 23 public abstract class AbstractTableComposite extends Composite { 24 25 protected TableViewer tableViewer; 26 protected Table table; 27 28 public AbstractTableComposite(Composite parent, int style) { 29 this(parent, style, true); 30 } 31 32 public AbstractTableComposite(Composite parent, int style, boolean initTable) { 33 this(parent, style, initTable, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI); 34 } 35 36 public AbstractTableComposite(Composite parent, int style, boolean initTable, int viewerStyle) { 37 super(parent, style); 38 GridLayout thisLayout = new GridLayout(); 39 this.setLayout(thisLayout); 40 41 GridData gd = new GridData(GridData.FILL_BOTH); 42 this.setLayoutData(gd); 43 44 tableViewer = new TableViewer(this, viewerStyle); 45 GridData tgd = new GridData(GridData.FILL_BOTH); 46 table = tableViewer.getTable(); 47 table.setHeaderVisible(true); 48 table.setLinesVisible(true); 49 table.setLayoutData(tgd); 50 table.setLayout(new TableLayout()); 51 52 init(); 53 if (initTable) 54 initTable(); 55 } 56 57 protected void initTable() { 58 createTableColumns(table); 59 setTableProvider(tableViewer); 60 } 61 62 65 public void refresh() { 66 tableViewer.refresh(); 67 } 68 69 public TableViewer getTableViewer() { 70 return tableViewer; 71 } 72 73 78 public void init() {} 79 80 85 protected abstract void createTableColumns(Table table); 86 87 92 protected abstract void setTableProvider(TableViewer tableViewer); 93 94 public Table getTable() { 95 return table; 96 } 97 98 99 103 public void setInput(Object input) { 104 if (tableViewer != null) 105 tableViewer.setInput(input); 106 } 107 108 109 } 110 | Popular Tags |