Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Cannot Edit cells of table using TableViewerColumn.setEditingSupport(Not Able the edit cells of the table)
Cannot Edit cells of table using TableViewerColumn.setEditingSupport [message #1752126] Thu, 19 January 2017 05:13 Go to next message
Kallol Ghose is currently offline Kallol GhoseFriend
Messages: 3
Registered: January 2017
Junior Member
Hi,

I m trying to edit my table cell using TextCellEditor but the extended function of EditingSupport are not getting called -

My code is as follows -

//Creation of tableviewer and the columns
TableViewer testscriptsViewer = new TableViewer(script_composite, SWT.BORDER | SWT.FULL_SELECTION);
testscriptTable = testscriptsViewer.getTable();
testscriptTable.setLinesVisible(true);
testscriptTable.setHeaderVisible(true);
testscriptTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

TableViewerColumn snoViewer = new TableViewerColumn(testscriptsViewer, SWT.NONE);
TableColumn snoCol = snoViewer.getColumn();
snoCol.setResizable(false);
snoCol.setWidth(57);
snoCol.setText("S.No");

TableViewerColumn oprViewer = new TableViewerColumn(testscriptsViewer, SWT.NONE);
TableColumn operationCol = oprViewer.getColumn();
operationCol.setWidth(107);
operationCol.setText("Operation");
oprViewer.setEditingSupport(new TableColumnsEditable(testscriptsViewer));

TableViewerColumn pgViewer = new TableViewerColumn(testscriptsViewer, SWT.NONE);
TableColumn pageNameCol = pgViewer.getColumn();
pageNameCol.setWidth(114);
pageNameCol.setText("Page Name");
pgViewer.setEditingSupport(new TableColumnsEditable(testscriptsViewer));


TableViewerColumn objViewer = new TableViewerColumn(testscriptsViewer, SWT.NONE);
TableColumn objCol = objViewer.getColumn();
objCol.setWidth(106);
objCol.setText("Object Name");
objViewer.setEditingSupport(new TableColumnsEditable(testscriptsViewer));

TableViewerColumn argColViewer = new TableViewerColumn(testscriptsViewer, SWT.NONE);
TableColumn argCol = argColViewer.getColumn();
argCol.setWidth(100);
argCol.setText("Argument");
argColViewer.setEditingSupport(new TableColumnsEditable(testscriptsViewer));

TableViewerColumn varColViewer = new TableViewerColumn(testscriptsViewer, SWT.NONE);
TableColumn varNameCol = varColViewer.getColumn();
varNameCol.setWidth(100);
varNameCol.setText("Variable Name");
varColViewer.setEditingSupport(new TableColumnsEditable(testscriptsViewer));

//Editing Support Class

public class TableColumnsEditable extends EditingSupport
{
private TableViewer tableViewer = null;
private CellEditor editor = null;

public TableColumnsEditable(TableViewer viewer) {
super(viewer);
// TODO Auto-generated constructor stub
this.tableViewer = viewer;
editor = new TextCellEditor(tableViewer.getTable());
}

@Override
protected CellEditor getCellEditor(Object element) {
// TODO Auto-generated method stub
return editor;
}

@Override
protected boolean canEdit(Object element) {
// TODO Auto-generated method stub
return true;
}

@Override
protected Object getValue(Object element) {
// TODO Auto-generated method stub
return element.toString();
}

@Override
protected void setValue(Object element, Object value) {
// TODO Auto-generated method stub
element = value;
getViewer().update(value, null);
}

}

Please make this work

Thanks

Re: Cannot Edit cells of table using TableViewerColumn.setEditingSupport [message #1752202 is a reply to message #1752126] Thu, 19 January 2017 20:50 Go to previous message
Brian de Alwis is currently offline Brian de AlwisFriend
Messages: 693
Registered: January 2012
Senior Member

Your setValue() method does nothing: you need to change the content of `element`. And `update()` takes the object to show, not the new content that's being set.
@Override
protected void setValue(Object element, Object value) {
// TODO Auto-generated method stub
element = value;  // <--- this needs to do something like "element.setText((String)value))"
getViewer().update(value, null);
}


Take a look at the JFace example.


Eclipse Platform committer. Ask me about Eclipse support, training, and consulting.
Previous Topic:Global Key Listener
Next Topic:Where is Neon update site for SWT GTK plugin
Goto Forum:
  


Current Time: Mon Dec 11 04:00:32 GMT 2017

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

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