Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Default: case sensitive sort, change to case insensitive(change default sorting for Strings)
Default: case sensitive sort, change to case insensitive [message #1710989] Mon, 12 October 2015 07:55 Go to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member
Hello ladies and gentlemen,

i noticed nattable (using glazed lists) is sorting 'different', than my users expect results to be sorted.

Apple1, apple2, Bunny, bee,
sort this with nattable
it sorts

  1. Apple1
  2. Bunny
  3. apple2
  4. bee

but users expect


  1. Apple1
  2. apple2
  3. bee
  4. Bunny



so the sorting shall ignore the case of the chars iff its string.

how can i do so?
Re: Default: case sensitive sort, change to case insensitive [message #1711009 is a reply to message #1710989] Mon, 12 October 2015 10:37 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2803
Registered: July 2012
Senior Member
Register a custom comparator as explained here: https://www.eclipse.org/nattable/documentation.php?page=sorting
Re: Default: case sensitive sort, change to case insensitive [message #1711122 is a reply to message #1711009] Tue, 13 October 2015 08:57 Go to previous messageGo to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member
thats what i actually did, but whenever i remove
configRegistry.registerConfigAttribute(SortConfigAttributes.SORT_COMPARATOR, new DefaultComparator());

sorting is fully disabled.
even though i added my custom comparators, registered labels and added a label accumulator.

so my code does this:
// Add label accumulator
ColumnOverrideLabelAccumulator labelAccumulator = new ColumnOverrideLabelAccumulator(columnHeaderDataLayer);
		columnHeaderDataLayer.setConfigLabelAccumulator(labelAccumulator);

// Register labels
List<FieldInfo> infos = ds.getFieldInfoCollection().getAllWithFeaturePath();//
for (int i = 0; i < infos.size(); i++) {
	FieldInfo fi = infos.get(i);
	labelAccumulator.registerColumnOverrides(ds.getColumnIndexOfProperty(fi.getInternal()),
	fi.getFieldType().name().toUpperCase());
	System.out.println(String.format("register label %s for column %s", fi.getFieldType().name().toUpperCase(),
	fi.getInternal()));
}

// Register custom comparators for each field type
FieldType[] types = FieldType.values();
for (int i = 0; i < types.length; i++) {
	configRegistry.registerConfigAttribute(SortConfigAttributes.SORT_COMPARATOR, types[i].getComparator(),
	DisplayMode.NORMAL, types[i].name().toUpperCase());
	System.out.println(String.format("register %s for %s", types[i].getComparator().getClass().getSimpleName(),
	types[i].name().toUpperCase()));
}


here the code of my CustomSingleClickSortConfiguration (actually a copy of the SingleClickSortConfiguration, but i removed the line with default sorting.

public class CustomSingleClickSortConfiguration implements IConfiguration {

	public static final String SORT_DOWN_CONFIG_TYPE = "SORT_DOWN"; //$NON-NLS-1$
	public static final String SORT_UP_CONFIG_TYPE = "SORT_UP"; //$NON-NLS-1$

	/** The sort sequence can be appended to this base */
	public static final String SORT_SEQ_CONFIG_TYPE = "SORT_SEQ_"; //$NON-NLS-1$

	private ICellPainter cellPainter;

	public CustomSingleClickSortConfiguration() {
		this(new BeveledBorderDecorator(new SortableHeaderTextPainter()));
	}

	public CustomSingleClickSortConfiguration(ICellPainter cellPainter) {
		this.cellPainter = cellPainter;
	}

	public void configureLayer(ILayer layer) {
	}

	public void configureRegistry(IConfigRegistry configRegistry) {
		// removed as we defined our own Comparators for each column
		// configRegistry.registerConfigAttribute(SortConfigAttributes.SORT_COMPARATOR,
		// new DefaultComparator());

		configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, cellPainter, DisplayMode.NORMAL,
				SORT_DOWN_CONFIG_TYPE);
		configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, cellPainter, DisplayMode.NORMAL,
				SORT_UP_CONFIG_TYPE);
	}

	public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
		// Register new bindings
		uiBindingRegistry.registerFirstSingleClickBinding(new ColumnHeaderClickEventMatcher(SWT.NONE, 1),
				new SortColumnAction(false));

		uiBindingRegistry.registerSingleClickBinding(MouseEventMatcher.columnHeaderLeftClick(SWT.ALT),
				new SortColumnAction(true));
	}
}


and the output for registering Labels and Comparators seems fine:
Quote:

// labels
register label INTEGER for column id
register label STRING for column guid
register label STRING for column generatedName
register label STRING for column oldName
register label STRING for column salutation
register label STRING for column title
register label STRING for column firstName
register label STRING for column lastName
register label DATE for column dateBirth
register label DATE for column dateDeath
register label STRING for column profession
register label STRING for column organisation
register label STRING for column department
register label STRING for column street
register label STRING for column zip
register label STRING for column city
register label STRING for column country
register label STRING for column phoneBusiness
register label STRING for column phonePrivate
register label STRING for column phoneMobile
register label STRING for column fax
register label ACTIONEMAIL for column email
register label ACTIONURL for column WWW
register label STRING for column categories
register label TEXT for column memo
register label TEXT for column text1
register label TEXT for column text2
register label TEXT for column text3
register label TEXT for column text4
register label TEXT for column text5
register label TEXT for column text6
register label TEXT for column text7
register label TEXT for column text8
register label TEXT for column text9
register label TEXT for column text10
register label INTEGER for column integer1
register label INTEGER for column integer2
register label INTEGER for column integer3
register label INTEGER for column integer4
register label INTEGER for column integer5
register label DOUBLE for column double1
register label DOUBLE for column double2
register label DOUBLE for column double3
register label DOUBLE for column double4
register label DOUBLE for column double5
register label DATE for column calendar1
register label DATE for column calendar2
register label BOOLEAN for column boolean1
register label BOOLEAN for column boolean2
register label BOOLEAN for column boolean3
register label BOOLEAN for column boolean4
register label BOOLEAN for column boolean5
register label DATETIME for column adminCreated
register label STRING for column adminCreator
register label DATETIME for column adminEdited
register label STRING for column adminEditor
register label STRING for column adminImport1
register label STRING for column adminImport2
// comparators
register NullComparator for UNDEFINED
register BooleanComparator for BOOLEAN
register IntegerComparator for INTEGER
register DoubleComparator for DOUBLE
register NullComparator for STRING
register StringComparator for TEXT
register StringComparator for ACTIONEMAIL
register StringComparator for ACTIONURL
register DoubleComparator for COORDINATE
register IntegerComparator for SHAPETYPE
register StringComparator for LOOKUP
register StringComparator for CHECKCOMBO
register StringComparator for HIERARCHICALLOOKUP
register StringComparator for EDITLINK
register StringComparator for EDITLINKS
register StringComparator for EDITSTRATIGRAPHYBUTTON
register CalendarComparator for DATE
register CalendarComparator for TIME
register CalendarComparator for DATETIME


NOTE: i also tried to move the registration of the custom comparators to the CustomSingleClickSortConfiguration, but it had no impact on the result.

can you see what i'm doing wrong?

NOTE: FieldInfoDataSource<E> ds, as used in first code is only a helper class to retrieve the field definition information for the table.
Re: Default: case sensitive sort, change to case insensitive [message #1711124 is a reply to message #1711122] Tue, 13 October 2015 09:52 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2803
Registered: July 2012
Senior Member
I'm not sure, but it sounds like there is some sort of race condition. Your code looks similar to _602_GlazedListsSortingExample, but I assume your dynamic mechanism is executed to early and therefore the cache in the sort model does not contain the correct information.

You could try to execute NatTable#refresh() which triggers a rebuilding of the NatTableComparatorChooser that caches the comparator information.

At least that was the issue in other projects that had such a dynamic comparator usage.
Re: Default: case sensitive sort, change to case insensitive [message #1711127 is a reply to message #1711124] Tue, 13 October 2015 10:32 Go to previous messageGo to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member
i tried to execute NatTable#refresh() after NatTable#configure() now. Still the same result.

Basically my Code is simply a wrapper class, which (re)creates a NatTable to render different Table Definitions with a one-fits-all configuration.
The Table gets automatically disposed/recreated when needed.
though my sort stuff and the whole table is dynamic, the values do not change.
unfortunately this includes EMF, and some parts of my model, so it is not that easy to seperate in a simple executeable example. (it's NOT because i do not want to show the code)

if you are willed to have a look at the code, let me know and i upload it for you.
Otherwise i need the information when/where i have to set the Sort stuff. or how it can get affected by oder stuff.
Re: Default: case sensitive sort, change to case insensitive [message #1711130 is a reply to message #1711127] Tue, 13 October 2015 11:04 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2803
Registered: July 2012
Senior Member
Have you ensured to use the same ConfigRegistry instance on the SortHeaderLayer and the NatTable instance?
Re: Default: case sensitive sort, change to case insensitive [message #1711202 is a reply to message #1711130] Wed, 14 October 2015 06:42 Go to previous messageGo to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member
i do create a new ConfigRegistry in the constructor of my wrapper component.
after this i create the FullFeaturedBodyLayerStack and FullFeaturedColumnHeaderLayerStack passing the new ConfigRegistry.

when i (re)create the NatTable:
natTable = new NatTable(parent, getLayer(), false);
natTable.setConfigRegistry(configRegistry);


after doing this i add CustomSingleClickSortConfiguration, FilterRowCustomConfigruation, styling and listeners etc.

finally i call
nattable.configure();


so the used ConfigRegistry should be the same, right?
Re: Default: case sensitive sort, change to case insensitive [message #1711209 is a reply to message #1711202] Wed, 14 October 2015 07:15 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2803
Registered: July 2012
Senior Member
Should be, yes. So the only option is to debug into the GlazedListsSortModel, the NatTableComparatorChooser and NatColumnTableFormat to see why there are no sort comparators found.

In NatColumnTableFormat#getColumnComparator(int) the comparator should be retrieved out of the ConfigRegistry dependent to the column header cell.

As you are referring to some of our example layer stacks, do you really use our example layers and consume the NatTable examples plugin? Or did you create a similar one in your environment?
Re: Default: case sensitive sort, change to case insensitive [message #1711247 is a reply to message #1711209] Wed, 14 October 2015 10:01 Go to previous message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member
finally i found MY bug!

i got wrong return values when i asked my datasource for the index of a field.

thanks for pointing me towards the GlazedListsSortModel!
excellent help once again, thanks Dirk!

[Updated on: Wed, 14 October 2015 10:40]

Report message to a moderator

Previous Topic:Uhoh - Corrupted .JARs in the NatTable 1.3.0 Update Site
Next Topic:Refresh NatTable
Goto Forum:
  


Current Time: Thu Mar 04 01:26:09 GMT 2021

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

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

Back to the top