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: 17
Registered: June 2018
Junior Member
Hello,

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(ArrayList.java:418)
	at java.util.ArrayList.get(ArrayList.java:431)
	at ca.odell.glazedlists.gui.AbstractTableComparatorChooser.getComparatorsForColumn(AbstractTableComparatorChooser.java:178)
	at org.eclipse.nebula.widgets.nattable.extension.glazedlists.NatTableComparatorChooser.sort(NatTableComparatorChooser.java:36)
	at org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsSortModel.sort(GlazedListsSortModel.java:114)
	at org.eclipse.nebula.widgets.nattable.sort.command.SortCommandHandler$1.run(SortCommandHandler.java:50)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
	at org.eclipse.nebula.widgets.nattable.sort.command.SortCommandHandler.doCommand(SortCommandHandler.java:53)
	at org.eclipse.nebula.widgets.nattable.sort.command.SortCommandHandler.doCommand(SortCommandHandler.java:1)
	at org.eclipse.nebula.widgets.nattable.command.AbstractLayerCommandHandler.doCommand(AbstractLayerCommandHandler.java:21)
	at org.eclipse.nebula.widgets.nattable.layer.AbstractLayer.doCommand(AbstractLayer.java:186)
	at org.eclipse.nebula.widgets.nattable.layer.AbstractLayerTransform.doCommand(AbstractLayerTransform.java:101)
	at org.eclipse.nebula.widgets.nattable.layer.CompositeLayer.doCommandOnChildLayers(CompositeLayer.java:159)
	at org.eclipse.nebula.widgets.nattable.layer.CompositeLayer.doCommand(CompositeLayer.java:151)
	at org.eclipse.nebula.widgets.nattable.NatTable.doCommand(NatTable.java:820)


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?


Thanks,


Tom

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: 2902
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: 17
Registered: June 2018
Junior Member
The PaintListener did the trick:

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


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: Wed Apr 24 23:19:41 GMT 2024

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

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

Back to the top