Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Different CellEditors in one column
Different CellEditors in one column [message #444591] Fri, 15 October 2004 16:28
Eclipse UserFriend
Originally posted by: teber.gmx.net

Hy all,

I have a problem with my TableTree.
It consists of two columns. The first one
shows the name of a variable and the second
one its value.
What I like to do is to have different CellEditors
in the same column which can show and edit the
variable values. Since each variable can have a
different value I like to set different CellEditors.
For example one row has a color label, next row a
combo box and another row a checkbox and so on.
The problem is that I can only set an editor for
the whole column, but not for a cell.
As an example take the code below. You will notice
that the second editor will replace the first on.
Any hints how I can preserve both editors?

Thanks in advance,

torsten


CODE:
-----

public class TableTreeEditors extends ApplicationWindow {
public TableTreeEditors() {
super(null);
}

protected Control createContents(final Composite parent) {
//create table
final TableTree tableTree = new TableTree(parent, SWT.FULL_SELECTION
| SWT.HIDE_SELECTION);
final Table table = tableTree.getTable();
table.setHeaderVisible(true);
TableColumn column1 = new TableColumn(table, SWT.NONE);
column1.setText("item");
TableColumn column2 = new TableColumn(table, SWT.NONE);
column2.setText("value");
for (int i = 0; i < 10; i++) {
TableTreeItem item = new TableTreeItem(tableTree, SWT.NONE);
item.setText(0, "item " + i);
item.setText(1, "edit this value");
for (int j = 0; j < 3; j++) {
TableTreeItem subitem = new TableTreeItem(item, SWT.NONE);
subitem.setText(0, "subitem " + i + " " + j);
subitem.setText(1, "edit this value");
}
}
column1.setWidth(100);
column2.pack();

//try to set different editors
final TableTreeEditor editor = new TableTreeEditor(tableTree);
//a simple button
Button buttonEditor = new Button(table, SWT.PUSH);
buttonEditor.setText("button");
TableTreeItem item = tableTree.getItems()[0];
editor.setEditor(buttonEditor, item, 1);

//checkbox button:
Button cbEditor = new Button(table, SWT.CHECK);
TableTreeItem secondItem = tableTree.getItems()[1];
editor.setEditor(cbEditor, secondItem, 1);

//editor must have cell size
editor.horizontalAlignment = SWT.LEFT;
editor.grabHorizontal = true;
editor.minimumWidth = 50;

return tableTree;
}


public static void main(String[] args) {
TableTreeEditors w = new TableTreeEditors();
w.setBlockOnOpen(true);
w.open();
Display.getCurrent().dispose();
}
}
Previous Topic:Wrap Text on Button
Next Topic:Viewer and widget
Goto Forum:
  


Current Time: Sun Oct 25 20:27:23 GMT 2020

Powered by FUDForum. Page generated in 0.01790 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top