use of ca.odell.glazedlists.FilterList in project nebula.widgets.nattable by eclipse.
the class _801_VerticalCompositionWithFeaturesExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
ConfigRegistry configRegistry = new ConfigRegistry();
Composite panel = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
panel.setLayout(layout);
GridDataFactory.fillDefaults().grab(true, true).applyTo(panel);
Composite gridPanel = new Composite(panel, SWT.NONE);
gridPanel.setLayout(layout);
GridDataFactory.fillDefaults().grab(true, true).applyTo(gridPanel);
Composite buttonPanel = new Composite(panel, SWT.NONE);
buttonPanel.setLayout(new GridLayout());
GridDataFactory.fillDefaults().grab(false, false).applyTo(buttonPanel);
// 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");
IColumnPropertyAccessor<Person> columnPropertyAccessor = new ExtendedReflectiveColumnPropertyAccessor<>(propertyNames);
List<Person> values = PersonService.getPersons(10);
final EventList<Person> eventList = GlazedLists.eventList(values);
TransformedList<Person, Person> rowObjectsGlazedList = GlazedLists.threadSafeList(eventList);
// use the SortedList constructor with 'null' for the Comparator because
// the Comparator will be set by configuration
SortedList<Person> sortedList = new SortedList<>(rowObjectsGlazedList, null);
// wrap the SortedList with the FilterList
FilterList<Person> filterList = new FilterList<>(sortedList);
IRowDataProvider<Person> bodyDataProvider = new ListDataProvider<>(filterList, columnPropertyAccessor);
final DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
bodyDataLayer.setConfigLabelAccumulator(new ColumnLabelAccumulator());
GlazedListsEventLayer<Person> eventLayer = new GlazedListsEventLayer<>(bodyDataLayer, filterList);
final SelectionLayer selectionLayer = new SelectionLayer(eventLayer);
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
DataLayer columnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, viewportLayer, selectionLayer);
// add sorting
SortHeaderLayer<Person> sortHeaderLayer = new SortHeaderLayer<>(columnHeaderLayer, new GlazedListsSortModel<>(sortedList, columnPropertyAccessor, configRegistry, columnHeaderDataLayer), false);
// add the filter row functionality
final FilterRowHeaderComposite<Person> filterRowHeaderLayer = new FilterRowHeaderComposite<>(new DefaultGlazedListsFilterStrategy<>(filterList, columnPropertyAccessor, configRegistry), sortHeaderLayer, columnHeaderDataProvider, configRegistry);
// set the region labels to make default configurations work, e.g.
// editing, selection
CompositeLayer compositeLayer = new CompositeLayer(1, 2);
compositeLayer.setChildLayer(GridRegion.COLUMN_HEADER, filterRowHeaderLayer, 0, 0);
compositeLayer.setChildLayer(GridRegion.BODY, viewportLayer, 0, 1);
// add edit configurations
compositeLayer.addConfiguration(new DefaultEditConfiguration());
compositeLayer.addConfiguration(new DefaultEditBindings());
// add print support
compositeLayer.registerCommandHandler(new PrintCommandHandler(compositeLayer));
compositeLayer.addConfiguration(new DefaultPrintBindings());
// add excel export support
compositeLayer.registerCommandHandler(new ExportCommandHandler(compositeLayer));
compositeLayer.addConfiguration(new DefaultExportBindings());
final NatTable natTable = new NatTable(gridPanel, compositeLayer, false);
natTable.setConfigRegistry(configRegistry);
// adding this configuration adds the styles and the painters to use
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
// add sorting configuration
natTable.addConfiguration(new SingleClickSortConfiguration());
natTable.addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.ALWAYS_EDITABLE);
// birthday is never editable
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.NEVER_EDITABLE, DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 4);
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new ComboBoxCellEditor(Arrays.asList(Gender.FEMALE, Gender.MALE)), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 2);
configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, getGenderBooleanConverter(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 2);
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new ComboBoxCellEditor(Arrays.asList(Boolean.TRUE, Boolean.FALSE)), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 3);
configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultBooleanDisplayConverter(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 3);
}
});
natTable.configure();
final RowSelectionProvider<Person> selectionProvider = new RowSelectionProvider<>(selectionLayer, bodyDataProvider, false);
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
Button button = new Button(buttonPanel, SWT.PUSH);
button.setText("Remove selected item");
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// the NatTable context
if (natTable.getActiveCellEditor() != null) {
natTable.commitAndCloseActiveCellEditor();
}
Person item = (Person) ((IStructuredSelection) selectionProvider.getSelection()).getFirstElement();
eventList.remove(item);
}
});
return panel;
}
use of ca.odell.glazedlists.FilterList in project nebula.widgets.nattable by eclipse.
the class DynamicColumnHeaderHeightExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
IConfigRegistry configRegistry = new ConfigRegistry();
// Underlying data source
EventList<RowDataFixture> eventList = GlazedLists.eventList(RowDataListFixture.getList(200));
FilterList<RowDataFixture> filterList = new FilterList<>(eventList);
String[] propertyNames = RowDataListFixture.getPropertyNames();
Map<String, String> propertyToLabelMap = RowDataListFixture.getPropertyToLabelMap();
// Body
IColumnPropertyAccessor<RowDataFixture> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
ListDataProvider<RowDataFixture> bodyDataProvider = new ListDataProvider<>(filterList, columnPropertyAccessor);
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
ColumnGroupBodyLayerStack bodyLayer = new ColumnGroupBodyLayerStack(bodyDataLayer, this.columnGroupModel);
ColumnOverrideLabelAccumulator bodyLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
bodyDataLayer.setConfigLabelAccumulator(bodyLabelAccumulator);
bodyLabelAccumulator.registerColumnOverrides(RowDataListFixture.getColumnIndexOfProperty(RowDataListFixture.PRICING_TYPE_PROP_NAME), "PRICING_TYPE_PROP_NAME");
// Column header
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
this.columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, bodyLayer, bodyLayer.getSelectionLayer());
ColumnGroupHeaderLayer columnGroupHeaderLayer = new ColumnGroupHeaderLayer(this.columnHeaderLayer, bodyLayer.getSelectionLayer(), this.columnGroupModel);
columnGroupHeaderLayer.addColumnsIndexesToGroup("Group 1", 1, 2);
// calculate the height of the column header area dependent if column
// groups exist or not
columnGroupHeaderLayer.setCalculateHeight(true);
// Note: The column header layer is wrapped in a filter row composite.
// This plugs in the filter row functionality
final FilterRowHeaderComposite<RowDataFixture> filterRowHeaderLayer = new FilterRowHeaderComposite<>(new DefaultGlazedListsFilterStrategy<>(filterList, columnPropertyAccessor, configRegistry), columnGroupHeaderLayer, columnHeaderDataProvider, configRegistry);
filterRowHeaderLayer.setFilterRowVisible(false);
ColumnOverrideLabelAccumulator labelAccumulator = new ColumnOverrideLabelAccumulator(columnHeaderDataLayer);
columnHeaderDataLayer.setConfigLabelAccumulator(labelAccumulator);
// Register labels
labelAccumulator.registerColumnOverrides(RowDataListFixture.getColumnIndexOfProperty(RowDataListFixture.RATING_PROP_NAME), "CUSTOM_COMPARATOR_LABEL");
// Row header
final DefaultRowHeaderDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
DefaultRowHeaderDataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, bodyLayer, bodyLayer.getSelectionLayer());
// Corner
final DefaultCornerDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider);
DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, filterRowHeaderLayer);
// Grid
GridLayer gridLayer = new GridLayer(bodyLayer, filterRowHeaderLayer, rowHeaderLayer, cornerLayer);
NatTable natTable = new NatTable(parent, gridLayer, false);
// Register create column group command handler
// Register column chooser
DisplayColumnChooserCommandHandler columnChooserCommandHandler = new DisplayColumnChooserCommandHandler(bodyLayer.getSelectionLayer(), bodyLayer.getColumnHideShowLayer(), this.columnHeaderLayer, columnHeaderDataLayer, columnGroupHeaderLayer, this.columnGroupModel);
bodyLayer.registerCommandHandler(columnChooserCommandHandler);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new HeaderMenuConfiguration(natTable) {
@Override
protected PopupMenuBuilder createColumnHeaderMenu(NatTable natTable) {
return super.createColumnHeaderMenu(natTable).withColumnChooserMenuItem();
}
});
natTable.addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
configRegistry.registerConfigAttribute(ExportConfigAttributes.EXPORTER, new HSSFExcelExporter());
}
});
natTable.addConfiguration(new FilterRowCustomConfiguration());
natTable.setConfigRegistry(configRegistry);
natTable.configure();
// add button
Button button = new Button(parent, SWT.NONE);
button.setText("Switch FilterRow visibility");
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
filterRowHeaderLayer.setFilterRowVisible(!filterRowHeaderLayer.isFilterRowVisible());
}
});
return natTable;
}
use of ca.odell.glazedlists.FilterList 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;
}
use of ca.odell.glazedlists.FilterList in project nebula.widgets.nattable by eclipse.
the class _900_Everything_but_the_kitchen_sink method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
final String[] propertyNames = RowDataListFixture.getPropertyNames();
final Map<String, String> propertyToLabelMap = RowDataListFixture.getPropertyToLabelMap();
ConfigRegistry configRegistry = new ConfigRegistry();
ColumnGroupModel columnGroupModel = new ColumnGroupModel();
// Body
LinkedList<BlinkingRowDataFixture> rowData = new LinkedList<>();
this.baseEventList = GlazedLists.threadSafeList(GlazedLists.eventList(rowData));
ObservableElementList<BlinkingRowDataFixture> observableElementList = new ObservableElementList<>(this.baseEventList, GlazedLists.beanConnector(BlinkingRowDataFixture.class));
FilterList<BlinkingRowDataFixture> filterList = new FilterList<>(observableElementList);
SortedList<BlinkingRowDataFixture> sortedList = new SortedList<>(filterList, null);
FullFeaturedBodyLayerStack<BlinkingRowDataFixture> bodyLayer = new FullFeaturedBodyLayerStack<>(sortedList, new IRowIdAccessor<BlinkingRowDataFixture>() {
@Override
public Serializable getRowId(BlinkingRowDataFixture rowObject) {
return rowObject.getSecurity_description();
}
}, propertyNames, configRegistry, columnGroupModel);
this.bodyDataProvider = bodyLayer.getBodyDataProvider();
this.propertyChangeListener = bodyLayer.getGlazedListEventsLayer();
// blinking
registerBlinkingConfigCells(configRegistry);
// Column header
FullFeaturedColumnHeaderLayerStack<BlinkingRowDataFixture> columnHeaderLayer = new FullFeaturedColumnHeaderLayerStack<>(sortedList, filterList, propertyNames, propertyToLabelMap, bodyLayer, bodyLayer.getSelectionLayer(), columnGroupModel, configRegistry);
// column groups
setUpColumnGroups(columnHeaderLayer);
// Row header
final DefaultRowHeaderDataProvider rowHeaderDataProvider = new DefaultSummaryRowHeaderDataProvider(this.bodyDataProvider);
DefaultRowHeaderDataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
rowHeaderDataLayer.setDefaultColumnWidth(50);
ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, bodyLayer, bodyLayer.getSelectionLayer());
// Corner
final DefaultCornerDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderLayer.getColumnHeaderDataProvider(), rowHeaderDataProvider);
DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, columnHeaderLayer);
// Grid
GridLayer gridLayer = new GridLayer(bodyLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
this.natTable = new NatTable(parent, gridLayer, false);
this.natTable.setConfigRegistry(configRegistry);
this.natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
// Popup menu
this.natTable.addConfiguration(new HeaderMenuConfiguration(this.natTable) {
@Override
protected PopupMenuBuilder createColumnHeaderMenu(NatTable natTable) {
return super.createColumnHeaderMenu(natTable).withColumnChooserMenuItem();
}
});
this.natTable.addConfiguration(new SingleClickSortConfiguration());
// Editing
ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyLayer.getBodyDataLayer());
bodyLayer.getBodyDataLayer().setConfigLabelAccumulator(columnLabelAccumulator);
this.natTable.addConfiguration(EditableGridExample.editableGridConfiguration(columnLabelAccumulator, this.bodyDataProvider));
this.natTable.addConfiguration(new FilterRowGridExample.FilterRowCustomConfiguration());
// Column chooser
DisplayColumnChooserCommandHandler columnChooserCommandHandler = new DisplayColumnChooserCommandHandler(bodyLayer.getSelectionLayer(), bodyLayer.getColumnHideShowLayer(), columnHeaderLayer.getColumnHeaderLayer(), columnHeaderLayer.getColumnHeaderDataLayer(), columnHeaderLayer.getColumnGroupHeaderLayer(), columnGroupModel);
bodyLayer.registerCommandHandler(columnChooserCommandHandler);
// Summary row configuration
this.natTable.addConfiguration(new MySummaryRow<>(this.bodyDataProvider));
this.natTable.configure();
return this.natTable;
}
Aggregations