Search in sources :

Example 1 with DummyColumnHeaderDataProvider

use of org.eclipse.nebula.widgets.nattable.grid.data.DummyColumnHeaderDataProvider in project nebula.widgets.nattable by eclipse.

the class ViewportIntegrationTest method shouldInitWithNoScroll.

@Test
public void shouldInitWithNoScroll() {
    List<String> contents = new ArrayList<>(Arrays.asList("one", "two", "three", "four", "five"));
    IDataProvider bodyDataProvider = new ListDataProvider<>(contents, new IColumnAccessor<String>() {

        @Override
        public Object getDataValue(String rowObject, int columnIndex) {
            return rowObject;
        }

        @Override
        public void setDataValue(String rowObject, int columnIndex, Object newValue) {
        // ignore
        }

        @Override
        public int getColumnCount() {
            return 1;
        }
    });
    SelectionLayer selectionLayer = new SelectionLayer(new DataLayer(bodyDataProvider));
    ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
    IDataProvider colDataProvider = new DummyColumnHeaderDataProvider(bodyDataProvider);
    ColumnHeaderLayer colHeader = new ColumnHeaderLayer(new DataLayer(colDataProvider), viewportLayer, selectionLayer);
    IDataProvider rowDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
    RowHeaderLayer rowHeaderLayer = new RowHeaderLayer(new DataLayer(rowDataProvider), viewportLayer, selectionLayer);
    CornerLayer cornerLayer = new CornerLayer(new DataLayer(new DefaultCornerDataProvider(colDataProvider, rowDataProvider)), rowHeaderLayer, colHeader);
    GridLayer grid = new GridLayer(viewportLayer, colHeader, rowHeaderLayer, cornerLayer);
    // create the table with no scrollbars
    NatTable natTable = new NatTable(new Shell(), SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE | SWT.DOUBLE_BUFFERED, grid);
    // this caused a NPE for scrollbar initialization
    natTable.setSize(600, 600);
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) ArrayList(java.util.ArrayList) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) DummyColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DummyColumnHeaderDataProvider) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) RowHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer) Shell(org.eclipse.swt.widgets.Shell) CornerLayer(org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) Test(org.junit.Test)

Example 2 with DummyColumnHeaderDataProvider

use of org.eclipse.nebula.widgets.nattable.grid.data.DummyColumnHeaderDataProvider in project nebula.widgets.nattable by eclipse.

the class PercentageExample method postConstruct.

@PostConstruct
public void postConstruct(Composite parent) {
    // Setup the layer stack
    final MyDataProvider myDataProvider = new MyDataProvider();
    SelectionLayer selectionLayer = new SelectionLayer(new DataLayer(myDataProvider));
    ILayer columnHeaderLayer = new ColumnHeaderLayer(new DataLayer(new DummyColumnHeaderDataProvider(myDataProvider)), selectionLayer, selectionLayer);
    CompositeLayer compositeLayer = new CompositeLayer(1, 2);
    compositeLayer.setChildLayer(GridRegion.COLUMN_HEADER, columnHeaderLayer, 0, 0);
    compositeLayer.setChildLayer(GridRegion.BODY, selectionLayer, 0, 1);
    NatTable natTable = new NatTable(parent, compositeLayer);
    natTable.setData(CSSSWTConstants.CSS_CLASS_NAME_KEY, "percentage");
    parent.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
    showSourceLinks(parent, getClass().getName());
}
Also used : DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) GridLayout(org.eclipse.swt.layout.GridLayout) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) CompositeLayer(org.eclipse.nebula.widgets.nattable.layer.CompositeLayer) DummyColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DummyColumnHeaderDataProvider) PostConstruct(javax.annotation.PostConstruct)

Example 3 with DummyColumnHeaderDataProvider

use of org.eclipse.nebula.widgets.nattable.grid.data.DummyColumnHeaderDataProvider in project nebula.widgets.nattable by eclipse.

the class _001_Custom_styling_of_specific_cells method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    List<SimplePerson> myList = new ArrayList<>();
    for (int i = 1; i <= 100; i++) {
        myList.add(new SimplePerson(i, "Joe" + i, new Date()));
    }
    String[] propertyNames = { "id", "name", "birthDate" };
    IColumnPropertyAccessor<SimplePerson> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
    ListDataProvider<SimplePerson> listDataProvider = new ListDataProvider<>(myList, columnPropertyAccessor);
    DefaultGridLayer gridLayer = new DefaultGridLayer(listDataProvider, new DummyColumnHeaderDataProvider(listDataProvider));
    final DefaultBodyLayerStack bodyLayer = gridLayer.getBodyLayer();
    // Custom label "FOO" for cell at column, row index (1, 5)
    IConfigLabelAccumulator cellLabelAccumulator = new IConfigLabelAccumulator() {

        @Override
        public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
            int columnIndex = bodyLayer.getColumnIndexByPosition(columnPosition);
            int rowIndex = bodyLayer.getRowIndexByPosition(rowPosition);
            if (columnIndex == 1 && rowIndex == 5) {
                configLabels.addLabel(FOO_LABEL);
            }
            if (columnIndex == 1 && rowIndex == 10) {
                configLabels.addLabel(BAR_LABEL);
            }
            // add labels for surrounding borders
            if (rowIndex == 13) {
                configLabels.addLabel(CustomLineBorderDecorator.TOP_LINE_BORDER_LABEL);
                configLabels.addLabel(CustomLineBorderDecorator.BOTTOM_LINE_BORDER_LABEL);
                if (columnIndex == 0) {
                    configLabels.addLabel(CustomLineBorderDecorator.LEFT_LINE_BORDER_LABEL);
                }
                if (columnIndex == 2) {
                    configLabels.addLabel(CustomLineBorderDecorator.RIGHT_LINE_BORDER_LABEL);
                }
            }
        }
    };
    bodyLayer.setConfigLabelAccumulator(cellLabelAccumulator);
    NatTable natTable = new NatTable(parent, gridLayer, false);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration() {

        {
            // override the LineBorderDecorator here to show how to paint
            // borders on single sides of a cell
            this.cellPainter = new CustomLineBorderDecorator(new TextPainter());
            // set a border style
            this.borderStyle = new BorderStyle(2, GUIHelper.COLOR_BLUE, LineStyleEnum.DASHDOT);
        }
    });
    // Custom style for label "FOO"
    natTable.addConfiguration(new AbstractRegistryConfiguration() {

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            Style cellStyle = new Style();
            cellStyle.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, GUIHelper.COLOR_GREEN);
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, DisplayMode.NORMAL, FOO_LABEL);
            cellStyle = new Style();
            cellStyle.setAttributeValue(CellStyleAttributes.TEXT_DECORATION, TextDecorationEnum.UNDERLINE_STRIKETHROUGH);
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, DisplayMode.NORMAL, BAR_LABEL);
        }
    });
    natTable.configure();
    return natTable;
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack) AbstractRegistryConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration) ArrayList(java.util.ArrayList) IConfigLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.IConfigLabelAccumulator) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) Style(org.eclipse.nebula.widgets.nattable.style.Style) BorderStyle(org.eclipse.nebula.widgets.nattable.style.BorderStyle) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) BorderStyle(org.eclipse.nebula.widgets.nattable.style.BorderStyle) TextPainter(org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter) Date(java.util.Date) DummyColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DummyColumnHeaderDataProvider) ReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor) CustomLineBorderDecorator(org.eclipse.nebula.widgets.nattable.painter.cell.decorator.CustomLineBorderDecorator) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer) DefaultBodyLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack) SimplePerson(org.eclipse.nebula.widgets.nattable.dataset.person.SimplePerson)

Example 4 with DummyColumnHeaderDataProvider

use of org.eclipse.nebula.widgets.nattable.grid.data.DummyColumnHeaderDataProvider in project nebula.widgets.nattable by eclipse.

the class TextPainter_Examples method createNatTable3.

@SuppressWarnings("unused")
private void createNatTable3(Composite parent, final ICellPainter painter) {
    IDataProvider bodyDataProvider = new ExampleHeaderDataProvider();
    DataLayer dataLayer = new DataLayer(bodyDataProvider);
    SelectionLayer selectionLayer = new SelectionLayer(dataLayer);
    ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
    ILayer columnHeaderLayer = new ColumnHeaderLayer(new DataLayer(new DummyColumnHeaderDataProvider(bodyDataProvider)), viewportLayer, selectionLayer);
    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.TOP;
            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) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) 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) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) NatTable(org.eclipse.nebula.widgets.nattable.NatTable)

Example 5 with DummyColumnHeaderDataProvider

use of org.eclipse.nebula.widgets.nattable.grid.data.DummyColumnHeaderDataProvider in project nebula.widgets.nattable by eclipse.

the class TextPainter_Examples method createNatTable.

private void createNatTable(Composite parent, final ICellPainter painter) {
    IDataProvider bodyDataProvider = new ExampleTextBodyDataProvider();
    DataLayer dataLayer = new DataLayer(bodyDataProvider);
    dataLayer.setRowHeightByPosition(0, 32);
    SelectionLayer selectionLayer = new SelectionLayer(dataLayer);
    ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
    ILayer columnHeaderLayer = new ColumnHeaderLayer(new DataLayer(new DummyColumnHeaderDataProvider(bodyDataProvider)), viewportLayer, selectionLayer);
    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.TOP;
            this.hAlign = HorizontalAlignmentEnum.LEFT;
            this.cellPainter = new LineBorderDecorator(painter);
        }
    });
    natTable.configure();
    GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
}
Also used : DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) LineBorderDecorator(org.eclipse.nebula.widgets.nattable.painter.cell.decorator.LineBorderDecorator) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) 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)

Aggregations

DummyColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DummyColumnHeaderDataProvider)17 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)16 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)16 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)16 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)16 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)13 ViewportLayer (org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer)11 CompositeLayer (org.eclipse.nebula.widgets.nattable.layer.CompositeLayer)10 DummyBodyDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DummyBodyDataProvider)8 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)7 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)6 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)6 DefaultRowHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider)6 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)6 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)6 RowHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer)6 ColumnReorderLayer (org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer)5 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)4 LineBorderDecorator (org.eclipse.nebula.widgets.nattable.painter.cell.decorator.LineBorderDecorator)3 ArrayList (java.util.ArrayList)2