Top Description Fields Constructors Methods
org.eclipse.swt.custom

public Class TreeEditor

extends ControlEditor
Class Inheritance
Imports
org.eclipse.swt.*, org.eclipse.swt.events.*, org.eclipse.swt.graphics.*, org.eclipse.swt.widgets.*

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.

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);
		}
	});
 
See Also
TreeEditor snippets, Sample code and further information

Field Summary

Modifier and TypeField and Description
pack-priv int
pack-priv ControlListener
pack-priv TreeItem
pack-priv static final int
pack-priv Runnable
pack-priv Tree
pack-priv TreeListener
Inherited from org.eclipse.swt.custom.ControlEditor:
editorgrabHorizontalgrabVerticalhorizontalAlignmentminimumHeightminimumWidthparentverticalAlignment

Constructor Summary

AccessConstructor and Description
public
TreeEditor(Tree
the Tree Control above which this editor will be displayed
tree
)

Creates a TreeEditor for the specified Tree.

Method Summary

Modifier and TypeMethod and Description
pack-priv Rectangle
public void
dispose()

Overrides org.eclipse.swt.custom.ControlEditor.dispose.

Removes all associations between the TreeEditor and the row in the tree.
public int

Returns:

the zero based index of the column of the cell being tracked by this editor
getColumn
()

Returns the zero based index of the column of the cell being tracked by this editor.

public TreeItem

Returns:

the TreeItem for the row of the cell being tracked by this editor
getItem
()

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

public void
layout()

Overrides org.eclipse.swt.custom.ControlEditor.layout.

Lays out the control within the underlying composite.
pack-priv void
public void
setColumn(int
the zero based index of the column of the cell being tracked by this editor
column
)

Sets the zero based index of the column of the cell being tracked by this editor.

public void
setEditor(Control
the Control that is displayed above the cell being edited
editor
,
TreeItem
the TreeItem for the row of the cell being tracked by this editor
item
,
int
the zero based index of the column of the cell being tracked by this editor
column
)

Specify the Control that is to be displayed and the cell in the tree that it is to be positioned above.

public void
setEditor(Control
the Control that is displayed above the composite being edited
editor
)

Overrides org.eclipse.swt.custom.ControlEditor.setEditor.

Specify the Control that is to be displayed.
public void
setEditor(Control
the Control that is displayed above the cell being edited
editor
,
TreeItem
the TreeItem for the row of the cell being tracked by this editor
item
)

Specify the Control that is to be displayed and the cell in the tree that it is to be positioned above.

public void
setItem(TreeItem
the item to be edited
item
)

Specifies the TreeItem that is to be edited.

Inherited from org.eclipse.swt.custom.ControlEditor:
getEditorscroll

Field Detail

columnback to summary
pack-priv int column
columnListenerback to summary
pack-priv ControlListener columnListener
itemback to summary
pack-priv TreeItem item
TIMEOUTback to summary
pack-priv static final int TIMEOUT
timerback to summary
pack-priv Runnable timer
treeback to summary
pack-priv Tree tree
treeListenerback to summary
pack-priv TreeListener treeListener

Constructor Detail

TreeEditorback to summary
public TreeEditor(Tree tree)

Creates a TreeEditor for the specified Tree.

Parameters
tree:Tree

the Tree Control above which this editor will be displayed

Method Detail

computeBoundsback to summary
pack-priv Rectangle computeBounds()

Overrides org.eclipse.swt.custom.ControlEditor.computeBounds.

Annotations
@Override
disposeback to summary
public void dispose()

Overrides org.eclipse.swt.custom.ControlEditor.dispose.

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

Annotations
@Override
getColumnback to summary
public int getColumn()

Returns the zero based index of the column of the cell being tracked by this editor.

Returns:int

the zero based index of the column of the cell being tracked by this editor

Since
3.1
getItemback to summary
public TreeItem getItem()

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

Returns:TreeItem

the TreeItem for the row of the cell being tracked by this editor

layoutback to summary
public void layout()

Overrides org.eclipse.swt.custom.ControlEditor.layout.

Doc from org.eclipse.swt.custom.ControlEditor.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.

Annotations
@Override
resizeback to summary
pack-priv void resize()
setColumnback to summary
public void setColumn(int column)

Sets the zero based index of the column of the cell being tracked by this editor.

Parameters
column:int

the zero based index of the column of the cell being tracked by this editor

Since
3.1
setEditorback to summary
public 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.

Note

The Control provided as the editor must be created with its parent being the Tree control specified in the TreeEditor constructor.

Parameters
editor:Control

the Control that is displayed above the cell being edited

item:TreeItem

the TreeItem for the row of the cell being tracked by this editor

column:int

the zero based index of the column of the cell being tracked by this editor

Since
3.1
setEditorback to summary
public void setEditor(Control editor)

Overrides org.eclipse.swt.custom.ControlEditor.setEditor.

Doc from org.eclipse.swt.custom.ControlEditor.setEditor.

Specify the Control that is to be displayed.

Note

The Control provided as the editor must be created with its parent being the Composite specified in the ControlEditor constructor.

Parameters
editor:Control

the Control that is displayed above the composite being edited

Annotations
@Override
setEditorback to summary
public 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.

Note

The Control provided as the editor must be created with its parent being the Tree control specified in the TreeEditor constructor.

Parameters
editor:Control

the Control that is displayed above the cell being edited

item:TreeItem

the TreeItem for the row of the cell being tracked by this editor

setItemback to summary
public void setItem(TreeItem item)

Specifies the TreeItem that is to be edited.

Parameters
item:TreeItem

the item to be edited