CellEditors in Table [message #466263] |
Thu, 05 January 2006 15:34 |
Eclipse User |
|
|
|
Originally posted by: a.heikhaus.cenit.de
Hello,
at the moment I implement a table with key/value-pairs as input. I need to edit the values. Now I have the problem that sometimes I will need a ComboBox and sometimes a Text-Object - unfortunately I need this in the same column so I can not use the method TableViewer.setCellEditors(...)
Is there a possibility to link a CellEditor with one cell or row? Or may be I have to implement a new CellEditor with the described behavior?!
Thanks
André
|
|
|
Re: CellEditors in Table [message #466325 is a reply to message #466263] |
Fri, 06 January 2006 16:02 |
Yichao Zhang Messages: 7 Registered: July 2009 |
Junior Member |
|
|
Hi Andre
no, you need not implement a new CellEditor.
see a snippet below, wish it help.
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 selectedItem = (TableItem)e.item;
if (selectedItem == null) return;
if(selectedItem == something you'd like to edit by Text){
// The control that will be the editor must be a child of the Table
Text newEditor = new Text(table, SWT.NONE);
newEditor.setText(selectedItem.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, selectedItem, EDITABLECOLUMN);
}else if(selectedItem == something you'd like to edit by ComboBox){
comboBoxCellEditor = new ComboBoxCellEditor(table, new String[] {"true",
"false" });
editor.setEditor(comboBoxCellEditor.getControl(), selectedItem,
EDITABLECOLUMN);
Integer i = new Integer(0);
if(selectedItem.getText(1).equals("false")) i = new Integer(1);
comboBoxCellEditor.setValue(i);
comboBoxCellEditor.addListener(new ICellEditorListener(){
public void applyEditorValue() {
selectedItem.setText(EDITABLECOLUMN,comboBoxCellEditor.getIt ems()[((Integer)
comboBoxCellEditor.getValue()).intValue()]);
}
});
}
}
"Heikhaus" <a.heikhaus@cenit.de> wrote in message
news:3449973.1136475285249.JavaMail.root@cp1.javalobby.org...
> Hello,
>
> at the moment I implement a table with key/value-pairs as input. I need to
edit the values. Now I have the problem that sometimes I will need a
ComboBox and sometimes a Text-Object - unfortunately I need this in the same
column so I can not use the method TableViewer.setCellEditors(...)
>
> Is there a possibility to link a CellEditor with one cell or row? Or may
be I have to implement a new CellEditor with the described behavior?!
>
> Thanks
>
> Andr
|
|
|
|
Powered by
FUDForum. Page generated in 0.02670 seconds