Search in sources :

Example 6 with GroupByObject

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

the class GroupByDataLayerTest method testTwoLevelGroupSortSummary.

@Test
public void testTwoLevelGroupSortSummary() {
    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);
    // groupBy firstname
    this.groupByModel.addGroupByColumnIndex(0);
    // 18 data rows + 2 GroupBy rows lastname + 8 data rows firstname
    assertEquals(28, this.dataLayer.getRowCount());
    // Flanders
    int row = 0;
    Object o = this.dataLayer.getTreeList().get(row);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Flanders", ((GroupByObject) o).getValue());
    LabelStack labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
    assertEquals(2800.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
    row = 1;
    o = this.dataLayer.getTreeList().get(row);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Maude", ((GroupByObject) o).getValue());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
    assertEquals(800.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
    row = 4;
    o = this.dataLayer.getTreeList().get(row);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Ned", ((GroupByObject) o).getValue());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
    assertEquals(1000.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
    row = 7;
    o = this.dataLayer.getTreeList().get(row);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Rodd", ((GroupByObject) o).getValue());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
    assertEquals(600.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
    row = 10;
    o = this.dataLayer.getTreeList().get(row);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Todd", ((GroupByObject) o).getValue());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
    assertEquals(400.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
    // Simpsons
    row = 13;
    o = this.dataLayer.getTreeList().get(row);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Simpson", ((GroupByObject) o).getValue());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
    assertEquals(1000.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
    row = 14;
    o = this.dataLayer.getTreeList().get(row);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Bart", ((GroupByObject) o).getValue());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
    assertEquals(300.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
    row = 18;
    o = this.dataLayer.getTreeList().get(row);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Homer", ((GroupByObject) o).getValue());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
    assertEquals(300.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
    row = 22;
    o = this.dataLayer.getTreeList().get(row);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Lisa", ((GroupByObject) o).getValue());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
    assertEquals(200.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
    row = 25;
    o = this.dataLayer.getTreeList().get(row);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Marge", ((GroupByObject) o).getValue());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
    assertEquals(200.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
    // sort ascending by money
    this.sortModel.sort(2, SortDirectionEnum.ASC, false);
    // Simpsons
    row = 0;
    o = this.dataLayer.getTreeList().get(row);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Simpson", ((GroupByObject) o).getValue());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
    assertEquals(1000.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
    row = 1;
    o = this.dataLayer.getTreeList().get(row);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Lisa", ((GroupByObject) o).getValue());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
    assertEquals(200.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
    row = 4;
    o = this.dataLayer.getTreeList().get(row);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Marge", ((GroupByObject) o).getValue());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
    assertEquals(200.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
    row = 7;
    o = this.dataLayer.getTreeList().get(row);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Bart", ((GroupByObject) o).getValue());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
    assertEquals(300.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
    row = 11;
    o = this.dataLayer.getTreeList().get(row);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Homer", ((GroupByObject) o).getValue());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
    assertEquals(300.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
    // Flanders
    row = 15;
    o = this.dataLayer.getTreeList().get(row);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Flanders", ((GroupByObject) o).getValue());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
    assertEquals(2800.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
    row = 16;
    o = this.dataLayer.getTreeList().get(row);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Todd", ((GroupByObject) o).getValue());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
    assertEquals(400.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
    row = 19;
    o = this.dataLayer.getTreeList().get(row);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Rodd", ((GroupByObject) o).getValue());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
    assertEquals(600.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
    row = 22;
    o = this.dataLayer.getTreeList().get(row);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Maude", ((GroupByObject) o).getValue());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
    assertEquals(800.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
    row = 25;
    o = this.dataLayer.getTreeList().get(row);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Ned", ((GroupByObject) o).getValue());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
    assertEquals(1000.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
    // sort descending by money
    this.sortModel.sort(2, SortDirectionEnum.DESC, false);
    // Flanders
    row = 0;
    o = this.dataLayer.getTreeList().get(row);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Flanders", ((GroupByObject) o).getValue());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
    assertEquals(2800.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
    row = 1;
    o = this.dataLayer.getTreeList().get(row);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Ned", ((GroupByObject) o).getValue());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
    assertEquals(1000.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
    row = 4;
    o = this.dataLayer.getTreeList().get(row);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Maude", ((GroupByObject) o).getValue());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
    assertEquals(800.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
    row = 7;
    o = this.dataLayer.getTreeList().get(row);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Rodd", ((GroupByObject) o).getValue());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
    assertEquals(600.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
    row = 10;
    o = this.dataLayer.getTreeList().get(row);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Todd", ((GroupByObject) o).getValue());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
    assertEquals(400.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
    // Simpsons
    row = 13;
    o = this.dataLayer.getTreeList().get(row);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Simpson", ((GroupByObject) o).getValue());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
    assertEquals(1000.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
    row = 14;
    o = this.dataLayer.getTreeList().get(row);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Homer", ((GroupByObject) o).getValue());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
    assertEquals(300.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
    row = 18;
    o = this.dataLayer.getTreeList().get(row);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Bart", ((GroupByObject) o).getValue());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
    assertEquals(300.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
    row = 22;
    o = this.dataLayer.getTreeList().get(row);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Marge", ((GroupByObject) o).getValue());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
    assertEquals(200.0d, this.dataLayer.getDataValueByPosition(2, row, labelStack, false));
    row = 25;
    o = this.dataLayer.getTreeList().get(row);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Lisa", ((GroupByObject) o).getValue());
    labelStack = this.dataLayer.getConfigLabelsByPosition(2, row);
    assertEquals(200.0d, this.dataLayer.getDataValueByPosition(2, row, 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) Test(org.junit.Test)

Example 7 with GroupByObject

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

the class GroupByDataLayerTest method testOneLevelGrouping.

@Test
public void testOneLevelGrouping() {
    assertEquals(18, this.dataLayer.getRowCount());
    // 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());
}
Also used : GroupByObject(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByObject) GroupByObject(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByObject) Test(org.junit.Test)

Example 8 with GroupByObject

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

the class GroupByDataLayerTest method testGetElementsInGroupWithNullValue.

@Test
public void testGetElementsInGroupWithNullValue() {
    // Test with another list with null values
    this.sortedList.clear();
    this.sortedList.addAll(PersonService.getFixedPersonsWithNull());
    // groupBy lastname
    this.groupByModel.addGroupByColumnIndex(1);
    // collect GroupBy Objects
    List<GroupByObject> groupByObjects = new ArrayList<>();
    for (Object o : this.dataLayer.getTreeList()) {
        if (o instanceof GroupByObject) {
            groupByObjects.add((GroupByObject) o);
        }
    }
    // testing like this, cause setup would be complex
    for (GroupByObject o : groupByObjects) {
        this.dataLayer.getItemsInGroup(o);
    }
// if we get here, there is no NullPointerException in
// GroupDescriptorMatcher.
}
Also used : GroupByObject(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByObject) ArrayList(java.util.ArrayList) GroupByObject(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByObject) Test(org.junit.Test)

Example 9 with GroupByObject

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

the class GroupByDataLayerTest method testTwoLevelGrouping.

@Test
public void testTwoLevelGrouping() {
    assertEquals(18, this.dataLayer.getRowCount());
    // groupBy lastname
    this.groupByModel.addGroupByColumnIndex(1);
    this.groupByModel.addGroupByColumnIndex(0);
    // 18 data rows + 2 GroupBy rows lastname + 8 data rows firstname
    assertEquals(28, this.dataLayer.getRowCount());
    // Flanders
    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(1);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Maude", ((GroupByObject) o).getValue());
    o = this.dataLayer.getTreeList().get(4);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Ned", ((GroupByObject) o).getValue());
    o = this.dataLayer.getTreeList().get(7);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Rodd", ((GroupByObject) o).getValue());
    o = this.dataLayer.getTreeList().get(10);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Todd", ((GroupByObject) o).getValue());
    // Simpsons
    o = this.dataLayer.getTreeList().get(13);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Simpson", ((GroupByObject) o).getValue());
    o = this.dataLayer.getTreeList().get(14);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Bart", ((GroupByObject) o).getValue());
    o = this.dataLayer.getTreeList().get(18);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Homer", ((GroupByObject) o).getValue());
    o = this.dataLayer.getTreeList().get(22);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Lisa", ((GroupByObject) o).getValue());
    o = this.dataLayer.getTreeList().get(25);
    assertTrue("Object is not a GroupByObject", o instanceof GroupByObject);
    assertEquals("Marge", ((GroupByObject) o).getValue());
}
Also used : GroupByObject(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByObject) GroupByObject(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByObject) 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