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());
}
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());
}
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));
}
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);
}
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);
}
}
}
}
}
Aggregations