Search in sources :

Example 1 with VerticalTextPainter

use of org.eclipse.nebula.widgets.nattable.painter.cell.VerticalTextPainter in project nebula.widgets.nattable by eclipse.

the class _773_GridExcelExportFormatterExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    Composite panel = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    panel.setLayout(layout);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(panel);
    Composite gridPanel = new Composite(panel, SWT.NONE);
    gridPanel.setLayout(layout);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(gridPanel);
    Composite buttonPanel = new Composite(panel, SWT.NONE);
    buttonPanel.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().grab(true, false).applyTo(buttonPanel);
    // property names of the Person class
    String[] propertyNames = { "firstName", "lastName", "gender", "married", "birthday" };
    // mapping from property to label, needed for column header labels
    Map<String, String> propertyToLabelMap = new HashMap<>();
    propertyToLabelMap.put("firstName", "Firstname");
    propertyToLabelMap.put("lastName", "Lastname");
    propertyToLabelMap.put("gender", "Gender");
    propertyToLabelMap.put("married", "Married");
    propertyToLabelMap.put("birthday", "Birthday");
    // build the body layer stack
    // Usually you would create a new layer stack by extending
    // AbstractIndexLayerTransform and setting the ViewportLayer as
    // underlying layer. But in this case using the ViewportLayer directly
    // as body layer is also working.
    IDataProvider bodyDataProvider = new DefaultBodyDataProvider<>(PersonService.getPersons(10), propertyNames);
    DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
    SelectionLayer selectionLayer = new SelectionLayer(bodyDataLayer);
    ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
    bodyDataLayer.setConfigLabelAccumulator(new ColumnLabelAccumulator());
    // build the column header layer
    IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
    DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
    ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, viewportLayer, selectionLayer);
    // build the row header layer
    IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
    DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
    ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, viewportLayer, selectionLayer);
    // build the corner layer
    IDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider);
    DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
    ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, columnHeaderLayer);
    // build the grid layer
    GridLayer gridLayer = new GridLayer(viewportLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
    final NatTable natTable = new NatTable(gridPanel, gridLayer, false);
    // adding this configuration adds the styles and the painters to use
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.addConfiguration(new AbstractRegistryConfiguration() {

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

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

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

Example 2 with VerticalTextPainter

use of org.eclipse.nebula.widgets.nattable.painter.cell.VerticalTextPainter in project nebula.widgets.nattable by eclipse.

the class TextPainter_Examples method createVerticalNatTable.

@SuppressWarnings("unused")
private void createVerticalNatTable(Composite parent, final ICellPainter painter) {
    IDataProvider bodyDataProvider = new ExampleHeaderDataProvider();
    SelectionLayer selectionLayer = new SelectionLayer(new DataLayer(bodyDataProvider, 20, 100));
    ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
    ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(new DataLayer(new DummyColumnHeaderDataProvider(bodyDataProvider), 20, 100), viewportLayer, selectionLayer);
    columnHeaderLayer.addConfiguration(new DefaultColumnHeaderLayerConfiguration() {

        @Override
        protected void addColumnHeaderStyleConfig() {
            addConfiguration(new DefaultColumnHeaderStyleConfiguration() {

                {
                    this.cellPainter = new BeveledBorderDecorator(new VerticalTextPainter());
                }
            });
        }
    });
    CompositeLayer compositeLayer = new CompositeLayer(1, 2);
    compositeLayer.setChildLayer(GridRegion.COLUMN_HEADER, columnHeaderLayer, 0, 0);
    compositeLayer.setChildLayer(GridRegion.BODY, viewportLayer, 0, 1);
    NatTable natTable = new NatTable(parent, compositeLayer, false);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration() {

        {
            this.vAlign = VerticalAlignmentEnum.MIDDLE;
            this.hAlign = HorizontalAlignmentEnum.LEFT;
            this.cellPainter = new LineBorderDecorator(painter);
            this.font = GUIHelper.getFont(new FontData("Arial", 20, SWT.NORMAL));
        }
    });
    natTable.configure();
    GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
}
Also used : ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) FontData(org.eclipse.swt.graphics.FontData) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) CompositeLayer(org.eclipse.nebula.widgets.nattable.layer.CompositeLayer) DummyColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DummyColumnHeaderDataProvider) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) LineBorderDecorator(org.eclipse.nebula.widgets.nattable.painter.cell.decorator.LineBorderDecorator) BeveledBorderDecorator(org.eclipse.nebula.widgets.nattable.painter.cell.decorator.BeveledBorderDecorator) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) DefaultColumnHeaderLayerConfiguration(org.eclipse.nebula.widgets.nattable.layer.config.DefaultColumnHeaderLayerConfiguration) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) DefaultColumnHeaderStyleConfiguration(org.eclipse.nebula.widgets.nattable.layer.config.DefaultColumnHeaderStyleConfiguration) VerticalTextPainter(org.eclipse.nebula.widgets.nattable.painter.cell.VerticalTextPainter)

Example 3 with VerticalTextPainter

use of org.eclipse.nebula.widgets.nattable.painter.cell.VerticalTextPainter in project nebula.widgets.nattable by eclipse.

the class NatTableCSSHandler method retrieveCSSProperty.

@Override
public String retrieveCSSProperty(Object control, String property, String pseudo, CSSEngine engine) throws Exception {
    NatTable natTable = null;
    String label = null;
    String displayMode = NatTableCSSHelper.getDisplayMode(pseudo);
    if (control instanceof NatTable) {
        natTable = (NatTable) control;
    } else if (control instanceof NatTableWrapper) {
        natTable = ((NatTableWrapper) control).getNatTable();
        label = ((NatTableWrapper) control).getLabel();
    }
    if (natTable != null) {
        // check property
        if (NatTableCSSConstants.BACKGROUND_COLOR.equalsIgnoreCase(property)) {
            return CSSPropertyBackgroundSWTHandler.INSTANCE.retrieveCSSPropertyBackgroundColor(control, pseudo, engine);
        } else if (NatTableCSSConstants.BACKGROUND_IMAGE.equalsIgnoreCase(property)) {
            return CSSPropertyBackgroundSWTHandler.INSTANCE.retrieveCSSPropertyBackgroundImage(control, pseudo, engine);
        } else if (NatTableCSSConstants.CELL_BACKGROUND_COLOR.equalsIgnoreCase(property)) {
            ICSSValueConverter cssValueConverter = engine.getCSSValueConverter(String.class);
            return cssValueConverter.convert(NatTableCSSHelper.getNatTableStyle(natTable, CellStyleAttributes.BACKGROUND_COLOR, displayMode, label), engine, null);
        } else if (NatTableCSSConstants.CELL_BACKGROUND_IMAGE.equalsIgnoreCase(property)) {
            // TODO : manage path of Image.
            return "none";
        } else if (NatTableCSSConstants.FOREGROUND_COLOR.equalsIgnoreCase(property)) {
            ICSSValueConverter cssValueConverter = engine.getCSSValueConverter(String.class);
            return cssValueConverter.convert(NatTableCSSHelper.getNatTableStyle(natTable, CellStyleAttributes.FOREGROUND_COLOR, displayMode, label), engine, null);
        } else if (NatTableCSSConstants.HORIZONTAL_ALIGNMENT.equalsIgnoreCase(property)) {
            HorizontalAlignmentEnum align = NatTableCSSHelper.getNatTableStyle(natTable, CellStyleAttributes.HORIZONTAL_ALIGNMENT, displayMode, label);
            switch(align) {
                case CENTER:
                    return "center";
                case LEFT:
                    return "left";
                case RIGHT:
                    return "right";
            }
        } else if (NatTableCSSConstants.VERTICAL_ALIGNMENT.equalsIgnoreCase(property)) {
            VerticalAlignmentEnum align = NatTableCSSHelper.getNatTableStyle(natTable, CellStyleAttributes.VERTICAL_ALIGNMENT, displayMode, label);
            switch(align) {
                case TOP:
                    return "top";
                case MIDDLE:
                    return "middle";
                case BOTTOM:
                    return "bottom";
            }
        } else if (NatTableCSSConstants.FONT.equalsIgnoreCase(property)) {
            Font font = NatTableCSSHelper.getNatTableStyle(natTable, CellStyleAttributes.FONT, displayMode, label);
            return CSSSWTFontHelper.getFontComposite(font);
        } else if (NatTableCSSConstants.FONT_FAMILY.equalsIgnoreCase(property)) {
            Font font = NatTableCSSHelper.getNatTableStyle(natTable, CellStyleAttributes.FONT, displayMode, label);
            return CSSSWTFontHelper.getFontFamily(font);
        } else if (NatTableCSSConstants.FONT_SIZE.equalsIgnoreCase(property)) {
            Font font = NatTableCSSHelper.getNatTableStyle(natTable, CellStyleAttributes.FONT, displayMode, label);
            return CSSSWTFontHelper.getFontSize(font);
        } else if (NatTableCSSConstants.FONT_STYLE.equalsIgnoreCase(property)) {
            Font font = NatTableCSSHelper.getNatTableStyle(natTable, CellStyleAttributes.FONT, displayMode, label);
            return CSSSWTFontHelper.getFontStyle(font);
        } else if (NatTableCSSConstants.FONT_WEIGHT.equalsIgnoreCase(property)) {
            Font font = NatTableCSSHelper.getNatTableStyle(natTable, CellStyleAttributes.FONT, displayMode, label);
            return CSSSWTFontHelper.getFontWeight(font);
        } else if (NatTableCSSConstants.IMAGE.equalsIgnoreCase(property)) {
            // TODO : manage path of Image.
            return "none";
        } else if (NatTableCSSConstants.BORDER.equalsIgnoreCase(property)) {
            BorderStyle border = NatTableCSSHelper.getNatTableStyle(natTable, CellStyleAttributes.BORDER_STYLE, displayMode, label);
            ICSSValueConverter cssValueConverter = engine.getCSSValueConverter(String.class);
            return border.getThickness() + " " + border.getLineStyle().toString().toLowerCase() + " " + border.getBorderMode().toString().toLowerCase() + " " + cssValueConverter.convert(border.getColor(), engine, null);
        } else if (NatTableCSSConstants.BORDER_COLOR.equalsIgnoreCase(property)) {
            BorderStyle border = NatTableCSSHelper.getNatTableStyle(natTable, CellStyleAttributes.BORDER_STYLE, displayMode, label);
            ICSSValueConverter cssValueConverter = engine.getCSSValueConverter(String.class);
            return cssValueConverter.convert(border.getColor(), engine, null);
        } else if (NatTableCSSConstants.BORDER_STYLE.equalsIgnoreCase(property)) {
            BorderStyle border = NatTableCSSHelper.getNatTableStyle(natTable, CellStyleAttributes.BORDER_STYLE, displayMode, label);
            return border.getLineStyle().toString().toLowerCase();
        } else if (NatTableCSSConstants.BORDER_WIDTH.equalsIgnoreCase(property)) {
            BorderStyle border = NatTableCSSHelper.getNatTableStyle(natTable, CellStyleAttributes.BORDER_STYLE, displayMode, label);
            return "" + border.getThickness();
        } else if (NatTableCSSConstants.BORDER_MODE.equalsIgnoreCase(property)) {
            BorderStyle border = NatTableCSSHelper.getNatTableStyle(natTable, CellStyleAttributes.BORDER_STYLE, displayMode, label);
            return "" + border.getBorderMode();
        } else if (NatTableCSSConstants.PASSWORD_ECHO_CHAR.equalsIgnoreCase(property)) {
            return "" + NatTableCSSHelper.getNatTableStyle(natTable, CellStyleAttributes.PASSWORD_ECHO_CHAR, displayMode, label);
        } else if (NatTableCSSConstants.TEXT_DECORATION.equalsIgnoreCase(property)) {
            TextDecorationEnum decoration = NatTableCSSHelper.getNatTableStyle(natTable, CellStyleAttributes.TEXT_DECORATION, displayMode, label);
            switch(decoration) {
                case NONE:
                    return "none";
                case STRIKETHROUGH:
                    return "line-through";
                case UNDERLINE:
                    return "underline";
                case UNDERLINE_STRIKETHROUGH:
                    return "underline line-through";
            }
        } else if (NatTableCSSConstants.FREEZE_SEPARATOR_COLOR.equalsIgnoreCase(property)) {
            ICSSValueConverter cssValueConverter = engine.getCSSValueConverter(String.class);
            return cssValueConverter.convert(natTable.getConfigRegistry().getConfigAttribute(IFreezeConfigAttributes.SEPARATOR_COLOR, displayMode, label), engine, null);
        } else if (NatTableCSSConstants.GRID_LINE_COLOR.equalsIgnoreCase(property)) {
            ICSSValueConverter cssValueConverter = engine.getCSSValueConverter(String.class);
            return cssValueConverter.convert(natTable.getConfigRegistry().getConfigAttribute(CellConfigAttributes.GRID_LINE_COLOR, displayMode, label), engine, null);
        } else if (NatTableCSSConstants.GRID_LINE_WIDTH.equalsIgnoreCase(property)) {
            Integer width = natTable.getConfigRegistry().getConfigAttribute(CellConfigAttributes.GRID_LINE_WIDTH, displayMode, label);
            if (width == null) {
                return "0";
            } else {
                return width.toString();
            }
        } else if (NatTableCSSConstants.RENDER_GRID_LINES.equalsIgnoreCase(property)) {
            Boolean render = natTable.getConfigRegistry().getConfigAttribute(CellConfigAttributes.RENDER_GRID_LINES, displayMode, label);
            if (render == null) {
                return Boolean.TRUE.toString();
            } else {
                return render.toString();
            }
        } else if (NatTableCSSConstants.CONVERSION_ERROR_FONT.equalsIgnoreCase(property)) {
            IStyle style = natTable.getConfigRegistry().getConfigAttribute(EditConfigAttributes.CONVERSION_ERROR_STYLE, displayMode, label);
            Font font = style.getAttributeValue(CellStyleAttributes.FONT);
            return CSSSWTFontHelper.getFontComposite(font);
        } else if (NatTableCSSConstants.CONVERSION_ERROR_FONT_FAMILY.equalsIgnoreCase(property)) {
            IStyle style = natTable.getConfigRegistry().getConfigAttribute(EditConfigAttributes.CONVERSION_ERROR_STYLE, displayMode, label);
            Font font = style.getAttributeValue(CellStyleAttributes.FONT);
            return CSSSWTFontHelper.getFontFamily(font);
        } else if (NatTableCSSConstants.CONVERSION_ERROR_FONT_SIZE.equalsIgnoreCase(property)) {
            IStyle style = natTable.getConfigRegistry().getConfigAttribute(EditConfigAttributes.CONVERSION_ERROR_STYLE, displayMode, label);
            Font font = style.getAttributeValue(CellStyleAttributes.FONT);
            return CSSSWTFontHelper.getFontSize(font);
        } else if (NatTableCSSConstants.CONVERSION_ERROR_FONT_STYLE.equalsIgnoreCase(property)) {
            IStyle style = natTable.getConfigRegistry().getConfigAttribute(EditConfigAttributes.CONVERSION_ERROR_STYLE, displayMode, label);
            Font font = style.getAttributeValue(CellStyleAttributes.FONT);
            return CSSSWTFontHelper.getFontStyle(font);
        } else if (NatTableCSSConstants.CONVERSION_ERROR_FONT_WEIGHT.equalsIgnoreCase(property)) {
            IStyle style = natTable.getConfigRegistry().getConfigAttribute(EditConfigAttributes.CONVERSION_ERROR_STYLE, displayMode, label);
            Font font = style.getAttributeValue(CellStyleAttributes.FONT);
            return CSSSWTFontHelper.getFontWeight(font);
        } else if (NatTableCSSConstants.CONVERSION_ERROR_BACKGROUND_COLOR.equalsIgnoreCase(property)) {
            ICSSValueConverter cssValueConverter = engine.getCSSValueConverter(String.class);
            IStyle style = natTable.getConfigRegistry().getConfigAttribute(EditConfigAttributes.CONVERSION_ERROR_STYLE, displayMode, label);
            return cssValueConverter.convert(style.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR), engine, null);
        } else if (NatTableCSSConstants.CONVERSION_ERROR_FOREGROUND_COLOR.equalsIgnoreCase(property)) {
            ICSSValueConverter cssValueConverter = engine.getCSSValueConverter(String.class);
            IStyle style = natTable.getConfigRegistry().getConfigAttribute(EditConfigAttributes.CONVERSION_ERROR_STYLE, displayMode, label);
            return cssValueConverter.convert(style.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR), engine, null);
        } else if (NatTableCSSConstants.VALIDATION_ERROR_FONT.equalsIgnoreCase(property)) {
            IStyle style = natTable.getConfigRegistry().getConfigAttribute(EditConfigAttributes.VALIDATION_ERROR_STYLE, displayMode, label);
            Font font = style.getAttributeValue(CellStyleAttributes.FONT);
            return CSSSWTFontHelper.getFontComposite(font);
        } else if (NatTableCSSConstants.VALIDATION_ERROR_FONT_FAMILY.equalsIgnoreCase(property)) {
            IStyle style = natTable.getConfigRegistry().getConfigAttribute(EditConfigAttributes.VALIDATION_ERROR_STYLE, displayMode, label);
            Font font = style.getAttributeValue(CellStyleAttributes.FONT);
            return CSSSWTFontHelper.getFontFamily(font);
        } else if (NatTableCSSConstants.VALIDATION_ERROR_FONT_SIZE.equalsIgnoreCase(property)) {
            IStyle style = natTable.getConfigRegistry().getConfigAttribute(EditConfigAttributes.VALIDATION_ERROR_STYLE, displayMode, label);
            Font font = style.getAttributeValue(CellStyleAttributes.FONT);
            return CSSSWTFontHelper.getFontSize(font);
        } else if (NatTableCSSConstants.VALIDATION_ERROR_FONT_STYLE.equalsIgnoreCase(property)) {
            IStyle style = natTable.getConfigRegistry().getConfigAttribute(EditConfigAttributes.VALIDATION_ERROR_STYLE, displayMode, label);
            Font font = style.getAttributeValue(CellStyleAttributes.FONT);
            return CSSSWTFontHelper.getFontStyle(font);
        } else if (NatTableCSSConstants.VALIDATION_ERROR_FONT_WEIGHT.equalsIgnoreCase(property)) {
            IStyle style = natTable.getConfigRegistry().getConfigAttribute(EditConfigAttributes.VALIDATION_ERROR_STYLE, displayMode, label);
            Font font = style.getAttributeValue(CellStyleAttributes.FONT);
            return CSSSWTFontHelper.getFontWeight(font);
        } else if (NatTableCSSConstants.VALIDATION_ERROR_BACKGROUND_COLOR.equalsIgnoreCase(property)) {
            ICSSValueConverter cssValueConverter = engine.getCSSValueConverter(String.class);
            IStyle style = natTable.getConfigRegistry().getConfigAttribute(EditConfigAttributes.VALIDATION_ERROR_STYLE, displayMode, label);
            return cssValueConverter.convert(style.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR), engine, null);
        } else if (NatTableCSSConstants.VALIDATION_ERROR_FOREGROUND_COLOR.equalsIgnoreCase(property)) {
            ICSSValueConverter cssValueConverter = engine.getCSSValueConverter(String.class);
            IStyle style = natTable.getConfigRegistry().getConfigAttribute(EditConfigAttributes.VALIDATION_ERROR_STYLE, displayMode, label);
            return cssValueConverter.convert(style.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR), engine, null);
        } else if (NatTableCSSConstants.WORD_WRAP.equalsIgnoreCase(property)) {
            Boolean wrap = Boolean.FALSE;
            ICellPainter painter = natTable.getConfigRegistry().getConfigAttribute(CellConfigAttributes.CELL_PAINTER, displayMode, label);
            if (painter != null) {
                while (painter instanceof CellPainterWrapper) {
                    painter = ((CellPainterWrapper) painter).getWrappedPainter();
                }
            }
            if (painter instanceof AbstractTextPainter) {
                wrap = ((AbstractTextPainter) painter).isWordWrapping();
            }
            return wrap.toString();
        } else if (NatTableCSSConstants.TEXT_WRAP.equalsIgnoreCase(property)) {
            Boolean wrap = Boolean.FALSE;
            ICellPainter painter = natTable.getConfigRegistry().getConfigAttribute(CellConfigAttributes.CELL_PAINTER, displayMode, label);
            if (painter != null) {
                while (painter instanceof CellPainterWrapper) {
                    painter = ((CellPainterWrapper) painter).getWrappedPainter();
                }
            }
            if (painter instanceof AbstractTextPainter) {
                wrap = ((AbstractTextPainter) painter).isWrapText();
            }
            return wrap.toString();
        } else if (NatTableCSSConstants.TEXT_TRIM.equalsIgnoreCase(property)) {
            Boolean trim = Boolean.FALSE;
            ICellPainter painter = natTable.getConfigRegistry().getConfigAttribute(CellConfigAttributes.CELL_PAINTER, displayMode, label);
            if (painter != null) {
                while (painter instanceof CellPainterWrapper) {
                    painter = ((CellPainterWrapper) painter).getWrappedPainter();
                }
            }
            if (painter instanceof AbstractTextPainter) {
                trim = ((AbstractTextPainter) painter).isTrimText();
            }
            return trim.toString();
        } else if (NatTableCSSConstants.LINE_SPACING.equalsIgnoreCase(property)) {
            int spacing = 0;
            ICellPainter painter = natTable.getConfigRegistry().getConfigAttribute(CellConfigAttributes.CELL_PAINTER, displayMode, label);
            if (painter != null) {
                while (painter instanceof CellPainterWrapper) {
                    painter = ((CellPainterWrapper) painter).getWrappedPainter();
                }
            }
            if (painter instanceof AbstractTextPainter) {
                spacing = ((AbstractTextPainter) painter).getLineSpacing();
            }
            return "" + spacing;
        } else if (NatTableCSSConstants.TEXT_DIRECTION.equalsIgnoreCase(property)) {
            String direction = "horizontal";
            ICellPainter painter = natTable.getConfigRegistry().getConfigAttribute(CellConfigAttributes.CELL_PAINTER, displayMode, label);
            if (painter != null) {
                while (painter instanceof CellPainterWrapper) {
                    painter = ((CellPainterWrapper) painter).getWrappedPainter();
                }
            }
            if (painter instanceof VerticalTextPainter) {
                direction = "vertical";
            }
            return direction;
        } else if (NatTableCSSConstants.COLUMN_WIDTH.equalsIgnoreCase(property)) {
            // inherit is not supported here
            return "default";
        } else if (NatTableCSSConstants.ROW_HEIGHT.equalsIgnoreCase(property)) {
            // inherit is not supported here
            return "default";
        } else if (NatTableCSSConstants.PADDING.equalsIgnoreCase(property)) {
            ICellPainter painter = natTable.getConfigRegistry().getConfigAttribute(CellConfigAttributes.CELL_PAINTER, displayMode, label);
            if (painter != null) {
                while (painter instanceof CellPainterWrapper) {
                    painter = ((CellPainterWrapper) painter).getWrappedPainter();
                    if (painter instanceof PaddingDecorator) {
                        PaddingDecorator decorator = (PaddingDecorator) painter;
                        return new StringBuilder().append(decorator.getTopPadding()).append(" ").append(decorator.getRightPadding()).append(" ").append(decorator.getBottomPadding()).append(" ").append(decorator.getLeftPadding()).toString();
                    }
                }
            }
        } else if (NatTableCSSConstants.PADDING_TOP.equalsIgnoreCase(property)) {
            ICellPainter painter = natTable.getConfigRegistry().getConfigAttribute(CellConfigAttributes.CELL_PAINTER, displayMode, label);
            if (painter != null) {
                while (painter instanceof CellPainterWrapper) {
                    painter = ((CellPainterWrapper) painter).getWrappedPainter();
                    if (painter instanceof PaddingDecorator) {
                        return "" + ((PaddingDecorator) painter).getTopPadding();
                    }
                }
            }
            return "0";
        } else if (NatTableCSSConstants.PADDING_RIGHT.equalsIgnoreCase(property)) {
            ICellPainter painter = natTable.getConfigRegistry().getConfigAttribute(CellConfigAttributes.CELL_PAINTER, displayMode, label);
            if (painter != null) {
                while (painter instanceof CellPainterWrapper) {
                    painter = ((CellPainterWrapper) painter).getWrappedPainter();
                    if (painter instanceof PaddingDecorator) {
                        return "" + ((PaddingDecorator) painter).getRightPadding();
                    }
                }
            }
            return "0";
        } else if (NatTableCSSConstants.PADDING_BOTTOM.equalsIgnoreCase(property)) {
            ICellPainter painter = natTable.getConfigRegistry().getConfigAttribute(CellConfigAttributes.CELL_PAINTER, displayMode, label);
            if (painter != null) {
                while (painter instanceof CellPainterWrapper) {
                    painter = ((CellPainterWrapper) painter).getWrappedPainter();
                    if (painter instanceof PaddingDecorator) {
                        return "" + ((PaddingDecorator) painter).getBottomPadding();
                    }
                }
            }
            return "0";
        } else if (NatTableCSSConstants.PADDING_LEFT.equalsIgnoreCase(property)) {
            ICellPainter painter = natTable.getConfigRegistry().getConfigAttribute(CellConfigAttributes.CELL_PAINTER, displayMode, label);
            if (painter != null) {
                while (painter instanceof CellPainterWrapper) {
                    painter = ((CellPainterWrapper) painter).getWrappedPainter();
                    if (painter instanceof PaddingDecorator) {
                        return "" + ((PaddingDecorator) painter).getLeftPadding();
                    }
                }
            }
            return "0";
        } else if (NatTableCSSConstants.TABLE_BORDER_COLOR.equalsIgnoreCase(property)) {
            for (Iterator<IOverlayPainter> it = natTable.getOverlayPainters().iterator(); it.hasNext(); ) {
                IOverlayPainter painter = it.next();
                if (painter instanceof NatTableBorderOverlayPainter) {
                    return engine.getCSSValueConverter(String.class).convert(((NatTableBorderOverlayPainter) painter).getBorderColor(), engine, null);
                }
            }
        } else if (NatTableCSSConstants.FILL_HANDLE_BORDER.equalsIgnoreCase(property)) {
            BorderStyle border = NatTableCSSHelper.getNatTableStyle(natTable, FillHandleConfigAttributes.FILL_HANDLE_BORDER_STYLE, displayMode, label);
            ICSSValueConverter cssValueConverter = engine.getCSSValueConverter(String.class);
            return border.getThickness() + " " + border.getLineStyle().toString().toLowerCase() + " " + border.getBorderMode().toString().toLowerCase() + " " + cssValueConverter.convert(border.getColor(), engine, null);
        } else if (NatTableCSSConstants.FILL_HANDLE_COLOR.equalsIgnoreCase(property)) {
            ICSSValueConverter cssValueConverter = engine.getCSSValueConverter(String.class);
            return cssValueConverter.convert(natTable.getConfigRegistry().getConfigAttribute(FillHandleConfigAttributes.FILL_HANDLE_COLOR, displayMode, label), engine, null);
        } else if (NatTableCSSConstants.FILL_REGION_BORDER.equalsIgnoreCase(property)) {
            BorderStyle border = NatTableCSSHelper.getNatTableStyle(natTable, FillHandleConfigAttributes.FILL_HANDLE_REGION_BORDER_STYLE, displayMode, label);
            ICSSValueConverter cssValueConverter = engine.getCSSValueConverter(String.class);
            return border.getThickness() + " " + border.getLineStyle().toString().toLowerCase() + " " + border.getBorderMode().toString().toLowerCase() + " " + cssValueConverter.convert(border.getColor(), engine, null);
        } else if (NatTableCSSConstants.INVERT_ICONS.equalsIgnoreCase(property)) {
            // not able to determine it easily here
            return Boolean.FALSE.toString();
        } else if (NatTableCSSConstants.DECORATION.equalsIgnoreCase(property)) {
            // TODO : manage path of Image.
            return "none";
        } else if (NatTableCSSConstants.PERCENTAGE_DECORATOR_COLORS.equalsIgnoreCase(property)) {
            IStyle style = natTable.getConfigRegistry().getConfigAttribute(CellConfigAttributes.CELL_STYLE, displayMode, label);
            Color c1 = style.getAttributeValue(PercentageBarDecorator.PERCENTAGE_BAR_COMPLETE_REGION_START_COLOR);
            Color c2 = style.getAttributeValue(PercentageBarDecorator.PERCENTAGE_BAR_COMPLETE_REGION_END_COLOR);
            Color c3 = style.getAttributeValue(PercentageBarDecorator.PERCENTAGE_BAR_INCOMPLETE_REGION_COLOR);
            ICSSValueConverter cssValueConverter = engine.getCSSValueConverter(String.class);
            return cssValueConverter.convert(c1, engine, null) + " " + cssValueConverter.convert(c2, engine, null) + " " + cssValueConverter.convert(c3, engine, null);
        } else if (NatTableCSSConstants.CONVERTER.equalsIgnoreCase(property)) {
            IDisplayConverter converter = natTable.getConfigRegistry().getConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, displayMode, label);
            return NatTableCSSHelper.getDisplayConverterString(converter);
        }
    }
    return null;
}
Also used : IOverlayPainter(org.eclipse.nebula.widgets.nattable.painter.IOverlayPainter) BorderStyle(org.eclipse.nebula.widgets.nattable.style.BorderStyle) TextDecorationEnum(org.eclipse.nebula.widgets.nattable.style.TextDecorationEnum) ICSSValueConverter(org.eclipse.e4.ui.css.core.dom.properties.converters.ICSSValueConverter) Color(org.eclipse.swt.graphics.Color) CellPainterWrapper(org.eclipse.nebula.widgets.nattable.painter.cell.CellPainterWrapper) PaddingDecorator(org.eclipse.nebula.widgets.nattable.painter.cell.decorator.PaddingDecorator) VerticalAlignmentEnum(org.eclipse.nebula.widgets.nattable.style.VerticalAlignmentEnum) IDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.IDisplayConverter) Font(org.eclipse.swt.graphics.Font) ICellPainter(org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter) HorizontalAlignmentEnum(org.eclipse.nebula.widgets.nattable.style.HorizontalAlignmentEnum) IStyle(org.eclipse.nebula.widgets.nattable.style.IStyle) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) NatTableBorderOverlayPainter(org.eclipse.nebula.widgets.nattable.painter.NatTableBorderOverlayPainter) AbstractTextPainter(org.eclipse.nebula.widgets.nattable.painter.cell.AbstractTextPainter) VerticalTextPainter(org.eclipse.nebula.widgets.nattable.painter.cell.VerticalTextPainter)

Example 4 with VerticalTextPainter

use of org.eclipse.nebula.widgets.nattable.painter.cell.VerticalTextPainter in project nebula.widgets.nattable by eclipse.

the class TextPainter_Examples method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    parent.setLayout(new GridLayout(1, false));
    GridDataFactory.fillDefaults().grab(true, true).applyTo(parent);
    Composite tableContainer = new Composite(parent, SWT.NONE);
    tableContainer.setLayout(new GridLayout(6, true));
    GridDataFactory.fillDefaults().grab(true, true).applyTo(tableContainer);
    createNatTable(tableContainer, new GradientBackgroundPainter(new TextPainter(false, false, false), true));
    createNatTable(tableContainer, new TextPainter(true, true, false));
    createNatTable(tableContainer, new TextPainter(false, true, true));
    createNatTable(tableContainer, new TextPainter(true, true, true));
    createNatTable(tableContainer, new TextPainter(true, true, 5, true));
    createNatTable(tableContainer, new PaddingDecorator(new TextPainter(true, true, 5, true), 5));
    createVerticalHeaderNatTable(tableContainer, new VerticalTextPainter(false, true, false));
    createVerticalHeaderNatTable(tableContainer, new VerticalTextPainter(true, true, false));
    createVerticalHeaderNatTable(tableContainer, new GradientBackgroundPainter(new VerticalTextPainter(false, false, true)));
    createVerticalHeaderNatTable(tableContainer, new VerticalTextPainter(true, true, true));
    createVerticalHeaderNatTable(tableContainer, new VerticalTextPainter(true, true, 5, true));
    createVerticalHeaderNatTable(tableContainer, new PaddingDecorator(new VerticalTextPainter(true, true, 5, true), 5));
    TextPainter underlineTextPainer = new TextPainter();
    underlineTextPainer.setUnderline(true);
    createNatTable2(tableContainer, underlineTextPainer);
    TextPainter strikethroughTextPainer = new TextPainter();
    strikethroughTextPainer.setStrikethrough(true);
    createNatTable2(tableContainer, strikethroughTextPainer);
    TextPainter underlineStrikethroughTextPainer = new TextPainter();
    underlineStrikethroughTextPainer.setUnderline(true);
    underlineStrikethroughTextPainer.setStrikethrough(true);
    createNatTable2(tableContainer, underlineStrikethroughTextPainer);
    VerticalTextPainter vunderlineTextPainer = new VerticalTextPainter(true, true, true);
    vunderlineTextPainer.setUnderline(true);
    createVerticalHeaderNatTable(tableContainer, vunderlineTextPainer);
    VerticalTextPainter vstrikethroughTextPainer = new VerticalTextPainter(true, true, true);
    vstrikethroughTextPainer.setStrikethrough(true);
    createVerticalHeaderNatTable(tableContainer, vstrikethroughTextPainer);
    VerticalTextPainter vunderlineStrikethroughTextPainer = new VerticalTextPainter(true, true, true);
    vunderlineStrikethroughTextPainer.setUnderline(true);
    vunderlineStrikethroughTextPainer.setStrikethrough(true);
    createVerticalHeaderNatTable(tableContainer, vunderlineStrikethroughTextPainer);
    return tableContainer;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) PaddingDecorator(org.eclipse.nebula.widgets.nattable.painter.cell.decorator.PaddingDecorator) VerticalTextPainter(org.eclipse.nebula.widgets.nattable.painter.cell.VerticalTextPainter) TextPainter(org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter) GradientBackgroundPainter(org.eclipse.nebula.widgets.nattable.painter.cell.GradientBackgroundPainter) VerticalTextPainter(org.eclipse.nebula.widgets.nattable.painter.cell.VerticalTextPainter)

Aggregations

VerticalTextPainter (org.eclipse.nebula.widgets.nattable.painter.cell.VerticalTextPainter)4 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)3 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)2 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)2 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)2 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)2 BeveledBorderDecorator (org.eclipse.nebula.widgets.nattable.painter.cell.decorator.BeveledBorderDecorator)2 PaddingDecorator (org.eclipse.nebula.widgets.nattable.painter.cell.decorator.PaddingDecorator)2 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)2 ViewportLayer (org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 HashMap (java.util.HashMap)1 ICSSValueConverter (org.eclipse.e4.ui.css.core.dom.properties.converters.ICSSValueConverter)1 AbstractRegistryConfiguration (org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration)1 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)1 IDisplayConverter (org.eclipse.nebula.widgets.nattable.data.convert.IDisplayConverter)1 IExportFormatter (org.eclipse.nebula.widgets.nattable.export.IExportFormatter)1 ExportCommand (org.eclipse.nebula.widgets.nattable.export.command.ExportCommand)1 DefaultImageExportBindings (org.eclipse.nebula.widgets.nattable.export.image.config.DefaultImageExportBindings)1 HSSFExcelExporter (org.eclipse.nebula.widgets.nattable.extension.poi.HSSFExcelExporter)1