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);
}
});
btnAdd.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false,
1, 1));
toolkit.adapt(btnAdd, true, true);
btnAdd.setText("Add...");
btnRemove = new Button(container, SWT.NONE);
btnRemove.setEnabled(false);
btnRemove.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Table t = parentsTableViewer.getTable();
WritableList wl = (WritableList) parentsTableViewer.getInput();
int index = t.getSelectionIndex();
if (index >= 0) {
wl.remove(index);
if (index < wl.size()) {
t.setSelection(index);
} else {
t.setSelection(index - 1);
}
}
}
});
btnRemove.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
false, 1, 1));
toolkit.adapt(btnRemove, true, true);
btnRemove.setText("Remove");
btnUp = new Button(container, SWT.NONE);
btnUp.setEnabled(false);
btnUp.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Table t = parentsTableViewer.getTable();
WritableList wl = (WritableList) parentsTableViewer.getInput();
int index = t.getSelectionIndex();
Object obj1 = wl.get(index - 1);
Object obj2 = wl.get(index);
wl.set(index - 1, obj2);
wl.set(index, obj1);
t.setSelection(index - 1);
parentsTableViewer.refresh();
}
});
btnUp.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1,
1));
toolkit.adapt(btnUp, true, true);
btnUp.setText("Up");
btnDown = new Button(container, SWT.NONE);
btnDown.setEnabled(false);
btnDown.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Table t = parentsTableViewer.getTable();
WritableList wl = (WritableList) parentsTableViewer.getInput();
int index = t.getSelectionIndex();
Object obj1 = wl.get(index);
Object obj2 = wl.get(index + 1);
wl.set(index, obj2);
wl.set(index + 1, obj1);
t.setSelection(index + 1);
parentsTableViewer.refresh();
}
});
btnDown.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1,