Search in sources :

Example 46 with ConfigRegistry

use of org.eclipse.nebula.widgets.nattable.config.ConfigRegistry 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 47 with ConfigRegistry

use of org.eclipse.nebula.widgets.nattable.config.ConfigRegistry in project nebula.widgets.nattable by eclipse.

the class Creating_a_summary_row method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    this.myDataProvider = new IDataProvider() {

        @Override
        public int getColumnCount() {
            return 4;
        }

        @Override
        public int getRowCount() {
            return 10;
        }

        @Override
        public Object getDataValue(int columnIndex, int rowIndex) {
            if (columnIndex >= getColumnCount() || rowIndex >= getRowCount()) {
                throw new RuntimeException("Data value requested is out of bounds");
            }
            return (columnIndex % 2 == 0) ? 10 : "Apple";
        }

        @Override
        public void setDataValue(int columnIndex, int rowIndex, Object newValue) {
        }
    };
    IConfigRegistry configRegistry = new ConfigRegistry();
    IUniqueIndexLayer dataLayer = new DataLayer(this.myDataProvider);
    // Plug in the SummaryRowLayer
    IUniqueIndexLayer summaryRowLayer = new SummaryRowLayer(dataLayer, configRegistry, false);
    ViewportLayer viewportLayer = new ViewportLayer(summaryRowLayer);
    NatTable natTable = new NatTable(parent, viewportLayer, false);
    // Configure custom summary formula for a column
    natTable.addConfiguration(new MySummaryRowConfig(this.myDataProvider));
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.setConfigRegistry(configRegistry);
    natTable.configure();
    return natTable;
}
Also used : IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) SummaryRowLayer(org.eclipse.nebula.widgets.nattable.summaryrow.SummaryRowLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) IUniqueIndexLayer(org.eclipse.nebula.widgets.nattable.layer.IUniqueIndexLayer)

Example 48 with ConfigRegistry

use of org.eclipse.nebula.widgets.nattable.config.ConfigRegistry in project nebula.widgets.nattable by eclipse.

the class Applying_style_to_a_cell method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    SelectionExampleGridLayer gridLayer = new SelectionExampleGridLayer();
    NatTable natTable = new NatTable(parent, gridLayer, false);
    DataLayer bodyDataLayer = gridLayer.getBodyDataLayer();
    // Label accumulator - adds labels to all cells with the given data
    // value
    CellOverrideLabelAccumulator<RowDataFixture> cellLabelAccumulator = new CellOverrideLabelAccumulator<>(gridLayer.getBodyDataProvider());
    cellLabelAccumulator.registerOverride("AAA", 2, CELL_LABEL);
    // Register your cell style, against the label applied to the cell
    // Other configuration which can be added (apart from style) include
    // CellConfigAttributes, EditConfigAttributes, SortConfigAttributes etc.
    IConfigRegistry configRegistry = new ConfigRegistry();
    addColumnHighlight(configRegistry);
    // Register label accumulator
    bodyDataLayer.setConfigLabelAccumulator(cellLabelAccumulator);
    gridLayer.getSelectionLayer().addConfiguration(new DefaultSelectionLayerConfiguration());
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.setConfigRegistry(configRegistry);
    natTable.configure();
    return natTable;
}
Also used : SelectionExampleGridLayer(org.eclipse.nebula.widgets.nattable.examples.fixtures.SelectionExampleGridLayer) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) CellOverrideLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.CellOverrideLabelAccumulator) DefaultSelectionLayerConfiguration(org.eclipse.nebula.widgets.nattable.selection.config.DefaultSelectionLayerConfiguration)

Example 49 with ConfigRegistry

use of org.eclipse.nebula.widgets.nattable.config.ConfigRegistry in project nebula.widgets.nattable by eclipse.

the class NatTableBuilder method setupLayerStacks.

public NatTable setupLayerStacks() {
    IColumnPropertyAccessor<T> columnAccessor = new ColumnAccessor<T>(columns);
    configRegistry = new ConfigRegistry();
    SortedList<T> sortedRows = new SortedList<T>(eventList, null);
    filterList = new FilterList<T>(sortedRows);
    setUpColumnGroupModel();
    setUpColumnCategoriesModel();
    // Body
    bodyLayer = new BodyLayerStack<T>(tableModel, filterList);
    // Column header
    columnHeaderLayer = new ColumnHeaderLayerStack<T>(sortedRows, filterList, tableModel, bodyLayer, columnAccessor, configRegistry);
    // Row header
    rowHeaderLayer = new RowHeaderLayerStack<T>(bodyLayer, tableModel);
    // Corner
    cornerLayer = new CornerLayerStack<T>(columnHeaderLayer, rowHeaderLayer);
    // Grid
    gridLayer = new GridLayer(bodyLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer, false);
    natTable = new NatTable(parent, gridLayer, false);
    natTable.setConfigRegistry(configRegistry);
    natTable.setBackground(tableStyle.tableBgColor);
    // Configuration
    natTable.addConfiguration(new TableStyleConfiguration(tableStyle));
    configureColumnProperties();
    configureSorting();
    configureEditing();
    configureFiltering();
    configureColumnChooser();
    configureCategoriesBasedColumnChooser();
    configureColumnStyleCustomization();
    configureGridLayer();
    configureSelectionStyle();
    configureColumnHeaderRightClickMenu();
    return natTable;
}
Also used : SortedList(ca.odell.glazedlists.SortedList) TableStyleConfiguration(org.eclipse.nebula.widgets.nattable.extension.builder.configuration.TableStyleConfiguration) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) ColumnAccessor(org.eclipse.nebula.widgets.nattable.extension.builder.util.ColumnAccessor) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)

Example 50 with ConfigRegistry

use of org.eclipse.nebula.widgets.nattable.config.ConfigRegistry in project nebula.widgets.nattable by eclipse.

the class FilterRowDataLayerTest method setup.

@Before
public void setup() {
    this.columnHeaderLayer = new DataLayerFixture(10, 2, 100, 50);
    this.configRegistry = new ConfigRegistry();
    new DefaultNatTableStyleConfiguration().configureRegistry(this.configRegistry);
    new DefaultFilterRowConfiguration().configureRegistry(this.configRegistry);
    this.filterList = new FilterList<RowDataFixture>(GlazedLists.eventList(RowDataListFixture.getList()));
    this.layerUnderTest = new FilterRowDataLayer<RowDataFixture>(new DefaultGlazedListsFilterStrategy<RowDataFixture>(this.filterList, new ReflectiveColumnPropertyAccessor<RowDataFixture>(RowDataListFixture.getPropertyNames()), this.configRegistry), this.columnHeaderLayer, this.columnHeaderLayer.getDataProvider(), this.configRegistry);
    this.listener = new LayerListenerFixture();
    this.layerUnderTest.addLayerListener(this.listener);
}
Also used : ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) DataLayerFixture(org.eclipse.nebula.widgets.nattable.extension.glazedlists.fixture.DataLayerFixture) DefaultFilterRowConfiguration(org.eclipse.nebula.widgets.nattable.filterrow.config.DefaultFilterRowConfiguration) LayerListenerFixture(org.eclipse.nebula.widgets.nattable.extension.glazedlists.fixture.LayerListenerFixture) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) Before(org.junit.Before)

Aggregations

ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)92 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)72 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)61 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)54 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)54 HashMap (java.util.HashMap)40 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)38 DefaultRowHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer)38 DefaultColumnHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer)34 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)34 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)33 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)33 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)33 GridLayout (org.eclipse.swt.layout.GridLayout)33 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)32 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)31 RowHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer)31 Composite (org.eclipse.swt.widgets.Composite)31 DefaultRowHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider)28 SelectionEvent (org.eclipse.swt.events.SelectionEvent)28