org.eclipse.swt.custom
Class TableTreeEditor

java.lang.Object
  |
  +--org.eclipse.swt.custom.ControlEditor
        |
        +--org.eclipse.swt.custom.TableTreeEditor

public class TableTreeEditor
extends ControlEditor

Unsafe: A TableTreeEditor is a manager for a Control that appears above a cell in a TableTree and tracks with the moving and resizing of that cell. It can be used to display a text widget above a cell in a TableTree 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 TableTreeEditor:

 public static void main (String [] args) {
 	Display display = new Display ();
 	Shell shell = new Shell (display);
 	final TableTree tableTree = new TableTree(shell, SWT.FULL_SELECTION);
 	Table table = tableTree.getTable();
 	table.setLinesVisible(true);
 	TableColumn column1 = new TableColumn(table, SWT.NONE);
 	column1.setText("column 1");
 	TableColumn column2 = new TableColumn(table, SWT.NONE);
 	column2.setText("column 2");
 	for (int i = 0; i < 40; i++) {
 		TableTreeItem item = new TableTreeItem(tableTree, SWT.NONE);
 		item.setText(0, "table tree item"+i);
 		item.setText(1, "value "+i);
 	}
 	column1.pack();
 	column2.pack();
 	final TableTreeEditor editor = new TableTreeEditor (tableTree);
 	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[] selection = tableTree.getSelection();
 			if (selection.length == 0) return;
 			TableTreeItem item = selection[0];
 			// The control that will be the editor must be a child of the Table
 			// that underlies the TableTree
 			Text text = new Text(tableTree.getTable(), SWT.NONE);
 			//text.moveAbove(tableTree);
 			//The text 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;
 			// Open the text editor in the second column of the selected row.
 			editor.setEditor (text, item, 1);
 			// Assign focus to the text control
 			text.setFocus ();
 		}
 	});
 	tableTree.setBounds(10, 10, 200, 400);
 	shell.open ();
 	while (!shell.isDisposed ()) {
 		if (!display.readAndDispatch ()) display.sleep ();
 	}
 	display.dispose ();
 }
 


Field Summary
(package private)  int column
           
(package private)  ControlListener columnListener
           
(package private)  TableTreeItem item
           
(package private)  TableTree tableTree
           
(package private)  TreeListener treeListener
           
 
Fields inherited from class org.eclipse.swt.custom.ControlEditor
editor, grabHorizontal, grabVertical, horizontalAlignment, minimumHeight, minimumWidth, parent, verticalAlignment
 
Constructor Summary
TableTreeEditor(TableTree tableTree)
          Enabled: Creates a TableEditor for the specified Table.
 
Method Summary
(package private)  Rectangle computeBounds()
           
 void dispose()
          Enabled: Removes all associations between the TableEditor and the cell in the table.
 int getColumn()
          Enabled: Returns the zero based index of the column of the cell being tracked by this editor.
 TableTreeItem getItem()
          Enabled: Returns the TableItem for the row of the cell being tracked by this editor.
(package private)  void resize()
           
 void setColumn(int column)
          Enabled:
 void setEditor(Control editor, TableTreeItem item, int column)
          Enabled: 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)
          Enabled:
 
Methods inherited from class org.eclipse.swt.custom.ControlEditor
getEditor, layout, scroll, setEditor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tableTree

TableTree tableTree

item

TableTreeItem item

column

int column

columnListener

ControlListener columnListener

treeListener

TreeListener treeListener
Constructor Detail

TableTreeEditor

public TableTreeEditor(TableTree tableTree)
Enabled: Creates a TableEditor for the specified Table.

Method Detail

computeBounds

Rectangle computeBounds()
Overrides:
computeBounds in class ControlEditor

dispose

public void dispose()
Enabled: Removes all associations between the TableEditor and the cell in the table. The Table and the editor Control are not disposed.

Overrides:
dispose in class ControlEditor

getColumn

public int getColumn()
Enabled: 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

setColumn

public void setColumn(int column)
Enabled:


getItem

public TableTreeItem getItem()
Enabled: Returns the TableItem for the row of the cell being tracked by this editor.

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

setItem

public void setItem(TableTreeItem item)
Enabled:


setEditor

public void setEditor(Control editor,
                      TableTreeItem item,
                      int column)
Enabled: Specify the Control that is to be displayed and the cell in the table that it is to be positioned above.

Note: The Control provided as the editor must be created with its parent being the Table control specified in the TableEditor constructor.

Parameters:
editor - the Control that is displayed above the cell being edited
item - the TableItem 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

resize

void resize()
Overrides:
resize in class ControlEditor


comments?