Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Problem using SortColumnCommand on a table with a CompositeFreezeLayer
Problem using SortColumnCommand on a table with a CompositeFreezeLayer [message #1790958] Wed, 20 June 2018 15:31 Go to next message
Tom Wheeler is currently offline Tom WheelerFriend
Messages: 10
Registered: June 2018
Junior Member

I have configured a body layer stack with a CompositeFreezeLayer on top. The table have 6 columns. Using NatTable 1.5.0.

My ColumnHeaderLayer looks like this:
ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, aBodyLayerStack.getCompositeFreezeLayer(), aBodyLayerStack.getSelectionLayer(), false);

And here is my SortHeaderLayer:
aSortHeaderLayer = new SortHeaderLayer<TABLEENTRY>(columnHeaderLayer, new GlazedListsSortModel<TABLEENTRY>(aBodyLayerStack.getSortedList(), columnAccessor, columnPropertyResolverImpl, configRegistry, columnHeaderDataLayer));

When initializing the table, I would like to:
- have no columns frozen.
- have column #1 sorted.

After doing aNatTable.configure(), I issue this command:

aNatTable.doCommand(new SortColumnCommand(aSortHeaderLayer, 1, SortDirectionEnum.ASC));

Whenever no columns are frozen or the sort column index is greater than the index of the frozen column, I get this exception when issuing the SortColumnCommand:
java.lang.ArrayIndexOutOfBoundsException: -1
	at java.util.ArrayList.elementData(
	at java.util.ArrayList.get(
	at ca.odell.glazedlists.gui.AbstractTableComparatorChooser.getComparatorsForColumn(
	at org.eclipse.nebula.widgets.nattable.extension.glazedlists.NatTableComparatorChooser.sort(
	at org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsSortModel.sort(
	at org.eclipse.nebula.widgets.nattable.sort.command.SortCommandHandler$
	at org.eclipse.swt.custom.BusyIndicator.showWhile(
	at org.eclipse.nebula.widgets.nattable.sort.command.SortCommandHandler.doCommand(
	at org.eclipse.nebula.widgets.nattable.sort.command.SortCommandHandler.doCommand(
	at org.eclipse.nebula.widgets.nattable.command.AbstractLayerCommandHandler.doCommand(
	at org.eclipse.nebula.widgets.nattable.layer.AbstractLayer.doCommand(
	at org.eclipse.nebula.widgets.nattable.layer.AbstractLayerTransform.doCommand(
	at org.eclipse.nebula.widgets.nattable.layer.CompositeLayer.doCommandOnChildLayers(
	at org.eclipse.nebula.widgets.nattable.layer.CompositeLayer.doCommand(
	at org.eclipse.nebula.widgets.nattable.NatTable.doCommand(

The '-1' is obtained from this line in the SortCommandHandler.doCommand():
final int columnIndex = command.getLayer().getColumnIndexByPosition(command.getColumnPosition());

- and afterwards '-1' is passed further down, eventually resulting in the above exception.

The ColumnHeaderLayer is a DimensionallyDependentLayer.
From DimensionallyDependentLayer.getColumnIndexByPosition(1), I can see that horizontalLayerDependency is-a CompositeFreezeLayer

So the call horizontalLayerDependency.getColumnIndexByPosition(1) returns '-1':
public int getColumnIndexByPosition(int columnPosition) {
    return this.horizontalLayerDependency.getColumnIndexByPosition(columnPosition);

I have tried a few times single-stepping down the call horizontalLayerDependency.getColumnIndexByPosition(columnPosition), but I get lost in the transformation algorithms...

If I freeze column #1 or higher index before issuing the SortColumnCommand on column #1, everything seems to work fine:

aNatTable.doCommand(new FreezeColumnCommand(aBodyLayerStack.getCompositeFreezeLayer(), 1));

If I use another layer argument for the SortColumnCommand, like columnHeaderDataLayer or columnHeaderLayer, I get not effect at all, ie. no exception and no sorting.

Does anybody know how to make this work?



Re: Problem using SortColumnCommand on a table with a CompositeFreezeLayer [message #1791037 is a reply to message #1790958] Thu, 21 June 2018 17:32 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2814
Registered: July 2012
Senior Member
IIRC you are too early for sending that command correctly down the layer stack. The visible area needs to be set, which happens once the NatTable is painted. Directly after configure() the dimensions are not set yet and therefore the width of the table and the corresponding layers is 0.

I think I solved that use case by registering a PaintListener on the NatTable that performs the action and then unregisters itself. This way the NatTable is painted and the dimensions are set, so the position-index-transformation will work. But if you want to perform a pre-sorting on a column that is not visible, it will fail again. In such a case I would suggest to directly work on the ISortModel and avoid the command execution.
Re: Problem using SortColumnCommand on a table with a CompositeFreezeLayer [message #1791162 is a reply to message #1791037] Mon, 25 June 2018 11:16 Go to previous message
Tom Wheeler is currently offline Tom WheelerFriend
Messages: 10
Registered: June 2018
Junior Member
The PaintListener did the trick:

PaintListener pl = new PaintListener() {
  public void paintControl(PaintEvent pe) {
    if (aIndex >= 0) {
      try {
          aNatTable.doCommand(new SortColumnCommand(aSortHeaderLayer, aIndex, SortDirectionEnum.ASC));
      catch (Exception e) {
    // Only execute this listener once.

Thanks a lot.
Previous Topic:Avoid Nattable selecting the first char typed in edit mode
Next Topic:Use of coma in formula
Goto Forum:

Current Time: Fri Jun 18 00:51:02 GMT 2021

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

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

Back to the top