Search in sources :

Example 6 with AggregateConfigLabelAccumulator

use of org.eclipse.nebula.widgets.nattable.layer.cell.AggregateConfigLabelAccumulator in project nebula.widgets.nattable by eclipse.

the class ColumnHeaderLayerStack method setupAggregateLabelAccumulator.

private void setupAggregateLabelAccumulator() {
    aggregateLabelAccumulator = new AggregateConfigLabelAccumulator();
    getDataLayer().setConfigLabelAccumulator(aggregateLabelAccumulator);
}
Also used : AggregateConfigLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.AggregateConfigLabelAccumulator)

Example 7 with AggregateConfigLabelAccumulator

use of org.eclipse.nebula.widgets.nattable.layer.cell.AggregateConfigLabelAccumulator in project nebula.widgets.nattable by eclipse.

the class ColumnReorderLayerTest method registerCellStyleAccumulators.

private void registerCellStyleAccumulators(DataLayer bodyDataLayer, ColumnOverrideLabelAccumulator columnLabelAccumulator) {
    AggregateConfigLabelAccumulator aggregrateConfigLabelAccumulator = new AggregateConfigLabelAccumulator();
    aggregrateConfigLabelAccumulator.add(columnLabelAccumulator, new AlternatingRowConfigLabelAccumulator());
    bodyDataLayer.setConfigLabelAccumulator(aggregrateConfigLabelAccumulator);
}
Also used : AggregateConfigLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.AggregateConfigLabelAccumulator) AlternatingRowConfigLabelAccumulator(org.eclipse.nebula.widgets.nattable.grid.cell.AlternatingRowConfigLabelAccumulator)

Example 8 with AggregateConfigLabelAccumulator

use of org.eclipse.nebula.widgets.nattable.layer.cell.AggregateConfigLabelAccumulator in project nebula.widgets.nattable by eclipse.

the class EditTraversalStrategyUpDownTest method setUp.

@Before
public void setUp() {
    // only use 10 columns to make the test cases easier
    String[] propertyNames = Arrays.copyOfRange(RowDataListFixture.getPropertyNames(), 0, 10);
    IRowDataProvider<RowDataFixture> bodyDataProvider = new ListDataProvider<>(RowDataListFixture.getList(10), new ReflectiveColumnPropertyAccessor<RowDataFixture>(propertyNames));
    this.dataLayer = new DataLayer(bodyDataProvider, 20, 20);
    this.selectionLayer = new SelectionLayer(this.dataLayer);
    this.viewportLayer = new ViewportLayer(this.selectionLayer);
    this.viewportLayer.setRegionName(GridRegion.BODY);
    this.viewportLayer.addConfiguration(new DefaultEditBindings());
    this.viewportLayer.addConfiguration(new DefaultEditConfiguration() {

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new TextCellEditor(true, true));
            configRegistry.registerConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, new DefaultDataValidator());
            configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultBooleanDisplayConverter(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 9);
        }
    });
    this.natTable = new NatTableFixture(this.viewportLayer);
    this.natTable.enableEditingOnAllCells();
    this.natTable.getConfigRegistry().registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.NEVER_EDITABLE, DisplayMode.EDIT, NOT_EDITABLE);
    this.natTable.getConfigRegistry().registerConfigAttribute(EditConfigAttributes.OPEN_ADJACENT_EDITOR, Boolean.TRUE);
    // register non editable rows
    this.overrider = new RowOverrideLabelAccumulator<>(bodyDataProvider, new IRowIdAccessor<RowDataFixture>() {

        @Override
        public Serializable getRowId(RowDataFixture rowObject) {
            return rowObject.getSecurity_id();
        }
    });
    this.overrider.registerRowOverrides(2, NOT_EDITABLE);
    this.overrider.registerRowOverrides(5, NOT_EDITABLE);
    this.overrider.registerRowOverrides(6, NOT_EDITABLE);
    this.overrider.registerRowOverrides(7, NOT_EDITABLE);
    this.overrider.registerRowOverrides(8, NOT_EDITABLE);
    this.overrider.registerRowOverrides(9, NOT_EDITABLE);
    AggregateConfigLabelAccumulator accumulator = new AggregateConfigLabelAccumulator();
    accumulator.add(this.overrider);
    accumulator.add(new ColumnLabelAccumulator());
    this.dataLayer.setConfigLabelAccumulator(accumulator);
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) DefaultBooleanDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.DefaultBooleanDisplayConverter) NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) DefaultDataValidator(org.eclipse.nebula.widgets.nattable.data.validate.DefaultDataValidator) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) DefaultEditBindings(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings) AggregateConfigLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.AggregateConfigLabelAccumulator) IRowIdAccessor(org.eclipse.nebula.widgets.nattable.data.IRowIdAccessor) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultEditConfiguration(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) TextCellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.TextCellEditor) ColumnLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnLabelAccumulator) Before(org.junit.Before)

Example 9 with AggregateConfigLabelAccumulator

use of org.eclipse.nebula.widgets.nattable.layer.cell.AggregateConfigLabelAccumulator in project nebula.widgets.nattable by eclipse.

the class CompositeLayer method addConfigLabelAccumulatorForRegion.

/**
 * Adds the configLabelAccumulator to the existing label accumulators.
 */
public void addConfigLabelAccumulatorForRegion(String regionName, IConfigLabelAccumulator configLabelAccumulator) {
    IConfigLabelAccumulator existingConfigLabelAccumulator = this.regionNameToConfigLabelAccumulatorMap.get(regionName);
    AggregateConfigLabelAccumulator aggregateAccumulator;
    if (existingConfigLabelAccumulator instanceof AggregateConfigLabelAccumulator) {
        aggregateAccumulator = (AggregateConfigLabelAccumulator) existingConfigLabelAccumulator;
    } else {
        aggregateAccumulator = new AggregateConfigLabelAccumulator();
        if (existingConfigLabelAccumulator != null) {
            aggregateAccumulator.add(existingConfigLabelAccumulator);
        }
        this.regionNameToConfigLabelAccumulatorMap.put(regionName, aggregateAccumulator);
    }
    aggregateAccumulator.add(configLabelAccumulator);
}
Also used : IConfigLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.IConfigLabelAccumulator) AggregateConfigLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.AggregateConfigLabelAccumulator)

Example 10 with AggregateConfigLabelAccumulator

use of org.eclipse.nebula.widgets.nattable.layer.cell.AggregateConfigLabelAccumulator in project nebula.widgets.nattable by eclipse.

the class CSSExample method postConstruct.

@PostConstruct
public void postConstruct(Composite parent, Shell shell) {
    parent.setLayout(new GridLayout());
    // property names of the Person class
    // property names of the Person class
    String[] propertyNames = { "firstName", "lastName", "password", "description", "age", "money", "married", "gender", "address.street", "address.city", "favouriteFood", "favouriteDrinks" };
    // 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("password", "Password");
    propertyToLabelMap.put("description", "Description");
    propertyToLabelMap.put("age", "Age");
    propertyToLabelMap.put("money", "Money");
    propertyToLabelMap.put("married", "Married");
    propertyToLabelMap.put("gender", "Gender");
    propertyToLabelMap.put("address.street", "Street");
    propertyToLabelMap.put("address.city", "City");
    propertyToLabelMap.put("favouriteFood", "Food");
    propertyToLabelMap.put("favouriteDrinks", "Drinks");
    IDataProvider bodyDataProvider = new ListDataProvider<>(PersonService.getExtendedPersonsWithAddress(10), new ExtendedReflectiveColumnPropertyAccessor<ExtendedPersonWithAddress>(propertyNames));
    DefaultGridLayer gridLayer = new DefaultGridLayer(bodyDataProvider, new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap));
    // unregister the default registered commandhandler to make the fill
    // handle work here for the age column
    gridLayer.unregisterCommandHandler(CopyDataToClipboardCommand.class);
    gridLayer.getBodyLayer().unregisterCommandHandler(CopyDataToClipboardCommand.class);
    final DataLayer bodyDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
    AggregateConfigLabelAccumulator accumulator = new AggregateConfigLabelAccumulator();
    // create the ColumnLabelAccumulator with IDataProvider to be able to
    // tell the CSS engine about the added labels
    accumulator.add(new ColumnLabelAccumulator(bodyDataProvider));
    ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
    columnLabelAccumulator.registerColumnOverrides(5, CustomLineBorderDecorator.RIGHT_LINE_BORDER_LABEL);
    accumulator.add(columnLabelAccumulator);
    bodyDataLayer.setConfigLabelAccumulator(accumulator);
    NatTable natTable = new NatTable(parent, gridLayer, false);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.addConfiguration(new FillHandleConfiguration(gridLayer.getBodyLayer().getSelectionLayer()));
    gridLayer.addConfiguration(new DefaultEditConfiguration());
    gridLayer.addConfiguration(new DefaultEditBindings());
    natTable.addConfiguration(new AbstractRegistryConfiguration() {

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, EditableRule.ALWAYS_EDITABLE, DisplayMode.NORMAL, "COLUMN_4");
            configRegistry.registerConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, new DataValidator() {

                @Override
                public boolean validate(int columnIndex, int rowIndex, Object newValue) {
                    if (newValue instanceof Integer && ((Integer) newValue).intValue() > 100) {
                        return false;
                    }
                    return true;
                }
            }, DisplayMode.NORMAL, "COLUMN_4");
        }
    });
    natTable.setData(CSSSWTConstants.CSS_CLASS_NAME_KEY, "basic");
    // application model menu configuration
    menuService.registerContextMenu(natTable, "org.eclipse.nebula.widgets.nattable.examples.e4.popupmenu.0");
    // get the menu registered by EMenuService
    final Menu e4Menu = natTable.getMenu();
    // remove the menu reference from NatTable instance
    natTable.setMenu(null);
    natTable.addConfiguration(new AbstractUiBindingConfiguration() {

        @Override
        public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
            // add NatTable menu items
            // and register the DisposeListener
            new PopupMenuBuilder(natTable, e4Menu).withInspectLabelsMenuItem().build();
            // register the UI binding
            uiBindingRegistry.registerMouseDownBinding(new MouseEventMatcher(SWT.NONE, GridRegion.BODY, MouseEventMatcher.RIGHT_BUTTON), new PopupMenuAction(e4Menu));
        }
    });
    natTable.configure();
    GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
    // add a custom painter for key errortext
    int[] yErrorOffsets = { 0, 1, 2, 1 };
    CellPainterFactory.getInstance().registerContentPainter("errortext", (properties, underlying) -> {
        return new TextPainter(true, true, false) {

            @Override
            protected void paintDecoration(IStyle cellStyle, GC gc, int x, int y, int length, int fontHeight) {
                int underlineY = y + fontHeight - (gc.getFontMetrics().getDescent() / 2);
                Color previousColor = gc.getForeground();
                gc.setForeground(GUIHelper.COLOR_RED);
                int startX = x;
                underlineY--;
                int index = 0;
                while (startX <= (x + length)) {
                    gc.drawPoint(startX, underlineY + yErrorOffsets[(index % 4)]);
                    index++;
                    startX++;
                }
                gc.setForeground(previousColor);
            }
        };
    });
    showSourceLinks(parent, getClass().getName());
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) ExtendedPersonWithAddress(org.eclipse.nebula.widgets.nattable.dataset.person.ExtendedPersonWithAddress) HashMap(java.util.HashMap) AbstractRegistryConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) AggregateConfigLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.AggregateConfigLabelAccumulator) FillHandleConfiguration(org.eclipse.nebula.widgets.nattable.fillhandle.config.FillHandleConfiguration) DefaultEditBindings(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings) GridLayout(org.eclipse.swt.layout.GridLayout) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) PopupMenuAction(org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuAction) DefaultEditConfiguration(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) Menu(org.eclipse.swt.widgets.Menu) ColumnOverrideLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator) GC(org.eclipse.swt.graphics.GC) UiBindingRegistry(org.eclipse.nebula.widgets.nattable.ui.binding.UiBindingRegistry) MouseEventMatcher(org.eclipse.nebula.widgets.nattable.ui.matcher.MouseEventMatcher) Color(org.eclipse.swt.graphics.Color) TextPainter(org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter) AbstractUiBindingConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractUiBindingConfiguration) IStyle(org.eclipse.nebula.widgets.nattable.style.IStyle) DataValidator(org.eclipse.nebula.widgets.nattable.data.validate.DataValidator) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider) ColumnLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnLabelAccumulator) PopupMenuBuilder(org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer) PostConstruct(javax.annotation.PostConstruct)

Aggregations

AggregateConfigLabelAccumulator (org.eclipse.nebula.widgets.nattable.layer.cell.AggregateConfigLabelAccumulator)10 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)4 ColumnLabelAccumulator (org.eclipse.nebula.widgets.nattable.layer.cell.ColumnLabelAccumulator)4 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)3 ColumnOverrideLabelAccumulator (org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator)3 IConfigLabelAccumulator (org.eclipse.nebula.widgets.nattable.layer.cell.IConfigLabelAccumulator)3 HashMap (java.util.HashMap)2 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)2 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)2 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)2 DefaultEditBindings (org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings)2 DefaultEditConfiguration (org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration)2 AlternatingRowConfigLabelAccumulator (org.eclipse.nebula.widgets.nattable.grid.cell.AlternatingRowConfigLabelAccumulator)2 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)2 LabelStack (org.eclipse.nebula.widgets.nattable.layer.LabelStack)2 ViewportLayer (org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 PostConstruct (javax.annotation.PostConstruct)1 AbstractRegistryConfiguration (org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration)1 AbstractUiBindingConfiguration (org.eclipse.nebula.widgets.nattable.config.AbstractUiBindingConfiguration)1