use of org.eclipse.nebula.widgets.nattable.dataset.person.Person in project nebula.widgets.nattable by eclipse.
the class GroupByDataLayerTest method testOneLevelGroupSortTree.
@Test
public void testOneLevelGroupSortTree() {
addSortingCapability();
// groupBy lastname
this.groupByModel.addGroupByColumnIndex(1);
// 18 data rows + 2 GroupBy rows
assertEquals(20, this.dataLayer.getRowCount());
Object o = this.dataLayer.getTreeList().get(0);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Flanders", ((GroupByObject) o).getValue());
o = this.dataLayer.getTreeList().get(9);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Simpson", ((GroupByObject) o).getValue());
// unsorted leafs, first leaf in Simpson is Homer
o = this.dataLayer.getTreeList().get(10);
assertTrue("Object is not a Person", o instanceof Person);
assertEquals("Homer", ((Person) o).getFirstName());
// sort ascending
this.sortModel.sort(0, SortDirectionEnum.ASC, false);
o = this.dataLayer.getTreeList().get(0);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Flanders", ((GroupByObject) o).getValue());
o = this.dataLayer.getTreeList().get(9);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Simpson", ((GroupByObject) o).getValue());
// ascending sorted leafs, first leaf in Simpson is Bart
o = this.dataLayer.getTreeList().get(10);
assertTrue("Object is not a Person", o instanceof Person);
assertEquals("Bart", ((Person) o).getFirstName());
// sort descending
this.sortModel.sort(0, SortDirectionEnum.DESC, false);
o = this.dataLayer.getTreeList().get(0);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Simpson", ((GroupByObject) o).getValue());
o = this.dataLayer.getTreeList().get(11);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Flanders", ((GroupByObject) o).getValue());
// descending sorted leafs, first leaf in Flanders is Todd
o = this.dataLayer.getTreeList().get(12);
assertTrue("Object is not a Person", o instanceof Person);
assertEquals("Todd", ((Person) o).getFirstName());
}
use of org.eclipse.nebula.widgets.nattable.dataset.person.Person in project nebula.widgets.nattable by eclipse.
the class GroupByDataLayerTest method testOneLevelGroupSortSummary.
@Test
public void testOneLevelGroupSortSummary() {
addSortingCapability();
addSummaryConfiguration();
// increase the money amount for all flanders to show that the sort
// order is related to the summary value and not the groupBy value
double value = 600.0d;
for (int i = 10; i < this.sortedList.size(); i++) {
if ((i - 10) % 2 == 0) {
value -= 100.0d;
}
this.sortedList.get(i).setMoney(value);
}
// groupBy lastname
this.groupByModel.addGroupByColumnIndex(1);
// 18 data rows + 2 GroupBy rows
assertEquals(20, this.dataLayer.getRowCount());
Object o = this.dataLayer.getTreeList().get(0);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Flanders", ((GroupByObject) o).getValue());
LabelStack labelStack = this.dataLayer.getConfigLabelsByPosition(2, 0);
assertEquals(2800.0d, this.dataLayer.getDataValueByPosition(2, 0, labelStack, false));
o = this.dataLayer.getTreeList().get(1);
assertTrue("Object is not a Person", o instanceof Person);
assertEquals("Ned", ((Person) o).getFirstName());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, 1);
assertEquals(500.0d, this.dataLayer.getDataValueByPosition(2, 1, labelStack, false));
o = this.dataLayer.getTreeList().get(9);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Simpson", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, 9);
assertEquals(1000.0d, this.dataLayer.getDataValueByPosition(2, 9, labelStack, false));
// sort ascending by money
this.sortModel.sort(2, SortDirectionEnum.ASC, false);
o = this.dataLayer.getTreeList().get(0);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Simpson", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, 0);
assertEquals(1000.0d, this.dataLayer.getDataValueByPosition(2, 0, labelStack, false));
o = this.dataLayer.getTreeList().get(11);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Flanders", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, 11);
assertEquals(2800.0d, this.dataLayer.getDataValueByPosition(2, 11, labelStack, false));
o = this.dataLayer.getTreeList().get(12);
assertTrue("Object is not a Person", o instanceof Person);
assertEquals("Todd", ((Person) o).getFirstName());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, 1);
assertEquals(100.0d, this.dataLayer.getDataValueByPosition(2, 1, labelStack, false));
// sort descending by money
this.sortModel.sort(2, SortDirectionEnum.DESC, false);
o = this.dataLayer.getTreeList().get(0);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Flanders", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, 0);
assertEquals(2800.0d, this.dataLayer.getDataValueByPosition(2, 0, labelStack, false));
o = this.dataLayer.getTreeList().get(9);
assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
assertEquals("Simpson", ((GroupByObject) o).getValue());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, 9);
assertEquals(1000.0d, this.dataLayer.getDataValueByPosition(2, 9, labelStack, false));
o = this.dataLayer.getTreeList().get(1);
assertTrue("Object is not a Person", o instanceof Person);
assertEquals("Ned", ((Person) o).getFirstName());
labelStack = this.dataLayer.getConfigLabelsByPosition(2, 1);
assertEquals(500.0d, this.dataLayer.getDataValueByPosition(2, 1, labelStack, false));
}
use of org.eclipse.nebula.widgets.nattable.dataset.person.Person in project nebula.widgets.nattable by eclipse.
the class GroupByDataLayerTest method testGroupByItemCount.
@SuppressWarnings("deprecation")
@Test
public void testGroupByItemCount() {
// groupBy lastname
this.groupByModel.addGroupByColumnIndex(1);
GroupByObject flanders = (GroupByObject) this.dataLayer.getTreeList().get(0);
assertEquals("Flanders", flanders.getValue());
GroupByObject simpsons = (GroupByObject) this.dataLayer.getTreeList().get(9);
assertEquals("Simpson", simpsons.getValue());
List<Person> elementsInGroup = this.dataLayer.getElementsInGroup(flanders);
List<Person> itemsInGroup = this.dataLayer.getItemsInGroup(flanders);
List<Object> rowModelChildren = this.dataLayer.getTreeRowModel().getChildren(0);
assertEquals(8, elementsInGroup.size());
assertEquals(8, itemsInGroup.size());
assertEquals(8, rowModelChildren.size());
assertEquals(elementsInGroup, itemsInGroup);
assertEquals(itemsInGroup, rowModelChildren);
elementsInGroup = this.dataLayer.getElementsInGroup(simpsons);
itemsInGroup = this.dataLayer.getItemsInGroup(simpsons);
rowModelChildren = this.dataLayer.getTreeRowModel().getChildren(9);
assertEquals(10, elementsInGroup.size());
assertEquals(10, itemsInGroup.size());
assertEquals(10, rowModelChildren.size());
assertEquals(elementsInGroup, itemsInGroup);
assertEquals(itemsInGroup, rowModelChildren);
}
use of org.eclipse.nebula.widgets.nattable.dataset.person.Person in project nebula.widgets.nattable by eclipse.
the class GroupByDataLayerTest method setup.
@Before
public void setup() {
this.groupByModel = new GroupByModel();
EventList<Person> eventList = GlazedLists.eventList(PersonService.getFixedPersons());
this.sortedList = new SortedList<>(eventList, null);
this.columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(this.propertyNames);
this.dataLayer = new GroupByDataLayer<>(this.groupByModel, this.sortedList, this.columnPropertyAccessor, this.configRegistry);
this.dataLayer.setConfigLabelAccumulator(new ColumnLabelAccumulator());
}
use of org.eclipse.nebula.widgets.nattable.dataset.person.Person in project nebula.widgets.nattable by eclipse.
the class GroupByDataLayerTest method addSortingCapability.
void addSortingCapability() {
this.dataLayer.setComparator(new GroupByComparator<Person>(this.groupByModel, this.columnPropertyAccessor) {
@Override
protected boolean isTreeColumn(int columnIndex) {
// that column index 0 is the tree column
return columnIndex == 0;
}
});
// the ColumnHeaderDataLayer is needed to retrieve the comparator per
// column
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(this.propertyNames);
DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
columnHeaderDataLayer.setConfigLabelAccumulator(new ColumnLabelAccumulator());
this.sortModel = new GlazedListsSortModel<>(this.sortedList, this.columnPropertyAccessor, this.configRegistry, columnHeaderDataLayer);
this.dataLayer.initializeTreeComparator(this.sortModel, null, true);
this.configRegistry.registerConfigAttribute(SortConfigAttributes.SORT_COMPARATOR, DefaultComparator.getInstance());
}
Aggregations