Search in sources :

Example 56 with UpdateDataCommand

use of org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand in project nebula.widgets.nattable by eclipse.

the class DataChangeLayerTempStorageTest method shouldClearOnStructuralChange.

@Test
public void shouldClearOnStructuralChange() {
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 1));
    this.dataChangeLayer.doCommand(new UpdateDataCommand(this.dataChangeLayer, 1, 1, "Lovejoy"));
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 1));
    assertEquals("Lovejoy", this.dataChangeLayer.getDataValueByPosition(1, 1));
    // clear locally stored data changes
    this.dataChangeLayer.doCommand(new StructuralRefreshCommand());
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 1));
    assertEquals("Simpson", this.dataChangeLayer.getDataValueByPosition(1, 1));
    assertFalse("Dirty label not set", this.dataChangeLayer.getConfigLabelsByPosition(1, 1).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Column 1 is not dirty", this.dataChangeLayer.isColumnDirty(1));
    assertFalse("Row 1 is not dirty", this.dataChangeLayer.isRowDirty(1));
    assertFalse("Cell is not dirty", this.dataChangeLayer.isCellDirty(1, 1));
    assertTrue("changed columns are not empty", this.dataChangeLayer.changedColumns.isEmpty());
    assertTrue("changed rows are not empty", this.dataChangeLayer.changedRows.isEmpty());
    assertTrue("changes are not empty", this.dataChangeLayer.dataChanges.isEmpty());
}
Also used : StructuralRefreshCommand(org.eclipse.nebula.widgets.nattable.command.StructuralRefreshCommand) UpdateDataCommand(org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand) Test(org.junit.Test)

Example 57 with UpdateDataCommand

use of org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand in project nebula.widgets.nattable by eclipse.

the class DataChangeLayerTempStorageTest method shouldClearWithoutReset.

@Test
public void shouldClearWithoutReset() {
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 1));
    this.dataChangeLayer.doCommand(new UpdateDataCommand(this.dataChangeLayer, 1, 1, "Lovejoy"));
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 1));
    assertEquals("Lovejoy", this.dataChangeLayer.getDataValueByPosition(1, 1));
    // clear locally stored data changes
    this.dataChangeLayer.clearDataChanges();
    assertEquals("Simpson", this.dataLayer.getDataValue(1, 1));
    assertEquals("Simpson", this.dataChangeLayer.getDataValueByPosition(1, 1));
    assertFalse("Dirty label not set", this.dataChangeLayer.getConfigLabelsByPosition(1, 1).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Column 1 is not dirty", this.dataChangeLayer.isColumnDirty(1));
    assertFalse("Row 1 is not dirty", this.dataChangeLayer.isRowDirty(1));
    assertFalse("Cell is not dirty", this.dataChangeLayer.isCellDirty(1, 1));
    assertTrue("changed columns are not empty", this.dataChangeLayer.changedColumns.isEmpty());
    assertTrue("changed rows are not empty", this.dataChangeLayer.changedRows.isEmpty());
    assertTrue("changes are not empty", this.dataChangeLayer.dataChanges.isEmpty());
}
Also used : UpdateDataCommand(org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand) Test(org.junit.Test)

Example 58 with UpdateDataCommand

use of org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand in project nebula.widgets.nattable by eclipse.

the class DataChangeLayerTempStorageTest method shouldNotDirtyNullToNull.

@Test
public void shouldNotDirtyNullToNull() {
    this.dataLayer.setDataValue(1, 1, null);
    assertNull(this.dataLayer.getDataValue(1, 1));
    this.dataChangeLayer.doCommand(new UpdateDataCommand(this.dataChangeLayer, 1, 1, null));
    assertNull(this.dataLayer.getDataValue(1, 1));
    assertNull(this.dataChangeLayer.getDataValueByPosition(1, 1));
    assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 1).hasLabel(DataChangeLayer.DIRTY));
    assertFalse("Column 1 is dirty", this.dataChangeLayer.isColumnDirty(1));
    assertFalse("Row 1 is dirty", this.dataChangeLayer.isRowDirty(1));
    assertFalse("Cell is dirty", this.dataChangeLayer.isCellDirty(1, 1));
}
Also used : UpdateDataCommand(org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand) Test(org.junit.Test)

Example 59 with UpdateDataCommand

use of org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand in project nebula.widgets.nattable by eclipse.

the class DataLayerCommandHandlingTest method setup.

@Before
public void setup() {
    this.dataLayer = new DataLayerFixture();
    this.command = new UpdateDataCommand(this.dataLayer, 2, 2, TEST_VALUE);
}
Also used : DataLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture) UpdateDataCommand(org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand) Before(org.junit.Before)

Example 60 with UpdateDataCommand

use of org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand in project nebula.widgets.nattable by eclipse.

the class EditController method editCells.

/**
 * This method is used to edit cells in a sub dialog. In every case this
 * method will open a dialog for editing, regardless if the list of cells to
 * edit contain several or only one value. Only if the given list of cells
 * to edit is <code>null</code> or empty, there is no action performed.
 *
 * @param cells
 *            The list of cells to edit.
 * @param parent
 *            The parent composite to access the parent shell, or
 *            <code>null</code> to create a top-level shell dialog. In the
 *            last case, the dialog will be opened as non modal.
 * @param initialCanonicalValue
 *            The value that should be propagated to the editor control.
 *            Needed because for multi cell editing or editor activation by
 *            letter/digit key will result in a different value to populate
 *            for some editors than populating the value out of the
 *            cell/data model directly.
 * @param configRegistry
 *            The {@link IConfigRegistry} containing the configuration of
 *            the current NatTable instance the command should be executed
 *            for. This is necessary because the edit controllers in the
 *            current architecture are not aware of the instance they are
 *            running in and therefore it is needed for activation of
 *            editors.
 */
public static void editCells(final Collection<ILayerCell> cells, final Composite parent, Object initialCanonicalValue, final IConfigRegistry configRegistry) {
    if (cells != null && !cells.isEmpty()) {
        // get the editor to use, because the editor contains information if
        // it allows editing on a multi edit dialog
        // Note: this works because previous to calling this method it is
        // checked if all cells have the same editor configured. Otherwise
        // this method will have serious issues further on.
        ICellEditor cellEditor = configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, cells.iterator().next().getConfigLabels().getLabels());
        if (cells.size() == 1 || (cells.size() > 1 && supportMultiEdit(cells, cellEditor, configRegistry))) {
            if (cellEditor.openMultiEditDialog()) {
                // as the EditSelectionCommandHandler already ensured that
                // all cells have the same configuration, we can simply use
                // any cell for multi cell edit handling
                ICellEditDialog dialog = CellEditDialogFactory.createCellEditDialog(parent != null ? parent.getShell() : null, initialCanonicalValue, cells.iterator().next(), cellEditor, configRegistry);
                int returnValue = dialog.open();
                if (returnValue == Window.OK) {
                    for (ILayerCell selectedCell : cells) {
                        Object editorValue = dialog.getCommittedValue();
                        if (!(dialog.getEditType() == EditTypeEnum.SET)) {
                            editorValue = dialog.calculateValue(selectedCell.getDataValue(), editorValue);
                        }
                        ILayer layer = selectedCell.getLayer();
                        layer.doCommand(new UpdateDataCommand(layer, selectedCell.getColumnPosition(), selectedCell.getRowPosition(), editorValue));
                    }
                }
            } else {
                // directly changes the value and closes right away.
                for (ILayerCell cell : cells) {
                    ICellEditHandler editHandler = new InlineEditHandler(cell.getLayer(), cell.getColumnPosition(), cell.getRowPosition());
                    cellEditor.activateCell(parent, initialCanonicalValue, EditModeEnum.INLINE, editHandler, cell, configRegistry);
                }
            }
        }
    }
}
Also used : ICellEditDialog(org.eclipse.nebula.widgets.nattable.edit.gui.ICellEditDialog) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) ICellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor) UpdateDataCommand(org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)

Aggregations

UpdateDataCommand (org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand)63 Test (org.junit.Test)52 RowDeleteEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent)10 DiscardDataChangesCommand (org.eclipse.nebula.widgets.nattable.datachange.command.DiscardDataChangesCommand)7 SaveDataChangesCommand (org.eclipse.nebula.widgets.nattable.datachange.command.SaveDataChangesCommand)6 Person (org.eclipse.nebula.widgets.nattable.dataset.person.Person)6 ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)5 Date (java.util.Date)4 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)4 ColumnDeleteEvent (org.eclipse.nebula.widgets.nattable.layer.event.ColumnDeleteEvent)4 RowInsertEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowInsertEvent)4 StructuralRefreshCommand (org.eclipse.nebula.widgets.nattable.command.StructuralRefreshCommand)3 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)2 PositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)2 DataUpdateEvent (org.eclipse.nebula.widgets.nattable.edit.event.DataUpdateEvent)2 ClearAllFiltersCommand (org.eclipse.nebula.widgets.nattable.filterrow.command.ClearAllFiltersCommand)2 ClearFilterCommand (org.eclipse.nebula.widgets.nattable.filterrow.command.ClearFilterCommand)2 CellVisualChangeEvent (org.eclipse.nebula.widgets.nattable.layer.event.CellVisualChangeEvent)2