Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Nebula » StackOverflowError by traversing a table
StackOverflowError by traversing a table [message #592698] Mon, 17 November 2008 11:05
Tino is currently offline 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();

}
}
Previous Topic:GridColumn visibility problem
Next Topic:StackOverflowError by traversing a table
Goto Forum:
  


Current Time: Tue Sep 23 04:24:58 GMT 2014

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

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