Package org.eclipse.nebula.widgets.nattable.data

Examples of org.eclipse.nebula.widgets.nattable.data.IDataProvider


        // 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<Person>(
                PersonService.getPersons(10), propertyNames);
        DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
        ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(
                bodyDataLayer);
        ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(
                columnReorderLayer);
        final SelectionLayer selectionLayer = new SelectionLayer(
                columnHideShowLayer);
        final ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);

        final FreezeLayer freezeLayer = new FreezeLayer(selectionLayer);
        final CompositeFreezeLayer compositeFreezeLayer = new CompositeFreezeLayer(
                freezeLayer, viewportLayer, selectionLayer);

        // build the column header layer
        IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(
                propertyNames, propertyToLabelMap);
        DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(
                columnHeaderDataProvider);
        ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(
                columnHeaderDataLayer, compositeFreezeLayer, selectionLayer);

        // build the row header layer
        IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(
                bodyDataProvider);
        DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(
                rowHeaderDataProvider);
        ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer,
                compositeFreezeLayer, selectionLayer);

        // build the corner layer
        IDataProvider cornerDataProvider = new DefaultCornerDataProvider(
                columnHeaderDataProvider, rowHeaderDataProvider);
        DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
        ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer,
                columnHeaderLayer);
View Full Code Here


        propertyToLabelMap.put("lastName", "Lastname");
        propertyToLabelMap.put("gender", "Gender");
        propertyToLabelMap.put("married", "Married");
        propertyToLabelMap.put("birthday", "Birthday");

        IDataProvider bodyDataProvider = new DefaultBodyDataProvider<Person>(
                PersonService.getPersons(10), propertyNames);
        DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
        SelectionLayer selectionLayer = new SelectionLayer(bodyDataLayer);
        ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
View Full Code Here

        bodyLayerStack.getBodyDataLayer().setConfigLabelAccumulator(
                new ColumnLabelAccumulator());

        // build the column header layer
        IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(
                propertyNames, propertyToLabelMap);
        DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(
                columnHeaderDataProvider);
        ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer,
                bodyLayerStack, bodyLayerStack.getSelectionLayer());

        // add sorting
        SortHeaderLayer<ExtendedPersonWithAddress> sortHeaderLayer = new SortHeaderLayer<ExtendedPersonWithAddress>(
                columnHeaderLayer,
                new GlazedListsSortModel<ExtendedPersonWithAddress>(
                        bodyLayerStack.getSortedList(), columnPropertyAccessor,
                        configRegistry, columnHeaderDataLayer), false);

        // connect sortModel to GroupByDataLayer to support sorting by group by
        // summary values
        bodyLayerStack.getBodyDataLayer().setSortModel(
                sortHeaderLayer.getSortModel());

        // build the row header layer
        // Adding the specialized DefaultSummaryRowHeaderDataProvider to
        // indicate the summary row in the row header
        IDataProvider rowHeaderDataProvider = new DefaultSummaryRowHeaderDataProvider(
                bodyLayerStack.getBodyDataProvider(), "\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(ROW_HEADER_SUMMARY_ROW);
                    configLabels
                            .addLabel(SummaryRowLayer.DEFAULT_SUMMARY_ROW_CONFIG_LABEL);
                }
            }
        });
        ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer,
                bodyLayerStack, bodyLayerStack.getSelectionLayer());

        // build the corner layer
        IDataProvider cornerDataProvider = new DefaultCornerDataProvider(
                columnHeaderDataProvider, rowHeaderDataProvider);
        DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
        ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer,
                sortHeaderLayer);

        // build the grid layer
        GridLayer gridLayer = new GridLayer(bodyLayerStack, sortHeaderLayer,
                rowHeaderLayer, cornerLayer, false);

        // set the group by header on top of the grid
        CompositeLayer compositeGridLayer = new CompositeLayer(1, 2);
        final GroupByHeaderLayer groupByHeaderLayer = new GroupByHeaderLayer(
                bodyLayerStack.getGroupByModel(), gridLayer,
                columnHeaderDataProvider);
        compositeGridLayer.setChildLayer(GroupByHeaderLayer.GROUP_BY_REGION,
                groupByHeaderLayer, 0, 0);
        compositeGridLayer.setChildLayer("Grid", gridLayer, 0, 1);

        // turn the auto configuration off as we want to add our header menu
        // configuration
        final NatTable natTable = new NatTable(container, compositeGridLayer,
                false);

        // as the autoconfiguration of the NatTable is turned off, we have to
        // add the
        // DefaultNatTableStyleConfiguration and the ConfigRegistry manually
        natTable.setConfigRegistry(configRegistry);
        natTable.addConfiguration(new DefaultNatTableStyleConfiguration());

        // add some additional styling
        natTable.addConfiguration(new AbstractRegistryConfiguration() {

            @Override
            public void configureRegistry(IConfigRegistry configRegistry) {
                configRegistry.registerConfigAttribute(
                        CellConfigAttributes.CELL_PAINTER,
                        new CheckBoxPainter(), DisplayMode.NORMAL,
                        ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 4);

                IStyle style = new Style();
                style.setAttributeValue(
                        CellStyleAttributes.HORIZONTAL_ALIGNMENT,
                        HorizontalAlignmentEnum.RIGHT);
                configRegistry.registerConfigAttribute(
                        CellConfigAttributes.CELL_STYLE, style,
                        DisplayMode.NORMAL,
                        ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 2);
                configRegistry.registerConfigAttribute(
                        CellConfigAttributes.CELL_STYLE, style,
                        DisplayMode.NORMAL,
                        ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 3);

                configRegistry.registerConfigAttribute(
                        CellConfigAttributes.DISPLAY_CONVERTER,
                        new DefaultDoubleDisplayConverter(),
                        DisplayMode.NORMAL,
                        ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 3);

                // the main styling of the summary row cell in the row header is
                // done via
                // summary row default style, but we need to override the
                // alignment
                style = new Style();
                style.setAttributeValue(
                        CellStyleAttributes.HORIZONTAL_ALIGNMENT,
                        HorizontalAlignmentEnum.CENTER);
                configRegistry.registerConfigAttribute(
                        CellConfigAttributes.CELL_STYLE, style,
                        DisplayMode.NORMAL, ROW_HEADER_SUMMARY_ROW);
                configRegistry.registerConfigAttribute(
                        CellConfigAttributes.CELL_STYLE, style,
                        DisplayMode.SELECT, ROW_HEADER_SUMMARY_ROW);
            }
        });

        // add sorting configuration
        natTable.addConfiguration(new SingleClickSortConfiguration());

        this.sumMoneyGroupBySummaryProvider = new SummationGroupBySummaryProvider<ExtendedPersonWithAddress>(
                columnPropertyAccessor);
        this.avgMoneyGroupBySummaryProvider = new AverageMoneyGroupBySummaryProvider();

        // create a new IDataProvider that operates on the basic underlying list
        // this is necessary because the IDataProvider in the body layer stack
        // is operating
        // on the TreeList, and on collapsing a node, the children will be not
        // visible, which
        // has effect on the summary value.
        final IDataProvider summaryDataProvider = new ListDataProvider<ExtendedPersonWithAddress>(
                persons, columnPropertyAccessor);
        this.sumMoneySummaryProvider = new SummationSummaryProvider(
                summaryDataProvider, false);
        this.avgMoneySummaryProvider = new AverageMoneySummaryProvider(
                summaryDataProvider);
View Full Code Here

        IColumnPropertyAccessor<Person> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<Person>(
                propertyNames);

        final List<Person> data = PersonService.getPersons(10);

        IDataProvider bodyDataProvider = new ListDataProvider<Person>(data,
                columnPropertyAccessor);
        final DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
        final SelectionLayer selectionLayer = new SelectionLayer(bodyDataLayer);
        ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
View Full Code Here

        final BodyLayerStack<PersonWithAddress> bodyLayerStack = new BodyLayerStack<PersonWithAddress>(
                PersonService.getPersonsWithAddress(50), columnPropertyAccessor);

        // build the column header layer
        IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(
                propertyNames, propertyToLabelMap);
        DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(
                columnHeaderDataProvider);
        ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer,
                bodyLayerStack, bodyLayerStack.getSelectionLayer());

        ComboBoxFilterRowHeaderComposite<PersonWithAddress> filterRowHeaderLayer = new ComboBoxFilterRowHeaderComposite<PersonWithAddress>(
                bodyLayerStack.getFilterList(),
                bodyLayerStack.getGlazedListsEventLayer(),
                bodyLayerStack.getSortedList(), columnPropertyAccessor,
                columnHeaderLayer, columnHeaderDataProvider, configRegistry);

        // build the row header layer
        IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(
                bodyLayerStack.getBodyDataProvider());
        DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(
                rowHeaderDataProvider);
        ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer,
                bodyLayerStack, bodyLayerStack.getSelectionLayer());

        // build the corner layer
        IDataProvider cornerDataProvider = new DefaultCornerDataProvider(
                columnHeaderDataProvider, rowHeaderDataProvider);
        DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
        ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer,
                filterRowHeaderLayer);
View Full Code Here

                "married", "birthday" };

        IColumnPropertyAccessor<Person> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<Person>(
                propertyNames);

        IDataProvider bodyDataProvider = new ListDataProvider<Person>(
                PersonService.getPersons(10), columnPropertyAccessor);
        final DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);

        // use different style bits to avoid rendering of inactive scrollbars
        // for small table
View Full Code Here

                propertyNames);

        final List<Person> data = PersonService.getPersons(10);

        // create the body layer stack
        IDataProvider bodyDataProvider = new ListDataProvider<Person>(data,
                columnPropertyAccessor);
        final DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
        final SelectionLayer selectionLayer = new SelectionLayer(bodyDataLayer);
        ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);

        // create the column header layer stack
        IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(
                propertyNames, propertyToLabelMap);
        ILayer columnHeaderLayer = new ColumnHeaderLayer(new DataLayer(
                columnHeaderDataProvider), viewportLayer, selectionLayer);

        // create the row header layer stack
        IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(
                bodyDataProvider);
        ILayer rowHeaderLayer = new RowHeaderLayer(new DataLayer(
                rowHeaderDataProvider, 40, 20), viewportLayer, selectionLayer);

        // create the corner layer stack
View Full Code Here

        propertyToLabelMap.put("lastName", "Lastname");
        propertyToLabelMap.put("gender", "Gender");
        propertyToLabelMap.put("married", "Married");
        propertyToLabelMap.put("birthday", "Birthday");

        IDataProvider bodyDataProvider = new DefaultBodyDataProvider<Person>(
                PersonService.getPersons(100), propertyNames);
        DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
        SelectionLayer selectionLayer = new SelectionLayer(bodyDataLayer);
        ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
View Full Code Here

        // 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<Person>(
                PersonService.getPersons(10), propertyNames);
        DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
        SelectionLayer selectionLayer = new SelectionLayer(bodyDataLayer);
        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);
View Full Code Here

        final BodyLayerStack<PersonWithAddress> bodyLayer = new BodyLayerStack<PersonWithAddress>(
                PersonService.getPersonsWithAddress(50), columnPropertyAccessor);

        // build the row header layer
        IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(
                bodyLayer.getBodyDataProvider());
        DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(
                rowHeaderDataProvider);
        final ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer,
                bodyLayer, bodyLayer.getSelectionLayer());

        // build the column header layer
        IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(
                propertyNames, propertyToLabelMap);
        final DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(
                columnHeaderDataProvider);
        final AbstractLayer columnHeaderLayer = new ColumnHeaderLayer(
                columnHeaderDataLayer, bodyLayer, bodyLayer.getSelectionLayer());

        // Use this special layer painter that supports rendering of split
        // viewports although
        // the ColumnHeaderLayer is not split. Here is some custom calculation
        // included that
        // might not work correctly in case there are column groups or other
        // spanning involved.
        columnHeaderLayer.setLayerPainter(new CellLayerPainter() {
            @Override
            protected boolean isClipLeft(int position) {
                // check position-1 because of the row header column count
                // as the body is a composite layer, the default transformation
                // for the grid is not working correctly
                int index = LayerUtil.convertColumnPosition(columnHeaderLayer,
                        position - 1, columnHeaderDataLayer);
                return (index > SPLIT_COLUMN_INDEX);
            }

            @Override
            protected void paintCell(ILayerCell cell, GC gc,
                    IConfigRegistry configRegistry) {
                ILayer layer = cell.getLayer();
                int columnPosition = cell.getColumnPosition();
                int rowPosition = cell.getRowPosition();
                ICellPainter cellPainter = layer.getCellPainter(columnPosition,
                        rowPosition, cell, configRegistry);
                Rectangle adjustedCellBounds = layer.getLayerPainter()
                        .adjustCellBounds(columnPosition, rowPosition,
                                cell.getBounds());
                if (cellPainter != null) {
                    Rectangle originalClipping = gc.getClipping();

                    int startX = getStartXOfColumnPosition(columnPosition);
                    int startY = getStartYOfRowPosition(rowPosition);

                    int endX = getStartXOfColumnPosition(cell
                            .getOriginColumnPosition() + cell.getColumnSpan());
                    int endY = getStartYOfRowPosition(cell
                            .getOriginRowPosition() + cell.getRowSpan());

                    // correct position of first column in right region
                    // find the last visible column in left region
                    int viewportBorderX = bodyLayer.getViewportLayerLeft()
                            .getClientAreaWidth() + rowHeaderLayer.getWidth();
                    if (isClipLeft(columnPosition) && startX < viewportBorderX) {
                        startX = viewportBorderX;
                    }
                    if (!isClipLeft(columnPosition - 1)
                            && startX > viewportBorderX) {
                        startX = viewportBorderX;
                    }
                    if (isClipLeft(cell.getOriginColumnPosition()
                            + cell.getColumnSpan())
                            && endX < viewportBorderX) {
                        endX = viewportBorderX;
                    }

                    Rectangle cellClipBounds = originalClipping
                            .intersection(new Rectangle(startX, startY, endX
                                    - startX, endY - startY));
                    gc.setClipping(cellClipBounds
                            .intersection(adjustedCellBounds));

                    cellPainter.paintCell(cell, gc, adjustedCellBounds,
                            configRegistry);

                    gc.setClipping(originalClipping);
                }
            }
        });

        // build the corner layer
        IDataProvider cornerDataProvider = new DefaultCornerDataProvider(
                columnHeaderDataProvider, rowHeaderDataProvider);
        DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
        final ILayer cornerLayer = new CornerLayer(cornerDataLayer,
                rowHeaderLayer, columnHeaderLayer);
View Full Code Here

TOP

Related Classes of org.eclipse.nebula.widgets.nattable.data.IDataProvider

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.