Search in sources :

Example 11 with HeaderMenuConfiguration

use of org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration in project nebula.widgets.nattable by eclipse.

the class _6035_ExcelLikeFilterRowCustomTypesExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    // create a new ConfigRegistry which will be needed for GlazedLists
    // handling
    ConfigRegistry configRegistry = new ConfigRegistry();
    String[] propertyNames = { "name", "age", "money", "gender", "city" };
    // mapping from property to label, needed for column header labels
    Map<String, String> propertyToLabelMap = new HashMap<>();
    propertyToLabelMap.put("name", "Name");
    propertyToLabelMap.put("age", "Age");
    propertyToLabelMap.put("money", "Money");
    propertyToLabelMap.put("gender", "Gender");
    propertyToLabelMap.put("city", "City");
    IColumnPropertyAccessor<MyRowObject> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
    BodyLayerStack<MyRowObject> bodyLayerStack = new BodyLayerStack<>(createMyRowObjects(50), columnPropertyAccessor);
    // add a label accumulator to be able to register converter
    bodyLayerStack.getBodyDataLayer().setConfigLabelAccumulator(new ColumnLabelAccumulator());
    // build the column header layer
    IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
    DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
    ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, bodyLayerStack, bodyLayerStack.getSelectionLayer());
    // example on how to configure a different icon if a filter is applied
    ComboBoxFilterRowHeaderComposite<MyRowObject> filterRowHeaderLayer = new ComboBoxFilterRowHeaderComposite<>(bodyLayerStack.getFilterList(), bodyLayerStack.getBodyDataLayer(), bodyLayerStack.getSortedList(), columnPropertyAccessor, columnHeaderLayer, columnHeaderDataProvider, configRegistry, false);
    final IComboBoxDataProvider comboBoxDataProvider = filterRowHeaderLayer.getComboBoxDataProvider();
    filterRowHeaderLayer.addConfiguration(new ComboBoxFilterRowConfiguration() {

        {
            this.cellEditor = new FilterRowComboBoxCellEditor(comboBoxDataProvider, 5);
            this.filterIconPainter = new ComboBoxFilterIconPainter(comboBoxDataProvider, GUIHelper.getImage("filter"), null);
        }
    });
    // build the row header layer
    IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyLayerStack.getBodyDataProvider());
    DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
    ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, bodyLayerStack, bodyLayerStack.getSelectionLayer());
    // build the corner layer
    IDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider);
    DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
    ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, filterRowHeaderLayer);
    // build the grid layer
    GridLayer gridLayer = new GridLayer(bodyLayerStack, filterRowHeaderLayer, 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 and the ConfigRegistry manually
    natTable.setConfigRegistry(configRegistry);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.addConfiguration(new MyRowObjectTableConfiguration());
    natTable.addConfiguration(new FilterRowConfiguration());
    natTable.addConfiguration(new HeaderMenuConfiguration(natTable) {

        @Override
        protected PopupMenuBuilder createCornerMenu(NatTable natTable) {
            return super.createCornerMenu(natTable).withStateManagerMenuItemProvider();
        }
    });
    natTable.addConfiguration(new AbstractRegistryConfiguration() {

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.ALWAYS_EDITABLE);
        }
    });
    natTable.configure();
    natTable.registerCommandHandler(new DisplayPersistenceDialogCommandHandler(natTable));
    return natTable;
}
Also used : HashMap(java.util.HashMap) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) AbstractRegistryConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration) HeaderMenuConfiguration(org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) ComboBoxFilterRowConfiguration(org.eclipse.nebula.widgets.nattable.filterrow.combobox.ComboBoxFilterRowConfiguration) IComboBoxDataProvider(org.eclipse.nebula.widgets.nattable.edit.editor.IComboBoxDataProvider) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) FilterRowDataLayer(org.eclipse.nebula.widgets.nattable.filterrow.FilterRowDataLayer) 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) ComboBoxFilterRowHeaderComposite(org.eclipse.nebula.widgets.nattable.extension.glazedlists.filterrow.ComboBoxFilterRowHeaderComposite) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) FilterRowComboBoxCellEditor(org.eclipse.nebula.widgets.nattable.filterrow.combobox.FilterRowComboBoxCellEditor) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) ReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor) ComboBoxFilterIconPainter(org.eclipse.nebula.widgets.nattable.filterrow.combobox.ComboBoxFilterIconPainter) RowHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer) CornerLayer(org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer) ComboBoxFilterRowConfiguration(org.eclipse.nebula.widgets.nattable.filterrow.combobox.ComboBoxFilterRowConfiguration) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) ColumnLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnLabelAccumulator) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider) PopupMenuBuilder(org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder)

Example 12 with HeaderMenuConfiguration

use of org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration in project nebula.widgets.nattable by eclipse.

the class PercentageSizingDataLayerExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    Composite panel = new Composite(parent, SWT.NONE);
    panel.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().grab(true, true).applyTo(panel);
    Composite simplePanel = new Composite(panel, SWT.NONE);
    simplePanel.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().grab(true, true).applyTo(simplePanel);
    Composite gridPanel = new Composite(panel, SWT.NONE);
    gridPanel.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().grab(true, true).applyTo(gridPanel);
    Composite buttonPanel = new Composite(panel, SWT.NONE);
    buttonPanel.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().grab(true, true).applyTo(buttonPanel);
    final DummyModifiableBodyDataProvider dataProvider = new DummyModifiableBodyDataProvider(3, 2);
    // example for percentage calculation with default sizing
    // all columns will be same size while the NatTable itself will have
    // 100%
    final DataLayer n1DataLayer = new DataLayer(dataProvider);
    n1DataLayer.setColumnPercentageSizing(true);
    n1DataLayer.setRowPercentageSizing(true);
    ViewportLayer layer = new ViewportLayer(new SelectionLayer(n1DataLayer));
    layer.setRegionName(GridRegion.BODY);
    final NatTable n1 = new NatTable(simplePanel, layer);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(n1);
    // example for fixed percentage sizing
    // ensure that the sum of column sizes is not greater than 100
    final DataLayer n2DataLayer = new DataLayer(dataProvider);
    n2DataLayer.setColumnWidthPercentageByPosition(0, 25);
    n2DataLayer.setColumnWidthPercentageByPosition(1, 25);
    n2DataLayer.setColumnWidthPercentageByPosition(2, 50);
    layer = new ViewportLayer(new SelectionLayer(n2DataLayer));
    layer.setRegionName(GridRegion.BODY);
    final NatTable n2 = new NatTable(simplePanel, layer);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(n2);
    // example for mixed percentage sizing
    // configure not every column with the exact percentage value, this way
    // the columns for which
    // no exact values are set will use the remaining space
    final DataLayer n3DataLayer = new DataLayer(dataProvider);
    n3DataLayer.setColumnPercentageSizing(true);
    n3DataLayer.setColumnWidthPercentageByPosition(0, 40);
    n3DataLayer.setColumnWidthPercentageByPosition(2, 40);
    layer = new ViewportLayer(new SelectionLayer(n3DataLayer));
    layer.setRegionName(GridRegion.BODY);
    final NatTable n3 = new NatTable(simplePanel, layer);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(n3);
    // example for mixed fixed/percentage sizing
    // configure not every column with the exact percentage value, this way
    // the columns for which
    // no exact values are set will use the remaining space
    final DataLayer mixDataLayer = new DataLayer(dataProvider);
    mixDataLayer.setColumnPercentageSizing(true);
    mixDataLayer.setColumnPercentageSizing(0, false);
    mixDataLayer.setColumnPercentageSizing(1, false);
    mixDataLayer.setColumnWidthByPosition(0, 100);
    mixDataLayer.setColumnWidthByPosition(1, 100);
    layer = new ViewportLayer(new SelectionLayer(mixDataLayer));
    layer.setRegionName(GridRegion.BODY);
    final NatTable mix = new NatTable(simplePanel, layer);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(mix);
    // example for percentage calculation with default sizing in a grid
    // all columns will be same size while the NatTable itself will have
    // 100%
    DummyGridLayerStack gridLayer = new DummyGridLayerStack(dataProvider);
    final DataLayer n4DataLayer = (DataLayer) gridLayer.getBodyDataLayer();
    n4DataLayer.setColumnPercentageSizing(true);
    n4DataLayer.setRowPercentageSizing(true);
    final NatTable n4 = new NatTable(gridPanel, gridLayer, false);
    n4.addConfiguration(new DefaultNatTableStyleConfiguration());
    n4.addConfiguration(new HeaderMenuConfiguration(n4));
    n4.configure();
    GridDataFactory.fillDefaults().grab(true, true).applyTo(n4);
    // example for fixed percentage sizing in a grid
    // ensure that the sum of column sizes is not greater than 100
    gridLayer = new DummyGridLayerStack(dataProvider);
    final DataLayer n5DataLayer = (DataLayer) gridLayer.getBodyDataLayer();
    n5DataLayer.setColumnWidthByPosition(0, 25);
    n5DataLayer.setColumnWidthByPosition(1, 25);
    n5DataLayer.setColumnWidthByPosition(2, 50);
    n5DataLayer.setColumnPercentageSizing(true);
    final NatTable n5 = new NatTable(gridPanel, gridLayer, false);
    n5.addConfiguration(new DefaultNatTableStyleConfiguration());
    n5.addConfiguration(new HeaderMenuConfiguration(n5));
    n5.configure();
    GridDataFactory.fillDefaults().grab(true, true).applyTo(n5);
    // example for mixed percentage sizing in a grid
    // configure not every column with the exact percentage value, this way
    // the columns for which
    // no exact values are set will use the remaining space
    gridLayer = new DummyGridLayerStack(dataProvider);
    final DataLayer n6DataLayer = (DataLayer) gridLayer.getBodyDataLayer();
    n6DataLayer.setColumnWidthByPosition(0, 20);
    n6DataLayer.setColumnWidthByPosition(2, 20);
    n6DataLayer.setColumnPercentageSizing(true);
    final NatTable n6 = new NatTable(gridPanel, gridLayer, false);
    n6.addConfiguration(new DefaultNatTableStyleConfiguration());
    n6.addConfiguration(new HeaderMenuConfiguration(n6));
    n6.configure();
    GridDataFactory.fillDefaults().grab(true, true).applyTo(n6);
    // example for mixed fixed/percentage sizing in a grid
    // configure not every column with the exact percentage value, this way
    // the columns for which
    // no exact values are set will use the remaining space
    gridLayer = new DummyGridLayerStack(dataProvider);
    final DataLayer mixGridDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
    mixGridDataLayer.setColumnPercentageSizing(true);
    mixGridDataLayer.setColumnPercentageSizing(0, false);
    mixGridDataLayer.setColumnPercentageSizing(1, false);
    mixGridDataLayer.setColumnWidthByPosition(0, 100);
    mixGridDataLayer.setColumnWidthByPosition(1, 100);
    final NatTable mixGrid = new NatTable(gridPanel, gridLayer, false);
    mixGrid.addConfiguration(new DefaultNatTableStyleConfiguration());
    mixGrid.addConfiguration(new HeaderMenuConfiguration(mixGrid));
    mixGrid.configure();
    GridDataFactory.fillDefaults().grab(true, true).applyTo(mixGrid);
    Button addColumnButton = new Button(buttonPanel, SWT.PUSH);
    addColumnButton.setText("add column - no width");
    addColumnButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            dataProvider.setColumnCount(dataProvider.getColumnCount() + 1);
            n1.refresh();
            n2.refresh();
            n3.refresh();
            mix.refresh();
            n4.refresh();
            n5.refresh();
            n6.refresh();
            mixGrid.refresh();
        }
    });
    Button addColumnButton2 = new Button(buttonPanel, SWT.PUSH);
    addColumnButton2.setText("add column - 20 percent width");
    addColumnButton2.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            dataProvider.setColumnCount(dataProvider.getColumnCount() + 1);
            n1DataLayer.setColumnWidthPercentageByPosition(dataProvider.getColumnCount() - 1, 20);
            n2DataLayer.setColumnWidthPercentageByPosition(dataProvider.getColumnCount() - 1, 20);
            n3DataLayer.setColumnWidthPercentageByPosition(dataProvider.getColumnCount() - 1, 20);
            mixDataLayer.setColumnWidthPercentageByPosition(dataProvider.getColumnCount() - 1, 20);
            n4DataLayer.setColumnWidthPercentageByPosition(dataProvider.getColumnCount() - 1, 20);
            n5DataLayer.setColumnWidthPercentageByPosition(dataProvider.getColumnCount() - 1, 20);
            n6DataLayer.setColumnWidthPercentageByPosition(dataProvider.getColumnCount() - 1, 20);
            mixGridDataLayer.setColumnWidthPercentageByPosition(dataProvider.getColumnCount() - 1, 20);
            n1.refresh();
            n2.refresh();
            n3.refresh();
            mix.refresh();
            n4.refresh();
            n5.refresh();
            n6.refresh();
            mixGrid.refresh();
        }
    });
    return panel;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) HeaderMenuConfiguration(org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) GridLayout(org.eclipse.swt.layout.GridLayout) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) DummyGridLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DummyGridLayerStack) Button(org.eclipse.swt.widgets.Button) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DummyModifiableBodyDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DummyModifiableBodyDataProvider) NatTable(org.eclipse.nebula.widgets.nattable.NatTable)

Example 13 with HeaderMenuConfiguration

use of org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration in project nebula.widgets.nattable by eclipse.

the class StaticFilterGridExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    IConfigRegistry configRegistry = new ConfigRegistry();
    StaticFilterExampleGridLayer underlyingLayer = new StaticFilterExampleGridLayer(configRegistry);
    DataLayer bodyDataLayer = underlyingLayer.getBodyDataLayer();
    IDataProvider dataProvider = underlyingLayer.getBodyDataProvider();
    // NOTE: Register the accumulator on the body data layer.
    // This ensures that the labels are bound to the column index and are
    // unaffected by column order.
    final ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
    bodyDataLayer.setConfigLabelAccumulator(columnLabelAccumulator);
    NatTable natTable = new NatTable(parent, underlyingLayer, false);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.addConfiguration(new HeaderMenuConfiguration(natTable));
    // natTable.addConfiguration(new DebugMenuConfiguration(natTable));
    natTable.addConfiguration(new FilterRowCustomConfiguration());
    natTable.addConfiguration(EditableGridExample.editableGridConfiguration(columnLabelAccumulator, dataProvider));
    natTable.setConfigRegistry(configRegistry);
    natTable.configure();
    return natTable;
}
Also used : ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) StaticFilterExampleGridLayer(org.eclipse.nebula.widgets.nattable.examples.fixtures.StaticFilterExampleGridLayer) FilterRowDataLayer(org.eclipse.nebula.widgets.nattable.filterrow.FilterRowDataLayer) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) HeaderMenuConfiguration(org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) ColumnOverrideLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator)

Example 14 with HeaderMenuConfiguration

use of org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration 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;
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) AbstractRegistryConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration) HeaderMenuConfiguration(org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) FilterRowDataLayer(org.eclipse.nebula.widgets.nattable.filterrow.FilterRowDataLayer) 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) Button(org.eclipse.swt.widgets.Button) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) ColumnGroupBodyLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.ColumnGroupBodyLayerStack) ColumnOverrideLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator) FilterRowHeaderComposite(org.eclipse.nebula.widgets.nattable.filterrow.FilterRowHeaderComposite) DisplayColumnChooserCommandHandler(org.eclipse.nebula.widgets.nattable.columnChooser.command.DisplayColumnChooserCommandHandler) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FilterList(ca.odell.glazedlists.FilterList) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) 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) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) 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) HSSFExcelExporter(org.eclipse.nebula.widgets.nattable.extension.poi.HSSFExcelExporter)

Example 15 with HeaderMenuConfiguration

use of org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration in project nebula.widgets.nattable by eclipse.

the class _6032_GlazedListsFilterCustomTypesExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    // create a new ConfigRegistry which will be needed for GlazedLists
    // handling
    ConfigRegistry configRegistry = new ConfigRegistry();
    String[] propertyNames = { "name", "age", "money", "gender", "city" };
    // mapping from property to label, needed for column header labels
    Map<String, String> propertyToLabelMap = new HashMap<>();
    propertyToLabelMap.put("name", "Name");
    propertyToLabelMap.put("age", "Age");
    propertyToLabelMap.put("money", "Money");
    propertyToLabelMap.put("gender", "Gender");
    propertyToLabelMap.put("city", "City");
    IColumnPropertyAccessor<MyRowObject> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
    BodyLayerStack<MyRowObject> bodyLayerStack = new BodyLayerStack<>(createMyRowObjects(50), columnPropertyAccessor);
    // add a label accumulator to be able to register converter
    bodyLayerStack.getBodyDataLayer().setConfigLabelAccumulator(new ColumnLabelAccumulator());
    // build the column header layer
    IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
    DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
    ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, bodyLayerStack, bodyLayerStack.getSelectionLayer());
    // Note: The column header layer is wrapped in a filter row composite.
    // This plugs in the filter row functionality
    FilterRowHeaderComposite<MyRowObject> filterRowHeaderLayer = new FilterRowHeaderComposite<>(new DefaultGlazedListsFilterStrategy<>(bodyLayerStack.getFilterList(), columnPropertyAccessor, configRegistry), columnHeaderLayer, columnHeaderDataLayer.getDataProvider(), configRegistry);
    // build the row header layer
    IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyLayerStack.getBodyDataProvider());
    DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
    ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, bodyLayerStack, bodyLayerStack.getSelectionLayer());
    // build the corner layer
    IDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider);
    DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
    ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, filterRowHeaderLayer);
    // build the grid layer
    GridLayer gridLayer = new GridLayer(bodyLayerStack, filterRowHeaderLayer, 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 and the ConfigRegistry manually
    natTable.setConfigRegistry(configRegistry);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    // add filter row configuration
    natTable.addConfiguration(new FilterRowConfiguration());
    natTable.addConfiguration(new MyRowObjectTableConfiguration());
    natTable.addConfiguration(new HeaderMenuConfiguration(natTable) {

        @Override
        protected PopupMenuBuilder createCornerMenu(NatTable natTable) {
            return super.createCornerMenu(natTable).withStateManagerMenuItemProvider();
        }
    });
    natTable.configure();
    natTable.registerCommandHandler(new DisplayPersistenceDialogCommandHandler(natTable));
    return natTable;
}
Also used : HashMap(java.util.HashMap) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) HeaderMenuConfiguration(org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) FilterRowDataLayer(org.eclipse.nebula.widgets.nattable.filterrow.FilterRowDataLayer) 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) FilterRowHeaderComposite(org.eclipse.nebula.widgets.nattable.filterrow.FilterRowHeaderComposite) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) ReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor) RowHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer) CornerLayer(org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) ColumnLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnLabelAccumulator) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider) PopupMenuBuilder(org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder)

Aggregations

DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)35 HeaderMenuConfiguration (org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration)35 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)34 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)28 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)24 DefaultRowHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider)24 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)24 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)24 RowHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer)24 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)23 DefaultRowHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer)22 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)22 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)21 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)20 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)20 DefaultColumnHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer)18 PopupMenuBuilder (org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder)18 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)17 HashMap (java.util.HashMap)16 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)12