public class MainClass {
private Shell sShell = null;
public static void main(String[] args) {
Display display = Display.getDefault();
MainClass thisClass = new MainClass();
thisClass.createSShell();
thisClass.sShell.open();
while (!thisClass.sShell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
private void createSShell() {
sShell = new Shell();
sShell.setText("Shell");
sShell.setSize(new Point(300, 200));
sShell.setLayout(new GridLayout());
Composite parent = new Composite(sShell, SWT.NONE);
parent.setLayout(new FillLayout());
TableViewer tableViewer = new TableViewer(parent, SWT.BORDER
| SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
tableViewer.getTable().setHeaderVisible(true);
tableViewer.getTable().setLinesVisible(true);
tableViewer.setContentProvider(new MyContentProvider());
MyLabelProvider labelProv = new MyLabelProvider();
tableViewer.setLabelProvider(labelProv);
labelProv.createColumns(tableViewer.getTable());
tableViewer.setInput(getFamily());
tableViewer.refresh();
Table table = tableViewer.getTable();
TableItem[] items = table.getItems();
for (TableItem item : items) {
TableEditor editor = new TableEditor(table);
Button button = new Button(table, SWT.PUSH);
button.setText("dateils");
button.pack();
editor.minimumWidth = button.getSize().x;
editor.horizontalAlignment = SWT.LEFT;
editor.setEditor(button, item, 3);
}
}
private ArrayList<Person> getFamily() {
ArrayList<Person> family = new ArrayList<Person>();
family.add(new Person("Meier", "Werner", 40));
family.add(new Person("Meier", "Monika", 38));
family.add(new Person("Meier", "Verena", 14));
family.add(new Person("Meier", "Sven", 10));
return family;
}
}