StackOverflowError by traversing a table [message #60443] |
Mon, 17 November 2008 11:05 |
Tino Messages: 8 Registered: July 2009 |
Junior Member |
|
|
Hello,
I have a table with readonly columns at the first and last position of the
table and editable columns between them (as shown in the snippet).
The table has more rows than the display can show.
If I double click an editable column to activate the edit mode and press
TAB the cursor goes to the next column as expected. If I press TAB at the
end of the screen I would expect that the cursor jumps to the next (not
visible) row and makes the row visible. But the program stops with a
java.lang.StackOverflowError.
Without readonly columns the traversing works as expected.
Any reply is highly appreciated.
Thanks in advance.
Regards
Tino
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ColumnViewerEditor;
import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent;
import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrate gy;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.nebula.jface.gridviewer.GridTableViewer;
import org.eclipse.nebula.jface.gridviewer.GridViewerColumn;
import org.eclipse.nebula.jface.gridviewer.GridViewerEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class Snippet {
private class MyContentProvider implements IStructuredContentProvider {
public Object[] getElements(Object inputElement) {
return (MyModel[]) inputElement;
}
public void dispose() {
}
public void inputChanged(Viewer viewer, Object oldInput, Object
newInput) {
}
}
public class MyModel {
public int counter;
public MyModel(int counter) {
this.counter = counter;
}
public String toString() {
return "Item " + this.counter;
}
}
private class ElementEditingSupport extends EditingSupport {
private TextCellEditor cellEditor;
public ElementEditingSupport(GridTableViewer viewer) {
super(viewer);
cellEditor = new TextCellEditor(viewer.getGrid());
}
protected boolean canEdit(Object element) {
return true;
}
protected CellEditor getCellEditor(Object element) {
return cellEditor;
}
protected Object getValue(Object element) {
((GridTableViewer)getViewer()).getGrid().showSelection();
return String.valueOf(((MyModel) element).counter);
}
protected void setValue(Object element, Object value) {
((MyModel) element).counter = Integer.parseInt(value.toString());
getViewer().update(element, null);
}
}
public Snippet(Shell shell) {
final GridTableViewer v = new GridTableViewer(shell, SWT.BORDER |
SWT.V_SCROLL | SWT.H_SCROLL);
v.setLabelProvider(new ColumnLabelProvider());
v.setContentProvider(new MyContentProvider());
v.getGrid().setCellSelectionEnabled(true);
GridViewerColumn column = new GridViewerColumn(v, SWT.NONE);
column.getColumn().setWidth(100);
column.getColumn().setText("Readonly 1");
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return ((MyModel) element).toString();
}
@Override
public Color getBackground(Object element) {
return Display.getDefault().getSystemColor(SWT.COLOR_GRAY);
}
});
// Writable columns
for (int i = 0; i < 3; i++) {
column = new GridViewerColumn(v, SWT.NONE);
column.getColumn().setWidth(100);
column.getColumn().setText("Editable" + i);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return ((MyModel) element).toString();
}
});
column.setEditingSupport(new ElementEditingSupport(v));
}
//2nd Readonly column
column = new GridViewerColumn(v, SWT.NONE);
column.getColumn().setWidth(100);
column.getColumn().setText("Readonly 2");
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return ((MyModel) element).toString();
}
@Override
public Color getBackground(Object element) {
return Display.getDefault().getSystemColor(SWT.COLOR_GRAY);
}
});
ColumnViewerEditorActivationStrategy actSupport = new
ColumnViewerEditorActivationStrategy(v) {
protected boolean isEditorActivationEvent(
ColumnViewerEditorActivationEvent event) {
return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
|| event.eventType ==
ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTI ON
|| (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED
&& event.keyCode == SWT.CR);
}
};
GridViewerEditor.create(v, actSupport,
ColumnViewerEditor.TABBING_HORIZONTAL
| ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
| ColumnViewerEditor.TABBING_VERTICAL |
ColumnViewerEditor.KEYBOARD_ACTIVATION);
MyModel[] model = createModel();
v.setInput(model);
v.getGrid().setLinesVisible(true);
v.getGrid().setHeaderVisible(true);
}
private MyModel[] createModel() {
MyModel[] elements = new MyModel[10000];
for (int i = 0; i < 10000; i++) {
elements[i] = new MyModel(i);
}
return elements;
}
/**
* @param args
*/
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
new Snippet(shell);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
|
|
|
Re: StackOverflowError by traversing a table [message #60465 is a reply to message #60443] |
Mon, 17 November 2008 13:38 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
Hi,
Which version of JFace and GridViewer are you using? I think we had a
bug in JFace 3.4.0 we fixed in 3.4.1 but I could also be that I fixed
the bug in the header_footer branch of Grid where we are combining the
grid and viewer code in one code base.
Could you by chance give the header_footer branch a try else please file
a bugzilla and CC me on it then I'll fix the problem.
Tom
Tino schrieb:
> Hello,
>
> I have a table with readonly columns at the first and last position of
> the table and editable columns between them (as shown in the snippet).
> The table has more rows than the display can show.
>
> If I double click an editable column to activate the edit mode and press
> TAB the cursor goes to the next column as expected. If I press TAB at
> the end of the screen I would expect that the cursor jumps to the next
> (not visible) row and makes the row visible. But the program stops with
> a java.lang.StackOverflowError.
>
> Without readonly columns the traversing works as expected.
>
> Any reply is highly appreciated.
> Thanks in advance.
>
> Regards
> Tino
>
>
>
>
>
>
> import org.eclipse.jface.viewers.CellEditor;
> import org.eclipse.jface.viewers.ColumnLabelProvider;
> import org.eclipse.jface.viewers.ColumnViewerEditor;
> import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent;
> import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrate gy;
> import org.eclipse.jface.viewers.EditingSupport;
> import org.eclipse.jface.viewers.IStructuredContentProvider;
> import org.eclipse.jface.viewers.TextCellEditor;
> import org.eclipse.jface.viewers.Viewer;
> import org.eclipse.nebula.jface.gridviewer.GridTableViewer;
> import org.eclipse.nebula.jface.gridviewer.GridViewerColumn;
> import org.eclipse.nebula.jface.gridviewer.GridViewerEditor;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.graphics.Color;
> import org.eclipse.swt.layout.FillLayout;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Shell;
>
>
>
> public class Snippet {
>
> private class MyContentProvider implements IStructuredContentProvider {
>
> public Object[] getElements(Object inputElement) {
> return (MyModel[]) inputElement;
> }
>
> public void dispose() {
> }
>
> public void inputChanged(Viewer viewer, Object oldInput, Object
> newInput) {
> }
> }
>
>
> public class MyModel {
> public int counter;
>
> public MyModel(int counter) {
> this.counter = counter;
> }
>
> public String toString() {
> return "Item " + this.counter;
> }
> }
>
>
> private class ElementEditingSupport extends EditingSupport {
> private TextCellEditor cellEditor;
>
> public ElementEditingSupport(GridTableViewer viewer) {
> super(viewer);
> cellEditor = new TextCellEditor(viewer.getGrid());
> }
>
> protected boolean canEdit(Object element) {
> return true;
> }
>
> protected CellEditor getCellEditor(Object element) {
> return cellEditor;
> }
>
> protected Object getValue(Object element) {
> ((GridTableViewer)getViewer()).getGrid().showSelection();
> return String.valueOf(((MyModel) element).counter);
> }
>
> protected void setValue(Object element, Object value) {
> ((MyModel) element).counter =
> Integer.parseInt(value.toString());
> getViewer().update(element, null);
> }
> }
>
>
>
> public Snippet(Shell shell) {
>
> final GridTableViewer v = new GridTableViewer(shell, SWT.BORDER
> | SWT.V_SCROLL | SWT.H_SCROLL);
> v.setLabelProvider(new ColumnLabelProvider());
> v.setContentProvider(new MyContentProvider());
> v.getGrid().setCellSelectionEnabled(true);
>
>
> GridViewerColumn column = new GridViewerColumn(v, SWT.NONE);
> column.getColumn().setWidth(100);
> column.getColumn().setText("Readonly 1");
> column.setLabelProvider(new ColumnLabelProvider() {
> @Override
> public String getText(Object element) {
> return ((MyModel) element).toString();
> }
>
> @Override
> public Color getBackground(Object element) {
> return Display.getDefault().getSystemColor(SWT.COLOR_GRAY);
> }
> });
>
>
> // Writable columns
> for (int i = 0; i < 3; i++) {
> column = new GridViewerColumn(v, SWT.NONE);
> column.getColumn().setWidth(100);
> column.getColumn().setText("Editable" + i);
> column.setLabelProvider(new ColumnLabelProvider() {
> @Override
> public String getText(Object element) {
> return ((MyModel) element).toString();
> }
> });
> column.setEditingSupport(new ElementEditingSupport(v));
> }
>
>
> //2nd Readonly column
> column = new GridViewerColumn(v, SWT.NONE);
> column.getColumn().setWidth(100);
> column.getColumn().setText("Readonly 2");
> column.setLabelProvider(new ColumnLabelProvider() {
> @Override
> public String getText(Object element) {
> return ((MyModel) element).toString();
> }
>
> @Override
> public Color getBackground(Object element) {
> return Display.getDefault().getSystemColor(SWT.COLOR_GRAY);
> }
> });
>
>
>
> ColumnViewerEditorActivationStrategy actSupport = new
> ColumnViewerEditorActivationStrategy(v) {
> protected boolean isEditorActivationEvent(
> ColumnViewerEditorActivationEvent event) {
> return event.eventType ==
> ColumnViewerEditorActivationEvent.TRAVERSAL
> || event.eventType ==
> ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTI ON
> || (event.eventType ==
> ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR);
> }
> };
>
> GridViewerEditor.create(v, actSupport,
> ColumnViewerEditor.TABBING_HORIZONTAL
> | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
> | ColumnViewerEditor.TABBING_VERTICAL |
> ColumnViewerEditor.KEYBOARD_ACTIVATION);
>
>
> MyModel[] model = createModel();
> v.setInput(model);
> v.getGrid().setLinesVisible(true);
> v.getGrid().setHeaderVisible(true);
> }
>
>
> private MyModel[] createModel() {
> MyModel[] elements = new MyModel[10000];
>
> for (int i = 0; i < 10000; i++) {
> elements[i] = new MyModel(i);
> }
>
> return elements;
> }
>
>
> /**
> * @param args
> */
> public static void main(String[] args) {
> Display display = new Display();
>
> Shell shell = new Shell(display);
> shell.setLayout(new FillLayout());
> new Snippet(shell);
> shell.open();
>
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep();
> }
>
> display.dispose();
>
> }
> }
>
>
--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
|
|
|
|
|
|
Re: StackOverflowError by traversing a table [message #592708 is a reply to message #60443] |
Mon, 17 November 2008 13:38 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
Hi,
Which version of JFace and GridViewer are you using? I think we had a
bug in JFace 3.4.0 we fixed in 3.4.1 but I could also be that I fixed
the bug in the header_footer branch of Grid where we are combining the
grid and viewer code in one code base.
Could you by chance give the header_footer branch a try else please file
a bugzilla and CC me on it then I'll fix the problem.
Tom
Tino schrieb:
> Hello,
>
> I have a table with readonly columns at the first and last position of
> the table and editable columns between them (as shown in the snippet).
> The table has more rows than the display can show.
>
> If I double click an editable column to activate the edit mode and press
> TAB the cursor goes to the next column as expected. If I press TAB at
> the end of the screen I would expect that the cursor jumps to the next
> (not visible) row and makes the row visible. But the program stops with
> a java.lang.StackOverflowError.
>
> Without readonly columns the traversing works as expected.
>
> Any reply is highly appreciated.
> Thanks in advance.
>
> Regards
> Tino
>
>
>
>
>
>
> import org.eclipse.jface.viewers.CellEditor;
> import org.eclipse.jface.viewers.ColumnLabelProvider;
> import org.eclipse.jface.viewers.ColumnViewerEditor;
> import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent;
> import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrate gy;
> import org.eclipse.jface.viewers.EditingSupport;
> import org.eclipse.jface.viewers.IStructuredContentProvider;
> import org.eclipse.jface.viewers.TextCellEditor;
> import org.eclipse.jface.viewers.Viewer;
> import org.eclipse.nebula.jface.gridviewer.GridTableViewer;
> import org.eclipse.nebula.jface.gridviewer.GridViewerColumn;
> import org.eclipse.nebula.jface.gridviewer.GridViewerEditor;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.graphics.Color;
> import org.eclipse.swt.layout.FillLayout;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Shell;
>
>
>
> public class Snippet {
>
> private class MyContentProvider implements IStructuredContentProvider {
>
> public Object[] getElements(Object inputElement) {
> return (MyModel[]) inputElement;
> }
>
> public void dispose() {
> }
>
> public void inputChanged(Viewer viewer, Object oldInput, Object
> newInput) {
> }
> }
>
>
> public class MyModel {
> public int counter;
>
> public MyModel(int counter) {
> this.counter = counter;
> }
>
> public String toString() {
> return "Item " + this.counter;
> }
> }
>
>
> private class ElementEditingSupport extends EditingSupport {
> private TextCellEditor cellEditor;
>
> public ElementEditingSupport(GridTableViewer viewer) {
> super(viewer);
> cellEditor = new TextCellEditor(viewer.getGrid());
> }
>
> protected boolean canEdit(Object element) {
> return true;
> }
>
> protected CellEditor getCellEditor(Object element) {
> return cellEditor;
> }
>
> protected Object getValue(Object element) {
> ((GridTableViewer)getViewer()).getGrid().showSelection();
> return String.valueOf(((MyModel) element).counter);
> }
>
> protected void setValue(Object element, Object value) {
> ((MyModel) element).counter =
> Integer.parseInt(value.toString());
> getViewer().update(element, null);
> }
> }
>
>
>
> public Snippet(Shell shell) {
>
> final GridTableViewer v = new GridTableViewer(shell, SWT.BORDER
> | SWT.V_SCROLL | SWT.H_SCROLL);
> v.setLabelProvider(new ColumnLabelProvider());
> v.setContentProvider(new MyContentProvider());
> v.getGrid().setCellSelectionEnabled(true);
>
>
> GridViewerColumn column = new GridViewerColumn(v, SWT.NONE);
> column.getColumn().setWidth(100);
> column.getColumn().setText("Readonly 1");
> column.setLabelProvider(new ColumnLabelProvider() {
> @Override
> public String getText(Object element) {
> return ((MyModel) element).toString();
> }
>
> @Override
> public Color getBackground(Object element) {
> return Display.getDefault().getSystemColor(SWT.COLOR_GRAY);
> }
> });
>
>
> // Writable columns
> for (int i = 0; i < 3; i++) {
> column = new GridViewerColumn(v, SWT.NONE);
> column.getColumn().setWidth(100);
> column.getColumn().setText("Editable" + i);
> column.setLabelProvider(new ColumnLabelProvider() {
> @Override
> public String getText(Object element) {
> return ((MyModel) element).toString();
> }
> });
> column.setEditingSupport(new ElementEditingSupport(v));
> }
>
>
> //2nd Readonly column
> column = new GridViewerColumn(v, SWT.NONE);
> column.getColumn().setWidth(100);
> column.getColumn().setText("Readonly 2");
> column.setLabelProvider(new ColumnLabelProvider() {
> @Override
> public String getText(Object element) {
> return ((MyModel) element).toString();
> }
>
> @Override
> public Color getBackground(Object element) {
> return Display.getDefault().getSystemColor(SWT.COLOR_GRAY);
> }
> });
>
>
>
> ColumnViewerEditorActivationStrategy actSupport = new
> ColumnViewerEditorActivationStrategy(v) {
> protected boolean isEditorActivationEvent(
> ColumnViewerEditorActivationEvent event) {
> return event.eventType ==
> ColumnViewerEditorActivationEvent.TRAVERSAL
> || event.eventType ==
> ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTI ON
> || (event.eventType ==
> ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR);
> }
> };
>
> GridViewerEditor.create(v, actSupport,
> ColumnViewerEditor.TABBING_HORIZONTAL
> | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
> | ColumnViewerEditor.TABBING_VERTICAL |
> ColumnViewerEditor.KEYBOARD_ACTIVATION);
>
>
> MyModel[] model = createModel();
> v.setInput(model);
> v.getGrid().setLinesVisible(true);
> v.getGrid().setHeaderVisible(true);
> }
>
>
> private MyModel[] createModel() {
> MyModel[] elements = new MyModel[10000];
>
> for (int i = 0; i < 10000; i++) {
> elements[i] = new MyModel(i);
> }
>
> return elements;
> }
>
>
> /**
> * @param args
> */
> public static void main(String[] args) {
> Display display = new Display();
>
> Shell shell = new Shell(display);
> shell.setLayout(new FillLayout());
> new Snippet(shell);
> shell.open();
>
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep();
> }
>
> display.dispose();
>
> }
> }
>
>
--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05424 seconds