item.setText(1, "");
}
final TableCursor cursor = new TableCursor(table, SWT.NONE);
final ControlEditor editor = new ControlEditor(cursor);
editor.grabHorizontal = true;
editor.grabVertical = true;
cursor.addMouseListener(new MouseAdapter() {
public void mouseDoubleClick(MouseEvent arg0) {
if (cursor.getColumn() == 1) {
final Text text = new Text(cursor, SWT.NONE);
text.setFocus();
text.setText(cursor.getRow().getText(cursor.getColumn()));
text.setFocus();
text.addFocusListener(new FocusListener() {
public void focusLost(FocusEvent event) {
cursor.getRow().setText(cursor.getColumn(), text.getText());
text.dispose();
}
public void focusGained(FocusEvent arg0) {
}
});
text.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent event) {
switch (event.keyCode) {
case SWT.CR:
cursor.getRow().setText(cursor.getColumn(), text.getText());
case SWT.ESC:
text.dispose();
break;
}
}
});
editor.setEditor(text);
}
}
});
cursor.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
table.setSelection(new TableItem[] { cursor.getRow() });
}
public void widgetDefaultSelected(SelectionEvent event) {
if (cursor.getColumn() == 1) {
final Text text = new Text(cursor, SWT.NONE);
text.setFocus();
text.setText(cursor.getRow().getText(cursor.getColumn()));
text.setFocus();
text.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent event) {
switch (event.keyCode) {
case SWT.CR:
cursor.getRow().setText(cursor.getColumn(), text.getText());
case SWT.ESC:
text.dispose();
break;
}
}
});
text.addFocusListener(new FocusListener() {
public void focusLost(FocusEvent event) {
cursor.getRow().setText(cursor.getColumn(), text.getText());
text.dispose();
}
public void focusGained(FocusEvent arg0) {
}
});
editor.setEditor(text);
}
}
});
FormData data = new FormData();