Package org.eclipse.nebula.widgets.nattable

Examples of org.eclipse.nebula.widgets.nattable.NatTable


        GridLayer gridLayer = new GridLayer(bodyLayerStack,
                filterRowHeaderLayer, rowHeaderLayer, cornerLayer);

        // turn the auto configuration off as we want to add our header menu
        // configuration
        NatTable natTable = new NatTable(container, gridLayer, 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());

        natTable.addConfiguration(new HeaderMenuConfiguration(natTable) {
            @Override
            protected PopupMenuBuilder createCornerMenu(NatTable natTable) {
                return super.createCornerMenu(natTable)
                        .withStateManagerMenuItemProvider();
            }
        });

        natTable.addConfiguration(new AbstractRegistryConfiguration() {

            @Override
            public void configureRegistry(IConfigRegistry configRegistry) {
                configRegistry.registerConfigAttribute(
                        EditConfigAttributes.CELL_EDITABLE_RULE,
                        IEditableRule.ALWAYS_EDITABLE);
            }

        });

        natTable.configure();

        natTable.registerCommandHandler(new DisplayPersistenceDialogCommandHandler(
                natTable));

        GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);

        Button button = new Button(container, SWT.PUSH);
View Full Code Here


        CompositeLayer compositeLayer = new CompositeLayer(1, 2);
        compositeLayer.setChildLayer(GridRegion.COLUMN_HEADER,
                columnHeaderLayer, 0, 0);
        compositeLayer.setChildLayer(GridRegion.BODY, viewportLayer, 0, 1);

        return new NatTable(parent, compositeLayer);
    }
View Full Code Here

                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);
            }
        });

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

        sumMoneySummaryProvider = new SummationGroupBySummaryProvider<ExtendedPersonWithAddress>(
                columnPropertyAccessor);
        avgMoneySummaryProvider = new AverageMoneyGroupBySummaryProvider();

        // add group by summary configuration
        natTable.addConfiguration(new AbstractRegistryConfiguration() {

            @Override
            public void configureRegistry(IConfigRegistry configRegistry) {
                configRegistry.registerConfigAttribute(
                        GroupByConfigAttributes.GROUP_BY_SUMMARY_PROVIDER,
                        sumMoneySummaryProvider, DisplayMode.NORMAL,
                        GroupByDataLayer.GROUP_BY_COLUMN_PREFIX + 3);

                configRegistry.registerConfigAttribute(
                        GroupByConfigAttributes.GROUP_BY_SUMMARY_PROVIDER,
                        new AverageAgeGroupBySummaryProvider(),
                        DisplayMode.NORMAL,
                        GroupByDataLayer.GROUP_BY_COLUMN_PREFIX + 2);

                configRegistry.registerConfigAttribute(
                        GroupByConfigAttributes.GROUP_BY_CHILD_COUNT_PATTERN,
                        "[{0}] - ({1})");

                // set a custom display converter to the money groupby column
                // that transforms the
                // values correctly localized
                configRegistry.registerConfigAttribute(
                        CellConfigAttributes.DISPLAY_CONVERTER,
                        new SummaryDisplayConverter(
                                new DefaultDoubleDisplayConverter()),
                        DisplayMode.NORMAL,
                        GroupByDataLayer.GROUP_BY_SUMMARY_COLUMN_PREFIX + 3);
            }
        });

        // add group by header configuration
        natTable.addConfiguration(new GroupByHeaderMenuConfiguration(natTable,
                groupByHeaderLayer));

        natTable.addConfiguration(new AbstractHeaderMenuConfiguration(natTable) {

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

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

        natTable.configure();

        natTable.registerCommandHandler(new DisplayPersistenceDialogCommandHandler(
                natTable));

        GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);

        Composite buttonPanel = new Composite(container, SWT.NONE);
        buttonPanel.setLayout(new RowLayout());
        GridDataFactory.fillDefaults().grab(true, false).applyTo(buttonPanel);

        Button toggleHeaderButton = new Button(buttonPanel, SWT.PUSH);
        toggleHeaderButton.setText("Toggle Group By Header");
        toggleHeaderButton.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                groupByHeaderLayer.setVisible(!groupByHeaderLayer.isVisible());
            }
        });

        Button collapseAllButton = new Button(buttonPanel, SWT.PUSH);
        collapseAllButton.setText("Collapse All");
        collapseAllButton.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                natTable.doCommand(new TreeCollapseAllCommand());
            }
        });

        Button expandAllButton = new Button(buttonPanel, SWT.PUSH);
        expandAllButton.setText("Expand All");
        expandAllButton.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                natTable.doCommand(new TreeExpandAllCommand());
            }
        });

        Button toggleMoneySummaryButton = new Button(buttonPanel, SWT.PUSH);
        toggleMoneySummaryButton
                .setText("Toggle Money Group Summary (SUM/AVG)");
        toggleMoneySummaryButton.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                // clear the group by summary cache so the new summary
                // calculation gets triggered
                bodyLayerStack.getBodyDataLayer().clearCache();

                useMoneySum = !useMoneySum;
                if (useMoneySum) {
                    configRegistry.registerConfigAttribute(
                            GroupByConfigAttributes.GROUP_BY_SUMMARY_PROVIDER,
                            sumMoneySummaryProvider, DisplayMode.NORMAL,
                            GroupByDataLayer.GROUP_BY_COLUMN_PREFIX + 3);
                } else {
                    configRegistry.registerConfigAttribute(
                            GroupByConfigAttributes.GROUP_BY_SUMMARY_PROVIDER,
                            avgMoneySummaryProvider, DisplayMode.NORMAL,
                            GroupByDataLayer.GROUP_BY_COLUMN_PREFIX + 3);
                }
                natTable.doCommand(new VisualRefreshCommand());
            }
        });

        return container;
    }
View Full Code Here

        final ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(
                bodyDataLayer);
        bodyDataLayer.setConfigLabelAccumulator(columnLabelAccumulator);
        registerColumnLabels(columnLabelAccumulator);

        NatTable natTable = new NatTable(parent, gridLayer, false);
        natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
        natTable.addConfiguration(new TableEditConfiguration());
        natTable.configure();

        return natTable;
    }
View Full Code Here

        // add the PrintCommandHandler to the ViewportLayer in order to make
        // printing work
        viewportLayer.registerCommandHandler(new PrintCommandHandler(
                viewportLayer));

        final NatTable natTable = new NatTable(gridPanel, viewportLayer, false);

        // adding this configuration adds the styles and the painters to use
        natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
        natTable.addConfiguration(new DefaultPrintBindings());

        natTable.configure();

        GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);

        Button addColumnButton = new Button(buttonPanel, SWT.PUSH);
        addColumnButton.setText("Print");
        addColumnButton.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                natTable.doCommand(new PrintCommand(natTable
                        .getConfigRegistry(), natTable.getShell()));
            }
        });

        return panel;
    }
View Full Code Here

        // Note: The enabling/disabling and showing of the scrollbars is handled
        // by the ViewportLayer.
        // Without the ViewportLayer the scrollbars will always be visible with
        // the default
        // style bits of NatTable.
        final NatTable natTable = new NatTable(parent, SWT.NO_BACKGROUND
                | SWT.NO_REDRAW_RESIZE | SWT.DOUBLE_BUFFERED, bodyDataLayer);

        GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);

        Button b1 = new Button(parent, SWT.PUSH);
        b1.setText("Toggle column width");
        b1.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                showDefaultColumnWidth = !showDefaultColumnWidth;
                if (showDefaultColumnWidth) {
                    // reset to default
                    bodyDataLayer.setColumnWidthByPosition(0,
                            DataLayer.DEFAULT_COLUMN_WIDTH, false);
                    bodyDataLayer.setColumnWidthByPosition(1,
                            DataLayer.DEFAULT_COLUMN_WIDTH, false);
                    bodyDataLayer.setColumnWidthByPosition(2,
                            DataLayer.DEFAULT_COLUMN_WIDTH, false);
                    bodyDataLayer.setColumnWidthByPosition(3,
                            DataLayer.DEFAULT_COLUMN_WIDTH, false);
                    // this one will trigger the refresh
                    bodyDataLayer.setColumnWidthByPosition(4,
                            DataLayer.DEFAULT_COLUMN_WIDTH, true);
                } else {
                    bodyDataLayer.setColumnWidthByPosition(0, 70, false);
                    bodyDataLayer.setColumnWidthByPosition(1, 70, false);
                    bodyDataLayer.setColumnWidthByPosition(2, 50, false);
                    bodyDataLayer.setColumnWidthByPosition(3, 30, false);
                    // this one will trigger the refresh
                    bodyDataLayer.setColumnWidthByPosition(4, 200, true);
                }
            }
        });

        Button b2 = new Button(parent, SWT.PUSH);
        b2.setText("Toggle row height");
        b2.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                showDefaultRowHeight = !showDefaultRowHeight;
                if (showDefaultRowHeight) {
                    // reset to default
                    bodyDataLayer
                            .setDefaultRowHeight(DataLayer.DEFAULT_ROW_HEIGHT);
                } else {
                    bodyDataLayer.setDefaultRowHeight(50);
                }

                // repaint the table, as setting the default height is not
                // triggering a refresh automatically
                // this is because setting the default usually should be done
                // prior rendering
                natTable.doCommand(new VisualRefreshCommand());
            }
        });

        return natTable;
    }
View Full Code Here

        // create the grid layer composed with the prior created layer stacks
        GridLayer gridLayer = new GridLayer(viewportLayer, columnHeaderLayer,
                rowHeaderLayer, cornerLayer);

        return new NatTable(parent, gridLayer);
    }
View Full Code Here

        GridLayer gridLayer = new GridLayer(viewportLayer, columnHeaderLayer,
                rowHeaderLayer, cornerLayer);

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

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

        natTable.addConfiguration(new AbstractUiBindingConfiguration() {
            @Override
            public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
                uiBindingRegistry.registerMouseMoveBinding(
                        new MouseEventMatcher(GridRegion.BODY),
                        new ClearHoverStylingAction());
            }
        });

        // add the style configuration for hover
        natTable.addConfiguration(new AbstractRegistryConfiguration() {

            @Override
            public void configureRegistry(IConfigRegistry configRegistry) {
                Style style = new Style();
                style.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR,
                        GUIHelper.COLOR_RED);

                configRegistry.registerConfigAttribute(
                        CellConfigAttributes.CELL_STYLE, style,
                        DisplayMode.HOVER, GridRegion.ROW_HEADER);

                Image bgImage = new Image(
                        Display.getDefault(),
                        getClass()
                                .getResourceAsStream(
                                        "/org/eclipse/nebula/widgets/nattable/examples/resources/column_header_bg.png"));
                Image hoverBgImage = new Image(
                        Display.getDefault(),
                        getClass()
                                .getResourceAsStream(
                                        "/org/eclipse/nebula/widgets/nattable/examples/resources/hovered_column_header_bg.png"));
                Image selectedBgImage = new Image(
                        Display.getDefault(),
                        getClass()
                                .getResourceAsStream(
                                        "/org/eclipse/nebula/widgets/nattable/examples/resources/selected_column_header_bg.png"));

                TextPainter txtPainter = new TextPainter(false, false);

                ICellPainter bgImagePainter = new BackgroundImagePainter(
                        txtPainter, bgImage, GUIHelper.getColor(192, 192, 192));

                configRegistry.registerConfigAttribute(
                        CellConfigAttributes.CELL_PAINTER, bgImagePainter,
                        DisplayMode.NORMAL, GridRegion.COLUMN_HEADER);
                configRegistry.registerConfigAttribute(
                        CellConfigAttributes.CELL_PAINTER, bgImagePainter,
                        DisplayMode.NORMAL, GridRegion.CORNER);

                ICellPainter hoveredHeaderPainter = new BackgroundImagePainter(
                        txtPainter, hoverBgImage, GUIHelper.getColor(192, 192,
                                192));

                configRegistry.registerConfigAttribute(
                        CellConfigAttributes.CELL_PAINTER,
                        hoveredHeaderPainter, DisplayMode.HOVER,
                        GridRegion.COLUMN_HEADER);

                ICellPainter selectedHeaderPainter = new BackgroundImagePainter(
                        txtPainter, selectedBgImage, GUIHelper.getColor(192,
                                192, 192));

                configRegistry.registerConfigAttribute(
                        CellConfigAttributes.CELL_PAINTER,
                        selectedHeaderPainter, DisplayMode.SELECT,
                        GridRegion.COLUMN_HEADER);

            }
        });
        natTable.configure();

        return natTable;
    }
View Full Code Here

        gridLayout.marginWidth = 0;
        gridLayout.horizontalSpacing = 0;
        gridLayout.verticalSpacing = 0;
        composite.setLayout(gridLayout);

        NatTable natTable = new NatTable(composite, gridLayer, false);
        GridData gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.verticalAlignment = GridData.FILL;
        gridData.grabExcessHorizontalSpace = true;
        gridData.grabExcessVerticalSpace = true;
        natTable.setLayoutData(gridData);

        createSplitSliders(composite, rowHeaderLayer,
                bodyLayer.getViewportLayerLeft(),
                bodyLayer.getViewportLayerRight());

        // add an IOverlayPainter to ensure the right border of the left
        // viewport always
        // this is necessary because the left border of layer stacks is not
        // rendered by default
        natTable.addOverlayPainter(new IOverlayPainter() {

            @Override
            public void paintOverlay(GC gc, ILayer layer) {
                Color beforeColor = gc.getForeground();
                gc.setForeground(GUIHelper.COLOR_GRAY);
                int viewportBorderX = bodyLayer.getViewportLayerLeft()
                        .getWidth() + rowHeaderLayer.getWidth() - 1;
                gc.drawLine(viewportBorderX, 0, viewportBorderX,
                        layer.getHeight() - 1);
                gc.setForeground(beforeColor);
            }
        });

        natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
        natTable.addConfiguration(new HeaderMenuConfiguration(natTable));
        natTable.configure();

        return composite;
    }
View Full Code Here

        ViewportLayer layer = new ViewportLayer(new SelectionLayer(
                new SpanningDataLayer(new DummySpanningBodyDataProvider(100,
                        100))));
        layer.setRegionName(GridRegion.BODY);

        NatTable natTable = new NatTable(parent, layer, false);

        natTable.addConfiguration(new DefaultNatTableStyleConfiguration());

        // add configurations to enable editing
        // this is to verify that spanned cells are also editable and update the
        // data model correctly
        // @see Bug 414754
        layer.addConfiguration(new DefaultEditBindings());
        layer.addConfiguration(new DefaultEditConfiguration());
        layer.addConfiguration(new AbstractRegistryConfiguration() {

            @Override
            public void configureRegistry(IConfigRegistry configRegistry) {
                configRegistry.registerConfigAttribute(
                        EditConfigAttributes.CELL_EDITABLE_RULE,
                        IEditableRule.ALWAYS_EDITABLE);
            }

        });

        natTable.configure();

        return natTable;
    }
View Full Code Here

TOP

Related Classes of org.eclipse.nebula.widgets.nattable.NatTable

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.