Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » [TextCellEditor] TableViewer not updated?
[TextCellEditor] TableViewer not updated? [message #156588] Fri, 14 November 2003 03:19 Go to next message
Eclipse UserFriend
Originally posted by: jovezhong.21cn.com

Here is a simple jface tableviewer demo I wrote.
all cell can be edited using TextCellEditor, but the new value seems not
apply to the view.
i.e if the old value is 3, after I edit the value to 6, after pressing
Enter key, the value of the cell is still 3.

thanks for your help.

//code
import org.eclipse.jface.viewers.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

/**
* @author Jove
*/
public class TextTable {

public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell();
shell.setLayout(new GridLayout());
shell.setText("Text Table");
{
final Table table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION);
table.setLayoutData(new GridData(GridData.FILL_BOTH));
table.setLinesVisible(true);
table.setHeaderVisible(true);
{
final TableColumn tableColumn = new TableColumn(table, SWT.NONE);
tableColumn.setWidth(100);
tableColumn.setText("A");
}
{
final TableColumn tableColumn = new TableColumn(table, SWT.NONE);
tableColumn.setWidth(100);
tableColumn.setText("B");
}
{
final TableColumn tableColumn = new TableColumn(table, SWT.NONE);
tableColumn.setWidth(100);
tableColumn.setText("C");
}
final TableViewer tableViewer = new TableViewer(table);
final String[] columns = { "A", "B", "C" };
class MyData {
String a, b, c;
MyData(String a, String b, String c) {
this.a = a;
this.b = b;
this.c = c;
}
}
tableViewer.setColumnProperties(columns);
CellEditor[] cellEditor = new CellEditor[columns.length];
for (int i = 0; i < cellEditor.length; i++) {
cellEditor[i] = new TextCellEditor(table);
}
tableViewer.setCellEditors(cellEditor);
tableViewer.setCellModifier(new ICellModifier() {
public boolean canModify(Object element, String property) {
return true;
}
public Object getValue(Object element, String property) {
MyData data = (MyData) element;
if ("A".equals(property)) {
return data.a;
} else if ("B".equals(property)) {
return data.b;
} else if ("C".equals(property)) {
return data.c;
}
return "";
}
public void modify(Object element, String property, Object value) {
TableItem tableItem = (TableItem) element;
MyData data = (MyData) tableItem.getData();
String newValue = (String) value;
if ("A".equals(property)) {
data.a = newValue;
} else if ("B".equals(property)) {
data.b = newValue;
} else if ("C".equals(property)) {
data.c = newValue;
}
}
});
tableViewer.setContentProvider(new IStructuredContentProvider() {
public Object[] getElements(Object inputElement) {
return (MyData[]) inputElement;
}
public void dispose() {
}
public void inputChanged(Viewer viewer, Object oldInput, Object
newInput) {
}
});
tableViewer.setLabelProvider(new ITableLabelProvider() {
public Image getColumnImage(Object element, int columnIndex) {
return null;
}
public String getColumnText(Object element, int columnIndex) {
MyData data = (MyData) element;
switch (columnIndex) {
case 0 :
return data.a;
case 1 :
return data.b;
case 2 :
return data.c;
}
return "";
}
public void addListener(ILabelProviderListener listener) {
}
public void dispose() {
}
public boolean isLabelProperty(Object element, String property) {
return false;
}
public void removeListener(ILabelProviderListener listener) {
}
});
MyData[] data = { new MyData("1", "2", "3"), new MyData("a", "b", "c")};
tableViewer.setInput(data);
}
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
}
Re: [TextCellEditor] TableViewer not updated? [message #156629 is a reply to message #156588] Fri, 14 November 2003 07:19 Go to previous message
Eclipse UserFriend
Originally posted by: jovezhong.21cn.com

:) I've got the answer.
Just add a statement -- tableViewer.refresh(); at the end of modify(..)
method.

"Jove Zhong" <jovezhong@21cn.com> д
Previous Topic:Editor Plugin Tutorial
Next Topic:Change proejct type on the fly?
Goto Forum:
  


Current Time: Thu Nov 21 11:12:21 GMT 2024

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

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

Back to the top