Search in sources :

Example 51 with Style

use of org.eclipse.nebula.widgets.nattable.style.Style in project nebula.widgets.nattable by eclipse.

the class _774_MultiExportExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    Composite panel = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    panel.setLayout(layout);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(panel);
    Composite gridPanel = new Composite(panel, SWT.NONE);
    gridPanel.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().grab(true, true).applyTo(gridPanel);
    Composite buttonPanel = new Composite(panel, SWT.NONE);
    buttonPanel.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().grab(true, false).applyTo(buttonPanel);
    // property names of the Person class
    String[] propertyNames = { "firstName", "lastName", "gender", "married", "birthday" };
    // mapping from property to label, needed for column header labels
    Map<String, String> propertyToLabelMap = new HashMap<>();
    propertyToLabelMap.put("firstName", "Firstname");
    propertyToLabelMap.put("lastName", "Lastname");
    propertyToLabelMap.put("gender", "Gender");
    propertyToLabelMap.put("married", "Married");
    propertyToLabelMap.put("birthday", "Birthday");
    GridLayer grid = createGrid(propertyNames, propertyToLabelMap, PersonService.getPersons(5));
    final NatTable natTable = new NatTable(gridPanel, grid, false);
    // add labels to show that alignment configurations are also exported
    // correctly
    final ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(grid.getBodyLayer());
    ((AbstractLayer) grid.getBodyLayer()).setConfigLabelAccumulator(columnLabelAccumulator);
    columnLabelAccumulator.registerColumnOverrides(0, COLUMN_ONE_LABEL);
    columnLabelAccumulator.registerColumnOverrides(1, COLUMN_TWO_LABEL);
    natTable.addConfiguration(new AbstractRegistryConfiguration() {

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            Style style = new Style();
            style.setAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT, HorizontalAlignmentEnum.LEFT);
            style.setAttributeValue(CellStyleAttributes.VERTICAL_ALIGNMENT, VerticalAlignmentEnum.TOP);
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.NORMAL, COLUMN_ONE_LABEL);
            style = new Style();
            style.setAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT, HorizontalAlignmentEnum.RIGHT);
            style.setAttributeValue(CellStyleAttributes.VERTICAL_ALIGNMENT, VerticalAlignmentEnum.BOTTOM);
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.NORMAL, COLUMN_TWO_LABEL);
        }
    });
    // adding this configuration adds the styles and the painters to use
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.addConfiguration(new AbstractRegistryConfiguration() {

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

                @Override
                public Object formatForExport(ILayerCell cell, IConfigRegistry configRegistry) {
                    // string for export
                    return cell.getDataValue();
                }
            }, DisplayMode.NORMAL, GridRegion.ROW_HEADER);
        }
    });
    natTable.configure();
    GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
    // property names of the NumberValues class
    String[] numberPropertyNames = { "columnOneNumber", "columnTwoNumber", "columnThreeNumber", "columnFourNumber", "columnFiveNumber" };
    // mapping from property to label, needed for column header labels
    Map<String, String> numberPropertyToLabelMap = new HashMap<>();
    numberPropertyToLabelMap.put("columnOneNumber", "Value One");
    numberPropertyToLabelMap.put("columnTwoNumber", "Value Two");
    numberPropertyToLabelMap.put("columnThreeNumber", "Value Three");
    numberPropertyToLabelMap.put("columnFourNumber", "Value Four");
    numberPropertyToLabelMap.put("columnFiveNumber", "Value Five");
    List<NumberValues> valuesToShow = new ArrayList<>();
    valuesToShow.add(createNumberValues());
    valuesToShow.add(createNumberValues());
    valuesToShow.add(createNumberValues());
    valuesToShow.add(createNumberValues());
    valuesToShow.add(createNumberValues());
    final NatTable numberNatTable = new NatTable(gridPanel, createGrid(numberPropertyNames, numberPropertyToLabelMap, valuesToShow), false);
    // adding this configuration adds the styles and the painters to use
    numberNatTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    numberNatTable.addConfiguration(new AbstractRegistryConfiguration() {

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            // register a custom formatter to the body of the grid
            // you could also implement different formatter for different
            // columns by using the label mechanism
            configRegistry.registerConfigAttribute(ExportConfigAttributes.EXPORT_FORMATTER, new IExportFormatter() {

                @Override
                public Object formatForExport(ILayerCell cell, IConfigRegistry configRegistry) {
                    // default conversion to string for export
                    return cell.getDataValue();
                }
            }, DisplayMode.NORMAL, GridRegion.BODY);
            configRegistry.registerConfigAttribute(ExportConfigAttributes.EXPORT_FORMATTER, new IExportFormatter() {

                @Override
                public Object formatForExport(ILayerCell cell, IConfigRegistry configRegistry) {
                    // default conversion to string for export
                    return cell.getDataValue();
                }
            }, DisplayMode.NORMAL, GridRegion.ROW_HEADER);
        }
    });
    numberNatTable.configure();
    GridDataFactory.fillDefaults().grab(true, true).applyTo(numberNatTable);
    Button addColumnButton = new Button(buttonPanel, SWT.PUSH);
    addColumnButton.setText("Export");
    addColumnButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // get the ILayerExporter that is registered for the persons
            // table, otherwise the exporter registered there would have no
            // effect. For multi table export the ILayerExporter specified
            // in the method call is used always
            ILayerExporter exporter = natTable.getConfigRegistry().getConfigAttribute(ExportConfigAttributes.EXPORTER, DisplayMode.NORMAL);
            Map<String, NatTable> export = new HashMap<>();
            export.put("Persons", natTable);
            export.put("Numbers", numberNatTable);
            new NatExporter(Display.getCurrent().getActiveShell()).exportMultipleNatTables(exporter, export);
        }
    });
    return panel;
}
Also used : AbstractLayer(org.eclipse.nebula.widgets.nattable.layer.AbstractLayer) ILayerExporter(org.eclipse.nebula.widgets.nattable.export.ILayerExporter) HashMap(java.util.HashMap) AbstractRegistryConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration) ArrayList(java.util.ArrayList) NatExporter(org.eclipse.nebula.widgets.nattable.export.NatExporter) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Style(org.eclipse.nebula.widgets.nattable.style.Style) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) ColumnOverrideLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) NumberValues(org.eclipse.nebula.widgets.nattable.dataset.NumberValues) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) IExportFormatter(org.eclipse.nebula.widgets.nattable.export.IExportFormatter) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) HSSFExcelExporter(org.eclipse.nebula.widgets.nattable.extension.poi.HSSFExcelExporter) Map(java.util.Map) HashMap(java.util.HashMap)

Example 52 with Style

use of org.eclipse.nebula.widgets.nattable.style.Style in project nebula.widgets.nattable by eclipse.

the class NatTableBuilder method configureColumnProperties.

protected void configureColumnProperties() {
    columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyLayer.getDataLayer());
    bodyLayer.addLabelAccumulator(columnLabelAccumulator);
    for (int colIndex = 0; colIndex < columns.length; colIndex++) {
        Integer width = columns[colIndex].width;
        if (isNotNull(width)) {
            bodyLayer.getDataLayer().setColumnWidthByPosition(colIndex, width);
        }
        // Register a label on each column
        String columnLabel = BODY_COLUMN_LABEL_PREFIX + colIndex;
        columnLabelAccumulator.registerColumnOverrides(colIndex, columnLabel);
        // Add the display converter/formatter to the column
        configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, columns[colIndex].displayConverter, DisplayMode.NORMAL, columnLabel);
        // Add column visual style
        Style style = new Style();
        ColumnStyle columnStyle = columns[colIndex].style;
        if (ObjectUtils.isNotNull(columnStyle)) {
            style.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, columnStyle.bgColor);
            style.setAttributeValue(CellStyleAttributes.FOREGROUND_COLOR, columnStyle.fgColor);
            style.setAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT, columnStyle.hAlign);
            style.setAttributeValue(CellStyleAttributes.VERTICAL_ALIGNMENT, columnStyle.vAlign);
            style.setAttributeValue(CellStyleAttributes.FONT, columnStyle.font);
            style.setAttributeValue(CellStyleAttributes.BORDER_STYLE, columnStyle.borderStyle);
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.NORMAL, columnLabel);
        }
    }
}
Also used : ColumnStyle(org.eclipse.nebula.widgets.nattable.extension.builder.model.ColumnStyle) ColumnStyle(org.eclipse.nebula.widgets.nattable.extension.builder.model.ColumnStyle) TableStyle(org.eclipse.nebula.widgets.nattable.extension.builder.model.TableStyle) Style(org.eclipse.nebula.widgets.nattable.style.Style) ColumnOverrideLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator)

Example 53 with Style

use of org.eclipse.nebula.widgets.nattable.style.Style in project nebula.widgets.nattable by eclipse.

the class NatTableBuilder method configureFiltering.

protected void configureFiltering() {
    if (!tableModel.enableFilterRow) {
        return;
    }
    for (int colIndex = 0; colIndex < columns.length; colIndex++) {
        String filterRowLabel = FilterRowDataLayer.FILTER_ROW_COLUMN_LABEL_PREFIX + colIndex;
        TableColumn column = columns[colIndex];
        configRegistry.registerConfigAttribute(FilterRowConfigAttributes.FILTER_COMPARATOR, column.comparator, DisplayMode.NORMAL, filterRowLabel);
        configRegistry.registerConfigAttribute(FilterRowConfigAttributes.FILTER_DISPLAY_CONVERTER, column.filterRowDisplayConverter, DisplayMode.NORMAL, filterRowLabel);
        configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, column.filterRowEditor.getCellEditor(), DisplayMode.NORMAL, filterRowLabel);
    }
    // Filter row style
    Style style = new Style();
    style.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, tableStyle.filterRowBGColor);
    style.setAttributeValue(CellStyleAttributes.FOREGROUND_COLOR, tableStyle.filterRowFGColor);
    style.setAttributeValue(CellStyleAttributes.FONT, tableStyle.filterRowFont);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.NORMAL, GridRegion.FILTER_ROW);
}
Also used : ColumnStyle(org.eclipse.nebula.widgets.nattable.extension.builder.model.ColumnStyle) TableStyle(org.eclipse.nebula.widgets.nattable.extension.builder.model.TableStyle) Style(org.eclipse.nebula.widgets.nattable.style.Style) TableColumn(org.eclipse.nebula.widgets.nattable.extension.builder.model.TableColumn)

Example 54 with Style

use of org.eclipse.nebula.widgets.nattable.style.Style in project nebula.widgets.nattable by eclipse.

the class AlternateRowStyleConfiguration method configureOddRowStyle.

protected void configureOddRowStyle(IConfigRegistry configRegistry) {
    Style cellStyle = new Style();
    cellStyle.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, oddRowBgColor);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, DisplayMode.NORMAL, AlternatingRowConfigLabelAccumulator.EVEN_ROW_CONFIG_TYPE);
}
Also used : Style(org.eclipse.nebula.widgets.nattable.style.Style)

Example 55 with Style

use of org.eclipse.nebula.widgets.nattable.style.Style in project nebula.widgets.nattable by eclipse.

the class ColumnHeaderConfiguration method addNormalModeStyling.

private void addNormalModeStyling(IConfigRegistry configRegistry) {
    Style cellStyle = new Style();
    cellStyle.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, tableStyle.columnHeaderBGColor);
    cellStyle.setAttributeValue(CellStyleAttributes.FOREGROUND_COLOR, tableStyle.columnHeaderFGColor);
    cellStyle.setAttributeValue(CellStyleAttributes.FONT, tableStyle.columnHeaderFont);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, DisplayMode.NORMAL, GridRegion.COLUMN_HEADER);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, DisplayMode.NORMAL, GridRegion.CORNER);
    // Gradient painter
    Image bgImage = tableStyle.columnHeaderBgImage;
    if (ObjectUtils.isNotNull(bgImage)) {
        TextPainter txtPainter = new TextPainter(false, false);
        ICellPainter cellPainter = new BackgroundImagePainter(txtPainter, bgImage, GUIHelper.getColor(192, 192, 192));
        SortableHeaderTextPainter sortHeaderPainter = new SortableHeaderTextPainter(cellPainter, false, false);
        configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, sortHeaderPainter, DisplayMode.NORMAL, GridRegion.COLUMN_HEADER);
        configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, sortHeaderPainter, DisplayMode.NORMAL, GridRegion.CORNER);
    } else {
        SortableHeaderTextPainter sortHeaderPainter = new SortableHeaderTextPainter(new BeveledBorderDecorator(new TextPainter()), false, false);
        configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, sortHeaderPainter, DisplayMode.NORMAL, GridRegion.COLUMN_HEADER);
        configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, sortHeaderPainter, DisplayMode.NORMAL, GridRegion.CORNER);
    }
}
Also used : SortableHeaderTextPainter(org.eclipse.nebula.widgets.nattable.sort.painter.SortableHeaderTextPainter) BeveledBorderDecorator(org.eclipse.nebula.widgets.nattable.painter.cell.decorator.BeveledBorderDecorator) TableStyle(org.eclipse.nebula.widgets.nattable.extension.builder.model.TableStyle) Style(org.eclipse.nebula.widgets.nattable.style.Style) TextPainter(org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter) SortableHeaderTextPainter(org.eclipse.nebula.widgets.nattable.sort.painter.SortableHeaderTextPainter) BackgroundImagePainter(org.eclipse.nebula.widgets.nattable.painter.cell.BackgroundImagePainter) Image(org.eclipse.swt.graphics.Image) ICellPainter(org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter)

Aggregations

Style (org.eclipse.nebula.widgets.nattable.style.Style)115 BorderStyle (org.eclipse.nebula.widgets.nattable.style.BorderStyle)60 IStyle (org.eclipse.nebula.widgets.nattable.style.IStyle)52 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)18 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)17 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)16 HashMap (java.util.HashMap)15 AbstractRegistryConfiguration (org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration)15 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)13 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)13 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)12 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)12 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)12 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)12 DefaultColumnHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer)11 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)11 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)10 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)10 DefaultRowHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer)10 RowHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer)10