Search in sources :

Example 36 with DefaultColumnHeaderDataProvider

use of org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider in project nebula.widgets.nattable by eclipse.

the class _773_GridExcelExportFormatterExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    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(true, 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");
    // 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.
    IDataProvider bodyDataProvider = new DefaultBodyDataProvider<>(PersonService.getPersons(10), propertyNames);
    DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
    SelectionLayer selectionLayer = new SelectionLayer(bodyDataLayer);
    ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
    bodyDataLayer.setConfigLabelAccumulator(new ColumnLabelAccumulator());
    // 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);
    final NatTable natTable = new NatTable(gridPanel, gridLayer, false);
    // adding this configuration adds the styles and the painters to use
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.addConfiguration(new AbstractRegistryConfiguration() {

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            PoiExcelExporter exporter = new HSSFExcelExporter();
            exporter.setApplyVerticalTextConfiguration(true);
            exporter.setApplyBackgroundColor(false);
            configRegistry.registerConfigAttribute(ExportConfigAttributes.EXPORTER, exporter);
            configRegistry.registerConfigAttribute(ExportConfigAttributes.DATE_FORMAT, "dd.MM.yyyy");
            // register a custom formatter to the body of the grid
            // you could also implement different formatter for different
            // columns by using the label mechanism
            configRegistry.registerConfigAttribute(ExportConfigAttributes.EXPORT_FORMATTER, new ExampleExportFormatter(), DisplayMode.NORMAL, GridRegion.BODY);
            configRegistry.registerConfigAttribute(ExportConfigAttributes.EXPORT_FORMATTER, new IExportFormatter() {

                @Override
                public Object formatForExport(ILayerCell cell, IConfigRegistry configRegistry) {
                    // the default conversion to string for export
                    return cell.getDataValue();
                }
            }, DisplayMode.NORMAL, GridRegion.ROW_HEADER);
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new BeveledBorderDecorator(new VerticalTextPainter(false, true, true)), DisplayMode.NORMAL, GridRegion.COLUMN_HEADER);
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CheckBoxPainter(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 3);
        }
    });
    gridLayer.addConfiguration(new DefaultImageExportBindings());
    natTable.configure();
    GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
    Button addColumnButton = new Button(buttonPanel, SWT.PUSH);
    addColumnButton.setText("Export");
    addColumnButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            natTable.doCommand(new ExportCommand(natTable.getConfigRegistry(), natTable.getShell()));
        }
    });
    return panel;
}
Also used : HashMap(java.util.HashMap) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) AbstractRegistryConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) ExportCommand(org.eclipse.nebula.widgets.nattable.export.command.ExportCommand) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) DefaultBodyDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultBodyDataProvider) DefaultImageExportBindings(org.eclipse.nebula.widgets.nattable.export.image.config.DefaultImageExportBindings) GridLayout(org.eclipse.swt.layout.GridLayout) 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) CheckBoxPainter(org.eclipse.nebula.widgets.nattable.painter.cell.CheckBoxPainter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) VerticalTextPainter(org.eclipse.nebula.widgets.nattable.painter.cell.VerticalTextPainter) Composite(org.eclipse.swt.widgets.Composite) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) RowHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer) PoiExcelExporter(org.eclipse.nebula.widgets.nattable.extension.poi.PoiExcelExporter) CornerLayer(org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer) BeveledBorderDecorator(org.eclipse.nebula.widgets.nattable.painter.cell.decorator.BeveledBorderDecorator) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) IExportFormatter(org.eclipse.nebula.widgets.nattable.export.IExportFormatter) 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) HSSFExcelExporter(org.eclipse.nebula.widgets.nattable.extension.poi.HSSFExcelExporter)

Example 37 with DefaultColumnHeaderDataProvider

use of org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider in project nebula.widgets.nattable by eclipse.

the class BlinkingGridExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    final String[] propertyNames = RowDataListFixture.getPropertyNames();
    final Map<String, String> propertyToLabelMap = RowDataListFixture.getPropertyToLabelMap();
    ConfigRegistry configRegistry = new ConfigRegistry();
    // Body
    LinkedList<BlinkingRowDataFixture> rowData = new LinkedList<>();
    EventList<BlinkingRowDataFixture> eventList = GlazedLists.eventList(rowData);
    ObservableElementList<BlinkingRowDataFixture> observableElementList = new ObservableElementList<>(eventList, GlazedLists.beanConnector(BlinkingRowDataFixture.class));
    IColumnPropertyAccessor<BlinkingRowDataFixture> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
    this.bodyDataProvider = new ListDataProvider<>(observableElementList, columnPropertyAccessor);
    final DataLayer bodyLayer = new DataLayer(this.bodyDataProvider);
    GlazedListsEventLayer<BlinkingRowDataFixture> glazedListsEventLayer = new GlazedListsEventLayer<>(bodyLayer, observableElementList);
    BlinkLayer<BlinkingRowDataFixture> blinkingLayer = new BlinkLayer<>(glazedListsEventLayer, this.bodyDataProvider, new IRowIdAccessor<BlinkingRowDataFixture>() {

        @Override
        public Serializable getRowId(BlinkingRowDataFixture rowObject) {
            return rowObject.getSecurity_description();
        }
    }, columnPropertyAccessor, configRegistry);
    registerBlinkingConfigCells(configRegistry);
    insertRowData(glazedListsEventLayer, this.bodyDataProvider);
    // Column header
    final DefaultColumnHeaderDataProvider defaultColumnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
    // Row header
    final DefaultRowHeaderDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(this.bodyDataProvider);
    // Corner
    final DefaultCornerDataProvider cornerDataProvider = new DefaultCornerDataProvider(defaultColumnHeaderDataProvider, rowHeaderDataProvider);
    // Grid
    GridLayer gridLayer = new DefaultGridLayer(blinkingLayer, new DefaultColumnHeaderDataLayer(defaultColumnHeaderDataProvider), new DefaultRowHeaderDataLayer(rowHeaderDataProvider), new DataLayer(cornerDataProvider));
    NatTable natTable = new NatTable(parent, gridLayer, false);
    natTable.setConfigRegistry(configRegistry);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.configure();
    return natTable;
}
Also used : Serializable(java.io.Serializable) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) GlazedListsEventLayer(org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer) ObservableElementList(ca.odell.glazedlists.ObservableElementList) 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) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) LinkedList(java.util.LinkedList) ReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor) BlinkingRowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.BlinkingRowDataFixture) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer) BlinkLayer(org.eclipse.nebula.widgets.nattable.blink.BlinkLayer)

Example 38 with DefaultColumnHeaderDataProvider

use of org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider 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 39 with DefaultColumnHeaderDataProvider

use of org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider in project nebula.widgets.nattable by eclipse.

the class _6041_TreeGridExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    container.setLayout(new GridLayout());
    // create a new ConfigRegistry which will be needed for GlazedLists
    // handling
    ConfigRegistry configRegistry = new ConfigRegistry();
    // property names of the Person class
    String[] propertyNames = { "lastName", "firstName", "gender", "married", "birthday" };
    // mapping from property to label, needed for column header labels
    Map<String, String> propertyToLabelMap = new HashMap<>();
    propertyToLabelMap.put("lastName", "Lastname");
    propertyToLabelMap.put("firstName", "Firstname");
    propertyToLabelMap.put("gender", "Gender");
    propertyToLabelMap.put("married", "Married");
    propertyToLabelMap.put("birthday", "Birthday");
    IColumnPropertyAccessor<PersonWithAddress> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
    final BodyLayerStack<PersonWithAddress> bodyLayerStack = new BodyLayerStack<>(PersonService.getPersonsWithAddress(50), columnPropertyAccessor, new PersonWithAddressTreeFormat());
    // build the column header layer
    IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
    DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
    ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, bodyLayerStack, bodyLayerStack.getSelectionLayer());
    // 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, columnHeaderLayer);
    // build the grid layer
    GridLayer gridLayer = new GridLayer(bodyLayerStack, columnHeaderLayer, rowHeaderLayer, cornerLayer);
    // turn the auto configuration off as we want to add our header menu
    // configuration
    final NatTable natTable = new NatTable(container, 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 AbstractRegistryConfiguration() {

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            // register a CheckBoxPainter as CellPainter for the married
            // information
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CheckBoxPainter(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 3);
            configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultDateDisplayConverter("MM/dd/yyyy"), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 4);
        }
    });
    // adds the key bindings that allows pressing space bar to
    // expand/collapse tree nodes
    natTable.addConfiguration(new TreeLayerExpandCollapseKeyBindings(bodyLayerStack.getTreeLayer(), bodyLayerStack.getSelectionLayer()));
    natTable.configure();
    GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
    Composite buttonPanel = new Composite(container, SWT.NONE);
    buttonPanel.setLayout(new RowLayout());
    GridDataFactory.fillDefaults().grab(true, false).applyTo(buttonPanel);
    Button collapseAllButton = new Button(buttonPanel, SWT.PUSH);
    collapseAllButton.setText("Collapse All");
    collapseAllButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            natTable.doCommand(new TreeCollapseAllCommand());
        }
    });
    Button expandAllButton = new Button(buttonPanel, SWT.PUSH);
    expandAllButton.setText("Expand All");
    expandAllButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            natTable.doCommand(new TreeExpandAllCommand());
        }
    });
    return container;
}
Also used : HashMap(java.util.HashMap) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) AbstractRegistryConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration) DefaultDateDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.DefaultDateDisplayConverter) 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) GridLayout(org.eclipse.swt.layout.GridLayout) 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) TreeCollapseAllCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeCollapseAllCommand) Button(org.eclipse.swt.widgets.Button) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) CheckBoxPainter(org.eclipse.nebula.widgets.nattable.painter.cell.CheckBoxPainter) TreeLayerExpandCollapseKeyBindings(org.eclipse.nebula.widgets.nattable.tree.config.TreeLayerExpandCollapseKeyBindings) RowLayout(org.eclipse.swt.layout.RowLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) PersonWithAddress(org.eclipse.nebula.widgets.nattable.dataset.person.PersonWithAddress) Composite(org.eclipse.swt.widgets.Composite) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) 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) TreeExpandAllCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandAllCommand) 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)

Example 40 with DefaultColumnHeaderDataProvider

use of org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider in project nebula.widgets.nattable by eclipse.

the class _6043_HierarchicalTreeExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    // mapping from property to label, needed for column header labels
    Map<String, String> propertyToLabelMap = new HashMap<>();
    propertyToLabelMap.put("manufacturer", "Manufacturer");
    propertyToLabelMap.put("model", "Model");
    propertyToLabelMap.put("motors.identifier", "Identifier");
    propertyToLabelMap.put("motors.capacity", "Capacity");
    propertyToLabelMap.put("motors.capacityUnit", "Capacity Unit");
    propertyToLabelMap.put("motors.maximumSpeed", "Maximum Speed");
    propertyToLabelMap.put("motors.feedbacks.creationTime", "Creation Time");
    propertyToLabelMap.put("motors.feedbacks.classification", "Classification");
    propertyToLabelMap.put("motors.feedbacks.comment", "Comment");
    BodyLayerStack bodyLayerStack = new BodyLayerStack(CarService.getInput(), CarService.PROPERTY_NAMES, new HierarchicalWrapperTreeFormat(CarService.PROPERTY_NAMES));
    // create the column header layer stack
    IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(CarService.PROPERTY_NAMES, propertyToLabelMap);
    ILayer columnHeaderLayer = new ColumnHeaderLayer(new DataLayer(columnHeaderDataProvider), bodyLayerStack, bodyLayerStack.getSelectionLayer());
    // create the row header layer stack
    IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyLayerStack.getBodyDataProvider());
    ILayer rowHeaderLayer = new RowHeaderLayer(new DataLayer(rowHeaderDataProvider, 40, 20), bodyLayerStack, bodyLayerStack.getSelectionLayer());
    // create the corner layer stack
    ILayer cornerLayer = new CornerLayer(new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider)), rowHeaderLayer, columnHeaderLayer);
    // create the grid layer composed with the prior created layer stacks
    GridLayer gridLayer = new GridLayer(bodyLayerStack, columnHeaderLayer, rowHeaderLayer, cornerLayer);
    NatTable natTable = new NatTable(parent, gridLayer);
    return natTable;
}
Also used : HashMap(java.util.HashMap) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) RowHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer) CornerLayer(org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) HierarchicalWrapperTreeFormat(org.eclipse.nebula.widgets.nattable.extension.glazedlists.hierarchical.HierarchicalWrapperTreeFormat) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)

Aggregations

DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)85 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)82 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)79 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)74 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)72 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)69 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)68 HashMap (java.util.HashMap)67 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)67 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)66 RowHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer)66 DefaultRowHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider)62 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)61 DefaultRowHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer)61 DefaultColumnHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer)59 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)42 ViewportLayer (org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer)39 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)34 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)33 GridLayout (org.eclipse.swt.layout.GridLayout)33