Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Nebula » Problem sorting on XViewer
Problem sorting on XViewer [message #1766900] Wed, 28 June 2017 15:58 Go to next message
Jim 20100 is currently offline Jim 20100Friend
Messages: 69
Registered: June 2016
Member
Hello,

I display an EMF model in a Xviewer.

The sorting by clicking on the columns header does not work correctly on several columns.

Example:
On the Quantity column it works correctly.
On the Unit Cost Column, it does not sort, and the node tree is even reduced when I click on the column header.

the getBackingData method is very simple, so I don't understand why it works for Quantity and not for Unit Cost:

if (xCol.equals(QuoteXViewerFactoryMain.Quantity_Col))
return (priceObject.getQuantity() != null ? priceObject.getQuantity() : new Double(0));

if (xCol.equals(QuoteXViewerFactoryMain.UnitCost_Col))
return (priceObject.getUnitCost() != null ?priceObject.getUnitCost() : new Double(0));

thx for any help



Re: Problem sorting on XViewer [message #1766974 is a reply to message #1766900] Thu, 29 June 2017 08:20 Go to previous messageGo to next message
Wim Jongman is currently offline Wim JongmanFriend
Messages: 430
Registered: July 2009
Senior Member

Hi Jim,

Please provide the smallest possible snippet in which the problem manifests.

Best regards,

Wim
Re: Problem sorting on XViewer [message #1766975 is a reply to message #1766974] Thu, 29 June 2017 08:22 Go to previous messageGo to next message
Wim Jongman is currently offline Wim JongmanFriend
Messages: 430
Registered: July 2009
Senior Member

e.g. https://github.com/eclipse/nebula/blob/master/widgets/xviewer/org.eclipse.nebula.widgets.xviewer.example/src/org/eclipse/nebula/widgets/xviewer/example/MyXViewerTest.java
Re: Problem sorting on XViewer [message #1767393 is a reply to message #1766975] Wed, 05 July 2017 15:16 Go to previous message
Jim 20100 is currently offline Jim 20100Friend
Messages: 69
Registered: June 2016
Member
In fact I know the reason of the problem. It comes from org.eclipse.nebula.widgets.xviewer.XViewerSorter class.

Example:
I have my unitWeight column to sort. I use of course SortDataType.Float for the column.

in my EMF provider classes, I implemented the 2 methods

public Object getBackingData(Object object, XViewerColumn xCol,
int columnIndex) throws Exception

public String getColumnText(Object object, XViewerColumn xCol,
int columnIndex) throws Exception {


in the columnText method, I format the unit weight with this:
return new DecimalFormat("#,##0.000");

If I remove the DecimalFormat("#,##0.000"), it works.

The getBackingData is not used for sorting.
I debugged and I see this amazing code in XViewer sorter class:

String o1Str = treeViewer.getColumnText(o1, columnNum);
Object obj1 = null;
String o2Str = treeViewer.getColumnText(o2, columnNum);
Object obj2 = null;

IBaseLabelProvider labelProvider = treeViewer.getLabelProvider();
if (labelProvider instanceof IXViewerLabelProvider) {
obj1 = ((IXViewerLabelProvider) labelProvider).getBackingData(o1, sortXCol, columnNum);
obj2 = ((IXViewerLabelProvider) labelProvider).getBackingData(o2, sortXCol, columnNum);
}

// System.out.println("sortForward.get(columnNum) *" +
// sortXCol.isSortForward() + "*");
int compareInt = 0;
if (o1Str == null) {
compareInt = -1;
} else if (o2Str == null) {
compareInt = 1;
} else if (sortXCol.getSortDataType() == SortDataType.Date) {
compareInt = getCompareForDate(o1Str, obj1, o2Str, obj2);
} else if (sortXCol.getSortDataType() == SortDataType.Percent) {
compareInt = getCompareForPercent(o1Str, o2Str);
} else if (sortXCol.getSortDataType() == SortDataType.Float) {
compareInt = getCompareForFloat(o1Str, o2Str);
} else if (sortXCol.getSortDataType() == SortDataType.Integer) {
compareInt = getCompareForInteger(o1Str, o2Str);
} else if (sortXCol.getSortDataType() == SortDataType.Long) {
compareInt = getCompareForLong(o1Str, o2Str);
} else if (sortXCol.getSortDataType() == SortDataType.Paragraph_Number) {
compareInt = paragraphNumberCompare(o1Str, o2Str);
} else {
compareInt = getComparator().compare(o1Str, o2Str);
}


Why the getBackingData is not used????







Previous Topic:NatTable (and other nebula widgets) in a maven repo?
Next Topic:Eclipse unable to resolve import statement
Goto Forum:
  


Current Time: Wed Sep 19 10:32:35 GMT 2018

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

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

Back to the top