public class TableTreeEditor extends ControlEditor
Here is an example of using a TableTreeEditor:
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);
}
});
Modifier and Type | Field and Description |
---|---|
(package private) int |
column
Deprecated.
|
(package private) ControlListener |
columnListener
Deprecated.
|
(package private) TableTreeItem |
item
Deprecated.
|
(package private) TableTree |
tableTree
Deprecated.
|
(package private) TreeListener |
treeListener
Deprecated.
|
editor, grabHorizontal, grabVertical, horizontalAlignment, minimumHeight, minimumWidth, parent, verticalAlignment
Constructor and Description |
---|
TableTreeEditor(TableTree tableTree)
Deprecated.
Creates a TableTreeEditor for the specified TableTree.
|
Modifier and Type | Method and Description |
---|---|
(package private) Rectangle |
computeBounds()
Deprecated.
|
void |
dispose()
Deprecated.
Removes all associations between the TableTreeEditor and the cell in the table tree.
|
int |
getColumn()
Deprecated.
Returns the zero based index of the column of the cell being tracked by this editor.
|
TableTreeItem |
getItem()
Deprecated.
Returns the TableTreeItem for the row of the cell being tracked by this editor.
|
void |
layout()
Deprecated.
Lays out the control within the underlying composite.
|
void |
setColumn(int column)
Deprecated.
|
void |
setEditor(Control editor,
TableTreeItem item,
int column)
Deprecated.
Specify the Control that is to be displayed and the cell in the table that it is to be positioned above.
|
void |
setItem(TableTreeItem item)
Deprecated.
|
getEditor, scroll, setEditor
TableTree tableTree
TableTreeItem item
int column
ControlListener columnListener
TreeListener treeListener
public TableTreeEditor(TableTree tableTree)
tableTree
- the TableTree Control above which this editor will be displayedRectangle computeBounds()
computeBounds
in class ControlEditor
public void dispose()
dispose
in class ControlEditor
public int getColumn()
public TableTreeItem getItem()
public void setColumn(int column)
public void setItem(TableTreeItem item)
public void setEditor(Control editor, TableTreeItem item, int column)
Note: The Control provided as the editor must be created with its parent being the Table control specified in the TableEditor constructor.
editor
- the Control that is displayed above the cell being editeditem
- the TableItem for the row of the cell being tracked by this editorcolumn
- the zero based index of the column of the cell being tracked by this editorpublic void layout()
ControlEditor
layout
in class ControlEditor