parentsTableViewer = new TableViewer(composite, SWT.BORDER | SWT.FULL_SELECTION);
parentsTableViewer.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
Parent parent = (Parent) element;
return parent.getName();
}
});
Table table = parentsTableViewer.getTable();
table.setHeaderVisible(false);
table.setLinesVisible(false);
table.setLayoutData(new ColumnWeightData(1));
toolkit.paintBordersFor(table);
TableColumn tcName = new TableColumn(table, SWT.NONE);
tcLayout.setColumnData(tcName, new ColumnWeightData(100));
parentsTableViewer.setColumnProperties(new String[] { "name" });
parentsTableViewer.setCellEditors(new CellEditor[] {
new TextCellEditor(table)
});
parentsTableViewer.setCellModifier(new ICellModifier() {
@Override
public void modify(Object element, String property, Object value) {
Parent parent = (Parent) ((Item) element).getData();
parent.setName((String) value);
parentsTableViewer.refresh();
}
@Override
public Object getValue(Object element, String property) {
Parent parent = (Parent) element;
return parent.getName();
}
@Override
public boolean canModify(Object element, String property) {
return true;
}
});
parentsTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
updateButtonStates();
}
});
btnAdd = new Button(container, SWT.NONE);
btnAdd.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Table t = parentsTableViewer.getTable();
WritableList wl = (WritableList) parentsTableViewer.getInput();
Parent p = new Parent(null, "");
wl.add(p);
parentsTableViewer.editElement(p, 0);
t.setSelection(wl.size() - 1);
}
});