Search in sources :

Example 1 with IMenuItemProvider

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

the class ColumnGroupMenuItemProviders method removeColumnGroupMenuItemProvider.

public static IMenuItemProvider removeColumnGroupMenuItemProvider(final String menuLabel) {
    return new IMenuItemProvider() {

        @Override
        public void addMenuItem(final NatTable natTable, final Menu popupMenu) {
            MenuItem columnStyleEditor = new MenuItem(popupMenu, SWT.PUSH);
            columnStyleEditor.setText(menuLabel);
            columnStyleEditor.setEnabled(true);
            columnStyleEditor.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    NatEventData natEventData = MenuItemProviders.getNatEventData(e);
                    int columnPosition = natEventData.getColumnPosition();
                    int columnIndex = natEventData.getNatTable().getColumnIndexByPosition(columnPosition);
                    natTable.doCommand(new RemoveColumnGroupCommand(columnIndex));
                }
            });
        }
    };
}
Also used : RemoveColumnGroupCommand(org.eclipse.nebula.widgets.nattable.group.command.RemoveColumnGroupCommand) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) IMenuItemProvider(org.eclipse.nebula.widgets.nattable.ui.menu.IMenuItemProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) MenuItem(org.eclipse.swt.widgets.MenuItem) NatEventData(org.eclipse.nebula.widgets.nattable.ui.NatEventData) Menu(org.eclipse.swt.widgets.Menu)

Example 2 with IMenuItemProvider

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

the class _5016_DataChangeLayerExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    // property names of the Person class
    String[] propertyNames = { "firstName", "lastName", "gender", "married", "birthday" };
    // mapping from property to label, needed for column header labels
    Map<String, String> propertyToLabelMap = new HashMap<>();
    propertyToLabelMap.put("firstName", "Firstname");
    propertyToLabelMap.put("lastName", "Lastname");
    propertyToLabelMap.put("gender", "Gender");
    propertyToLabelMap.put("married", "Married");
    propertyToLabelMap.put("birthday", "Birthday");
    IColumnPropertyAccessor<Person> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
    final List<Person> data = PersonService.getPersons(10);
    // create the body layer stack
    IDataProvider bodyDataProvider = new ListDataProvider<>(data, columnPropertyAccessor);
    DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
    final ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
    bodyDataLayer.setConfigLabelAccumulator(columnLabelAccumulator);
    registerColumnLabels(columnLabelAccumulator);
    // add a DataChangeLayer that tracks data changes but directly updates
    // the underlying data model
    DataChangeLayer dataChangeLayer = new DataChangeLayer(bodyDataLayer, new PointKeyHandler(), false);
    // we register a special command handler to perform custom changes on
    // save
    dataChangeLayer.registerCommandHandler(new SaveDataChangesCommandHandler(dataChangeLayer) {

        @Override
        public boolean doCommand(ILayer targetLayer, SaveDataChangesCommand command) {
            if (MessageDialog.openQuestion(parent.getShell(), "Save data", "Do you really want to save to database?")) {
                // you would implement the storage to database here
                System.out.println("We save the data to the database");
                return super.doCommand(targetLayer, command);
            }
            return true;
        }
    });
    ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(dataChangeLayer);
    ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(columnReorderLayer);
    SelectionLayer selectionLayer = new SelectionLayer(columnHideShowLayer);
    ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
    // create the column header layer stack
    IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
    ILayer columnHeaderLayer = new ColumnHeaderLayer(new DataLayer(columnHeaderDataProvider), viewportLayer, selectionLayer);
    // create the row header layer stack
    IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
    ILayer rowHeaderLayer = new RowHeaderLayer(new DataLayer(rowHeaderDataProvider, 40, 20), viewportLayer, selectionLayer);
    // 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(viewportLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
    NatTable natTable = new NatTable(parent, gridLayer, false);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.addConfiguration(new EditorConfiguration());
    natTable.addConfiguration(new HeaderMenuConfiguration(natTable) {

        @Override
        protected PopupMenuBuilder createCornerMenu(NatTable natTable) {
            return super.createCornerMenu(natTable).withMenuItemProvider(new IMenuItemProvider() {

                @Override
                public void addMenuItem(NatTable natTable, Menu popupMenu) {
                    MenuItem export = new MenuItem(popupMenu, SWT.PUSH);
                    export.setText("Discard changes");
                    export.setEnabled(true);
                    export.addSelectionListener(new SelectionAdapter() {

                        @Override
                        public void widgetSelected(SelectionEvent e) {
                            natTable.doCommand(new DiscardDataChangesCommand());
                        }
                    });
                }
            }).withMenuItemProvider(new IMenuItemProvider() {

                @Override
                public void addMenuItem(NatTable natTable, Menu popupMenu) {
                    MenuItem export = new MenuItem(popupMenu, SWT.PUSH);
                    export.setText("Save changes");
                    export.setEnabled(true);
                    export.addSelectionListener(new SelectionAdapter() {

                        @Override
                        public void widgetSelected(SelectionEvent e) {
                            natTable.doCommand(new SaveDataChangesCommand());
                        }
                    });
                }
            });
        }
    });
    natTable.configure();
    return natTable;
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) HashMap(java.util.HashMap) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) HeaderMenuConfiguration(org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration) ColumnHideShowLayer(org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) SelectionEvent(org.eclipse.swt.events.SelectionEvent) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) Menu(org.eclipse.swt.widgets.Menu) ColumnOverrideLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator) PointKeyHandler(org.eclipse.nebula.widgets.nattable.datachange.PointKeyHandler) DiscardDataChangesCommand(org.eclipse.nebula.widgets.nattable.datachange.command.DiscardDataChangesCommand) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SaveDataChangesCommand(org.eclipse.nebula.widgets.nattable.datachange.command.SaveDataChangesCommand) ColumnReorderLayer(org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer) MenuItem(org.eclipse.swt.widgets.MenuItem) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) SaveDataChangesCommandHandler(org.eclipse.nebula.widgets.nattable.datachange.command.SaveDataChangesCommandHandler) ReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor) DataChangeLayer(org.eclipse.nebula.widgets.nattable.datachange.DataChangeLayer) RowHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer) CornerLayer(org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) IMenuItemProvider(org.eclipse.nebula.widgets.nattable.ui.menu.IMenuItemProvider) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider) PopupMenuBuilder(org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder) Person(org.eclipse.nebula.widgets.nattable.dataset.person.Person)

Example 3 with IMenuItemProvider

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

the class _5017_DataChangeLayerTempStorageExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    // property names of the Person class
    String[] propertyNames = { "firstName", "lastName", "gender", "married", "birthday" };
    // mapping from property to label, needed for column header labels
    Map<String, String> propertyToLabelMap = new HashMap<>();
    propertyToLabelMap.put("firstName", "Firstname");
    propertyToLabelMap.put("lastName", "Lastname");
    propertyToLabelMap.put("gender", "Gender");
    propertyToLabelMap.put("married", "Married");
    propertyToLabelMap.put("birthday", "Birthday");
    IColumnPropertyAccessor<Person> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
    final List<Person> data = PersonService.getPersons(10);
    // create the body layer stack
    IDataProvider bodyDataProvider = new ListDataProvider<>(data, columnPropertyAccessor);
    DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
    final ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
    bodyDataLayer.setConfigLabelAccumulator(columnLabelAccumulator);
    registerColumnLabels(columnLabelAccumulator);
    // add a DataChangeLayer that tracks data changes but directly updates
    // the underlying data model
    DataChangeLayer dataChangeLayer = new DataChangeLayer(bodyDataLayer, new PointKeyHandler(), true);
    ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(dataChangeLayer);
    ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(columnReorderLayer);
    SelectionLayer selectionLayer = new SelectionLayer(columnHideShowLayer);
    ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
    // create the column header layer stack
    IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
    ILayer columnHeaderLayer = new ColumnHeaderLayer(new DataLayer(columnHeaderDataProvider), viewportLayer, selectionLayer);
    // create the row header layer stack
    IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
    ILayer rowHeaderLayer = new RowHeaderLayer(new DataLayer(rowHeaderDataProvider, 40, 20), viewportLayer, selectionLayer);
    // 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(viewportLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
    NatTable natTable = new NatTable(parent, gridLayer, false);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.addConfiguration(new EditorConfiguration());
    natTable.addConfiguration(new HeaderMenuConfiguration(natTable) {

        @Override
        protected PopupMenuBuilder createCornerMenu(NatTable natTable) {
            return super.createCornerMenu(natTable).withMenuItemProvider(new IMenuItemProvider() {

                @Override
                public void addMenuItem(NatTable natTable, Menu popupMenu) {
                    MenuItem export = new MenuItem(popupMenu, SWT.PUSH);
                    export.setText("Discard changes");
                    export.setEnabled(true);
                    export.addSelectionListener(new SelectionAdapter() {

                        @Override
                        public void widgetSelected(SelectionEvent e) {
                            natTable.doCommand(new DiscardDataChangesCommand());
                        }
                    });
                }
            }).withMenuItemProvider(new IMenuItemProvider() {

                @Override
                public void addMenuItem(NatTable natTable, Menu popupMenu) {
                    MenuItem export = new MenuItem(popupMenu, SWT.PUSH);
                    export.setText("Save changes");
                    export.setEnabled(true);
                    export.addSelectionListener(new SelectionAdapter() {

                        @Override
                        public void widgetSelected(SelectionEvent e) {
                            natTable.doCommand(new SaveDataChangesCommand());
                        }
                    });
                }
            });
        }
    });
    natTable.configure();
    return natTable;
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) HashMap(java.util.HashMap) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) HeaderMenuConfiguration(org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration) ColumnHideShowLayer(org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) SelectionEvent(org.eclipse.swt.events.SelectionEvent) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) Menu(org.eclipse.swt.widgets.Menu) ColumnOverrideLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator) PointKeyHandler(org.eclipse.nebula.widgets.nattable.datachange.PointKeyHandler) DiscardDataChangesCommand(org.eclipse.nebula.widgets.nattable.datachange.command.DiscardDataChangesCommand) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SaveDataChangesCommand(org.eclipse.nebula.widgets.nattable.datachange.command.SaveDataChangesCommand) ColumnReorderLayer(org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer) MenuItem(org.eclipse.swt.widgets.MenuItem) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) ReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor) DataChangeLayer(org.eclipse.nebula.widgets.nattable.datachange.DataChangeLayer) RowHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer) CornerLayer(org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) IMenuItemProvider(org.eclipse.nebula.widgets.nattable.ui.menu.IMenuItemProvider) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider) PopupMenuBuilder(org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder) Person(org.eclipse.nebula.widgets.nattable.dataset.person.Person)

Example 4 with IMenuItemProvider

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

the class _814_EditableSortableGroupByWithFilterExample 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
    final BodyLayerStack<ExtendedPersonWithAddress> bodyLayerStack = new BodyLayerStack<>(PersonService.getExtendedPersonsWithAddress(20), columnPropertyAccessor, new IRowIdAccessor<ExtendedPersonWithAddress>() {

        @Override
        public Serializable getRowId(ExtendedPersonWithAddress rowObject) {
            return rowObject.getId();
        }
    }, configRegistry, (rowObject, columnIndex) -> {
        System.out.println("Save person with ID " + rowObject.getId() + " changing property " + columnPropertyAccessor.getColumnProperty(columnIndex) + " to " + columnPropertyAccessor.getDataValue(rowObject, columnIndex));
    });
    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);
    // add the filter row functionality
    final FilterRowHeaderComposite<ExtendedPersonWithAddress> filterRowHeaderLayer = new FilterRowHeaderComposite<>(new DefaultGlazedListsFilterStrategy<>(bodyLayerStack.getFilterList(), columnPropertyAccessor, configRegistry), sortHeaderLayer, columnHeaderDataLayer.getDataProvider(), configRegistry);
    // build the row header layer
    IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyLayerStack.getBodyDataProvider());
    DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
    ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, bodyLayerStack, bodyLayerStack.getSelectionLayer());
    // build the corner layer
    IDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider);
    DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
    ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, filterRowHeaderLayer);
    // build the grid layer
    GridLayer gridLayer = new GridLayer(bodyLayerStack, filterRowHeaderLayer, rowHeaderLayer, cornerLayer, 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());
    // 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);
            configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultDoubleDisplayConverter(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 3);
        }
    });
    // add sorting configuration
    natTable.addConfiguration(new SingleClickSortConfiguration());
    this.sumMoneySummaryProvider = new SummationGroupBySummaryProvider<>(columnPropertyAccessor);
    this.avgMoneySummaryProvider = new AverageMoneyGroupBySummaryProvider();
    // add group by summary configuration
    natTable.addConfiguration(new AbstractRegistryConfiguration() {

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            configRegistry.registerConfigAttribute(GroupByConfigAttributes.GROUP_BY_SUMMARY_PROVIDER, _814_EditableSortableGroupByWithFilterExample.this.sumMoneySummaryProvider, 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})");
            configRegistry.registerConfigAttribute(GroupByConfigAttributes.GROUP_BY_HINT, "Drag columns here");
            Style hintStyle = new Style();
            hintStyle.setAttributeValue(CellStyleAttributes.FONT, GUIHelper.getFont(new FontData("Arial", 10, SWT.ITALIC)));
            configRegistry.registerConfigAttribute(GroupByConfigAttributes.GROUP_BY_HINT_STYLE, hintStyle);
        }
    });
    // 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().withMenuItemProvider(new IMenuItemProvider() {

                @Override
                public void addMenuItem(NatTable natTable, Menu popupMenu) {
                    MenuItem export = new MenuItem(popupMenu, SWT.PUSH);
                    export.setText("Discard changes");
                    export.setEnabled(true);
                    export.addSelectionListener(new SelectionAdapter() {

                        @Override
                        public void widgetSelected(SelectionEvent e) {
                            natTable.doCommand(new DiscardDataChangesCommand());
                        }
                    });
                }
            }).withMenuItemProvider(new IMenuItemProvider() {

                @Override
                public void addMenuItem(NatTable natTable, Menu popupMenu) {
                    MenuItem export = new MenuItem(popupMenu, SWT.PUSH);
                    export.setText("Save changes");
                    export.setEnabled(true);
                    export.addSelectionListener(new SelectionAdapter() {

                        @Override
                        public void widgetSelected(SelectionEvent e) {
                            natTable.doCommand(new SaveDataChangesCommand());
                        }
                    });
                }
            });
        }
    });
    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);
    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 toggleFilterButton = new Button(buttonPanel, SWT.PUSH);
    toggleFilterButton.setText("Toggle Filter Row");
    toggleFilterButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            filterRowHeaderLayer.setFilterRowVisible(!filterRowHeaderLayer.isFilterRowVisible());
        }
    });
    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();
            _814_EditableSortableGroupByWithFilterExample.this.useMoneySum = !_814_EditableSortableGroupByWithFilterExample.this.useMoneySum;
            if (_814_EditableSortableGroupByWithFilterExample.this.useMoneySum) {
                configRegistry.registerConfigAttribute(GroupByConfigAttributes.GROUP_BY_SUMMARY_PROVIDER, _814_EditableSortableGroupByWithFilterExample.this.sumMoneySummaryProvider, DisplayMode.NORMAL, GroupByDataLayer.GROUP_BY_COLUMN_PREFIX + 3);
            } else {
                configRegistry.registerConfigAttribute(GroupByConfigAttributes.GROUP_BY_SUMMARY_PROVIDER, _814_EditableSortableGroupByWithFilterExample.this.avgMoneySummaryProvider, DisplayMode.NORMAL, GroupByDataLayer.GROUP_BY_COLUMN_PREFIX + 3);
            }
            natTable.doCommand(new VisualRefreshCommand());
        }
    });
    // this button adds data to the grid
    // try to group by last name, sort by last name desc and then add
    // dynamic data for verification
    Button addDynamicDataButton = new Button(buttonPanel, SWT.PUSH);
    addDynamicDataButton.setText("Add Data");
    addDynamicDataButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            Address address = new Address();
            address.setStreet("Some Street");
            address.setHousenumber(42);
            address.setPostalCode(12345);
            address.setCity("In the clouds");
            Person person = new Person(42, "Ralph", "Wiggum", Gender.MALE, false, new Date());
            ExtendedPersonWithAddress entry = new ExtendedPersonWithAddress(person, address, "0000", "The little Ralphy", 0, new ArrayList<String>(), new ArrayList<String>());
            bodyLayerStack.getEventList().add(entry);
            person = new Person(42, "Clancy", "Wiggum", Gender.MALE, true, new Date());
            entry = new ExtendedPersonWithAddress(person, address, "XXXL", "It is Chief Wiggum", 0, new ArrayList<String>(), new ArrayList<String>());
            bodyLayerStack.getEventList().add(entry);
            person = new Person(42, "Sarah", "Wiggum", Gender.FEMALE, true, new Date());
            entry = new ExtendedPersonWithAddress(person, address, "mommy", "Little Ralphy's mother", 0, new ArrayList<String>(), new ArrayList<String>());
            bodyLayerStack.getEventList().add(entry);
        }
    });
    return container;
}
Also used : Serializable(java.io.Serializable) ExtendedPersonWithAddress(org.eclipse.nebula.widgets.nattable.dataset.person.ExtendedPersonWithAddress) ExtendedPersonWithAddress(org.eclipse.nebula.widgets.nattable.dataset.person.ExtendedPersonWithAddress) Address(org.eclipse.nebula.widgets.nattable.dataset.person.Address) HashMap(java.util.HashMap) 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) DefaultGroupByThemeExtension(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.DefaultGroupByThemeExtension) CheckBoxCellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.CheckBoxCellEditor) ArrayList(java.util.ArrayList) EditCellCommandHandler(org.eclipse.nebula.widgets.nattable.edit.command.EditCellCommandHandler) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) Gender(org.eclipse.nebula.widgets.nattable.dataset.person.Person.Gender) 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) 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) TreeCollapseAllCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeCollapseAllCommand) Button(org.eclipse.swt.widgets.Button) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GroupByHeaderLayer(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByHeaderLayer) DiscardDataChangesCommand(org.eclipse.nebula.widgets.nattable.datachange.command.DiscardDataChangesCommand) DefaultBooleanDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.DefaultBooleanDisplayConverter) DarkGroupByThemeExtension(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.DarkGroupByThemeExtension) FontData(org.eclipse.swt.graphics.FontData) SaveDataChangesCommand(org.eclipse.nebula.widgets.nattable.datachange.command.SaveDataChangesCommand) SortHeaderLayer(org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) CompositeLayer(org.eclipse.nebula.widgets.nattable.layer.CompositeLayer) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) 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) Person(org.eclipse.nebula.widgets.nattable.dataset.person.Person) AbstractLayer(org.eclipse.nebula.widgets.nattable.layer.AbstractLayer) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) DefaultDateDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.DefaultDateDisplayConverter) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) DateCellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.DateCellEditor) GroupByHeaderMenuConfiguration(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByHeaderMenuConfiguration) DefaultDoubleDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.DefaultDoubleDisplayConverter) DefaultEditBindings(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings) GridLayout(org.eclipse.swt.layout.GridLayout) DisplayPersistenceDialogCommandHandler(org.eclipse.nebula.widgets.nattable.persistence.command.DisplayPersistenceDialogCommandHandler) ExtendedReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ExtendedReflectiveColumnPropertyAccessor) CheckBoxPainter(org.eclipse.nebula.widgets.nattable.painter.cell.CheckBoxPainter) RowLayout(org.eclipse.swt.layout.RowLayout) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) Style(org.eclipse.nebula.widgets.nattable.style.Style) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) Menu(org.eclipse.swt.widgets.Menu) 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) 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) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) DefaultDataValidator(org.eclipse.nebula.widgets.nattable.data.validate.DefaultDataValidator) DefaultNatTableThemeConfiguration(org.eclipse.nebula.widgets.nattable.style.theme.DefaultNatTableThemeConfiguration) Date(java.util.Date) 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) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) IMenuItemProvider(org.eclipse.nebula.widgets.nattable.ui.menu.IMenuItemProvider) 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) ModernGroupByThemeExtension(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.ModernGroupByThemeExtension)

Example 5 with IMenuItemProvider

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

the class _6051_GroupByExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    // create a new ConfigRegistry which will be needed for GlazedLists
    // handling
    ConfigRegistry configRegistry = new ConfigRegistry();
    // property names of the Person class
    String[] propertyNames = { "firstName", "lastName", "gender", "married", "birthday", "address.street", "address.housenumber", "address.postalCode", "address.city" };
    // 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");
    propertyToLabelMap.put("address.street", "Street");
    propertyToLabelMap.put("address.housenumber", "Housenumber");
    propertyToLabelMap.put("address.postalCode", "Postal Code");
    propertyToLabelMap.put("address.city", "City");
    IColumnPropertyAccessor<PersonWithAddress> columnPropertyAccessor = new ExtendedReflectiveColumnPropertyAccessor<>(propertyNames);
    BodyLayerStack<PersonWithAddress> bodyLayerStack = new BodyLayerStack<>(PersonService.getPersonsWithAddress(100), columnPropertyAccessor);
    // build the column header layer
    IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
    DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
    ColumnHeaderLayer 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);
    // 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, columnHeaderLayer);
    compositeGridLayer.setChildLayer(GroupByHeaderLayer.GROUP_BY_REGION, groupByHeaderLayer, 0, 0);
    compositeGridLayer.setChildLayer("Grid", gridLayer, 0, 1);
    // turn the auto configuration off as we want to add our header menu
    // configuration
    NatTable natTable = new NatTable(parent, 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 group by configuration
    natTable.addConfiguration(new GroupByHeaderMenuConfiguration(natTable, groupByHeaderLayer));
    natTable.addConfiguration(new HeaderMenuConfiguration(natTable) {

        @Override
        protected PopupMenuBuilder createCornerMenu(NatTable natTable) {
            return super.createCornerMenu(natTable).withStateManagerMenuItemProvider().withMenuItemProvider(new IMenuItemProvider() {

                @Override
                public void addMenuItem(NatTable natTable, Menu popupMenu) {
                    MenuItem menuItem = new MenuItem(popupMenu, SWT.PUSH);
                    // $NON-NLS-1$
                    menuItem.setText("Toggle Group By Header");
                    menuItem.setEnabled(true);
                    menuItem.addSelectionListener(new SelectionAdapter() {

                        @Override
                        public void widgetSelected(SelectionEvent event) {
                            groupByHeaderLayer.setVisible(!groupByHeaderLayer.isVisible());
                        }
                    });
                }
            }).withMenuItemProvider(new IMenuItemProvider() {

                @Override
                public void addMenuItem(final NatTable natTable, Menu popupMenu) {
                    MenuItem menuItem = new MenuItem(popupMenu, SWT.PUSH);
                    // $NON-NLS-1$
                    menuItem.setText("Collapse All");
                    menuItem.setEnabled(true);
                    menuItem.addSelectionListener(new SelectionAdapter() {

                        @Override
                        public void widgetSelected(SelectionEvent event) {
                            natTable.doCommand(new TreeCollapseAllCommand());
                        }
                    });
                }
            }).withMenuItemProvider(new IMenuItemProvider() {

                @Override
                public void addMenuItem(final NatTable natTable, Menu popupMenu) {
                    MenuItem menuItem = new MenuItem(popupMenu, SWT.PUSH);
                    // $NON-NLS-1$
                    menuItem.setText("Expand All");
                    menuItem.setEnabled(true);
                    menuItem.addSelectionListener(new SelectionAdapter() {

                        @Override
                        public void widgetSelected(SelectionEvent event) {
                            natTable.doCommand(new TreeExpandAllCommand());
                        }
                    });
                }
            }).withMenuItemProvider(new IMenuItemProvider() {

                @Override
                public void addMenuItem(final NatTable natTable, Menu popupMenu) {
                    MenuItem menuItem = new MenuItem(popupMenu, SWT.PUSH);
                    // $NON-NLS-1$
                    menuItem.setText("Expand to Level 2");
                    menuItem.setEnabled(true);
                    menuItem.addSelectionListener(new SelectionAdapter() {

                        @Override
                        public void widgetSelected(SelectionEvent event) {
                            natTable.doCommand(new TreeExpandToLevelCommand(2));
                        }
                    });
                }
            });
        }
    });
    natTable.configure();
    natTable.registerCommandHandler(new DisplayPersistenceDialogCommandHandler(natTable));
    return natTable;
}
Also used : HashMap(java.util.HashMap) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) HeaderMenuConfiguration(org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration) GroupByHeaderMenuConfiguration(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByHeaderMenuConfiguration) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) GroupByHeaderMenuConfiguration(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByHeaderMenuConfiguration) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) 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) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) TreeCollapseAllCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeCollapseAllCommand) TreeExpandToLevelCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandToLevelCommand) DisplayPersistenceDialogCommandHandler(org.eclipse.nebula.widgets.nattable.persistence.command.DisplayPersistenceDialogCommandHandler) ExtendedReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ExtendedReflectiveColumnPropertyAccessor) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) PersonWithAddress(org.eclipse.nebula.widgets.nattable.dataset.person.PersonWithAddress) Menu(org.eclipse.swt.widgets.Menu) GroupByHeaderLayer(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByHeaderLayer) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) CompositeLayer(org.eclipse.nebula.widgets.nattable.layer.CompositeLayer) 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) IMenuItemProvider(org.eclipse.nebula.widgets.nattable.ui.menu.IMenuItemProvider) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider) PopupMenuBuilder(org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder)

Aggregations

NatTable (org.eclipse.nebula.widgets.nattable.NatTable)9 IMenuItemProvider (org.eclipse.nebula.widgets.nattable.ui.menu.IMenuItemProvider)9 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)9 SelectionEvent (org.eclipse.swt.events.SelectionEvent)9 Menu (org.eclipse.swt.widgets.Menu)9 MenuItem (org.eclipse.swt.widgets.MenuItem)9 PopupMenuBuilder (org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder)7 HashMap (java.util.HashMap)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 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)6 DefaultRowHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider)6 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)6 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)6 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)6 RowHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer)6 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)6 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)6 HeaderMenuConfiguration (org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration)5