KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > rcp > table > AbstractTableComposite


1 /*
2  * Created on Mar 9, 2005
3  * by alex
4  *
5  */

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 /**
18  * An base Composite for all Table composites
19  *
20  * @author Alexander Bieber <alex[AT]nightlabs[DOT]de>
21  *
22  */

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     /**
63      * Calls refresh for the TableViewer.
64      */

65     public void refresh() {
66         tableViewer.refresh();
67     }
68     
69     public TableViewer getTableViewer() {
70         return tableViewer;
71     }
72     
73     /**
74      * Override for initializatioin to be done
75      * before {@link #createTableColumns(Table)} and {@link #setTableProvider(TableViewer)}.
76      * Default implementation does nothing.
77      */

78     public void init() {}
79     
80     /**
81      * Add your columns here to the Table.
82      *
83      * @param table
84      */

85     protected abstract void createTableColumns(Table table);
86     
87     /**
88      * Set your content and label provider for the tableViewer.
89      *
90      * @param tableViewer
91      */

92     protected abstract void setTableProvider(TableViewer tableViewer);
93
94     public Table getTable() {
95         return table;
96     }
97     
98     
99     /**
100      * Sets the tableViewers input.
101      *
102      */

103     public void setInput(Object JavaDoc input) {
104         if (tableViewer != null)
105             tableViewer.setInput(input);
106     }
107     
108
109 }
110
Popular Tags