Search in sources :

Example 46 with DefaultRowHeaderDataLayer

use of org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer in project nebula.widgets.nattable by eclipse.

the class _308_DataModificationExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    // set the GridLayout because the FillLayout seems to introduce a
    // scrollbar rendering issue on changing the content
    parent.setLayout(new GridLayout());
    // property names of the Person class
    String[] personPropertyNames = { "firstName", "lastName", "gender", "married", "birthday" };
    // mapping from property to label, needed for column header labels
    Map<String, String> personPropertyToLabelMap = new HashMap<>();
    personPropertyToLabelMap.put("firstName", "Firstname");
    personPropertyToLabelMap.put("lastName", "Lastname");
    personPropertyToLabelMap.put("gender", "Gender");
    personPropertyToLabelMap.put("married", "Married");
    personPropertyToLabelMap.put("birthday", "Birthday");
    ListDataProvider<Person> bodyDataProvider = new ListDataProvider<>(PersonService.getPersons(10), new ReflectiveColumnPropertyAccessor<Person>(personPropertyNames));
    IDataProvider personColumnHeaderDataProvider = new DefaultColumnHeaderDataProvider(personPropertyNames, personPropertyToLabelMap);
    IDataProvider personRowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
    // mapping from property to label, needed for column header labels
    Map<String, String> addressPropertyToLabelMap = new HashMap<>();
    addressPropertyToLabelMap.put("street", "Street");
    addressPropertyToLabelMap.put("housenumber", "Housenumber");
    addressPropertyToLabelMap.put("postalCode", "Postal Code");
    addressPropertyToLabelMap.put("city", "City");
    Composite panel = new Composite(parent, SWT.NONE);
    panel.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().grab(true, true).applyTo(panel);
    Composite gridPanel = new Composite(panel, SWT.NONE);
    gridPanel.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().grab(true, true).applyTo(gridPanel);
    Composite buttonPanel = new Composite(panel, SWT.NONE);
    buttonPanel.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().grab(true, true).applyTo(buttonPanel);
    ConfigRegistry configRegistry = new ConfigRegistry();
    // create the body layer stack
    DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
    bodyDataLayer.setConfigLabelAccumulator(new IConfigLabelAccumulator() {

        @Override
        public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
            switch(columnPosition) {
                case 3:
                    configLabels.addLabel("MARRIED");
                    break;
                case 4:
                    configLabels.addLabel("DATE");
                    break;
            }
        }
    });
    DefaultBodyLayerStack bodyLayerStack = new DefaultBodyLayerStack(bodyDataLayer);
    bodyDataLayer.registerCommandHandler(new DeleteRowCommandHandler<>(bodyDataProvider.getList()));
    bodyDataLayer.registerCommandHandler(new InsertRowCommandHandler<>(bodyDataProvider.getList()));
    // create the column header layer stack
    DataLayer columnHeaderDataLayer = new DataLayer(personColumnHeaderDataProvider);
    ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, bodyLayerStack.getViewportLayer(), bodyLayerStack.getSelectionLayer());
    // create the row header layer stack
    DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(personRowHeaderDataProvider);
    ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, bodyLayerStack.getViewportLayer(), bodyLayerStack.getSelectionLayer());
    // create the corner layer stack
    ILayer cornerLayer = new CornerLayer(new DataLayer(new DefaultCornerDataProvider(personColumnHeaderDataProvider, personRowHeaderDataProvider)), rowHeaderLayer, columnHeaderLayer);
    // create the grid layer composed with the prior created layer stacks
    GridLayer gridLayer = new GridLayer(bodyLayerStack, columnHeaderLayer, rowHeaderLayer, cornerLayer);
    final NatTable natTable = new NatTable(gridPanel, gridLayer, false);
    natTable.setConfigRegistry(configRegistry);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.addConfiguration(new HeaderMenuConfiguration(natTable));
    natTable.addConfiguration(new SingleClickSortConfiguration());
    natTable.addConfiguration(new AbstractRegistryConfiguration() {

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CheckBoxPainter(), DisplayMode.NORMAL, "MARRIED");
            configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultDateDisplayConverter("yyyy-MM-dd"), DisplayMode.NORMAL, "DATE");
        }
    });
    natTable.addConfiguration(new AbstractUiBindingConfiguration() {

        private final Menu bodyMenu = new PopupMenuBuilder(natTable).withMenuItemProvider(new IMenuItemProvider() {

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

                    @Override
                    public void widgetSelected(SelectionEvent event) {
                        int rowPosition = MenuItemProviders.getNatEventData(event).getRowPosition();
                        natTable.doCommand(new InsertRowCommand<>(bodyDataLayer, rowPosition, PersonService.getPersons(1).get(0)));
                    }
                });
            }
        }).withMenuItemProvider(new IMenuItemProvider() {

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

                    @Override
                    public void widgetSelected(SelectionEvent event) {
                        int rowPosition = MenuItemProviders.getNatEventData(event).getRowPosition();
                        natTable.doCommand(new DeleteRowCommand(natTable, rowPosition));
                    }
                });
            }
        }).build();

        @Override
        public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
            uiBindingRegistry.registerMouseDownBinding(new MouseEventMatcher(SWT.NONE, GridRegion.BODY, MouseEventMatcher.RIGHT_BUTTON), new PopupMenuAction(this.bodyMenu) {

                @Override
                public void run(NatTable natTable, MouseEvent event) {
                    int columnPosition = natTable.getColumnPositionByX(event.x);
                    int rowPosition = natTable.getRowPositionByY(event.y);
                    if (!bodyLayerStack.getSelectionLayer().isRowPositionFullySelected(rowPosition)) {
                        natTable.doCommand(new SelectRowsCommand(natTable, columnPosition, rowPosition, false, false));
                    }
                    super.run(natTable, event);
                }
            });
        }
    });
    natTable.configure();
    GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
    return panel;
}
Also used : HashMap(java.util.HashMap) AbstractRegistryConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration) HeaderMenuConfiguration(org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) SelectionEvent(org.eclipse.swt.events.SelectionEvent) UiBindingRegistry(org.eclipse.nebula.widgets.nattable.ui.binding.UiBindingRegistry) MouseEventMatcher(org.eclipse.nebula.widgets.nattable.ui.matcher.MouseEventMatcher) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) AbstractUiBindingConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractUiBindingConfiguration) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) Person(org.eclipse.nebula.widgets.nattable.dataset.person.Person) SelectRowsCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand) ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) IConfigLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.IConfigLabelAccumulator) DefaultDateDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.DefaultDateDisplayConverter) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) GridLayout(org.eclipse.swt.layout.GridLayout) PopupMenuAction(org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuAction) CheckBoxPainter(org.eclipse.nebula.widgets.nattable.painter.cell.CheckBoxPainter) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) Menu(org.eclipse.swt.widgets.Menu) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) 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) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) IMenuItemProvider(org.eclipse.nebula.widgets.nattable.ui.menu.IMenuItemProvider) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider) PopupMenuBuilder(org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder) DefaultBodyLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack)

Example 47 with DefaultRowHeaderDataLayer

use of org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer in project nebula.widgets.nattable by eclipse.

the class _5111_ColumnGroupingExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    // property names of the Person class
    String[] propertyNames = { "firstName", "lastName", "gender", "married", "address.street", "address.housenumber", "address.postalCode", "address.city", "age", "birthday", "money", "description", "favouriteFood", "favouriteDrinks" };
    // 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("address.street", "Street");
    propertyToLabelMap.put("address.housenumber", "Housenumber");
    propertyToLabelMap.put("address.postalCode", "Postalcode");
    propertyToLabelMap.put("address.city", "City");
    propertyToLabelMap.put("age", "Age");
    propertyToLabelMap.put("birthday", "Birthday");
    propertyToLabelMap.put("money", "Money");
    propertyToLabelMap.put("description", "Description");
    propertyToLabelMap.put("favouriteFood", "Food");
    propertyToLabelMap.put("favouriteDrinks", "Drinks");
    IColumnPropertyAccessor<ExtendedPersonWithAddress> columnPropertyAccessor = new ExtendedReflectiveColumnPropertyAccessor<>(propertyNames);
    ColumnGroupModel columnGroupModel = new ColumnGroupModel();
    // build the body layer stack
    // Usually you would create a new layer stack by extending
    // AbstractIndexLayerTransform and setting the ViewportLayer as
    // underlying layer. But in this case using the ViewportLayer
    // directly as body layer is also working.
    IDataProvider bodyDataProvider = new ListDataProvider<>(PersonService.getExtendedPersonsWithAddress(10), columnPropertyAccessor);
    DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
    ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(bodyDataLayer);
    ColumnGroupReorderLayer columnGroupReorderLayer = new ColumnGroupReorderLayer(columnReorderLayer, columnGroupModel);
    ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(columnGroupReorderLayer);
    ColumnGroupExpandCollapseLayer columnGroupExpandCollapseLayer = new ColumnGroupExpandCollapseLayer(columnHideShowLayer, columnGroupModel);
    final SelectionLayer selectionLayer = new SelectionLayer(columnGroupExpandCollapseLayer);
    ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
    // build the column header layer
    IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
    DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
    ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, viewportLayer, selectionLayer);
    ColumnGroupHeaderLayer columnGroupHeaderLayer = new ColumnGroupHeaderLayer(columnHeaderLayer, selectionLayer, columnGroupModel);
    // configure the column groups
    columnGroupHeaderLayer.addColumnsIndexesToGroup("Person", 0, 1, 2, 3);
    columnGroupHeaderLayer.addColumnsIndexesToGroup("Address", 4, 5, 6, 7);
    columnGroupHeaderLayer.addColumnsIndexesToGroup("Facts", 8, 9, 10);
    columnGroupHeaderLayer.addColumnsIndexesToGroup("Personal", 11, 12, 13);
    columnGroupHeaderLayer.setStaticColumnIndexesByGroup("Person", 0, 1);
    columnGroupHeaderLayer.setStaticColumnIndexesByGroup("Address", 4, 5, 6);
    columnGroupHeaderLayer.setGroupUnbreakable(1);
    // build the row header layer
    IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
    DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
    ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, viewportLayer, selectionLayer);
    // build the corner layer
    IDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider);
    DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
    ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, columnGroupHeaderLayer);
    // build the grid layer
    GridLayer gridLayer = new GridLayer(viewportLayer, columnGroupHeaderLayer, rowHeaderLayer, cornerLayer);
    // turn the auto configuration off as we want to add our header menu
    // configuration
    NatTable natTable = new NatTable(parent, gridLayer, false);
    // as the autoconfiguration of the NatTable is turned off, we have to
    // add the DefaultNatTableStyleConfiguration manually
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.addConfiguration(new HeaderMenuConfiguration(natTable) {

        @Override
        protected PopupMenuBuilder createColumnHeaderMenu(NatTable natTable) {
            PopupMenuBuilder builder = super.createColumnHeaderMenu(natTable).withColumnChooserMenuItem();
            builder.withEnabledState(PopupMenuBuilder.HIDE_COLUMN_MENU_ITEM_ID, new VisibleColumnsRemaining(selectionLayer));
            return builder;
        }
    });
    // Column group header menu
    final Menu columnGroupHeaderMenu = new PopupMenuBuilder(natTable).withRenameColumnGroupMenuItem().withRemoveColumnGroupMenuItem().build();
    natTable.addConfiguration(new AbstractUiBindingConfiguration() {

        @Override
        public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
            uiBindingRegistry.registerFirstMouseDownBinding(new MouseEventMatcher(SWT.NONE, GridRegion.COLUMN_GROUP_HEADER, MouseEventMatcher.RIGHT_BUTTON), new PopupMenuAction(columnGroupHeaderMenu));
        }
    });
    // enable this configuration to verify the automatic height calculation
    // when using vertical text painter
    // natTable.addConfiguration(new AbstractRegistryConfiguration() {
    // 
    // @Override
    // public void configureRegistry(IConfigRegistry configRegistry) {
    // ICellPainter cellPainter = new BeveledBorderDecorator(new
    // VerticalTextPainter(false, true, 5, true, true));
    // configRegistry.registerConfigAttribute(
    // CellConfigAttributes.CELL_PAINTER, cellPainter, DisplayMode.NORMAL,
    // GridRegion.COLUMN_HEADER);
    // }
    // });
    // Register column chooser
    DisplayColumnChooserCommandHandler columnChooserCommandHandler = new DisplayColumnChooserCommandHandler(selectionLayer, columnHideShowLayer, columnHeaderLayer, columnHeaderDataLayer, columnGroupHeaderLayer, columnGroupModel, false, true);
    viewportLayer.registerCommandHandler(columnChooserCommandHandler);
    natTable.configure();
    return natTable;
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) ExtendedPersonWithAddress(org.eclipse.nebula.widgets.nattable.dataset.person.ExtendedPersonWithAddress) 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) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) PopupMenuAction(org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuAction) ExtendedReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ExtendedReflectiveColumnPropertyAccessor) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) Menu(org.eclipse.swt.widgets.Menu) VisibleColumnsRemaining(org.eclipse.nebula.widgets.nattable.ui.menu.VisibleColumnsRemaining) UiBindingRegistry(org.eclipse.nebula.widgets.nattable.ui.binding.UiBindingRegistry) MouseEventMatcher(org.eclipse.nebula.widgets.nattable.ui.matcher.MouseEventMatcher) DisplayColumnChooserCommandHandler(org.eclipse.nebula.widgets.nattable.columnChooser.command.DisplayColumnChooserCommandHandler) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) ColumnGroupReorderLayer(org.eclipse.nebula.widgets.nattable.group.ColumnGroupReorderLayer) ColumnReorderLayer(org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) AbstractUiBindingConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractUiBindingConfiguration) ColumnGroupModel(org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel) ColumnGroupHeaderLayer(org.eclipse.nebula.widgets.nattable.group.ColumnGroupHeaderLayer) RowHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer) CornerLayer(org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) ColumnGroupExpandCollapseLayer(org.eclipse.nebula.widgets.nattable.group.ColumnGroupExpandCollapseLayer) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider) PopupMenuBuilder(org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder)

Example 48 with DefaultRowHeaderDataLayer

use of org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer in project nebula.widgets.nattable by eclipse.

the class ExampleSummaryRowGridConfiguration method init.

private void init(IDataProvider dataProvider, ConfigRegistry configRegistry, final String[] propertyNames, Map<String, String> propertyToLabelMap) {
    // Body
    SummaryRowBodyLayerStack bodyLayer = new SummaryRowBodyLayerStack(dataProvider, configRegistry);
    SelectionLayer selectionLayer = bodyLayer.getSelectionLayer();
    // Column header
    IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
    ILayer columnHeaderLayer = new ColumnHeaderLayer(new DefaultColumnHeaderDataLayer(columnHeaderDataProvider), bodyLayer, selectionLayer);
    // Row header
    // Adding the specialized DefaultSummaryRowHeaderDataProvider to
    // indicate the summary row in the row header
    IDataProvider rowHeaderDataProvider = new DefaultSummaryRowHeaderDataProvider(bodyLayer.getDataLayer().getDataProvider(), "\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(SummaryRowLayer.DEFAULT_SUMMARY_ROW_CONFIG_LABEL);
            }
        }
    });
    ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, bodyLayer, selectionLayer);
    // Corner
    ILayer cornerLayer = new CornerLayer(new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider)), rowHeaderLayer, columnHeaderLayer);
    setBodyLayer(bodyLayer);
    setColumnHeaderLayer(columnHeaderLayer);
    setRowHeaderLayer(rowHeaderLayer);
    setCornerLayer(cornerLayer);
}
Also used : DefaultSummaryRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultSummaryRowHeaderDataProvider) AbstractOverrider(org.eclipse.nebula.widgets.nattable.layer.cell.AbstractOverrider) LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) 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) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)

Example 49 with DefaultRowHeaderDataLayer

use of org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer in project nebula.widgets.nattable by eclipse.

the class _5065_GridHoverStylingExample 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");
    // build the body layer stack
    // Usually you would create a new layer stack by extending
    // AbstractIndexLayerTransform and setting the ViewportLayer
    // as underlying layer. But in this case using the ViewportLayer
    // directly as body layer is also working.
    IDataProvider bodyDataProvider = new DefaultBodyDataProvider<>(PersonService.getPersons(10), propertyNames);
    DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
    HoverLayer bodyHoverLayer = new HoverLayer(bodyDataLayer);
    SelectionLayer selectionLayer = new SelectionLayer(bodyHoverLayer);
    ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
    // build the column header layer
    IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
    DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
    HoverLayer columnHoverLayer = new HoverLayer(columnHeaderDataLayer, false);
    ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHoverLayer, viewportLayer, selectionLayer, false);
    // add ColumnHeaderHoverLayerConfiguration to ensure that hover styling
    // and resizing is working together
    columnHeaderLayer.addConfiguration(new ColumnHeaderHoverLayerConfiguration(columnHoverLayer));
    // build the row header layer
    IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
    DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
    HoverLayer rowHoverLayer = new HoverLayer(rowHeaderDataLayer, false);
    RowHeaderLayer rowHeaderLayer = new RowHeaderLayer(rowHoverLayer, viewportLayer, selectionLayer, false);
    // add RowHeaderHoverLayerConfiguration to ensure that hover styling and
    // resizing is working together
    rowHeaderLayer.addConfiguration(new RowHeaderHoverLayerConfiguration(rowHoverLayer));
    // build the corner layer
    IDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider);
    DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
    ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, columnHeaderLayer);
    // build the grid layer
    GridLayer gridLayer = new GridLayer(viewportLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
    // turn the auto configuration off as we want to add our header menu
    // configuration
    NatTable natTable = new NatTable(parent, gridLayer, false);
    // as the autoconfiguration of the NatTable is turned off, we have to
    // add the DefaultNatTableStyleConfiguration manually
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    // add the style configuration for hover
    natTable.addConfiguration(new HoverAndHeaderStyleConfiguration());
    natTable.configure();
    return natTable;
}
Also used : ColumnHeaderHoverLayerConfiguration(org.eclipse.nebula.widgets.nattable.hover.config.ColumnHeaderHoverLayerConfiguration) 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) HoverLayer(org.eclipse.nebula.widgets.nattable.hover.HoverLayer) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) DefaultBodyDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultBodyDataProvider) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) 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) RowHeaderHoverLayerConfiguration(org.eclipse.nebula.widgets.nattable.hover.config.RowHeaderHoverLayerConfiguration) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)

Example 50 with DefaultRowHeaderDataLayer

use of org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer in project nebula.widgets.nattable by eclipse.

the class _5073_ColumnAndRowHideShowExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    Composite panel = new Composite(parent, SWT.NONE);
    // property names of the Person class
    String[] propertyNames = { "firstName", "lastName", "gender", "married", "birthday" };
    // mapping from property to label, needed for column header labels
    Map<String, String> propertyToLabelMap = new HashMap<>();
    propertyToLabelMap.put("firstName", "Firstname");
    propertyToLabelMap.put("lastName", "Lastname");
    propertyToLabelMap.put("gender", "Gender");
    propertyToLabelMap.put("married", "Married");
    propertyToLabelMap.put("birthday", "Birthday");
    // build the body layer stack
    // Usually you would create a new layer stack by extending
    // AbstractIndexLayerTransform and setting the ViewportLayer as
    // underlying layer. But in this case using the ViewportLayer directly
    // as body layer is also working.
    IDataProvider bodyDataProvider = new DefaultBodyDataProvider<>(PersonService.getPersons(10), propertyNames);
    DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
    ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(bodyDataLayer);
    RowHideShowLayer rowHideShowLayer = new RowHideShowLayer(columnHideShowLayer);
    final SelectionLayer selectionLayer = new SelectionLayer(rowHideShowLayer);
    final ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
    // build the column header layer
    IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
    DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
    ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, viewportLayer, selectionLayer);
    // build the row header layer
    IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
    DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
    ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, viewportLayer, selectionLayer);
    // build the corner layer
    IDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider);
    DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
    ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, columnHeaderLayer);
    // build the grid layer
    GridLayer gridLayer = new GridLayer(viewportLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
    // turn the auto configuration off as we want to add our header menu
    // configuration
    final NatTable natTable = new NatTable(panel, gridLayer, false);
    // as the autoconfiguration of the NatTable is turned off, we have to
    // add the DefaultNatTableStyleConfiguration manually
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    // add the header menu configuration for adding the column header menu
    // with hide/show actions
    natTable.addConfiguration(new AbstractHeaderMenuConfiguration(natTable) {

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

        @Override
        protected PopupMenuBuilder createRowHeaderMenu(NatTable natTable) {
            return super.createRowHeaderMenu(natTable).withHideRowMenuItem().withShowAllRowsMenuItem().withStateManagerMenuItemProvider();
        }

        @Override
        protected PopupMenuBuilder createCornerMenu(NatTable natTable) {
            return super.createCornerMenu(natTable).withShowAllColumnsMenuItem().withShowAllRowsMenuItem().withStateManagerMenuItemProvider();
        }
    });
    natTable.configure();
    panel.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().grab(true, true).applyTo(panel);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
    gridLayer.registerCommandHandler(new DisplayPersistenceDialogCommandHandler(natTable));
    return panel;
}
Also used : HashMap(java.util.HashMap) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) 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) DefaultBodyDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultBodyDataProvider) 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) GridLayout(org.eclipse.swt.layout.GridLayout) DisplayPersistenceDialogCommandHandler(org.eclipse.nebula.widgets.nattable.persistence.command.DisplayPersistenceDialogCommandHandler) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) Composite(org.eclipse.swt.widgets.Composite) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) 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) AbstractHeaderMenuConfiguration(org.eclipse.nebula.widgets.nattable.ui.menu.AbstractHeaderMenuConfiguration) 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) RowHideShowLayer(org.eclipse.nebula.widgets.nattable.hideshow.RowHideShowLayer)

Aggregations

DefaultRowHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer)66 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)66 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)65 RowHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer)64 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)63 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)63 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)62 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)61 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)61 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)60 DefaultRowHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider)59 DefaultColumnHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer)58 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)57 HashMap (java.util.HashMap)50 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)49 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)36 ViewportLayer (org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer)33 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)31 PopupMenuBuilder (org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder)29 GridLayout (org.eclipse.swt.layout.GridLayout)29