TreeEditor

* A TreeEditor is a manager for a Control that appears above a cell in a Tree and tracks with the moving and resizing of that cell. It can be used to display a text widget above a cell in a Tree so that the user can edit the contents of that cell. It can also be used to display a button that can launch a dialog for modifying the contents of the associated cell. * <p> Here is an example of using a TreeEditor: <code><pre> final Tree tree = new Tree(shell, SWT.BORDER); for (int i = 0; i &lt; 3; i++) { TreeItem item = new TreeItem(tree, SWT.NONE); item.setText("item " + i); for (int j = 0; j &lt; 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 !is null) oldEditor.dispose(); * // Identify the selected row TreeItem item = (TreeItem)e.item; if (item is 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); } }); </pre></code> * @see <a href="http://www.eclipse.org/swt/snippets/#treeeditor">TreeEditor snippets</a> @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>

Constructors

this
this(Tree tree)

Creates a TreeEditor for the specified Tree. * @param tree the Tree Control above which this editor will be displayed *

Members

Functions

dispose
void dispose()

Removes all associations between the TreeEditor and the row in the tree. The tree and the editor Control are <b>not</b> disposed.

getColumn
int getColumn()

Returns the zero based index of the column of the cell being tracked by this editor. * @return the zero based index of the column of the cell being tracked by this editor * @since 3.1

getItem
TreeItem getItem()

Returns the TreeItem for the row of the cell being tracked by this editor. * @return the TreeItem for the row of the cell being tracked by this editor

setColumn
void setColumn(int column)

Sets the zero based index of the column of the cell being tracked by this editor. * @param column the zero based index of the column of the cell being tracked by this editor * @since 3.1

setEditor
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. * <p>Note: The Control provided as the editor <b>must</b> be created with its parent being the Tree control specified in the TreeEditor constructor. * @param editor the Control that is displayed above the cell being edited @param item the TreeItem for the row of the cell being tracked by this editor @param column the zero based index of the column of the cell being tracked by this editor * @since 3.1

setEditor
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. * <p>Note: The Control provided as the editor <b>must</b> be created with its parent being the Tree control specified in the TreeEditor constructor. * @param editor the Control that is displayed above the cell being edited @param item the TreeItem for the row of the cell being tracked by this editor

setItem
void setItem(TreeItem item)

Specifies the <code>TreeItem</code> that is to be edited. * @param item the item to be edited

Inherited Members

From ControlEditor

horizontalAlignment
int horizontalAlignment;

Specifies how the editor should be aligned relative to the control. Allowed values are SWT.LEFT, SWT.RIGHT and SWT.CENTER. The default value is SWT.CENTER.

grabHorizontal
bool grabHorizontal;

Specifies whether the editor should be sized to use the entire width of the control. True means resize the editor to the same width as the cell. False means do not adjust the width of the editor. The default value is false.

minimumWidth
int minimumWidth;

Specifies the minimum width the editor can have. This is used in association with a true value of grabHorizontal. If the cell becomes smaller than the minimumWidth, the editor will not made smaller than the minimum width value. The default value is 0.

verticalAlignment
int verticalAlignment;

Specifies how the editor should be aligned relative to the control. Allowed values are SWT.TOP, SWT.BOTTOM and SWT.CENTER. The default value is SWT.CENTER.

grabVertical
bool grabVertical;

Specifies whether the editor should be sized to use the entire height of the control. True means resize the editor to the same height as the underlying control. False means do not adjust the height of the editor. The default value is false.

minimumHeight
int minimumHeight;

Specifies the minimum height the editor can have. This is used in association with a true value of grabVertical. If the control becomes smaller than the minimumHeight, the editor will not made smaller than the minimum height value. The default value is 0.

dispose
void dispose()

Removes all associations between the Editor and the underlying composite. The composite and the editor Control are <b>not</b> disposed.

getEditor
Control getEditor()

Returns the Control that is displayed above the composite being edited. * @return the Control that is displayed above the composite being edited

layout
void layout()

Lays out the control within the underlying composite. This method should be called after changing one or more fields to force the Editor to resize.

setEditor
void setEditor(Control editor)

Specify the Control that is to be displayed. * <p>Note: The Control provided as the editor <b>must</b> be created with its parent being the Composite specified in the ControlEditor constructor. * @param editor the Control that is displayed above the composite being edited

Meta