Sorting while Adding / Removing columns with glazed lists sort model [message #895421] |
Thu, 12 July 2012 19:30 |
Timm Baumeister Messages: 14 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 #896044 is a reply to message #895885] |
Tue, 17 July 2012 03:33 |
Timm Baumeister Messages: 14 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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05864 seconds