Search in sources :

Example 26 with Person

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());
}
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 27 with Person

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));
}
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 28 with Person

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);
}
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 29 with Person

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());
}
Also used : GroupByModel(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByModel) ColumnLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnLabelAccumulator) Person(org.eclipse.nebula.widgets.nattable.dataset.person.Person) Before(org.junit.Before)

Example 30 with Person

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());
}
Also used : DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) GroupByDataLayer(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByDataLayer) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider) ColumnLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnLabelAccumulator) Person(org.eclipse.nebula.widgets.nattable.dataset.person.Person)

Aggregations

Person (org.eclipse.nebula.widgets.nattable.dataset.person.Person)55 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)31 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)29 HashMap (java.util.HashMap)25 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)25 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)25 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)25 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)23 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)23 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)22 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)21 RowHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer)21 ReflectiveColumnPropertyAccessor (org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor)19 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)19 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)19 ViewportLayer (org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer)19 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)18 DefaultRowHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider)18 DefaultRowHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer)17 GridLayout (org.eclipse.swt.layout.GridLayout)16