Search in sources :

Example 11 with TextCellEditor

use of org.eclipse.nebula.widgets.nattable.edit.editor.TextCellEditor in project nebula.widgets.nattable by eclipse.

the class EditUtilsTest method testGetLastSelectedCellEditorWithMultiSelection.

@Test
public void testGetLastSelectedCellEditorWithMultiSelection() {
    this.selectionLayer.selectCell(1, 1, false, true);
    this.selectionLayer.selectCell(2, 2, false, true);
    this.selectionLayer.selectCell(3, 3, false, true);
    ICellEditor editor = EditUtils.getLastSelectedCellEditor(this.selectionLayer, this.natTable.getConfigRegistry());
    assertNotNull(editor);
    assertTrue(editor instanceof TextCellEditor);
}
Also used : ICellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor) TextCellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.TextCellEditor) Test(org.junit.Test)

Example 12 with TextCellEditor

use of org.eclipse.nebula.widgets.nattable.edit.editor.TextCellEditor in project nebula.widgets.nattable by eclipse.

the class EditUtilsTest method testGetLastSelectedCellEditorWithSingleSelection.

@Test
public void testGetLastSelectedCellEditorWithSingleSelection() {
    this.selectionLayer.selectCell(1, 1, false, false);
    ICellEditor editor = EditUtils.getLastSelectedCellEditor(this.selectionLayer, this.natTable.getConfigRegistry());
    assertNotNull(editor);
    assertTrue(editor instanceof TextCellEditor);
}
Also used : ICellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor) TextCellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.TextCellEditor) Test(org.junit.Test)

Example 13 with TextCellEditor

use of org.eclipse.nebula.widgets.nattable.edit.editor.TextCellEditor in project nebula.widgets.nattable by eclipse.

the class MultiCellEditDialogRunner method shouldOpenDefaultDialogWithoutIncrementDecrementBox.

public void shouldOpenDefaultDialogWithoutIncrementDecrementBox() {
    CellFixture cell = new CellFixture();
    cell.setBounds(new Rectangle(100, 100, 100, 20));
    cell.setConfigLabels(new LabelStack("Cell_Edit"));
    cell.setDataValue("123");
    cell.setDisplayMode(DisplayMode.NORMAL);
    TextCellEditor cellEditor = new TextCellEditor();
    IDisplayConverter dataTypeConverter = new DisplayConverter() {

        @Override
        public Object canonicalToDisplayValue(Object canonicalValue) {
            return canonicalValue;
        }

        @Override
        public Object displayToCanonicalValue(Object displayValue) {
            return displayValue;
        }
    };
    final Character newValue = Character.valueOf('4');
    IDataValidator dataValidator = new DataValidator() {

        @Override
        public boolean validate(int columnIndex, int rowIndex, Object newValue) {
            Assert.assertEquals(newValue, newValue);
            return false;
        }
    };
    Shell shell = new Shell(Display.getDefault(), SWT.H_SCROLL | SWT.V_SCROLL | SWT.RESIZE);
    ConfigRegistry configRegistry = new ConfigRegistry();
    configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, dataTypeConverter);
    configRegistry.registerConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, dataValidator);
    final CellEditDialog dialog = new CellEditDialog(shell, newValue, cell, cellEditor, configRegistry);
    if (!this.interactive) {
        Display.getDefault().asyncExec(new Runnable() {

            @Override
            public void run() {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } finally {
                    dialog.close();
                }
            }
        });
    }
    dialog.open();
}
Also used : CellFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.CellFixture) LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack) IDataValidator(org.eclipse.nebula.widgets.nattable.data.validate.IDataValidator) DisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.DisplayConverter) IDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.IDisplayConverter) Rectangle(org.eclipse.swt.graphics.Rectangle) IDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.IDisplayConverter) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) Shell(org.eclipse.swt.widgets.Shell) IDataValidator(org.eclipse.nebula.widgets.nattable.data.validate.IDataValidator) DataValidator(org.eclipse.nebula.widgets.nattable.data.validate.DataValidator) TextCellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.TextCellEditor)

Example 14 with TextCellEditor

use of org.eclipse.nebula.widgets.nattable.edit.editor.TextCellEditor 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 15 with TextCellEditor

use of org.eclipse.nebula.widgets.nattable.edit.editor.TextCellEditor in project nebula.widgets.nattable by eclipse.

the class EditIntegrationTest method testEditorActivatedDuringInlineCellEdit.

@Test
public void testEditorActivatedDuringInlineCellEdit() {
    this.natTable.enableEditingOnAllCells();
    ILayerCell cell = this.natTable.getCellByPosition(4, 4);
    this.natTable.doCommand(new EditCellCommand(this.natTable, this.natTable.getConfigRegistry(), cell));
    ICellEditor cellEditor = this.natTable.getActiveCellEditor();
    assertNotNull(cellEditor);
    assertTrue(cellEditor instanceof TextCellEditor);
    TextCellEditor textCellEditor = (TextCellEditor) cellEditor;
    assertEquals("Col: 4, Row: 4", textCellEditor.getCanonicalValue());
    Control control = cellEditor.getEditorControl();
    assertNotNull(control);
    assertTrue(control instanceof Text);
}
Also used : Control(org.eclipse.swt.widgets.Control) ICellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor) Text(org.eclipse.swt.widgets.Text) TextCellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.TextCellEditor) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) EditCellCommand(org.eclipse.nebula.widgets.nattable.edit.command.EditCellCommand) Test(org.junit.Test)

Aggregations

TextCellEditor (org.eclipse.nebula.widgets.nattable.edit.editor.TextCellEditor)17 Test (org.junit.Test)6 ICellEditor (org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor)5 DefaultBooleanDisplayConverter (org.eclipse.nebula.widgets.nattable.data.convert.DefaultBooleanDisplayConverter)4 DefaultDataValidator (org.eclipse.nebula.widgets.nattable.data.validate.DefaultDataValidator)4 HashMap (java.util.HashMap)3 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)3 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)3 DefaultDoubleDisplayConverter (org.eclipse.nebula.widgets.nattable.data.convert.DefaultDoubleDisplayConverter)3 DefaultIntegerDisplayConverter (org.eclipse.nebula.widgets.nattable.data.convert.DefaultIntegerDisplayConverter)3 DisplayConverter (org.eclipse.nebula.widgets.nattable.data.convert.DisplayConverter)3 DefaultEditBindings (org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings)3 MultiLineTextCellEditor (org.eclipse.nebula.widgets.nattable.edit.editor.MultiLineTextCellEditor)3 DateFormat (java.text.DateFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)2 VisualRefreshCommand (org.eclipse.nebula.widgets.nattable.command.VisualRefreshCommand)2 AbstractRegistryConfiguration (org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration)2 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)2 ExtendedReflectiveColumnPropertyAccessor (org.eclipse.nebula.widgets.nattable.data.ExtendedReflectiveColumnPropertyAccessor)2