Search in sources :

Example 31 with Person

use of org.eclipse.nebula.widgets.nattable.dataset.person.Person 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 32 with Person

use of org.eclipse.nebula.widgets.nattable.dataset.person.Person 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)

Example 33 with Person

use of org.eclipse.nebula.widgets.nattable.dataset.person.Person in project nebula.widgets.nattable by eclipse.

the class ComboBoxGlazedListsFilterStrategyTest method init.

@BeforeClass
public static void init() {
    // initialize the collection with a big amount of values
    EventList<Person> baseCollection = GlazedLists.eventList(PersonService.getFixedPersons());
    for (int i = 1; i < 1000; i++) {
        baseCollection.addAll(PersonService.getFixedPersons());
    }
    filterList = new FilterList<>(GlazedLists.eventList(baseCollection));
    configRegistry = new ConfigRegistry();
    new DefaultNatTableStyleConfiguration().configureRegistry(configRegistry);
    new DefaultFilterRowConfiguration().configureRegistry(configRegistry);
    new ComboBoxFilterRowConfiguration().configureRegistry(configRegistry);
    columnHeaderLayer = new DataLayerFixture(5, 2, 100, 50);
    IColumnAccessor<Person> bodyDataColumnAccessor = new ReflectiveColumnPropertyAccessor<>(personPropertyNames);
    comboBoxDataProvider = new GlazedListsFilterRowComboBoxDataProvider<>(new DataLayer(new ListDataProvider<>(filterList, bodyDataColumnAccessor)), baseCollection, bodyDataColumnAccessor);
    filterStrategy = new ComboBoxGlazedListsFilterStrategy<>(comboBoxDataProvider, filterList, bodyDataColumnAccessor, configRegistry);
    dataProvider = new FilterRowDataProvider<>(filterStrategy, columnHeaderLayer, columnHeaderLayer.getDataProvider(), configRegistry);
}
Also used : ComboBoxFilterRowConfiguration(org.eclipse.nebula.widgets.nattable.filterrow.combobox.ComboBoxFilterRowConfiguration) ReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) DefaultFilterRowConfiguration(org.eclipse.nebula.widgets.nattable.filterrow.config.DefaultFilterRowConfiguration) DataLayerFixture(org.eclipse.nebula.widgets.nattable.extension.glazedlists.fixture.DataLayerFixture) Person(org.eclipse.nebula.widgets.nattable.dataset.person.Person) BeforeClass(org.junit.BeforeClass)

Example 34 with Person

use of org.eclipse.nebula.widgets.nattable.dataset.person.Person in project nebula.widgets.nattable by eclipse.

the class DefaultGlazedListsFilterStrategyTest method init.

@BeforeClass
public static void init() {
    // initialize the collection with a big amount of values
    filterList = new FilterList<>(GlazedLists.eventList(PersonService.getFixedPersons()));
    for (int i = 1; i < 1000; i++) {
        filterList.addAll(PersonService.getFixedPersons());
    }
    configRegistry = new ConfigRegistry();
    new DefaultNatTableStyleConfiguration().configureRegistry(configRegistry);
    new DefaultFilterRowConfiguration().configureRegistry(configRegistry);
    columnHeaderLayer = new DataLayerFixture(5, 2, 100, 50);
    dataProvider = new FilterRowDataProvider<>(new DefaultGlazedListsFilterStrategy<>(filterList, new ReflectiveColumnPropertyAccessor<Person>(personPropertyNames), configRegistry), columnHeaderLayer, columnHeaderLayer.getDataProvider(), configRegistry);
}
Also used : ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) DefaultFilterRowConfiguration(org.eclipse.nebula.widgets.nattable.filterrow.config.DefaultFilterRowConfiguration) DataLayerFixture(org.eclipse.nebula.widgets.nattable.extension.glazedlists.fixture.DataLayerFixture) Person(org.eclipse.nebula.widgets.nattable.dataset.person.Person) BeforeClass(org.junit.BeforeClass)

Example 35 with Person

use of org.eclipse.nebula.widgets.nattable.dataset.person.Person in project nebula.widgets.nattable by eclipse.

the class _606_GlazedListsRowHideShowExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    // property names of the Person class
    String[] propertyNames = { "firstName", "lastName", "gender", "married", "birthday" };
    // mapping from property to label, needed for column header labels
    Map<String, String> propertyToLabelMap = new HashMap<>();
    propertyToLabelMap.put("firstName", "Firstname");
    propertyToLabelMap.put("lastName", "Lastname");
    propertyToLabelMap.put("gender", "Gender");
    propertyToLabelMap.put("married", "Married");
    propertyToLabelMap.put("birthday", "Birthday");
    // build the body layer stack
    // Usually you would create a new layer stack by extending
    // AbstractIndexLayerTransform and setting the ViewportLayer as
    // underlying layer. But in this case using the ViewportLayer directly
    // as body layer is also working.
    // first wrap the base list in a GlazedLists EventList and a FilterList
    // so it is possible to filter
    EventList<Person> eventList = GlazedLists.eventList(PersonService.getPersons(10));
    FilterList<Person> filterList = new FilterList<>(eventList);
    // use the GlazedListsDataProvider for some performance tweaks
    final IRowDataProvider<Person> bodyDataProvider = new ListDataProvider<>(filterList, new ReflectiveColumnPropertyAccessor<Person>(propertyNames));
    // create the IRowIdAccessor that is necessary for row hide/show
    final IRowIdAccessor<Person> rowIdAccessor = new IRowIdAccessor<Person>() {

        @Override
        public Serializable getRowId(Person rowObject) {
            return rowObject.getId();
        }
    };
    DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
    // add a DetailGlazedListsEventLayer event layer that is responsible for
    // updating the grid on list changes
    DetailGlazedListsEventLayer<Person> glazedListsEventLayer = new DetailGlazedListsEventLayer<>(bodyDataLayer, filterList);
    GlazedListsRowHideShowLayer<Person> rowHideShowLayer = new GlazedListsRowHideShowLayer<>(glazedListsEventLayer, bodyDataProvider, rowIdAccessor, filterList);
    SelectionLayer selectionLayer = new SelectionLayer(rowHideShowLayer);
    ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
    // build the column header layer
    IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
    DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
    ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, viewportLayer, selectionLayer);
    // build the row header layer
    IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
    DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
    ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, viewportLayer, selectionLayer);
    // build the corner layer
    IDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider);
    DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
    ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, columnHeaderLayer);
    // build the grid layer
    GridLayer gridLayer = new GridLayer(viewportLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
    // turn the auto configuration off as we want to add our header menu
    // configuration
    NatTable natTable = new NatTable(parent, gridLayer, false);
    // as the autoconfiguration of the NatTable is turned off, we have to
    // add the DefaultNatTableStyleConfiguration manually
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    // add the header menu configuration for adding the column header menu
    // with hide/show actions
    natTable.addConfiguration(new AbstractHeaderMenuConfiguration(natTable) {

        @Override
        protected PopupMenuBuilder createRowHeaderMenu(NatTable natTable) {
            return new PopupMenuBuilder(natTable).withHideRowMenuItem().withShowAllRowsMenuItem();
        }

        @Override
        protected PopupMenuBuilder createCornerMenu(NatTable natTable) {
            return super.createCornerMenu(natTable).withShowAllRowsMenuItem().withStateManagerMenuItemProvider();
        }
    });
    natTable.configure();
    natTable.registerCommandHandler(new DisplayPersistenceDialogCommandHandler(natTable));
    return natTable;
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) HashMap(java.util.HashMap) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) IRowIdAccessor(org.eclipse.nebula.widgets.nattable.data.IRowIdAccessor) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) DisplayPersistenceDialogCommandHandler(org.eclipse.nebula.widgets.nattable.persistence.command.DisplayPersistenceDialogCommandHandler) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) FilterList(ca.odell.glazedlists.FilterList) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) RowHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer) CornerLayer(org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) GlazedListsRowHideShowLayer(org.eclipse.nebula.widgets.nattable.extension.glazedlists.hideshow.GlazedListsRowHideShowLayer) AbstractHeaderMenuConfiguration(org.eclipse.nebula.widgets.nattable.ui.menu.AbstractHeaderMenuConfiguration) DetailGlazedListsEventLayer(org.eclipse.nebula.widgets.nattable.extension.glazedlists.DetailGlazedListsEventLayer) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider) PopupMenuBuilder(org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder) 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