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());
}
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);
}
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);
}
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);
}
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;
}
Aggregations