[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.platform.swt] How to use TableTreeEditor??

How would I retrieve the column index of a cell? If I use the example shown on: http://help.eclipse.org/help30/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/custom/TableTreeEditor.html
(I also provided the example at the bottom of this post) how could I dynamically change the EDITABLECOLUMN property to reference the proper cell/column value?


Thank you for you help in advance.


final TableTree tableTree = new TableTree(shell, SWT.FULL_SELECTION | SWT.HIDE_SELECTION);
final Table table = tableTree.getTable();
TableColumn column1 = new TableColumn(table, SWT.NONE);
TableColumn column2 = new TableColumn(table, SWT.NONE);
for (int i = 0; i < 10; i++) {
TableTreeItem item = new TableTreeItem(tableTree, SWT.NONE);
item.setText(0, "item " + i);
item.setText(1, "edit this value");
for (int j = 0; j < 3; j++) {
TableTreeItem subitem = new TableTreeItem(item, SWT.NONE);
subitem.setText(0, "subitem " + i + " " + j);
subitem.setText(1, "edit this value");
}
}
column1.setWidth(100);
column2.pack();

final TableTreeEditor editor = new TableTreeEditor(tableTree);
//The editor must have the same size as the cell and must
//not be any smaller than 50 pixels.
editor.horizontalAlignment = SWT.LEFT;
editor.grabHorizontal = true;
editor.minimumWidth = 50;
// editing the second column
final int EDITABLECOLUMN = 1;

tableTree.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
// Clean up any previous editor control
Control oldEditor = editor.getEditor();
if (oldEditor != null) oldEditor.dispose();

// Identify the selected row
TableTreeItem item = (TableTreeItem)e.item;
if (item == null) return;

// The control that will be the editor must be a child of the Table
Text newEditor = new Text(table, SWT.NONE);
newEditor.setText(item.getText(EDITABLECOLUMN));
newEditor.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
Text text = (Text)editor.getEditor();
editor.getItem().setText(EDITABLECOLUMN, text.getText());
}
});
newEditor.selectAll();
newEditor.setFocus();
editor.setEditor(newEditor, item, EDITABLECOLUMN);
}
});