Skip to main content



      Home
Home » Eclipse Projects » NatTable » Issue with RowSelectionProvider(crash on grid with millions of rows)
Issue with RowSelectionProvider [message #1185216] Wed, 13 November 2013 19:11 Go to next message
Eclipse UserFriend
Hi,

I am using Nattable in an eclipse plugin. The grid is virtual and the data is provided from a file and the data is provided on demand using the IRowDataProvider<T> and it works well and the grid is really fast even for providing huge data from 1 or 2 GB file. I am using the RowSelectionProvider to listen for selected row(or cell in a row) and perform some actions.

		RowSelectionProvider<MyObj> selectionProvider = new RowSelectionProvider<MyObj>( selectionLayer, layer.getBodyProvider(), false );
		selectionProvider.addSelectionChangedListener( this );


This also works well and it provides the selected row object in the selection event. But the grid consumes too much memory when selecting a column header and eventually crashes with out of memory exception. The reason seems to be that the selection provider is trying to get the objects for all selected rows which is the entire table( the range shown in populateRowSelection method of RowSelectionProvider is Range[0,16544946] ). I am not sure if someone has faced a scenario like this with RowSelectionProvider

Here is the methods that store all the data in memory which defeats the virtual nature of the grid
	@SuppressWarnings("rawtypes")
	static StructuredSelection populateRowSelection(SelectionLayer selectionLayer, IRowDataProvider rowDataProvider, boolean fullySelectedRowsOnly) {
		List<RowObjectIndexHolder<Object>> rows = new ArrayList<RowObjectIndexHolder<Object>>();

		if (selectionLayer != null) {
			if (fullySelectedRowsOnly) {
				for (int rowPosition : selectionLayer.getFullySelectedRowPositions()) {
					addToSelection(rows, rowPosition, selectionLayer, rowDataProvider);
				}
			} else {
				Set<Range> rowRanges = selectionLayer.getSelectedRowPositions();
				for (Range rowRange : rowRanges) {
					for (int rowPosition = rowRange.start; rowPosition < rowRange.end; rowPosition++) {
						addToSelection(rows, rowPosition, selectionLayer, rowDataProvider);
					}
				}
			}
		}
		Collections.sort(rows);
		List<Object> rowObjects = new ArrayList<Object>();
		for(RowObjectIndexHolder<Object> holder : rows){
			rowObjects.add(holder.getRow());
		}
		return rows.isEmpty() ? StructuredSelection.EMPTY : new StructuredSelection(rowObjects);
	}
	
	@SuppressWarnings("rawtypes")
	private static void addToSelection(List<RowObjectIndexHolder<Object>> rows, int rowPosition, SelectionLayer selectionLayer, IRowDataProvider rowDataProvider) {
		int rowIndex = selectionLayer.getRowIndexByPosition(rowPosition);
		if (rowIndex >= 0 && rowIndex < rowDataProvider.getRowCount()) {
			Object rowObject = rowDataProvider.getRowObject(rowIndex);
			rows.add(new RowObjectIndexHolder<Object>(rowIndex, rowObject));
		}
	}


It crashed with the following error
java.lang.OutOfMemoryError: Java heap space
.....
......
	at org.eclipse.nebula.widgets.nattable.selection.RowSelectionProvider.addToSelection(RowSelectionProvider.java:211)
	at org.eclipse.nebula.widgets.nattable.selection.RowSelectionProvider.populateRowSelection(RowSelectionProvider.java:194)
	at org.eclipse.nebula.widgets.nattable.selection.RowSelectionProvider.getSelection(RowSelectionProvider.java:130)
	at org.eclipse.nebula.widgets.nattable.selection.RowSelectionProvider.handleLayerEvent(RowSelectionProvider.java:168)
	at org.eclipse.nebula.widgets.nattable.layer.AbstractLayer.fireLayerEvent(AbstractLayer.java:242)
	at org.eclipse.nebula.widgets.nattable.selection.SelectColumnCommandHandler.selectColumn(SelectColumnCommandHandler.java:59)
	at org.eclipse.nebula.widgets.nattable.selection.SelectColumnCommandHandler.doCommand(SelectColumnCommandHandler.java:35)
	at org.eclipse.nebula.widgets.nattable.selection.SelectColumnCommandHandler.doCommand(SelectColumnCommandHandler.java:1)
	at org.eclipse.nebula.widgets.nattable.layer.AbstractLayer.doCommand(AbstractLayer.java:154)
	at org.eclipse.nebula.widgets.nattable.layer.AbstractIndexLayerTransform.doCommand(AbstractIndexLayerTransform.java:109)
	at org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.doCommand(SelectionLayer.java:395)
	at org.eclipse.nebula.widgets.nattable.layer.AbstractLayerTransform.doCommand(AbstractLayerTransform.java:107)
	at org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer.doCommand(ViewportLayer.java:683)
	at org.eclipse.nebula.widgets.nattable.viewport.command.ViewportSelectColumnCommandHandler.doCommand(ViewportSelectColumnCommandHandler.java:33)
	at org.eclipse.nebula.widgets.nattable.viewport.command.ViewportSelectColumnCommandHandler.doCommand(ViewportSelectColumnCommandHandler.java:1)
	at org.eclipse.nebula.widgets.nattable.command.AbstractLayerCommandHandler.doCommand(AbstractLayerCommandHandler.java:19)
	at org.eclipse.nebula.widgets.nattable.layer.AbstractLayer.doCommand(AbstractLayer.java:154)
	at org.eclipse.nebula.widgets.nattable.layer.AbstractLayerTransform.doCommand(AbstractLayerTransform.java:102)
	at org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer.doCommand(ViewportLayer.java:683)
	at org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer.doCommandOnChildLayer(GridLayer.java:109)
	at org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer.doCommandOnChildLayers(GridLayer.java:96)
	at org.eclipse.nebula.widgets.nattable.layer.CompositeLayer.doCommand(CompositeLayer.java:137)
	at org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer.doCommand(GridLayer.java:178)
	at org.eclipse.nebula.widgets.nattable.NatTable.doCommand(NatTable.java:516)
	at org.eclipse.nebula.widgets.nattable.viewport.action.ViewportSelectColumnAction.run(ViewportSelectColumnAction.java:33)
	at org.eclipse.nebula.widgets.nattable.ui.mode.MouseModeEventHandler.executeSingleClickAction(MouseModeEventHandler.java:117)


Is there a way to not listen for rowselection events when an entire column is selected? As the rowselectionprovider works correctly for single cell/row selections.

Re: Issue with RowSelectionProvider [message #1185715 is a reply to message #1185216] Thu, 14 November 2013 03:09 Go to previous messageGo to next message
Eclipse UserFriend
Quote:
As the rowselectionprovider works correctly for single cell/row selections.


To be precise, it also works correctly in case of column selection. As it provides the selection of all selected rows. That matches the specification.

But I agree, your use case is valid and for huge data sets, there should be a way to disable that behaviour.

To answer your question: No at the moment it is not possible to simply disable it.

You could extend the RowSelectionProvider for an additional flag (say boolean provideColumnSelection or something like that) and in RowSelectionProvider.handleLayerEvent() you could inspect that flag and the type of ISelectionEvent. If the flag is set to false and the event is of type ColumnSelectionEvent you could skip the processing.

Would love to see something like that contributed by you.

Greez,
Dirk
Re: Issue with RowSelectionProvider [message #1186687 is a reply to message #1185715] Thu, 14 November 2013 15:54 Go to previous messageGo to next message
Eclipse UserFriend
Sure Dirk. How do i contribute the changes to Nattable. What is the process followed?
Re: Issue with RowSelectionProvider [message #1186724 is a reply to message #1186687] Thu, 14 November 2013 16:19 Go to previous messageGo to next message
Eclipse UserFriend
It's the default Eclipse development process.

1. Create a ticket
2. Attach a patch that contains your contribution
3. Provide the information that you authored everything yourself and that you are allowed to contribute (you should find the 3 statements somewhere in the eclipse wiki for contributions)
4. If everything is ok then I will apply and commit the patch Smile

Re: Issue with RowSelectionProvider [message #1230913 is a reply to message #1186724] Mon, 13 January 2014 06:11 Go to previous message
Eclipse UserFriend
To finish this topic:

Here is the ticket: https://bugs.eclipse.org/bugs/show_bug.cgi?id=421848
Previous Topic:ToggleCheckBoxColumnAction for spanned columns
Next Topic:ComboBoxCellEditor flickering
Goto Forum:
  


Current Time: Sat Jul 12 16:14:26 EDT 2025

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

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

Back to the top