public class TreeEditor extends ControlEditor
Here is an example of using a TreeEditor:
final Tree tree = new Tree(shell, SWT.BORDER);
for (int i = 0; i < 3; i++) {
TreeItem item = new TreeItem(tree, SWT.NONE);
item.setText("item " + i);
for (int j = 0; j < 3; j++) {
TreeItem subItem = new TreeItem(item, SWT.NONE);
subItem.setText("item " + i + " " + j);
}
}
final TreeEditor editor = new TreeEditor(tree);
//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;
tree.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
TreeItem item = (TreeItem)e.item;
if (item == null) return;
// The control that will be the editor must be a child of the Tree
Text newEditor = new Text(tree, SWT.NONE);
newEditor.setText(item.getText());
newEditor.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
Text text = (Text)editor.getEditor();
editor.getItem().setText(text.getText());
}
});
newEditor.selectAll();
newEditor.setFocus();
editor.setEditor(newEditor, item);
}
});
grabHorizontal, grabVertical, horizontalAlignment, minimumHeight, minimumWidth, verticalAlignment
Constructor and Description |
---|
TreeEditor(Tree tree)
Creates a TreeEditor for the specified Tree.
|
Modifier and Type | Method and Description |
---|---|
void |
dispose()
Removes all associations between the TreeEditor and the row in the tree.
|
int |
getColumn()
Returns the zero based index of the column of the cell being tracked by this editor.
|
TreeItem |
getItem()
Returns the TreeItem for the row of the cell being tracked by this editor.
|
void |
layout()
Lays out the control within the underlying composite.
|
void |
setColumn(int column)
Sets the zero based index of the column of the cell being tracked by this editor.
|
void |
setEditor(Control editor)
Specify the Control that is to be displayed.
|
void |
setEditor(Control editor,
TreeItem item)
Specify the Control that is to be displayed and the cell in the tree that it is to be positioned above.
|
void |
setEditor(Control editor,
TreeItem item,
int column)
Specify the Control that is to be displayed and the cell in the tree that it is to be positioned above.
|
void |
setItem(TreeItem item)
Specifies the
TreeItem that is to be edited. |
getEditor
public TreeEditor(Tree tree)
tree
- the Tree Control above which this editor will be displayedpublic void dispose()
dispose
in class ControlEditor
public int getColumn()
public TreeItem getItem()
public void setColumn(int column)
column
- the zero based index of the column of the cell being tracked by this editorpublic void setItem(TreeItem item)
TreeItem
that is to be edited.item
- the item to be editedpublic void setEditor(Control editor, TreeItem item, int column)
Note: The Control provided as the editor must be created with its parent being the Tree control specified in the TreeEditor constructor.
editor
- the Control that is displayed above the cell being editeditem
- the TreeItem 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 setEditor(Control editor)
ControlEditor
Note: The Control provided as the editor must be created with its parent being the Composite specified in the ControlEditor constructor.
setEditor
in class ControlEditor
editor
- the Control that is displayed above the composite being editedpublic void setEditor(Control editor, TreeItem item)
Note: The Control provided as the editor must be created with its parent being the Tree control specified in the TreeEditor constructor.
editor
- the Control that is displayed above the cell being editeditem
- the TreeItem for the row of the cell being tracked by this editorpublic void layout()
ControlEditor
layout
in class ControlEditor
Copyright © 2017. All Rights Reserved.