Search in sources :

Example 1 with GroupByObject

use of org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByObject 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());
}
Also used : GroupByObject(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByObject) GroupByObject(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByObject) Person(org.eclipse.nebula.widgets.nattable.dataset.person.Person) Test(org.junit.Test)

Example 2 with GroupByObject

use of org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByObject 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));
}
Also used : LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack) GroupByObject(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByObject) GroupByObject(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByObject) Person(org.eclipse.nebula.widgets.nattable.dataset.person.Person) Test(org.junit.Test)

Example 3 with GroupByObject

use of org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByObject 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);
}
Also used : GroupByObject(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByObject) GroupByObject(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByObject) Person(org.eclipse.nebula.widgets.nattable.dataset.person.Person) Test(org.junit.Test)

Example 4 with GroupByObject

use of org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByObject in project nebula.widgets.nattable by eclipse.

the class GroupByDataLayerTest method testOneLevelGroupSortOther.

@Test
public void testOneLevelGroupSortOther() {
    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, Maude is on position 3 within Flanders
    o = this.dataLayer.getTreeList().get(3);
    assertTrue("Object is not a Person", o instanceof Person);
    assertEquals("Maude", ((Person) o).getFirstName());
    // sort ascending by gender
    this.sortModel.sort(3, 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, Maude should be on last position within
    // Flanders
    o = this.dataLayer.getTreeList().get(8);
    assertTrue("Object is not a Person", o instanceof Person);
    assertEquals("Maude", ((Person) o).getFirstName());
    // sort descending by gender
    this.sortModel.sort(3, SortDirectionEnum.DESC, false);
    // no changes to tree
    o = this.dataLayer.getTreeList().get(0);
    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());
    // descending sorted leafs, Maude should be on first position within
    // Flanders
    o = this.dataLayer.getTreeList().get(1);
    assertTrue("Object is not a Person", o instanceof Person);
    assertEquals("Maude", ((Person) o).getFirstName());
}
Also used : GroupByObject(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByObject) GroupByObject(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByObject) Person(org.eclipse.nebula.widgets.nattable.dataset.person.Person) Test(org.junit.Test)

Example 5 with GroupByObject

use of org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByObject in project nebula.widgets.nattable by eclipse.

the class GroupByDataLayerTest method testGroupByItemCountAfterListChange.

@SuppressWarnings("deprecation")
@Test
public void testGroupByItemCountAfterListChange() {
    // 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);
    this.sortedList.addListEventListener(new ListEventListener<Person>() {

        @Override
        public void listChanged(ListEvent<Person> listChanges) {
            GroupByDataLayerTest.this.dataLayer.clearCache();
        }
    });
    // add new Flanders
    Person p = PersonService.createPersonWithAddress(4711);
    p.setLastName("Flanders");
    this.sortedList.add(p);
    elementsInGroup = this.dataLayer.getElementsInGroup(flanders);
    itemsInGroup = this.dataLayer.getItemsInGroup(flanders);
    rowModelChildren = this.dataLayer.getTreeRowModel().getChildren(0);
    assertEquals(9, elementsInGroup.size());
    assertEquals(9, itemsInGroup.size());
    assertEquals(9, rowModelChildren.size());
    assertEquals(elementsInGroup, itemsInGroup);
    assertEquals(itemsInGroup, rowModelChildren);
}
Also used : GroupByObject(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByObject) GroupByObject(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByObject) Person(org.eclipse.nebula.widgets.nattable.dataset.person.Person) Test(org.junit.Test)

Aggregations

GroupByObject (org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByObject)9 Test (org.junit.Test)9 Person (org.eclipse.nebula.widgets.nattable.dataset.person.Person)5 LabelStack (org.eclipse.nebula.widgets.nattable.layer.LabelStack)2 ArrayList (java.util.ArrayList)1