Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » CellEditors in Table
CellEditors in Table [message #466263] Thu, 05 January 2006 15:34 Go to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Yichao Zhang is currently offline Yichao ZhangFriend
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
Re: CellEditors in Table [message #466368 is a reply to message #466325] Mon, 09 January 2006 16:08 Go to previous message
Eclipse UserFriend
Originally posted by: a.heikhaus.cenit.de

Thank you. It works fine!!
Previous Topic:how to create Palette like menu structure in SWT/JFace
Next Topic:Few questions
Goto Forum:
  


Current Time: Sat Aug 17 12:35:11 GMT 2019

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

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

Back to the top