Search in sources :

Example 1 with TreeLayerExpandCollapseKeyBindings

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

the class _811_GroupBySummaryFixedSummaryRowExample 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
    final ConfigRegistry configRegistry = new ConfigRegistry();
    // property names of the ExtendedPersonWithAddress class
    String[] propertyNames = { "firstName", "lastName", "age", "money", "married", "gender", "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("age", "Age");
    propertyToLabelMap.put("money", "Money");
    propertyToLabelMap.put("married", "Married");
    propertyToLabelMap.put("gender", "Gender");
    propertyToLabelMap.put("birthday", "Birthday");
    final IColumnPropertyAccessor<ExtendedPersonWithAddress> columnPropertyAccessor = new ExtendedReflectiveColumnPropertyAccessor<>(propertyNames);
    // to enable the group by summary feature, the GroupByDataLayer needs to
    // know the ConfigRegistry
    List<ExtendedPersonWithAddress> persons = PersonService.getExtendedPersonsWithAddress(10);
    final BodyLayerStack<ExtendedPersonWithAddress> bodyLayerStack = new BodyLayerStack<>(persons, columnPropertyAccessor, configRegistry);
    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());
    // add sorting
    SortHeaderLayer<ExtendedPersonWithAddress> sortHeaderLayer = new SortHeaderLayer<>(columnHeaderLayer, new GlazedListsSortModel<>(bodyLayerStack.getSortedList(), columnPropertyAccessor, configRegistry, columnHeaderDataLayer), false);
    // connect sortModel to GroupByDataLayer to support sorting by group by
    // summary values
    bodyLayerStack.getBodyDataLayer().initializeTreeComparator(sortHeaderLayer.getSortModel(), bodyLayerStack.getTreeLayer(), true);
    // build the row header layer
    // Adding the specialized DefaultSummaryRowHeaderDataProvider to
    // indicate the summary row in the row header
    IDataProvider rowHeaderDataProvider = new DefaultSummaryRowHeaderDataProvider(bodyLayerStack.getBodyDataProvider(), "\u2211");
    final 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, sortHeaderLayer);
    // build the grid layer
    GridLayer gridLayer = new GridLayer(bodyLayerStack, sortHeaderLayer, rowHeaderLayer, cornerLayer, false);
    FixedSummaryRowLayer summaryRowLayer = new FixedSummaryRowLayer(bodyLayerStack.getGlazedListsEventLayer(), gridLayer, configRegistry, false);
    summaryRowLayer.setSummaryRowLabel("\u2211");
    summaryRowLayer.setConfigLabelAccumulator(new AbstractOverrider() {

        @Override
        public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
            if (columnPosition == 0) {
                // our label is more important regarding styling than the
                // summary row labels
                configLabels.addLabelOnTop(ROW_HEADER_SUMMARY_ROW);
            }
        }
    });
    // ensure the body data layer uses a layer painter with correct
    // configured clipping
    bodyLayerStack.getBodyDataLayer().setLayerPainter(new GridLineCellLayerPainter(false, true));
    // set the group by header on top of the grid
    CompositeLayer compositeGridLayer = new CompositeLayer(1, 3);
    final GroupByHeaderLayer groupByHeaderLayer = new GroupByHeaderLayer(bodyLayerStack.getGroupByModel(), gridLayer, columnHeaderDataProvider);
    compositeGridLayer.setChildLayer(GroupByHeaderLayer.GROUP_BY_REGION, groupByHeaderLayer, 0, 0);
    compositeGridLayer.setChildLayer("Grid", gridLayer, 0, 1);
    compositeGridLayer.setChildLayer("Summary", summaryRowLayer, 0, 2);
    // add the export configuration to the composite layer
    compositeGridLayer.registerCommandHandler(new ExportCommandHandler(compositeGridLayer));
    compositeGridLayer.addConfiguration(new IConfiguration() {

        @Override
        public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
            uiBindingRegistry.registerKeyBinding(new KeyEventMatcher(SWT.MOD1, 'e'), new ExportAction());
        }

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            PoiExcelExporter exporter = new HSSFExcelExporter();
            exporter.setApplyBackgroundColor(false);
            configRegistry.registerConfigAttribute(ExportConfigAttributes.EXPORTER, exporter);
            configRegistry.registerConfigAttribute(ExportConfigAttributes.EXPORT_FORMATTER, new DefaultExportFormatter());
            configRegistry.registerConfigAttribute(ExportConfigAttributes.DATE_FORMAT, // $NON-NLS-1$
            "m/d/yy h:mm");
        }

        @Override
        public void configureLayer(ILayer layer) {
        }
    });
    // turn the auto configuration off as we want to add our header menu
    // configuration
    final NatTable natTable = new NatTable(container, compositeGridLayer, 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 some additional styling
    natTable.addConfiguration(new AbstractRegistryConfiguration() {

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CheckBoxPainter(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 4);
            IStyle style = new Style();
            style.setAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT, HorizontalAlignmentEnum.RIGHT);
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 2);
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 3);
            configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultDoubleDisplayConverter(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 3);
            // the main styling of the summary row cell in the row header is
            // done via summary row default style, but we need to override
            // the alignment
            style = new Style();
            style.setAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT, HorizontalAlignmentEnum.CENTER);
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.NORMAL, ROW_HEADER_SUMMARY_ROW);
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.SELECT, ROW_HEADER_SUMMARY_ROW);
        }
    });
    // add sorting configuration
    natTable.addConfiguration(new SingleClickSortConfiguration());
    this.sumMoneyGroupBySummaryProvider = new SummationGroupBySummaryProvider<>(columnPropertyAccessor);
    this.avgMoneyGroupBySummaryProvider = new AverageMoneyGroupBySummaryProvider();
    // create a new IDataProvider that operates on the basic underlying list
    // this is necessary because the IDataProvider in the body layer stack
    // is operating on the TreeList, and on collapsing a node, the children
    // will be not visible, which has effect on the summary value.
    final IDataProvider summaryDataProvider = new ListDataProvider<>(bodyLayerStack.getSortedList(), columnPropertyAccessor);
    this.sumMoneySummaryProvider = new SummationSummaryProvider(summaryDataProvider, false);
    this.avgMoneySummaryProvider = new AverageMoneySummaryProvider(summaryDataProvider);
    // add group by summary configuration
    natTable.addConfiguration(new AbstractRegistryConfiguration() {

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            // GroupBy summary configuration
            configRegistry.registerConfigAttribute(GroupByConfigAttributes.GROUP_BY_SUMMARY_PROVIDER, _811_GroupBySummaryFixedSummaryRowExample.this.sumMoneyGroupBySummaryProvider, DisplayMode.NORMAL, GroupByDataLayer.GROUP_BY_COLUMN_PREFIX + 3);
            configRegistry.registerConfigAttribute(GroupByConfigAttributes.GROUP_BY_SUMMARY_PROVIDER, new AverageAgeGroupBySummaryProvider(), DisplayMode.NORMAL, GroupByDataLayer.GROUP_BY_COLUMN_PREFIX + 2);
            configRegistry.registerConfigAttribute(GroupByConfigAttributes.GROUP_BY_CHILD_COUNT_PATTERN, "[{0}] - ({1})");
            // SummaryRow configuration
            configRegistry.registerConfigAttribute(SummaryRowConfigAttributes.SUMMARY_PROVIDER, _811_GroupBySummaryFixedSummaryRowExample.this.sumMoneySummaryProvider, DisplayMode.NORMAL, SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX + 3);
            configRegistry.registerConfigAttribute(SummaryRowConfigAttributes.SUMMARY_PROVIDER, new AverageAgeSummaryProvider(summaryDataProvider), DisplayMode.NORMAL, SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX + 2);
            configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new SummaryDisplayConverter(new DefaultDoubleDisplayConverter()), DisplayMode.NORMAL, SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX + 3);
        }
    });
    // add group by header configuration
    natTable.addConfiguration(new GroupByHeaderMenuConfiguration(natTable, groupByHeaderLayer));
    natTable.addConfiguration(new AbstractHeaderMenuConfiguration(natTable) {

        @Override
        protected PopupMenuBuilder createColumnHeaderMenu(NatTable natTable) {
            return super.createColumnHeaderMenu(natTable).withHideColumnMenuItem().withShowAllColumnsMenuItem().withStateManagerMenuItemProvider();
        }

        @Override
        protected PopupMenuBuilder createCornerMenu(NatTable natTable) {
            return super.createCornerMenu(natTable).withShowAllColumnsMenuItem().withStateManagerMenuItemProvider();
        }
    });
    // adds the key bindings that allow space bar to be pressed to
    // expand/collapse tree nodes
    natTable.addConfiguration(new TreeLayerExpandCollapseKeyBindings(bodyLayerStack.getTreeLayer(), bodyLayerStack.getSelectionLayer()));
    natTable.configure();
    // set the modern theme to visualize the summary better
    final ThemeConfiguration defaultTheme = new DefaultNatTableThemeConfiguration();
    defaultTheme.addThemeExtension(new DefaultGroupByThemeExtension());
    final ThemeConfiguration modernTheme = new ModernNatTableThemeConfiguration();
    modernTheme.addThemeExtension(new ModernGroupByThemeExtension());
    final ThemeConfiguration darkTheme = new DarkNatTableThemeConfiguration();
    darkTheme.addThemeExtension(new DarkGroupByThemeExtension());
    natTable.setTheme(modernTheme);
    // add a border on every side of the table
    natTable.addOverlayPainter(new NatTableBorderOverlayPainter());
    natTable.registerCommandHandler(new DisplayPersistenceDialogCommandHandler(natTable));
    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 toggleHeaderButton = new Button(buttonPanel, SWT.PUSH);
    toggleHeaderButton.setText("Toggle Group By Header");
    toggleHeaderButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            groupByHeaderLayer.setVisible(!groupByHeaderLayer.isVisible());
        }
    });
    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());
        }
    });
    Button toggleMoneySummaryButton = new Button(buttonPanel, SWT.PUSH);
    toggleMoneySummaryButton.setText("Toggle Money Group Summary (SUM/AVG)");
    toggleMoneySummaryButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // clear the group by summary cache so the new summary
            // calculation gets triggered
            bodyLayerStack.getBodyDataLayer().clearCache();
            _811_GroupBySummaryFixedSummaryRowExample.this.useMoneySum = !_811_GroupBySummaryFixedSummaryRowExample.this.useMoneySum;
            if (_811_GroupBySummaryFixedSummaryRowExample.this.useMoneySum) {
                configRegistry.registerConfigAttribute(GroupByConfigAttributes.GROUP_BY_SUMMARY_PROVIDER, _811_GroupBySummaryFixedSummaryRowExample.this.sumMoneyGroupBySummaryProvider, DisplayMode.NORMAL, GroupByDataLayer.GROUP_BY_COLUMN_PREFIX + 3);
                configRegistry.registerConfigAttribute(SummaryRowConfigAttributes.SUMMARY_PROVIDER, _811_GroupBySummaryFixedSummaryRowExample.this.sumMoneySummaryProvider, DisplayMode.NORMAL, SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX + 3);
            } else {
                configRegistry.registerConfigAttribute(GroupByConfigAttributes.GROUP_BY_SUMMARY_PROVIDER, _811_GroupBySummaryFixedSummaryRowExample.this.avgMoneyGroupBySummaryProvider, DisplayMode.NORMAL, GroupByDataLayer.GROUP_BY_COLUMN_PREFIX + 3);
                configRegistry.registerConfigAttribute(SummaryRowConfigAttributes.SUMMARY_PROVIDER, _811_GroupBySummaryFixedSummaryRowExample.this.avgMoneySummaryProvider, DisplayMode.NORMAL, SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX + 3);
            }
            natTable.doCommand(new VisualRefreshCommand());
        }
    });
    Button toggleThemeButton = new Button(buttonPanel, SWT.PUSH);
    toggleThemeButton.setText("Toggle Theme");
    toggleThemeButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (_811_GroupBySummaryFixedSummaryRowExample.this.currentTheme == 0) {
                natTable.setTheme(modernTheme);
                _811_GroupBySummaryFixedSummaryRowExample.this.currentTheme++;
            } else if (_811_GroupBySummaryFixedSummaryRowExample.this.currentTheme == 1) {
                natTable.setTheme(darkTheme);
                _811_GroupBySummaryFixedSummaryRowExample.this.currentTheme++;
            } else if (_811_GroupBySummaryFixedSummaryRowExample.this.currentTheme == 2) {
                natTable.setTheme(defaultTheme);
                _811_GroupBySummaryFixedSummaryRowExample.this.currentTheme = 0;
            }
        }
    });
    Button button = new Button(buttonPanel, SWT.PUSH);
    button.setText("Add Row");
    button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            bodyLayerStack.getSortedList().add(PersonService.createExtendedPersonWithAddress(bodyLayerStack.getSortedList().size()));
        }
    });
    return container;
}
Also used : SummaryDisplayConverter(org.eclipse.nebula.widgets.nattable.summaryrow.SummaryDisplayConverter) ExtendedPersonWithAddress(org.eclipse.nebula.widgets.nattable.dataset.person.ExtendedPersonWithAddress) HashMap(java.util.HashMap) AbstractRegistryConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration) DefaultGroupByThemeExtension(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.DefaultGroupByThemeExtension) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) DarkNatTableThemeConfiguration(org.eclipse.nebula.widgets.nattable.style.theme.DarkNatTableThemeConfiguration) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) GroupByDataLayer(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByDataLayer) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) TreeCollapseAllCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeCollapseAllCommand) Button(org.eclipse.swt.widgets.Button) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) ExportCommandHandler(org.eclipse.nebula.widgets.nattable.export.command.ExportCommandHandler) SelectionEvent(org.eclipse.swt.events.SelectionEvent) NatTableBorderOverlayPainter(org.eclipse.nebula.widgets.nattable.painter.NatTableBorderOverlayPainter) GroupByHeaderLayer(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByHeaderLayer) UiBindingRegistry(org.eclipse.nebula.widgets.nattable.ui.binding.UiBindingRegistry) AbstractOverrider(org.eclipse.nebula.widgets.nattable.layer.cell.AbstractOverrider) DarkGroupByThemeExtension(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.DarkGroupByThemeExtension) SortHeaderLayer(org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer) SummationSummaryProvider(org.eclipse.nebula.widgets.nattable.summaryrow.SummationSummaryProvider) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) CompositeLayer(org.eclipse.nebula.widgets.nattable.layer.CompositeLayer) IStyle(org.eclipse.nebula.widgets.nattable.style.IStyle) PoiExcelExporter(org.eclipse.nebula.widgets.nattable.extension.poi.PoiExcelExporter) ExportAction(org.eclipse.nebula.widgets.nattable.export.action.ExportAction) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) ColumnLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnLabelAccumulator) GridLineCellLayerPainter(org.eclipse.nebula.widgets.nattable.painter.layer.GridLineCellLayerPainter) IConfiguration(org.eclipse.nebula.widgets.nattable.config.IConfiguration) ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) DefaultSummaryRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultSummaryRowHeaderDataProvider) LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack) DefaultExportFormatter(org.eclipse.nebula.widgets.nattable.export.excel.DefaultExportFormatter) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) GroupByHeaderMenuConfiguration(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByHeaderMenuConfiguration) DefaultDoubleDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.DefaultDoubleDisplayConverter) GridLayout(org.eclipse.swt.layout.GridLayout) DisplayPersistenceDialogCommandHandler(org.eclipse.nebula.widgets.nattable.persistence.command.DisplayPersistenceDialogCommandHandler) KeyEventMatcher(org.eclipse.nebula.widgets.nattable.ui.matcher.KeyEventMatcher) ExtendedReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ExtendedReflectiveColumnPropertyAccessor) CheckBoxPainter(org.eclipse.nebula.widgets.nattable.painter.cell.CheckBoxPainter) TreeLayerExpandCollapseKeyBindings(org.eclipse.nebula.widgets.nattable.tree.config.TreeLayerExpandCollapseKeyBindings) RowLayout(org.eclipse.swt.layout.RowLayout) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) IStyle(org.eclipse.nebula.widgets.nattable.style.IStyle) Style(org.eclipse.nebula.widgets.nattable.style.Style) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) VisualRefreshCommand(org.eclipse.nebula.widgets.nattable.command.VisualRefreshCommand) ModernNatTableThemeConfiguration(org.eclipse.nebula.widgets.nattable.style.theme.ModernNatTableThemeConfiguration) DefaultNatTableThemeConfiguration(org.eclipse.nebula.widgets.nattable.style.theme.DefaultNatTableThemeConfiguration) ThemeConfiguration(org.eclipse.nebula.widgets.nattable.style.theme.ThemeConfiguration) DarkNatTableThemeConfiguration(org.eclipse.nebula.widgets.nattable.style.theme.DarkNatTableThemeConfiguration) ModernNatTableThemeConfiguration(org.eclipse.nebula.widgets.nattable.style.theme.ModernNatTableThemeConfiguration) Composite(org.eclipse.swt.widgets.Composite) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DefaultNatTableThemeConfiguration(org.eclipse.nebula.widgets.nattable.style.theme.DefaultNatTableThemeConfiguration) FixedSummaryRowLayer(org.eclipse.nebula.widgets.nattable.summaryrow.FixedSummaryRowLayer) 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) SingleClickSortConfiguration(org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) AbstractHeaderMenuConfiguration(org.eclipse.nebula.widgets.nattable.ui.menu.AbstractHeaderMenuConfiguration) 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) ModernGroupByThemeExtension(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.ModernGroupByThemeExtension)

Example 2 with TreeLayerExpandCollapseKeyBindings

use of org.eclipse.nebula.widgets.nattable.tree.config.TreeLayerExpandCollapseKeyBindings 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 3 with TreeLayerExpandCollapseKeyBindings

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

the class _6044_HierarchicalTreeLayerGridExample 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");
    ConfigRegistry configRegistry = new ConfigRegistry();
    BodyLayerStack bodyLayerStack = new BodyLayerStack(CarService.getInput(), CarService.PROPERTY_NAMES);
    // create the column header layer stack
    IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(CarService.PROPERTY_NAMES, propertyToLabelMap);
    DataLayer columnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
    ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, bodyLayerStack, bodyLayerStack.getSelectionLayer());
    // add the SortHeaderLayer to the column header layer stack
    final SortHeaderLayer<HierarchicalWrapper> sortHeaderLayer = new SortHeaderLayer<>(columnHeaderLayer, new HierarchicalWrapperSortModel(bodyLayerStack.getSortedList(), bodyLayerStack.getColumnPropertyAccessor(), bodyLayerStack.getTreeLayer().getLevelIndexMapping(), columnHeaderDataLayer, configRegistry), false);
    // 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, sortHeaderLayer);
    // create the grid layer composed with the prior created layer stacks
    GridLayer gridLayer = new GridLayer(bodyLayerStack, sortHeaderLayer, rowHeaderLayer, cornerLayer);
    NatTable natTable = new NatTable(parent, gridLayer, false);
    natTable.setConfigRegistry(configRegistry);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration() {

        {
            this.vAlign = VerticalAlignmentEnum.TOP;
            this.hAlign = HorizontalAlignmentEnum.LEFT;
            this.cellPainter = new PaddingDecorator(new TextPainter(), 2);
        }
    });
    // adds the key bindings that allows pressing space bar to
    // expand/collapse tree nodes
    natTable.addConfiguration(new TreeLayerExpandCollapseKeyBindings(bodyLayerStack.getTreeLayer(), bodyLayerStack.getSelectionLayer()));
    // add sorting configuration
    natTable.addConfiguration(new SingleClickSortConfiguration());
    natTable.configure();
    return natTable;
}
Also used : HierarchicalWrapper(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalWrapper) HashMap(java.util.HashMap) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) 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) SpanningDataLayer(org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) TreeLayerExpandCollapseKeyBindings(org.eclipse.nebula.widgets.nattable.tree.config.TreeLayerExpandCollapseKeyBindings) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) SortHeaderLayer(org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer) PaddingDecorator(org.eclipse.nebula.widgets.nattable.painter.cell.decorator.PaddingDecorator) TextPainter(org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) HierarchicalWrapperSortModel(org.eclipse.nebula.widgets.nattable.extension.glazedlists.hierarchical.HierarchicalWrapperSortModel) RowHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer) 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) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)

Example 4 with TreeLayerExpandCollapseKeyBindings

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

the class _6045_HierarchicalTreeLayerExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    container.setLayout(new GridLayout());
    // 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");
    ConfigRegistry configRegistry = new ConfigRegistry();
    BodyLayerStack bodyLayerStack = new BodyLayerStack(CarService.getInput(), CarService.PROPERTY_NAMES);
    // create the column header layer stack
    IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(CarService.PROPERTY_NAMES, propertyToLabelMap);
    DataLayer columnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
    ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, bodyLayerStack, bodyLayerStack.getSelectionLayer());
    // add the SortHeaderLayer to the column header layer stack
    final SortHeaderLayer<HierarchicalWrapper> sortHeaderLayer = new SortHeaderLayer<>(columnHeaderLayer, new HierarchicalWrapperSortModel(bodyLayerStack.getSortedList(), bodyLayerStack.getColumnPropertyAccessor(), bodyLayerStack.getTreeLayer().getLevelIndexMapping(), columnHeaderDataLayer, configRegistry), false);
    // add the filter row functionality
    final FilterRowHeaderComposite<HierarchicalWrapper> filterRowHeaderLayer = new FilterRowHeaderComposite<>(new DefaultGlazedListsFilterStrategy<>(bodyLayerStack.getFilterList(), bodyLayerStack.getColumnPropertyAccessor(), configRegistry), sortHeaderLayer, columnHeaderDataLayer.getDataProvider(), configRegistry);
    filterRowHeaderLayer.addConfigLabelAccumulatorForRegion(GridRegion.FILTER_ROW, new IConfigLabelAccumulator() {

        @Override
        public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
            int columnIndex = filterRowHeaderLayer.getColumnIndexByPosition(columnPosition);
            // header column
            if (columnIndex < 0) {
                configLabels.addLabelOnTop(HierarchicalTreeLayer.LEVEL_HEADER_CELL);
            }
        }
    });
    // create the composite layer composed with the prior created layer
    // stacks
    CompositeLayer compositeLayer = new CompositeLayer(1, 2);
    compositeLayer.setChildLayer(GridRegion.COLUMN_HEADER, filterRowHeaderLayer, 0, 0);
    compositeLayer.setChildLayer(GridRegion.BODY, bodyLayerStack, 0, 1);
    compositeLayer.addConfiguration(new DefaultGridLayerConfiguration(compositeLayer) {

        @Override
        protected void addAlternateRowColoringConfig(CompositeLayer gridLayer) {
        // do nothing to avoid the default grid alternate row coloring
        // needed because the alternate row coloring in the hierarchical
        // tree
        // is based on the spanned cells and not per individual row
        // position
        }
    });
    NatTable natTable = new NatTable(container, compositeLayer, false);
    natTable.setConfigRegistry(configRegistry);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration() {

        {
            this.vAlign = VerticalAlignmentEnum.TOP;
            this.hAlign = HorizontalAlignmentEnum.LEFT;
            this.cellPainter = new PaddingDecorator(new TextPainter(), 2);
        }
    });
    // add editing configuration
    natTable.addConfiguration(new AbstractRegistryConfiguration() {

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            // make identifier editable
            configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, EditableRule.ALWAYS_EDITABLE, DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 2);
            // make capacity unit editable
            configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, EditableRule.ALWAYS_EDITABLE, DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 4);
            configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new ComboBoxCellEditor("KW", "PS"), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 4);
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new PaddingDecorator(new ComboBoxPainter(), 2), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 4);
            // make comment editable
            configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, EditableRule.ALWAYS_EDITABLE, DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 8);
        }
    });
    // adds the key bindings that allows pressing space bar to
    // expand/collapse tree nodes
    natTable.addConfiguration(new TreeLayerExpandCollapseKeyBindings(bodyLayerStack.getTreeLayer(), bodyLayerStack.getSelectionLayer()));
    // add sorting configuration
    natTable.addConfiguration(new SingleClickSortConfiguration());
    // add some additional filter configuration
    natTable.addConfiguration(new AbstractRegistryConfiguration() {

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            Style style = new Style();
            style.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, GUIHelper.getColor(173, 216, 230));
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.NORMAL, GridRegion.FILTER_ROW);
        }
    });
    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());
        }
    });
    Button expandAllFirstLevelButton = new Button(buttonPanel, SWT.PUSH);
    expandAllFirstLevelButton.setText("Expand All First Level");
    expandAllFirstLevelButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            natTable.doCommand(new TreeExpandToLevelCommand(0));
        }
    });
    Button toggleExpandButton = new Button(buttonPanel, SWT.PUSH);
    toggleExpandButton.setText("Enable Advanced Expand");
    toggleExpandButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            _6045_HierarchicalTreeLayerExample.this.advancedExpandEnabled = !_6045_HierarchicalTreeLayerExample.this.advancedExpandEnabled;
            if (_6045_HierarchicalTreeLayerExample.this.advancedExpandEnabled) {
                toggleExpandButton.setText("Disable Advanced Expand");
                // configure advanced action
                natTable.getUiBindingRegistry().registerFirstSingleClickBinding(_6045_HierarchicalTreeLayerExample.this.treeImagePainterMouseEventMatcher, _6045_HierarchicalTreeLayerExample.this.advancedTreeExpandCollapseAction);
            } else {
                toggleExpandButton.setText("Enable Advanced Expand");
                // configure simple action
                natTable.getUiBindingRegistry().registerFirstSingleClickBinding(_6045_HierarchicalTreeLayerExample.this.treeImagePainterMouseEventMatcher, _6045_HierarchicalTreeLayerExample.this.simpleTreeExpandCollapseAction);
            }
        }
    });
    Button multiReorderButton = new Button(buttonPanel, SWT.PUSH);
    multiReorderButton.setText("Reorder Second Level");
    multiReorderButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            List<Integer> fromColumnPositions = Arrays.asList(4, 5);
            natTable.doCommand(new MultiColumnReorderCommand(natTable, fromColumnPositions, 8));
        }
    });
    Button deleteButton = new Button(buttonPanel, SWT.PUSH);
    deleteButton.setText("Delete Row 4");
    deleteButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // remove the element
            HierarchicalWrapper rowObject = bodyLayerStack.getFilterList().remove(3);
            // fire the event to refresh
            bodyLayerStack.getBodyDataLayer().fireLayerEvent(new RowDeleteEvent(bodyLayerStack.getBodyDataLayer(), 3));
            bodyLayerStack.getTreeLayer().cleanupRetainedCollapsedNodes(rowObject);
        }
    });
    return container;
}
Also used : HierarchicalWrapper(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalWrapper) LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack) HashMap(java.util.HashMap) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) MultiColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.MultiColumnReorderCommand) AbstractRegistryConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration) IConfigLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.IConfigLabelAccumulator) 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) SpanningDataLayer(org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) TreeCollapseAllCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeCollapseAllCommand) TreeExpandToLevelCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandToLevelCommand) Button(org.eclipse.swt.widgets.Button) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) TreeLayerExpandCollapseKeyBindings(org.eclipse.nebula.widgets.nattable.tree.config.TreeLayerExpandCollapseKeyBindings) RowLayout(org.eclipse.swt.layout.RowLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Style(org.eclipse.nebula.widgets.nattable.style.Style) RowDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) SortedList(ca.odell.glazedlists.SortedList) TransformedList(ca.odell.glazedlists.TransformedList) List(java.util.List) EventList(ca.odell.glazedlists.EventList) FilterList(ca.odell.glazedlists.FilterList) FilterRowHeaderComposite(org.eclipse.nebula.widgets.nattable.filterrow.FilterRowHeaderComposite) Composite(org.eclipse.swt.widgets.Composite) FilterRowHeaderComposite(org.eclipse.nebula.widgets.nattable.filterrow.FilterRowHeaderComposite) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) ComboBoxPainter(org.eclipse.nebula.widgets.nattable.painter.cell.ComboBoxPainter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SortHeaderLayer(org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer) PaddingDecorator(org.eclipse.nebula.widgets.nattable.painter.cell.decorator.PaddingDecorator) ComboBoxCellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.ComboBoxCellEditor) TextPainter(org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter) CompositeLayer(org.eclipse.nebula.widgets.nattable.layer.CompositeLayer) HierarchicalWrapperSortModel(org.eclipse.nebula.widgets.nattable.extension.glazedlists.hierarchical.HierarchicalWrapperSortModel) TreeExpandAllCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandAllCommand) SingleClickSortConfiguration(org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider) DefaultGridLayerConfiguration(org.eclipse.nebula.widgets.nattable.grid.layer.config.DefaultGridLayerConfiguration)

Example 5 with TreeLayerExpandCollapseKeyBindings

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

the class _812_EditableGroupBySummarySummaryRowExample 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
    final ConfigRegistry configRegistry = new ConfigRegistry();
    // property names of the ExtendedPersonWithAddress class
    String[] propertyNames = { "firstName", "lastName", "age", "money", "married", "gender", "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("age", "Age");
    propertyToLabelMap.put("money", "Money");
    propertyToLabelMap.put("married", "Married");
    propertyToLabelMap.put("gender", "Gender");
    propertyToLabelMap.put("birthday", "Birthday");
    final IColumnPropertyAccessor<ExtendedPersonWithAddress> columnPropertyAccessor = new ExtendedReflectiveColumnPropertyAccessor<>(propertyNames);
    // to enable the group by summary feature, the GroupByDataLayer needs to
    // know the ConfigRegistry
    List<ExtendedPersonWithAddress> persons = PersonService.getExtendedPersonsWithAddress(10);
    final BodyLayerStack<ExtendedPersonWithAddress> bodyLayerStack = new BodyLayerStack<>(persons, columnPropertyAccessor, configRegistry);
    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());
    // add sorting
    SortHeaderLayer<ExtendedPersonWithAddress> sortHeaderLayer = new SortHeaderLayer<>(columnHeaderLayer, new GlazedListsSortModel<>(bodyLayerStack.getSortedList(), columnPropertyAccessor, configRegistry, columnHeaderDataLayer), false);
    // connect sortModel to GroupByDataLayer to support sorting by group by
    // summary values
    bodyLayerStack.getBodyDataLayer().initializeTreeComparator(sortHeaderLayer.getSortModel(), bodyLayerStack.getTreeLayer(), true);
    // build the row header layer
    // Adding the specialized DefaultSummaryRowHeaderDataProvider to
    // indicate the summary row in the row header
    IDataProvider rowHeaderDataProvider = new DefaultSummaryRowHeaderDataProvider(bodyLayerStack.getBodyDataProvider(), "\u2211");
    final DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
    // add a label to the row header summary row cell aswell, so it can be
    // styled differently too
    // in this case it will simply use the same styling as the summary row
    // in the body
    rowHeaderDataLayer.setConfigLabelAccumulator(new AbstractOverrider() {

        @Override
        public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
            if ((rowPosition + 1) == rowHeaderDataLayer.getRowCount()) {
                configLabels.addLabel(ROW_HEADER_SUMMARY_ROW);
                configLabels.addLabel(SummaryRowLayer.DEFAULT_SUMMARY_ROW_CONFIG_LABEL);
            }
        }
    });
    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, sortHeaderLayer);
    // build the grid layer
    GridLayer gridLayer = new GridLayer(bodyLayerStack, sortHeaderLayer, rowHeaderLayer, cornerLayer, false);
    // set the group by header on top of the grid
    CompositeLayer compositeGridLayer = new CompositeLayer(1, 2);
    final GroupByHeaderLayer groupByHeaderLayer = new GroupByHeaderLayer(bodyLayerStack.getGroupByModel(), gridLayer, columnHeaderDataProvider);
    compositeGridLayer.setChildLayer(GroupByHeaderLayer.GROUP_BY_REGION, groupByHeaderLayer, 0, 0);
    compositeGridLayer.setChildLayer("Grid", gridLayer, 0, 1);
    // add editing capability
    compositeGridLayer.addConfiguration(new AbstractLayerConfiguration<AbstractLayer>() {

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.ALWAYS_EDITABLE);
            configRegistry.registerConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, new DefaultDataValidator());
            // register matching editors
            configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new TextCellEditor());
            configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new CheckBoxCellEditor(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 4);
            configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new CheckBoxCellEditor(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 5);
            configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new DateCellEditor(), ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 6);
            // register the correct converters
            configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultIntegerDisplayConverter(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 2);
            configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultDoubleDisplayConverter(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 3);
            configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultBooleanDisplayConverter(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 4);
            configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DisplayConverter() {

                @Override
                public Object canonicalToDisplayValue(Object canonicalValue) {
                    if (canonicalValue instanceof Gender) {
                        return ((Gender) canonicalValue) == Gender.MALE;
                    }
                    return null;
                }

                @Override
                public Object displayToCanonicalValue(Object displayValue) {
                    Boolean displayBoolean = Boolean.valueOf(displayValue.toString());
                    return displayBoolean ? Gender.MALE : Gender.FEMALE;
                }
            }, DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 5);
            DateFormat formatter = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault());
            String pattern = ((SimpleDateFormat) formatter).toPattern();
            configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultDateDisplayConverter(pattern), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 6);
        }

        @Override
        public void configureTypedLayer(AbstractLayer layer) {
            layer.registerCommandHandler(new EditCellCommandHandler());
            layer.registerEventHandler(new InlineCellEditEventHandler(layer));
        }
    });
    compositeGridLayer.addConfiguration(new DefaultEditBindings());
    compositeGridLayer.addConfiguration(new DefaultExportBindings());
    compositeGridLayer.addConfiguration(new DefaultPrintBindings());
    // turn the auto configuration off as we want to add our header menu
    // configuration
    final NatTable natTable = new NatTable(container, compositeGridLayer, 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 some additional styling
    natTable.addConfiguration(new AbstractRegistryConfiguration() {

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CheckBoxPainter(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 4);
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CheckBoxPainter(GUIHelper.getImage("arrow_up"), GUIHelper.getImage("arrow_down")), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 5);
            IStyle style = new Style();
            style.setAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT, HorizontalAlignmentEnum.RIGHT);
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 2);
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 3);
            // the main styling of the summary row cell in the row header is
            // done via summary row default style, but we need to override
            // the alignment
            style = new Style();
            style.setAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT, HorizontalAlignmentEnum.CENTER);
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.NORMAL, ROW_HEADER_SUMMARY_ROW);
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.SELECT, ROW_HEADER_SUMMARY_ROW);
        }
    });
    // add sorting configuration
    natTable.addConfiguration(new SingleClickSortConfiguration());
    this.sumMoneyGroupBySummaryProvider = new SummationGroupBySummaryProvider<>(columnPropertyAccessor);
    this.avgMoneyGroupBySummaryProvider = new AverageMoneyGroupBySummaryProvider();
    // create a new IDataProvider that operates on the basic underlying list
    // this is necessary because the IDataProvider in the body layer stack
    // is operating on the TreeList, and on collapsing a node, the children
    // will be not visible, which has effect on the summary value.
    final IDataProvider summaryDataProvider = new ListDataProvider<>(bodyLayerStack.getSortedList(), columnPropertyAccessor);
    this.sumMoneySummaryProvider = new SummationSummaryProvider(summaryDataProvider, false);
    this.avgMoneySummaryProvider = new AverageMoneySummaryProvider(summaryDataProvider);
    // add group by summary configuration
    natTable.addConfiguration(new AbstractRegistryConfiguration() {

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            // GroupBy summary configuration
            configRegistry.registerConfigAttribute(GroupByConfigAttributes.GROUP_BY_SUMMARY_PROVIDER, _812_EditableGroupBySummarySummaryRowExample.this.sumMoneyGroupBySummaryProvider, DisplayMode.NORMAL, GroupByDataLayer.GROUP_BY_COLUMN_PREFIX + 3);
            configRegistry.registerConfigAttribute(GroupByConfigAttributes.GROUP_BY_SUMMARY_PROVIDER, new AverageAgeGroupBySummaryProvider(), DisplayMode.NORMAL, GroupByDataLayer.GROUP_BY_COLUMN_PREFIX + 2);
            configRegistry.registerConfigAttribute(GroupByConfigAttributes.GROUP_BY_CHILD_COUNT_PATTERN, "[{0}] - ({1})");
            // SummaryRow configuration
            configRegistry.registerConfigAttribute(SummaryRowConfigAttributes.SUMMARY_PROVIDER, _812_EditableGroupBySummarySummaryRowExample.this.sumMoneySummaryProvider, DisplayMode.NORMAL, SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX + 3);
            configRegistry.registerConfigAttribute(SummaryRowConfigAttributes.SUMMARY_PROVIDER, new AverageAgeSummaryProvider(summaryDataProvider), DisplayMode.NORMAL, SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX + 2);
            configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new SummaryDisplayConverter(new DefaultDoubleDisplayConverter()), DisplayMode.NORMAL, SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX + 3);
        }
    });
    // add group by header configuration
    natTable.addConfiguration(new GroupByHeaderMenuConfiguration(natTable, groupByHeaderLayer));
    natTable.addConfiguration(new AbstractHeaderMenuConfiguration(natTable) {

        @Override
        protected PopupMenuBuilder createColumnHeaderMenu(NatTable natTable) {
            return super.createColumnHeaderMenu(natTable).withHideColumnMenuItem().withShowAllColumnsMenuItem().withStateManagerMenuItemProvider();
        }

        @Override
        protected PopupMenuBuilder createCornerMenu(NatTable natTable) {
            return super.createCornerMenu(natTable).withShowAllColumnsMenuItem().withStateManagerMenuItemProvider();
        }
    });
    // adds the key bindings that allow space bar to be pressed to
    // expand/collapse tree nodes
    natTable.addConfiguration(new TreeLayerExpandCollapseKeyBindings(bodyLayerStack.getTreeLayer(), bodyLayerStack.getSelectionLayer()));
    natTable.addConfiguration(new TreeDebugMenuConfiguration(natTable));
    natTable.configure();
    // set the modern theme to visualize the summary better
    final ThemeConfiguration defaultTheme = new DefaultNatTableThemeConfiguration();
    defaultTheme.addThemeExtension(new DefaultGroupByThemeExtension());
    final ThemeConfiguration modernTheme = new ModernNatTableThemeConfiguration();
    modernTheme.addThemeExtension(new ModernGroupByThemeExtension());
    final ThemeConfiguration darkTheme = new DarkNatTableThemeConfiguration();
    darkTheme.addThemeExtension(new DarkGroupByThemeExtension());
    natTable.setTheme(modernTheme);
    // add a border on every side of the table
    natTable.addOverlayPainter(new NatTableBorderOverlayPainter());
    natTable.registerCommandHandler(new DisplayPersistenceDialogCommandHandler(natTable));
    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 toggleHeaderButton = new Button(buttonPanel, SWT.PUSH);
    toggleHeaderButton.setText("Toggle Group By Header");
    toggleHeaderButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            groupByHeaderLayer.setVisible(!groupByHeaderLayer.isVisible());
        }
    });
    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());
        }
    });
    Button toggleMoneySummaryButton = new Button(buttonPanel, SWT.PUSH);
    toggleMoneySummaryButton.setText("Toggle Money Group Summary (SUM/AVG)");
    toggleMoneySummaryButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // clear the group by summary cache so the new summary
            // calculation gets triggered
            bodyLayerStack.getBodyDataLayer().clearCache();
            _812_EditableGroupBySummarySummaryRowExample.this.useMoneySum = !_812_EditableGroupBySummarySummaryRowExample.this.useMoneySum;
            if (_812_EditableGroupBySummarySummaryRowExample.this.useMoneySum) {
                configRegistry.registerConfigAttribute(GroupByConfigAttributes.GROUP_BY_SUMMARY_PROVIDER, _812_EditableGroupBySummarySummaryRowExample.this.sumMoneyGroupBySummaryProvider, DisplayMode.NORMAL, GroupByDataLayer.GROUP_BY_COLUMN_PREFIX + 3);
                configRegistry.registerConfigAttribute(SummaryRowConfigAttributes.SUMMARY_PROVIDER, _812_EditableGroupBySummarySummaryRowExample.this.sumMoneySummaryProvider, DisplayMode.NORMAL, SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX + 3);
            } else {
                configRegistry.registerConfigAttribute(GroupByConfigAttributes.GROUP_BY_SUMMARY_PROVIDER, _812_EditableGroupBySummarySummaryRowExample.this.avgMoneyGroupBySummaryProvider, DisplayMode.NORMAL, GroupByDataLayer.GROUP_BY_COLUMN_PREFIX + 3);
                configRegistry.registerConfigAttribute(SummaryRowConfigAttributes.SUMMARY_PROVIDER, _812_EditableGroupBySummarySummaryRowExample.this.avgMoneySummaryProvider, DisplayMode.NORMAL, SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX + 3);
            }
            natTable.doCommand(new VisualRefreshCommand());
        }
    });
    Button toggleThemeButton = new Button(buttonPanel, SWT.PUSH);
    toggleThemeButton.setText("Toggle Theme");
    toggleThemeButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (_812_EditableGroupBySummarySummaryRowExample.this.currentTheme == 0) {
                natTable.setTheme(modernTheme);
                _812_EditableGroupBySummarySummaryRowExample.this.currentTheme++;
            } else if (_812_EditableGroupBySummarySummaryRowExample.this.currentTheme == 1) {
                natTable.setTheme(darkTheme);
                _812_EditableGroupBySummarySummaryRowExample.this.currentTheme++;
            } else if (_812_EditableGroupBySummarySummaryRowExample.this.currentTheme == 2) {
                natTable.setTheme(defaultTheme);
                _812_EditableGroupBySummarySummaryRowExample.this.currentTheme = 0;
            }
        }
    });
    Button button = new Button(buttonPanel, SWT.PUSH);
    button.setText("Add Row");
    button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            bodyLayerStack.getSortedList().add(PersonService.createExtendedPersonWithAddress(bodyLayerStack.getSortedList().size()));
        }
    });
    @SuppressWarnings("unchecked") final RowSelectionProvider<ExtendedPersonWithAddress> provider = new RowSelectionProvider<>(bodyLayerStack.selectionLayer, (IRowDataProvider<ExtendedPersonWithAddress>) bodyLayerStack.bodyDataProvider);
    Button updateButton = new Button(buttonPanel, SWT.PUSH);
    updateButton.setText("Update Row");
    updateButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            IStructuredSelection selection = (IStructuredSelection) provider.getSelection();
            @SuppressWarnings("rawtypes") Iterator it = selection.iterator();
            while (it.hasNext()) {
                ExtendedPersonWithAddress selected = (ExtendedPersonWithAddress) it.next();
                int index = bodyLayerStack.getSortedList().indexOf(selected);
                selected.setLastName("Simpson");
                bodyLayerStack.getSortedList().set(index, selected);
            }
        }
    });
    return container;
}
Also used : SummaryDisplayConverter(org.eclipse.nebula.widgets.nattable.summaryrow.SummaryDisplayConverter) ExtendedPersonWithAddress(org.eclipse.nebula.widgets.nattable.dataset.person.ExtendedPersonWithAddress) DefaultPrintBindings(org.eclipse.nebula.widgets.nattable.print.config.DefaultPrintBindings) DefaultGroupByThemeExtension(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.DefaultGroupByThemeExtension) DefaultExportBindings(org.eclipse.nebula.widgets.nattable.export.config.DefaultExportBindings) EditCellCommandHandler(org.eclipse.nebula.widgets.nattable.edit.command.EditCellCommandHandler) Gender(org.eclipse.nebula.widgets.nattable.dataset.person.Person.Gender) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DefaultIntegerDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.DefaultIntegerDisplayConverter) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) GroupByDataLayer(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByDataLayer) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) Button(org.eclipse.swt.widgets.Button) AbstractOverrider(org.eclipse.nebula.widgets.nattable.layer.cell.AbstractOverrider) DarkGroupByThemeExtension(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.DarkGroupByThemeExtension) SortHeaderLayer(org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer) SummationSummaryProvider(org.eclipse.nebula.widgets.nattable.summaryrow.SummationSummaryProvider) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) AbstractLayer(org.eclipse.nebula.widgets.nattable.layer.AbstractLayer) DefaultDateDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.DefaultDateDisplayConverter) GroupByHeaderMenuConfiguration(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByHeaderMenuConfiguration) DefaultEditBindings(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings) GridLayout(org.eclipse.swt.layout.GridLayout) CheckBoxPainter(org.eclipse.nebula.widgets.nattable.painter.cell.CheckBoxPainter) RowLayout(org.eclipse.swt.layout.RowLayout) IStyle(org.eclipse.nebula.widgets.nattable.style.IStyle) Style(org.eclipse.nebula.widgets.nattable.style.Style) Composite(org.eclipse.swt.widgets.Composite) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) DefaultDataValidator(org.eclipse.nebula.widgets.nattable.data.validate.DefaultDataValidator) RowSelectionProvider(org.eclipse.nebula.widgets.nattable.selection.RowSelectionProvider) CornerLayer(org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) PopupMenuBuilder(org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder) HashMap(java.util.HashMap) SummaryDisplayConverter(org.eclipse.nebula.widgets.nattable.summaryrow.SummaryDisplayConverter) DefaultDoubleDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.DefaultDoubleDisplayConverter) DisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.DisplayConverter) DefaultIntegerDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.DefaultIntegerDisplayConverter) DefaultDateDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.DefaultDateDisplayConverter) DefaultBooleanDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.DefaultBooleanDisplayConverter) AbstractRegistryConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration) CheckBoxCellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.CheckBoxCellEditor) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) DarkNatTableThemeConfiguration(org.eclipse.nebula.widgets.nattable.style.theme.DarkNatTableThemeConfiguration) TreeCollapseAllCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeCollapseAllCommand) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) SelectionEvent(org.eclipse.swt.events.SelectionEvent) NatTableBorderOverlayPainter(org.eclipse.nebula.widgets.nattable.painter.NatTableBorderOverlayPainter) GroupByHeaderLayer(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByHeaderLayer) DefaultBooleanDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.DefaultBooleanDisplayConverter) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) CompositeLayer(org.eclipse.nebula.widgets.nattable.layer.CompositeLayer) IStyle(org.eclipse.nebula.widgets.nattable.style.IStyle) TextCellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.TextCellEditor) ColumnLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnLabelAccumulator) InlineCellEditEventHandler(org.eclipse.nebula.widgets.nattable.edit.event.InlineCellEditEventHandler) ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) DefaultSummaryRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultSummaryRowHeaderDataProvider) LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) DateCellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.DateCellEditor) DefaultDoubleDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.DefaultDoubleDisplayConverter) DisplayPersistenceDialogCommandHandler(org.eclipse.nebula.widgets.nattable.persistence.command.DisplayPersistenceDialogCommandHandler) ExtendedReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ExtendedReflectiveColumnPropertyAccessor) TreeLayerExpandCollapseKeyBindings(org.eclipse.nebula.widgets.nattable.tree.config.TreeLayerExpandCollapseKeyBindings) Iterator(java.util.Iterator) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) VisualRefreshCommand(org.eclipse.nebula.widgets.nattable.command.VisualRefreshCommand) ModernNatTableThemeConfiguration(org.eclipse.nebula.widgets.nattable.style.theme.ModernNatTableThemeConfiguration) DefaultNatTableThemeConfiguration(org.eclipse.nebula.widgets.nattable.style.theme.DefaultNatTableThemeConfiguration) ThemeConfiguration(org.eclipse.nebula.widgets.nattable.style.theme.ThemeConfiguration) DarkNatTableThemeConfiguration(org.eclipse.nebula.widgets.nattable.style.theme.DarkNatTableThemeConfiguration) ModernNatTableThemeConfiguration(org.eclipse.nebula.widgets.nattable.style.theme.ModernNatTableThemeConfiguration) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DefaultNatTableThemeConfiguration(org.eclipse.nebula.widgets.nattable.style.theme.DefaultNatTableThemeConfiguration) RowHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer) TreeExpandAllCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandAllCommand) SingleClickSortConfiguration(org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration) AbstractHeaderMenuConfiguration(org.eclipse.nebula.widgets.nattable.ui.menu.AbstractHeaderMenuConfiguration) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider) ModernGroupByThemeExtension(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.ModernGroupByThemeExtension)

Aggregations

HashMap (java.util.HashMap)6 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)6 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)6 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)6 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)6 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)6 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)6 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)6 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)6 AbstractRegistryConfiguration (org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration)5 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)5 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)5 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)5 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)5 RowHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer)5 SortHeaderLayer (org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer)5 SingleClickSortConfiguration (org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration)5 DefaultColumnHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer)4 DefaultRowHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer)4 CompositeLayer (org.eclipse.nebula.widgets.nattable.layer.CompositeLayer)4