Search in sources :

Example 6 with DefaultEditConfiguration

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

the class EditIntegrationTest method updateAllUnderlyingCellsIfSpanned.

@Test
public void updateAllUnderlyingCellsIfSpanned() throws Exception {
    CompositeLayer layer = new CompositeLayer(1, 1);
    DummySpanningBodyDataProvider dataProvider = new DummySpanningBodyDataProvider(100, 100);
    SelectionLayer selectionLayer = new SelectionLayer(new SpanningDataLayer(dataProvider));
    layer.setChildLayer(GridRegion.BODY, new ViewportLayer(selectionLayer), 0, 0);
    this.natTable = new NatTableFixture(layer, 1200, 300, false);
    layer.addConfiguration(new DefaultEditBindings());
    layer.addConfiguration(new DefaultEditConfiguration());
    this.natTable.enableEditingOnAllCells();
    this.natTable.configure();
    assertEquals("Col: 1, Row: 1", dataProvider.getDataValue(0, 0));
    assertEquals("Col: 1, Row: 2", dataProvider.getDataValue(0, 1));
    assertEquals("Col: 2, Row: 1", dataProvider.getDataValue(1, 0));
    assertEquals("Col: 2, Row: 2", dataProvider.getDataValue(1, 1));
    this.natTable.doCommand(new SelectCellCommand(this.natTable, 1, 1, false, false));
    this.natTable.notifyListeners(SWT.KeyDown, SWTUtils.keyEventWithChar('C'));
    assertNotNull(this.natTable.getActiveCellEditor());
    this.natTable.getActiveCellEditor().getEditorControl().notifyListeners(SWT.KeyDown, SWTUtils.keyEvent(SWT.CR));
    assertEquals("C", dataProvider.getDataValue(0, 0));
    assertEquals("C", dataProvider.getDataValue(0, 1));
    assertEquals("C", dataProvider.getDataValue(1, 0));
    assertEquals("C", dataProvider.getDataValue(1, 1));
}
Also used : DefaultEditConfiguration(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) DummySpanningBodyDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DummySpanningBodyDataProvider) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) CompositeLayer(org.eclipse.nebula.widgets.nattable.layer.CompositeLayer) SpanningDataLayer(org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer) DefaultEditBindings(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings) Test(org.junit.Test)

Example 7 with DefaultEditConfiguration

use of org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration 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)

Example 8 with DefaultEditConfiguration

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

the class _5014_SpanningDataLayerExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    // To make the default edit and selection configurations work correctly,
    // the region label
    // GridRegion.BODY is necessary, which is directly set to the
    // ViewportLayer instance 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;
}
Also used : DefaultEditConfiguration(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) AbstractRegistryConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) SpanningDataLayer(org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer) DefaultEditBindings(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings)

Aggregations

DefaultEditBindings (org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings)8 DefaultEditConfiguration (org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration)8 ViewportLayer (org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer)7 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)5 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)4 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)4 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)4 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)4 AbstractRegistryConfiguration (org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration)3 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)3 CompositeLayer (org.eclipse.nebula.widgets.nattable.layer.CompositeLayer)3 SpanningDataLayer (org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer)3 ColumnLabelAccumulator (org.eclipse.nebula.widgets.nattable.layer.cell.ColumnLabelAccumulator)3 NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)3 HashMap (java.util.HashMap)2 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)2 DefaultBooleanDisplayConverter (org.eclipse.nebula.widgets.nattable.data.convert.DefaultBooleanDisplayConverter)2 Person (org.eclipse.nebula.widgets.nattable.dataset.person.Person)2 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)2 DummySpanningBodyDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DummySpanningBodyDataProvider)2