Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Sorting while Adding / Removing columns with glazed lists sort model
Sorting while Adding / Removing columns with glazed lists sort model [message #895421] Thu, 12 July 2012 19:30 Go to next message
Timm Baumeister is currently offline Timm Baumeister
Messages: 10
Registered: July 2012
Junior Member
I am using GlazedListsSortModel for my SortHeaderLayer and my own custom IColumnPropertyAccessor and IDataProvider for body data and column header.

My data has a dynamic number of columns which changes on user interaction.
Whenever a column is added/removed I fire a doCommand(new StructuralRefreshCommand()) on the nattable.

Everything works great, except that any of the dynamically added columns are not sortable. When I click on their column header to initiate sorting, I get the following exception:

!MESSAGE Unhandled event loop exception
!STACK 0
java.lang.IndexOutOfBoundsException: Index: 6, Size: 6
	at java.util.ArrayList.rangeCheck(ArrayList.java:604)
	at java.util.ArrayList.get(ArrayList.java:382)
	at ca.odell.glazedlists.gui.AbstractTableComparatorChooser.getComparatorsForColumn(AbstractTableComparatorChooser.java:178)
	at net.sourceforge.nattable.extension.glazedlists.NatTableComparatorChooser.sort(NatTableComparatorChooser.java:22)
	at net.sourceforge.nattable.extension.glazedlists.GlazedListsSortModel.sort(GlazedListsSortModel.java:73)
	at net.sourceforge.nattable.sort.command.SortCommandHandler$1.run(SortCommandHandler.java:33)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
	at net.sourceforge.nattable.sort.command.SortCommandHandler.doCommand(SortCommandHandler.java:36)
	at net.sourceforge.nattable.sort.command.SortCommandHandler.doCommand(SortCommandHandler.java:1)
	at net.sourceforge.nattable.command.AbstractLayerCommandHandler.doCommand(AbstractLayerCommandHandler.java:9)
	at net.sourceforge.nattable.layer.AbstractLayer.doCommand(AbstractLayer.java:137)
	at net.sourceforge.nattable.layer.AbstractLayerTransform.doCommand(AbstractLayerTransform.java:83)
	at net.sourceforge.nattable.layer.AbstractLayerTransform.doCommand(AbstractLayerTransform.java:88)
	at net.sourceforge.nattable.grid.layer.GridLayer.doCommandOnChildLayer(GridLayer.java:95)
	at net.sourceforge.nattable.grid.layer.GridLayer.doCommandOnChildLayers(GridLayer.java:84)
	at net.sourceforge.nattable.layer.CompositeLayer.doCommand(CompositeLayer.java:116)
	at net.sourceforge.nattable.NatTable.doCommand(NatTable.java:487)
	at net.sourceforge.nattable.sort.action.SortColumnAction.run(SortColumnAction.java:20)
	at net.sourceforge.nattable.ui.mode.MouseModeEventHandler.executeSingleClickAction(MouseModeEventHandler.java:108)
	at net.sourceforge.nattable.ui.mode.MouseModeEventHandler.mouseUp(MouseModeEventHandler.java:59)
	at net.sourceforge.nattable.ui.mode.ModeSupport.mouseUp(ModeSupport.java:89)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:219)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1258)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3588)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3209)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2701)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)


Apparently the GlazedListsSortModel does not update during the StructuralRefreshCommand. Can anyone give me a hint how I can fix this?

Any help is greatly appreciated.

Timm

[Updated on: Thu, 12 July 2012 19:41]

Report message to a moderator

Re: Sorting while Adding / Removing columns with glazed lists sort model [message #895885 is a reply to message #895421] Mon, 16 July 2012 12:42 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk Fauth
Messages: 1289
Registered: July 2012
Senior Member
Hi,

sorry for the delay in answering. I came up this issue before and helped myself by creating my own specialized ISortModel. But in fact this should be fixed in GlazedListsSortModel.

I created a bug with id 385171 and will have a look at it.

Greez,
Dirk
Re: Sorting while Adding / Removing columns with glazed lists sort model [message #896044 is a reply to message #895885] Tue, 17 July 2012 03:33 Go to previous messageGo to next message
Timm Baumeister is currently offline Timm Baumeister
Messages: 10
Registered: July 2012
Junior Member
Hi Dirk,

I have worked around it now by writing a wrapper for GlazedListsSortModel that has a refresh method that I call whenever a structural refresh happens. It then recreates the sortmodel if the number of columns changed and then reapplies the sorted by column (if possible):

class GlazedListsSortModelWrapper<T> implements ISortModel {
	SortedList<T> sortedList;
	IColumnPropertyAccessor<T> columnPropertyAccessor;
	IConfigRegistry configRegistry;
	DefaultColumnHeaderDataLayer columnHeaderDataLayer;
	int oldColumnCount;
	GlazedListsSortModel<T> model;
	public GlazedListsSortModelWrapper(SortedList<T> sortedList,
			IColumnPropertyAccessor<T> columnPropertyAccessor,
			IConfigRegistry configRegistry,
			DefaultColumnHeaderDataLayer columnHeaderDataLayer) {
		this.sortedList=sortedList;
		this.columnPropertyAccessor = columnPropertyAccessor;
		this.configRegistry = configRegistry;
		this.columnHeaderDataLayer = columnHeaderDataLayer;
		model = new GlazedListsSortModel<T>(sortedList,
			columnPropertyAccessor, configRegistry, columnHeaderDataLayer);
		oldColumnCount = columnPropertyAccessor.getColumnCount();
	}
	public void refresh() {
		int newColumnCount = columnPropertyAccessor.getColumnCount();
		if (newColumnCount==oldColumnCount)
			return;
		List<Integer> sortedColumnIndices = model.getSortedColumnIndexes();
		SortDirectionEnum sortDir = null;
		if (sortedColumnIndices.size()>0)
			sortDir = model.getSortDirection(sortedColumnIndices.get(0));
		model = new GlazedListsSortModel<T>(sortedList,
			columnPropertyAccessor, configRegistry, columnHeaderDataLayer);
		if (sortedColumnIndices.size()>0 && sortedColumnIndices.get(0)<newColumnCount)
			model.sort(sortedColumnIndices.get(0),sortDir,false);
		oldColumnCount = newColumnCount;
	}
	@Override
	public void clear() {
		model.clear();
	}

	@Override
	public List<Comparator> getComparatorsForColumnIndex(int arg0) {
		return model.getComparatorsForColumnIndex(arg0);
	}

	@Override
	public SortDirectionEnum getSortDirection(int arg0) {
		return model.getSortDirection(arg0);
	}

	@Override
	public int getSortOrder(int arg0) {
		return model.getSortOrder(arg0);
	}

	@Override
	public List<Integer> getSortedColumnIndexes() {
		return model.getSortedColumnIndexes();
	}

	@Override
	public boolean isColumnIndexSorted(int arg0) {
		return model.isColumnIndexSorted(arg0);
	}

	@Override
	public void sort(int arg0, SortDirectionEnum arg1, boolean arg2) {
		model.sort(arg0,arg1,arg2);
	}
}


As you say it would be nice if this could be fixed in GlazedListsSortModel. I'll watch the bug and go back to a cleaner solution if it gets fixed.

Thanks,

Timm
Re: Sorting while Adding / Removing columns with glazed lists sort model [message #900940 is a reply to message #896044] Thu, 09 August 2012 07:28 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk Fauth
Messages: 1289
Registered: July 2012
Senior Member
Hi,

I just checked in a fix for this as described in bugzilla. I also added a DynamicColumnExample to verify and show that it is working.

Please let me know if it also works for you or if there are issues I haven't thought of.

Greez,
Dirk
Re: Sorting while Adding / Removing columns with glazed lists sort model [message #901074 is a reply to message #900940] Thu, 09 August 2012 15:41 Go to previous message
Timm Baumeister is currently offline Timm Baumeister
Messages: 10
Registered: July 2012
Junior Member
Hi Dirk,

Your commit fixes the problem for me.

Thanks,
Timm
Previous Topic:Custom Editors
Next Topic:Welcome
Goto Forum:
  


Current Time: Fri Sep 19 06:06:33 GMT 2014

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

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