table = new Table(parent, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
table.setLayoutData(data);
IDynTableProvider provider = ((FStringList)target).getDataProvider();
initTable(provider);
table.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent arg0) {
//TODO control.fireDescriptionChanged(false, desc);
}
});
table.addMenuDetectListener(new MenuDetectListener() {
@Override
public void menuDetected(MenuDetectEvent arg0) {
final IDynTableProvider provider = ((FStringList) target)
.getDataProvider();
if (!table.isEnabled() || provider == null)
return;
final Menu menu = new Menu(parent.getShell(), SWT.POP_UP);
MenuItem item = new MenuItem(menu, SWT.PUSH);
item.setText("Create");
item.addListener(SWT.Selection,
new org.eclipse.swt.widgets.Listener() {
public void handleEvent(Event e) {
int pos = table.getSelectionIndex();
TableItem item = null;
if (pos >= 0) {
item = new TableItem(table, SWT.NONE, pos);
} else {
item = new TableItem(table, SWT.NONE);
}
IDynTableProvider provider = ((FStringList) target)
.getDataProvider();
item.setText(provider.getDefaultRow());
}
});
int pos = table.getSelectionIndex();
if (pos > 0) {
item = new MenuItem(menu, SWT.PUSH);
item.setText("Move Up");
item.addListener(SWT.Selection,
new org.eclipse.swt.widgets.Listener() {
public void handleEvent(Event e) {
int pos = table.getSelectionIndex();
TableItem it1 = table.getItem(pos);
String[] sa = new String[provider
.getColumnCount()];
for (int i = 0; i < sa.length; i++)
sa[i] = it1.getText(i);
table.remove(pos);
TableItem it2 = new TableItem(table,
SWT.NONE, pos - 1);
it2.setText(sa);
}
});
}
if (pos < table.getItemCount() - 1 && pos >= 0) {
item = new MenuItem(menu, SWT.PUSH);
item.setText("Move Down");
item.addListener(SWT.Selection,
new org.eclipse.swt.widgets.Listener() {
public void handleEvent(Event e) {
int pos = table.getSelectionIndex();
TableItem it1 = table.getItem(pos);
String[] sa = new String[provider
.getColumnCount()];
for (int i = 0; i < sa.length; i++)
sa[i] = it1.getText(i);
table.remove(pos);
TableItem it2 = new TableItem(table,