Search in sources :

Example 41 with IConfigRegistry

use of org.eclipse.nebula.widgets.nattable.config.IConfigRegistry in project nebula.widgets.nattable by eclipse.

the class BoxingStyleTest method retrievedCellShouldBeConvertedUsingTheDisplayConverter.

@Test
public void retrievedCellShouldBeConvertedUsingTheDisplayConverter() throws Exception {
    IConfigRegistry configRegistry = new ConfigRegistry();
    configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DisplayConverter() {

        @Override
        public Object canonicalToDisplayValue(Object canonicalValue) {
            if (canonicalValue == null) {
                return null;
            } else {
                return canonicalValue.toString().equals("MN") ? "Manual" : "Automatic";
            }
        }

        @Override
        public Object displayToCanonicalValue(Object displayValue) {
            return displayValue.toString().equals("Manual") ? new PricingTypeBean("MN") : new PricingTypeBean("AT");
        }
    });
    NatTableFixture natTableFixture = new NatTableFixture(new DefaultGridLayer(RowDataListFixture.getList(), RowDataListFixture.getPropertyNames(), RowDataListFixture.getPropertyToLabelMap()), false);
    natTableFixture.setConfigRegistry(configRegistry);
    natTableFixture.configure();
    int columnIndex = RowDataListFixture.getColumnIndexOfProperty(RowDataListFixture.PRICING_TYPE_PROP_NAME);
    Object dataValue = natTableFixture.getDataValueByPosition(columnIndex + ROW_HEADER_COLUMN_COUNT, 2);
    // Verify displayed value
    ILayerCell cell = natTableFixture.getCellByPosition(columnIndex + ROW_HEADER_COLUMN_COUNT, 2);
    TextPainter cellPainter = new TextPainter();
    Assert.assertEquals("Automatic", cellPainter.convertDataType(cell, configRegistry));
    // Assert that the display value is converted to an Object
    Assert.assertTrue(dataValue instanceof PricingTypeBean);
}
Also used : ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.DisplayConverter) NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) PricingTypeBean(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.PricingTypeBean) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer) Test(org.junit.Test)

Example 42 with IConfigRegistry

use of org.eclipse.nebula.widgets.nattable.config.IConfigRegistry 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 43 with IConfigRegistry

use of org.eclipse.nebula.widgets.nattable.config.IConfigRegistry in project nebula.widgets.nattable by eclipse.

the class EditSelectionCommandHandler method doCommand.

@Override
public boolean doCommand(EditSelectionCommand command) {
    Composite parent = command.getParent();
    IConfigRegistry configRegistry = command.getConfigRegistry();
    Character initialValue = command.getCharacter();
    if (EditUtils.allCellsEditable(this.selectionLayer, configRegistry) && EditUtils.isEditorSame(this.selectionLayer, configRegistry) && EditUtils.isConverterSame(this.selectionLayer, configRegistry) && EditUtils.activateLastSelectedCellEditor(this.selectionLayer, configRegistry, command.isByTraversal())) {
        // check how many cells are selected
        Collection<ILayerCell> selectedCells = EditUtils.getSelectedCellsForEditing(this.selectionLayer);
        if (selectedCells.size() == 1) {
            // editing is triggered by key for a single cell
            // we need to fire the InlineCellEditEvent here because we
            // don't know the correct bounds of the cell to edit inline
            // corresponding to the NatTable.
            // On firing the event, a translation process is triggered,
            // converting the information to the correct values
            // needed for inline editing
            ILayerCell cell = selectedCells.iterator().next();
            this.selectionLayer.fireLayerEvent(new InlineCellEditEvent(this.selectionLayer, new PositionCoordinate(this.selectionLayer, cell.getOriginColumnPosition(), cell.getOriginRowPosition()), parent, configRegistry, (initialValue != null ? initialValue : cell.getDataValue())));
        } else if (selectedCells.size() > 1) {
            // determine the initial value
            Object initialEditValue = initialValue;
            if (initialValue == null && EditUtils.isValueSame(this.selectionLayer)) {
                ILayerCell cell = selectedCells.iterator().next();
                initialEditValue = this.selectionLayer.getDataValueByPosition(cell.getColumnPosition(), cell.getRowPosition());
            }
            EditController.editCells(selectedCells, parent, initialEditValue, configRegistry);
        }
    }
    // successful or not
    return true;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) InlineCellEditEvent(org.eclipse.nebula.widgets.nattable.edit.event.InlineCellEditEvent) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)

Example 44 with IConfigRegistry

use of org.eclipse.nebula.widgets.nattable.config.IConfigRegistry in project nebula.widgets.nattable by eclipse.

the class ExportTableCommandHandler method doCommand.

@Override
public boolean doCommand(ExportTableCommand command) {
    Shell shell = command.getShell();
    IConfigRegistry configRegistry = command.getConfigRegistry();
    new NatExporter(shell).exportSingleTable(this.layer, configRegistry);
    return true;
}
Also used : NatExporter(org.eclipse.nebula.widgets.nattable.export.NatExporter) Shell(org.eclipse.swt.widgets.Shell) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)

Example 45 with IConfigRegistry

use of org.eclipse.nebula.widgets.nattable.config.IConfigRegistry in project nebula.widgets.nattable by eclipse.

the class TickUpdateCommandHandler method doCommand.

@Override
public boolean doCommand(TickUpdateCommand command) {
    PositionCoordinate[] selectedPositions = this.selectionLayer.getSelectedCellPositions();
    IConfigRegistry configRegistry = command.getConfigRegistry();
    // Tick update for multiple cells in selection
    if (selectedPositions.length > 1) {
        // Can all cells be updated ?
        if (EditUtils.allCellsEditable(this.selectionLayer, configRegistry) && EditUtils.isEditorSame(this.selectionLayer, configRegistry) && EditUtils.isConverterSame(this.selectionLayer, configRegistry)) {
            for (PositionCoordinate position : selectedPositions) {
                updateSingleCell(command, position);
            }
        }
    } else {
        // Tick update for single selected cell
        updateSingleCell(command, this.selectionLayer.getLastSelectedCellPosition());
    }
    return true;
}
Also used : IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)

Aggregations

IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)64 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)42 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)42 AbstractRegistryConfiguration (org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration)38 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)37 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)34 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)31 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)29 HashMap (java.util.HashMap)28 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)27 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)26 DefaultColumnHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer)24 DefaultRowHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer)24 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)24 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)23 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)23 RowHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer)23 GridLayout (org.eclipse.swt.layout.GridLayout)23 Composite (org.eclipse.swt.widgets.Composite)23 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)20