public class TableEditor extends ControlEditor
Here is an example of using a TableEditor:
final Table table = new Table(shell, SWT.FULL_SELECTION | SWT.HIDE_SELECTION);
TableColumn column1 = new TableColumn(table, SWT.NONE);
TableColumn column2 = new TableColumn(table, SWT.NONE);
for (int i = 0; i < 10; i++) {
TableItem item = new TableItem(table, SWT.NONE);
item.setText(new String[] {"item " + i, "edit this value"});
}
column1.pack();
column2.pack();
final TableEditor editor = new TableEditor(table);
//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;
// editing the second column
final int EDITABLECOLUMN = 1;
table.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
TableItem item = (TableItem)e.item;
if (item == null) return;
// The control that will be the editor must be a child of the Table
Text newEditor = new Text(table, SWT.NONE);
newEditor.setText(item.getText(EDITABLECOLUMN));
newEditor.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
Text text = (Text)editor.getEditor();
editor.getItem().setText(EDITABLECOLUMN, text.getText());
}
});
newEditor.selectAll();
newEditor.setFocus();
editor.setEditor(newEditor, item, EDITABLECOLUMN);
}
});
grabHorizontal, grabVertical, horizontalAlignment, minimumHeight, minimumWidth, verticalAlignment
Constructor and Description |
---|
TableEditor(Table table)
Creates a TableEditor for the specified Table.
|
Modifier and Type | Method and Description |
---|---|
void |
dispose()
Removes all associations between the TableEditor and the cell in the table.
|
int |
getColumn()
Returns the zero based index of the column of the cell being tracked by this editor.
|
TableItem |
getItem()
Returns the TableItem 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,
TableItem item,
int column)
Specify the Control that is to be displayed and the cell in the table that it is to be positioned above.
|
void |
setItem(TableItem item)
Specifies the
TableItem that is to be edited. |
getEditor
public TableEditor(Table table)
table
- the Table Control above which this editor will be displayedpublic void dispose()
dispose
in class ControlEditor
public int getColumn()
public TableItem getItem()
public void setColumn(int column)
column
- the zero based index of the column of the cell being tracked by this editorpublic void setItem(TableItem item)
TableItem
that is to be edited.item
- the item to be editedpublic 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, TableItem item, int column)
Note: The Control provided as the editor must be created with its parent being the Table control specified in the TableEditor constructor.
editor
- the Control that is displayed above the cell being editeditem
- the TableItem 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 layout()
ControlEditor
layout
in class ControlEditor
Copyright (c) EclipseSource and others 2002, 2017.
All rights reserved. This program and the accompanying materials
are made available under the terms of the
Eclipse Public License v1.0