Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Eclipse Rich Ajax Platform
Release 1.2

org.eclipse.swt.custom
Class TreeEditor

java.lang.Object
  extended by

org.eclipse.swt.custom.ControlEditor
      extended by
org.eclipse.swt.custom.TreeEditor

public class TreeEditor
extends ControlEditor

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);
 		}
 	});
 

Since:
1.0

Field Summary
 
Fields inherited from class org.eclipse.swt.custom. ControlEditor
grabHorizontal, grabVertical, horizontalAlignment, minimumHeight, minimumWidth, verticalAlignment
 
Constructor Summary
TreeEditor ( Tree tree)
          Creates a TreeEditor for the specified Tree.
 
Method Summary
 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)
           
 
Methods inherited from class org.eclipse.swt.custom. ControlEditor
getEditor
 
Methods inherited from class java.lang. Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TreeEditor

public TreeEditor(
Tree tree)
Creates a TreeEditor for the specified Tree.

Parameters:
tree - the Tree Control above which this editor will be displayed
Method Detail

dispose

public void dispose()
Removes all associations between the TreeEditor and the row in the tree. The tree and the editor Control are not disposed.

Overrides:
dispose in class ControlEditor

getColumn

public int getColumn()
Returns the zero based index of the column of the cell being tracked by this editor.

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

getItem

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

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

setColumn

public void setColumn(int column)
Sets the zero based index of the column of the cell being tracked by this editor.

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

setItem

public void setItem(
TreeItem item)

setEditor

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 - the Control that is displayed above the cell being edited
item - the TreeItem for the row of the cell being tracked by this editor
column - the zero based index of the column of the cell being tracked by this editor

setEditor

public void setEditor(
Control editor)
Description copied from class: ControlEditor
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.

Overrides:
setEditor in class ControlEditor
Parameters:
editor - the Control that is displayed above the composite being edited

setEditor

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 - the Control that is displayed above the cell being edited
item - the TreeItem for the row of the cell being tracked by this editor

layout

public void layout()
Description copied from class: ControlEditor
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.

Overrides:
layout in class ControlEditor

Eclipse Rich Ajax Platform
Release 1.2

Copyright (c) Innoopract Informationssysteme GmbH and others 2002, 2008. All rights reserved.


 
 
  Published under the terms of the Eclipse Public License Version 1.0 ("EPL") Design by Interspire