Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Possible bug in FilterRowDataProvider.getDataValue(int, int)
Possible bug in FilterRowDataProvider.getDataValue(int, int) [message #1366209] Mon, 19 May 2014 07:53 Go to next message
István Mészáros is currently offline István MészárosFriend
Messages: 51
Registered: October 2009
Member
There might be a bug in the getDataValue method of the FilterRowDataProvider.

setDataValue does a column index translation before accessing the filter map:

	@Override
	public void setDataValue(int columnIndex, int rowIndex, Object newValue) {
		columnIndex = columnHeaderLayer.getColumnIndexByPosition(columnIndex);

		if (ObjectUtils.isNotNull(newValue)) {
			filterIndexToObjectMap.put(columnIndex, newValue);
		} else {
			filterIndexToObjectMap.remove(columnIndex);
		}

		filterStrategy.applyFilter(filterIndexToObjectMap);

		columnHeaderLayer.fireLayerEvent(new FilterAppliedEvent(columnHeaderLayer));
	}


but getDataValue does not:

	@Override
	public Object getDataValue(int columnIndex, int rowIndex) {
		return filterIndexToObjectMap.get(columnIndex);
	}


Although this caused problems for me using my custom multi-combo filter editor, and i could solve those problems overriding getDataValue like

	@Override
	public Object getDataValue(int columnIndex, int rowIndex) {
		columnIndex = columnHeaderLayer.getColumnIndexByPosition(columnIndex);
		return super.getDataValue(columnIndex, rowIndex);
	}


i'm still not sure this is a bug, but might worth to post it if someone else has similar problems.
Re: Possible bug in FilterRowDataProvider.getDataValue(int, int) [message #1366251 is a reply to message #1366209] Mon, 19 May 2014 08:18 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
If I am applying your proposed solution, the NatTable combobox filters are not working correctly in a multi-viewport composition.

Also I think all the filter related NatTable examples are working correctly. I agree it looks inconsistent, but for me it looks correct when checking the examples, which might be related to the composition of the filter row in a CompositeLayer. But I would need to dig deeper to be sure.

Do you need to call getDataValue() in your custom multi-combo filter editor?
Re: Possible bug in FilterRowDataProvider.getDataValue(int, int) [message #1366252 is a reply to message #1366251] Mon, 19 May 2014 08:20 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
BTW, applying your proposed solution will also break the viewport, as the filter value will jump on scrolling. So for me it looks like the current implementation is intended because of the CompositeLayer composition and the viewport implementation.
Re: Possible bug in FilterRowDataProvider.getDataValue(int, int) [message #1366295 is a reply to message #1366252] Mon, 19 May 2014 08:41 Go to previous messageGo to next message
István Mészáros is currently offline István MészárosFriend
Messages: 51
Registered: October 2009
Member
You are right. Just noticed that my other (standard) filters are now broken Sad

My custom filter works like this:
- if there is no filtering, the "filter value" is null
- if there are some filtering turned on, the "filter value" is some arbitrary object containing the details

The problem i noticed is in org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommandHandler

If you set a breakpoint on line 52, you will see that it checks if the new value equals with the old value. It uses the DataLayer's getDataValue and setDataValue methods which call directly the get/set methods of the DataProvider. In the case of FilterRowDataProvider the get/set column indices will differ because getDataValue does no column index translation.

Therefore when i clear my filter settings (so null is the new fitler value to set), UpdateDataCommandHandler will refuse to set it because the value it get's from the DataProvider will also be null, since it was set at a different column index previously.

What do you think?
Re: Possible bug in FilterRowDataProvider.getDataValue(int, int) [message #1366320 is a reply to message #1366295] Mon, 19 May 2014 08:59 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
I think I'm not sure what you are doing and why you need a custom editor that does value transformations.

Regarding the null value for removing a filter, that is how the default implementation is working also.

Did you check that the composition is similar to the examples layer compositions? There was never such an issue before.
Re: Possible bug in FilterRowDataProvider.getDataValue(int, int) [message #1366355 is a reply to message #1366320] Mon, 19 May 2014 09:17 Go to previous messageGo to next message
István Mészáros is currently offline István MészárosFriend
Messages: 51
Registered: October 2009
Member
I needed to change the combo filtering because afaik the default combo filter does not use null to indicate that no filtering is active (= all items are selected). Therefore when the filter state is persisted, all the items are listed in the presisted state as "selection" of the filter combo. In my project this is not acceptable because items of the combo columns may change frequently, so accidental filtering may occur when a previosly persisted filter state is loaded. This can be avoided if the filter editor uses null if all items are selected.

Yes the composition is similar to the examples, although quite complex because i need a lot of functionality.

Currently i solved my issue by overriding the registerCommandHandlers() methond in my FilterRowDataLayer subclass:

	@Override
	protected void registerCommandHandlers() {
		registerCommandHandler(new ColumnResizeCommandHandler(this));
		registerCommandHandler(new MultiColumnResizeCommandHandler(this));
		registerCommandHandler(new RowResizeCommandHandler(this));
		registerCommandHandler(new MultiRowResizeCommandHandler(this));
		registerCommandHandler(new StructuralRefreshCommandHandler());
		registerCommandHandler(new VisualRefreshCommandHandler());
		registerCommandHandler(new UpdateDataCommandHandler(this) {

			@Override
			protected boolean doCommand(UpdateDataCommand command) {
				try {
					int columnPosition = command.getColumnPosition();
					int rowPosition = command.getRowPosition();
					if (!ObjectUtils.equals(
							getDataValue(columnHeaderLayer.getColumnIndexByPosition(columnPosition), rowPosition),
							command.getNewValue())) {

						setDataValue(columnPosition, rowPosition, command.getNewValue());
						fireLayerEvent(new CellVisualChangeEvent(
								ProjectMonitorFilterRowDataLayer.this, columnPosition, rowPosition));
					}
					return true;
				} catch (Exception e) {
					return false;
				}
			}
		});
	}


The key change is that an inline override of UpdateDataCommandHandler does the column index translation before calling getDataValue so the comparsion will always succeed.

It looks like both the regular and my custom filter are now working properly.

[Updated on: Mon, 19 May 2014 09:17]

Report message to a moderator

Re: Possible bug in FilterRowDataProvider.getDataValue(int, int) [message #1366381 is a reply to message #1366355] Mon, 19 May 2014 09:32 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
You are implementing a custom editor and need to handle stuff that complicated way with a lot of dependencies on composition because of persistence? Really?

If that is your only issue, why don't you override the saveState() and loadState()?

[Updated on: Mon, 19 May 2014 09:36]

Report message to a moderator

Re: Possible bug in FilterRowDataProvider.getDataValue(int, int) [message #1366424 is a reply to message #1366381] Mon, 19 May 2014 09:58 Go to previous messageGo to next message
István Mészáros is currently offline István MészárosFriend
Messages: 51
Registered: October 2009
Member
I remember differently. If i had a combo with items "A, B, C", and all was selected, the persisted value was something like:
[A,B,C]


prefixed with some strange separator sequence.

As i said my requirements are very complex. I have a lot of regular textbox filters, some combo filters and a very special filter on the tree column of my table. I found it easer to implement custom editors to achieve what my requirements are.

I dont feel that i handle anything more complicated than it should be or have dependencies on composition. I't is really just a custom cell editor.

The issue can be esily replicated using the latest source available in the git repo.

1. run the FilterRowGridExample class
2. scroll to the right to create a situation where columnIndex != columnPosition
3. enter a filter value at a column (e.g. Field 38)
4. click on the filter cell again (not on the clear filter button!)
5. use backspace to clear the field
6. hit enter to apply the "empty filter value"

The filtering now should be cleared, but instead the the old value reappears.
Re: Possible bug in FilterRowDataProvider.getDataValue(int, int) [message #1366433 is a reply to message #1366424] Mon, 19 May 2014 10:02 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Quote:
I remember differently. If i had a combo with items "A, B, C", and all was selected, the persisted value was something like:


I already updated my post as I was wrong. Looked at the wrong example!

Yes, that way the issue can be reproduced. Please open a ticket!
Re: Possible bug in FilterRowDataProvider.getDataValue(int, int) [message #1366569 is a reply to message #1366433] Mon, 19 May 2014 11:23 Go to previous messageGo to next message
István Mészáros is currently offline István MészárosFriend
Messages: 51
Registered: October 2009
Member
Thanks for your effort Dirk, i opened a ticket:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=435188

greetz,
Istvan
Re: Possible bug in FilterRowDataProvider.getDataValue(int, int) [message #1366648 is a reply to message #1366569] Mon, 19 May 2014 12:05 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Quite hard work to find the reason. It was related to some wrong position-index transformation handling in the base composition because of dimensional dependencies.

Should be fixed with the latest changes. Please verify via SNAPSHOT build #319.
Re: Possible bug in FilterRowDataProvider.getDataValue(int, int) [message #1366728 is a reply to message #1366648] Mon, 19 May 2014 12:53 Go to previous message
István Mészáros is currently offline István MészárosFriend
Messages: 51
Registered: October 2009
Member
Hello Dirk,

tested with #319, everything works like charm! Thank you very much for your effort.
Previous Topic:Adding SWT DragSource support without breaking NatTable DragMode?
Next Topic:How fix "OutOfMemoryError" when Nattable contain huge data
Goto Forum:
  


Current Time: Tue Apr 23 09:38:21 GMT 2024

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

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

Back to the top