Search in sources :

Example 11 with ColumnGroupModel

use of org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel in project nebula.widgets.nattable by eclipse.

the class _806_SortableColumnGroupingExample 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");
    ColumnGroupModel columnGroupModel = new ColumnGroupModel();
    // 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.
    EventList<Person> persons = GlazedLists.eventList(PersonService.getPersons(10));
    SortedList<Person> sortedList = new SortedList<>(persons, null);
    IColumnPropertyAccessor<Person> accessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
    IDataProvider bodyDataProvider = new ListDataProvider<>(sortedList, accessor);
    DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
    GlazedListsEventLayer<Person> eventLayer = new GlazedListsEventLayer<>(bodyDataLayer, sortedList);
    ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(eventLayer);
    ColumnGroupReorderLayer columnGroupReorderLayer = new ColumnGroupReorderLayer(columnReorderLayer, columnGroupModel);
    ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(columnGroupReorderLayer);
    ColumnGroupExpandCollapseLayer columnGroupExpandCollapseLayer = new ColumnGroupExpandCollapseLayer(columnHideShowLayer, columnGroupModel);
    SelectionLayer selectionLayer = new SelectionLayer(columnGroupExpandCollapseLayer);
    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);
    ConfigRegistry configRegistry = new ConfigRegistry();
    SortHeaderLayer<Person> sortHeaderLayer = new SortHeaderLayer<>(columnHeaderLayer, new GlazedListsSortModel<>(sortedList, accessor, configRegistry, columnHeaderDataLayer));
    ColumnGroupHeaderLayer columnGroupHeaderLayer = new ColumnGroupHeaderLayer(sortHeaderLayer, selectionLayer, columnGroupModel);
    // configure the column groups
    columnGroupHeaderLayer.addColumnsIndexesToGroup("Name", 0, 1);
    columnGroupHeaderLayer.addColumnsIndexesToGroup("Details", 2, 3, 4);
    columnGroupHeaderLayer.setGroupUnbreakable(1);
    // 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, columnGroupHeaderLayer);
    // build the grid layer
    GridLayer gridLayer = new GridLayer(viewportLayer, columnGroupHeaderLayer, rowHeaderLayer, cornerLayer);
    // turn the auto configuration off as we want to add our header menu
    // configuration
    NatTable natTable = new NatTable(parent, gridLayer, false);
    natTable.setConfigRegistry(configRegistry);
    // as the autoconfiguration of the NatTable is turned off, we have to
    // add the DefaultNatTableStyleConfiguration manually
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.addConfiguration(new SingleClickSortConfiguration());
    natTable.configure();
    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) SortedList(ca.odell.glazedlists.SortedList) ColumnHideShowLayer(org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) GlazedListsEventLayer(org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) 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) 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) ColumnGroupReorderLayer(org.eclipse.nebula.widgets.nattable.group.ColumnGroupReorderLayer) ColumnReorderLayer(org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer) SortHeaderLayer(org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) ColumnGroupModel(org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel) ReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor) ColumnGroupHeaderLayer(org.eclipse.nebula.widgets.nattable.group.ColumnGroupHeaderLayer) 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) SingleClickSortConfiguration(org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) ColumnGroupExpandCollapseLayer(org.eclipse.nebula.widgets.nattable.group.ColumnGroupExpandCollapseLayer) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider) Person(org.eclipse.nebula.widgets.nattable.dataset.person.Person)

Example 12 with ColumnGroupModel

use of org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel 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;
}
Also used : Serializable(java.io.Serializable) DefaultSummaryRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultSummaryRowHeaderDataProvider) FullFeaturedColumnHeaderLayerStack(org.eclipse.nebula.widgets.nattable.examples.fixtures.FullFeaturedColumnHeaderLayerStack) HeaderMenuConfiguration(org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration) SortedList(ca.odell.glazedlists.SortedList) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) ObservableElementList(ca.odell.glazedlists.ObservableElementList) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) ColumnOverrideLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator) FilterRowGridExample(org.eclipse.nebula.widgets.nattable.examples.examples._131_Filtering.FilterRowGridExample) DisplayColumnChooserCommandHandler(org.eclipse.nebula.widgets.nattable.columnChooser.command.DisplayColumnChooserCommandHandler) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) FilterList(ca.odell.glazedlists.FilterList) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) ColumnGroupModel(org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel) LinkedList(java.util.LinkedList) BlinkingRowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.BlinkingRowDataFixture) RowHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer) FullFeaturedBodyLayerStack(org.eclipse.nebula.widgets.nattable.examples.fixtures.FullFeaturedBodyLayerStack) CornerLayer(org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer) SingleClickSortConfiguration(org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) PopupMenuBuilder(org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder)

Aggregations

ColumnGroupModel (org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel)12 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)5 ColumnGroupHeaderLayer (org.eclipse.nebula.widgets.nattable.group.ColumnGroupHeaderLayer)5 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)5 HashMap (java.util.HashMap)4 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)4 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)4 DefaultRowHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider)4 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)4 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)4 DefaultRowHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer)4 RowHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer)4 ColumnGroupExpandCollapseLayer (org.eclipse.nebula.widgets.nattable.group.ColumnGroupExpandCollapseLayer)4 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)4 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)4 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)3 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)3 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)3 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)3 DefaultColumnHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer)3