Search in sources :

Example 6 with DefaultColumnHeaderDataProvider

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

the class _6031_GlazedListsFilterExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    // create a new ConfigRegistry which will be needed for GlazedLists
    // handling
    ConfigRegistry configRegistry = new ConfigRegistry();
    // property names of the Person class
    String[] propertyNames = { "firstName", "lastName", "gender", "married", "birthday", "address.street", "address.housenumber", "address.postalCode", "address.city" };
    // 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");
    propertyToLabelMap.put("address.street", "Street");
    propertyToLabelMap.put("address.housenumber", "Housenumber");
    propertyToLabelMap.put("address.postalCode", "Postal Code");
    propertyToLabelMap.put("address.city", "City");
    IColumnPropertyAccessor<PersonWithAddress> columnPropertyAccessor = new ExtendedReflectiveColumnPropertyAccessor<>(propertyNames);
    BodyLayerStack<PersonWithAddress> bodyLayerStack = new BodyLayerStack<>(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());
    // Note: The column header layer is wrapped in a filter row composite.
    // This plugs in the filter row functionality
    FilterRowHeaderComposite<PersonWithAddress> filterRowHeaderLayer = new FilterRowHeaderComposite<>(new DefaultGlazedListsFilterStrategy<>(bodyLayerStack.getFilterList(), columnPropertyAccessor, configRegistry), columnHeaderLayer, columnHeaderDataLayer.getDataProvider(), 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);
    // build the grid layer
    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(parent, 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());
    // add filter row configuration
    natTable.addConfiguration(new FilterRowConfiguration());
    natTable.addConfiguration(new HeaderMenuConfiguration(natTable) {

        @Override
        protected PopupMenuBuilder createCornerMenu(NatTable natTable) {
            return super.createCornerMenu(natTable).withStateManagerMenuItemProvider();
        }
    });
    natTable.configure();
    natTable.registerCommandHandler(new DisplayPersistenceDialogCommandHandler(natTable));
    return natTable;
}
Also used : HashMap(java.util.HashMap) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) HeaderMenuConfiguration(org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) FilterRowDataLayer(org.eclipse.nebula.widgets.nattable.filterrow.FilterRowDataLayer) 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) DisplayPersistenceDialogCommandHandler(org.eclipse.nebula.widgets.nattable.persistence.command.DisplayPersistenceDialogCommandHandler) ExtendedReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ExtendedReflectiveColumnPropertyAccessor) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) PersonWithAddress(org.eclipse.nebula.widgets.nattable.dataset.person.PersonWithAddress) FilterRowHeaderComposite(org.eclipse.nebula.widgets.nattable.filterrow.FilterRowHeaderComposite) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) RowHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer) CornerLayer(org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider) PopupMenuBuilder(org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder)

Example 7 with DefaultColumnHeaderDataProvider

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

the class _5016_DataChangeLayerExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    // 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");
    IColumnPropertyAccessor<Person> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
    final List<Person> data = PersonService.getPersons(10);
    // create the body layer stack
    IDataProvider bodyDataProvider = new ListDataProvider<>(data, columnPropertyAccessor);
    DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
    final ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
    bodyDataLayer.setConfigLabelAccumulator(columnLabelAccumulator);
    registerColumnLabels(columnLabelAccumulator);
    // add a DataChangeLayer that tracks data changes but directly updates
    // the underlying data model
    DataChangeLayer dataChangeLayer = new DataChangeLayer(bodyDataLayer, new PointKeyHandler(), false);
    // we register a special command handler to perform custom changes on
    // save
    dataChangeLayer.registerCommandHandler(new SaveDataChangesCommandHandler(dataChangeLayer) {

        @Override
        public boolean doCommand(ILayer targetLayer, SaveDataChangesCommand command) {
            if (MessageDialog.openQuestion(parent.getShell(), "Save data", "Do you really want to save to database?")) {
                // you would implement the storage to database here
                System.out.println("We save the data to the database");
                return super.doCommand(targetLayer, command);
            }
            return true;
        }
    });
    ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(dataChangeLayer);
    ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(columnReorderLayer);
    SelectionLayer selectionLayer = new SelectionLayer(columnHideShowLayer);
    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
    ILayer cornerLayer = new CornerLayer(new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider)), rowHeaderLayer, columnHeaderLayer);
    // create the grid layer composed with the prior created layer stacks
    GridLayer gridLayer = new GridLayer(viewportLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
    NatTable natTable = new NatTable(parent, gridLayer, false);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.addConfiguration(new EditorConfiguration());
    natTable.addConfiguration(new HeaderMenuConfiguration(natTable) {

        @Override
        protected PopupMenuBuilder createCornerMenu(NatTable natTable) {
            return super.createCornerMenu(natTable).withMenuItemProvider(new IMenuItemProvider() {

                @Override
                public void addMenuItem(NatTable natTable, Menu popupMenu) {
                    MenuItem export = new MenuItem(popupMenu, SWT.PUSH);
                    export.setText("Discard changes");
                    export.setEnabled(true);
                    export.addSelectionListener(new SelectionAdapter() {

                        @Override
                        public void widgetSelected(SelectionEvent e) {
                            natTable.doCommand(new DiscardDataChangesCommand());
                        }
                    });
                }
            }).withMenuItemProvider(new IMenuItemProvider() {

                @Override
                public void addMenuItem(NatTable natTable, Menu popupMenu) {
                    MenuItem export = new MenuItem(popupMenu, SWT.PUSH);
                    export.setText("Save changes");
                    export.setEnabled(true);
                    export.addSelectionListener(new SelectionAdapter() {

                        @Override
                        public void widgetSelected(SelectionEvent e) {
                            natTable.doCommand(new SaveDataChangesCommand());
                        }
                    });
                }
            });
        }
    });
    natTable.configure();
    return natTable;
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) HashMap(java.util.HashMap) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) HeaderMenuConfiguration(org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration) ColumnHideShowLayer(org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) SelectionEvent(org.eclipse.swt.events.SelectionEvent) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) Menu(org.eclipse.swt.widgets.Menu) ColumnOverrideLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator) PointKeyHandler(org.eclipse.nebula.widgets.nattable.datachange.PointKeyHandler) DiscardDataChangesCommand(org.eclipse.nebula.widgets.nattable.datachange.command.DiscardDataChangesCommand) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SaveDataChangesCommand(org.eclipse.nebula.widgets.nattable.datachange.command.SaveDataChangesCommand) ColumnReorderLayer(org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer) MenuItem(org.eclipse.swt.widgets.MenuItem) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) SaveDataChangesCommandHandler(org.eclipse.nebula.widgets.nattable.datachange.command.SaveDataChangesCommandHandler) ReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor) DataChangeLayer(org.eclipse.nebula.widgets.nattable.datachange.DataChangeLayer) RowHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer) CornerLayer(org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) IMenuItemProvider(org.eclipse.nebula.widgets.nattable.ui.menu.IMenuItemProvider) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider) PopupMenuBuilder(org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder) Person(org.eclipse.nebula.widgets.nattable.dataset.person.Person)

Example 8 with DefaultColumnHeaderDataProvider

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

the class _5017_DataChangeLayerTempStorageExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    // 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");
    IColumnPropertyAccessor<Person> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
    final List<Person> data = PersonService.getPersons(10);
    // create the body layer stack
    IDataProvider bodyDataProvider = new ListDataProvider<>(data, columnPropertyAccessor);
    DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
    final ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
    bodyDataLayer.setConfigLabelAccumulator(columnLabelAccumulator);
    registerColumnLabels(columnLabelAccumulator);
    // add a DataChangeLayer that tracks data changes but directly updates
    // the underlying data model
    DataChangeLayer dataChangeLayer = new DataChangeLayer(bodyDataLayer, new PointKeyHandler(), true);
    ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(dataChangeLayer);
    ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(columnReorderLayer);
    SelectionLayer selectionLayer = new SelectionLayer(columnHideShowLayer);
    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
    ILayer cornerLayer = new CornerLayer(new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider)), rowHeaderLayer, columnHeaderLayer);
    // create the grid layer composed with the prior created layer stacks
    GridLayer gridLayer = new GridLayer(viewportLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
    NatTable natTable = new NatTable(parent, gridLayer, false);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.addConfiguration(new EditorConfiguration());
    natTable.addConfiguration(new HeaderMenuConfiguration(natTable) {

        @Override
        protected PopupMenuBuilder createCornerMenu(NatTable natTable) {
            return super.createCornerMenu(natTable).withMenuItemProvider(new IMenuItemProvider() {

                @Override
                public void addMenuItem(NatTable natTable, Menu popupMenu) {
                    MenuItem export = new MenuItem(popupMenu, SWT.PUSH);
                    export.setText("Discard changes");
                    export.setEnabled(true);
                    export.addSelectionListener(new SelectionAdapter() {

                        @Override
                        public void widgetSelected(SelectionEvent e) {
                            natTable.doCommand(new DiscardDataChangesCommand());
                        }
                    });
                }
            }).withMenuItemProvider(new IMenuItemProvider() {

                @Override
                public void addMenuItem(NatTable natTable, Menu popupMenu) {
                    MenuItem export = new MenuItem(popupMenu, SWT.PUSH);
                    export.setText("Save changes");
                    export.setEnabled(true);
                    export.addSelectionListener(new SelectionAdapter() {

                        @Override
                        public void widgetSelected(SelectionEvent e) {
                            natTable.doCommand(new SaveDataChangesCommand());
                        }
                    });
                }
            });
        }
    });
    natTable.configure();
    return natTable;
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) HashMap(java.util.HashMap) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) HeaderMenuConfiguration(org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration) ColumnHideShowLayer(org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) SelectionEvent(org.eclipse.swt.events.SelectionEvent) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) Menu(org.eclipse.swt.widgets.Menu) ColumnOverrideLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator) PointKeyHandler(org.eclipse.nebula.widgets.nattable.datachange.PointKeyHandler) DiscardDataChangesCommand(org.eclipse.nebula.widgets.nattable.datachange.command.DiscardDataChangesCommand) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SaveDataChangesCommand(org.eclipse.nebula.widgets.nattable.datachange.command.SaveDataChangesCommand) ColumnReorderLayer(org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer) MenuItem(org.eclipse.swt.widgets.MenuItem) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) ReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor) DataChangeLayer(org.eclipse.nebula.widgets.nattable.datachange.DataChangeLayer) RowHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer) CornerLayer(org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) IMenuItemProvider(org.eclipse.nebula.widgets.nattable.ui.menu.IMenuItemProvider) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider) PopupMenuBuilder(org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder) Person(org.eclipse.nebula.widgets.nattable.dataset.person.Person)

Example 9 with DefaultColumnHeaderDataProvider

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

the class _5033_GridLayerExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    // 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");
    IColumnPropertyAccessor<Person> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
    final List<Person> data = PersonService.getPersons(10);
    // create the body layer stack
    IDataProvider bodyDataProvider = new ListDataProvider<>(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
    ILayer cornerLayer = new CornerLayer(new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider)), rowHeaderLayer, columnHeaderLayer);
    // create the grid layer composed with the prior created layer stacks
    GridLayer gridLayer = new GridLayer(viewportLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
    return new NatTable(parent, gridLayer);
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) HashMap(java.util.HashMap) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) 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) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) ReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) RowHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer) 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) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider) Person(org.eclipse.nebula.widgets.nattable.dataset.person.Person)

Example 10 with DefaultColumnHeaderDataProvider

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

the class _5044_HorizontalSplitViewportGridExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    // property names of the Person class
    String[] propertyNames = { "firstName", "lastName", "gender", "married", "birthday", "address.street", "address.housenumber", "address.postalCode", "address.city" };
    // 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");
    propertyToLabelMap.put("address.street", "Street");
    propertyToLabelMap.put("address.housenumber", "Housenumber");
    propertyToLabelMap.put("address.postalCode", "Postal Code");
    propertyToLabelMap.put("address.city", "City");
    IColumnPropertyAccessor<PersonWithAddress> columnPropertyAccessor = new ExtendedReflectiveColumnPropertyAccessor<>(propertyNames);
    final BodyLayerStack<PersonWithAddress> bodyLayer = new BodyLayerStack<>(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);
    // build the grid layer
    GridLayer gridLayer = new GridLayer(bodyLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
    // in order to make printing and exporting work correctly you need to
    // register the following command handlers
    gridLayer.registerCommandHandler(new MultiTurnViewportOnCommandHandler(bodyLayer.getViewportLayerLeft(), bodyLayer.getViewportLayerRight()));
    gridLayer.registerCommandHandler(new MultiTurnViewportOffCommandHandler(bodyLayer.getViewportLayerLeft(), bodyLayer.getViewportLayerRight()));
    // Wrap NatTable in composite so we can slap on the external horizontal
    // sliders
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout gridLayout = new GridLayout(1, false);
    gridLayout.marginHeight = 0;
    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;
}
Also used : AbstractLayer(org.eclipse.nebula.widgets.nattable.layer.AbstractLayer) HashMap(java.util.HashMap) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) HeaderMenuConfiguration(org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration) Rectangle(org.eclipse.swt.graphics.Rectangle) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) ICellPainter(org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter) MultiTurnViewportOffCommandHandler(org.eclipse.nebula.widgets.nattable.print.command.MultiTurnViewportOffCommandHandler) MultiTurnViewportOnCommandHandler(org.eclipse.nebula.widgets.nattable.print.command.MultiTurnViewportOnCommandHandler) 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) GridLayout(org.eclipse.swt.layout.GridLayout) ExtendedReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ExtendedReflectiveColumnPropertyAccessor) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) PersonWithAddress(org.eclipse.nebula.widgets.nattable.dataset.person.PersonWithAddress) GC(org.eclipse.swt.graphics.GC) Composite(org.eclipse.swt.widgets.Composite) IOverlayPainter(org.eclipse.nebula.widgets.nattable.painter.IOverlayPainter) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) Color(org.eclipse.swt.graphics.Color) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) Point(org.eclipse.swt.graphics.Point) RowHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer) CornerLayer(org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer) CellLayerPainter(org.eclipse.nebula.widgets.nattable.painter.layer.CellLayerPainter) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) GridData(org.eclipse.swt.layout.GridData) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)

Aggregations

DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)85 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)82 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)79 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)74 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)72 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)69 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)68 HashMap (java.util.HashMap)67 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)67 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)66 RowHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer)66 DefaultRowHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider)62 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)61 DefaultRowHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer)61 DefaultColumnHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer)59 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)42 ViewportLayer (org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer)39 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)34 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)33 GridLayout (org.eclipse.swt.layout.GridLayout)33