use of org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand in project nebula.widgets.nattable by eclipse.
the class DataChangeLayer method handleLayerEvent.
@SuppressWarnings("unchecked")
@Override
public void handleLayerEvent(ILayerEvent event) {
// updated and we remember the modifications via DataUpdateEvent
if (!this.temporaryDataStorage && this.handleDataUpdateEvents && event instanceof DataUpdateEvent) {
DataUpdateEvent updateEvent = (DataUpdateEvent) event;
Object key = this.keyHandler.getKey(updateEvent.getColumnPosition(), updateEvent.getRowPosition());
synchronized (this.dataChanges) {
// this ensures that a discard really restores the original
if (!this.dataChanges.containsKey(key)) {
this.changedColumns.add(updateEvent.getColumnPosition());
this.changedRows.add(updateEvent.getRowPosition());
// store an UpdateDataCommand that can be used to revert the
// change
this.dataChanges.put(key, new UpdateDataCommand(this, updateEvent.getColumnPosition(), updateEvent.getRowPosition(), updateEvent.getOldValue()));
} else if ((this.dataChanges.get(key).getNewValue() != null && this.dataChanges.get(key).getNewValue().equals(updateEvent.getNewValue()) || (this.dataChanges.get(key).getNewValue() == null && updateEvent.getNewValue() == null))) {
// the value was changed back to the original value in
// the underlying layer simply remove the local storage
// to not showing the cell as dirty
this.dataChanges.remove(this.keyHandler.getKey(updateEvent.getColumnPosition(), updateEvent.getRowPosition()));
rebuildPositionCollections();
}
}
} else if (event instanceof IStructuralChangeEvent) {
IStructuralChangeEvent structuralChangeEvent = (IStructuralChangeEvent) event;
if (structuralChangeEvent.getColumnDiffs() == null && structuralChangeEvent.getRowDiffs() == null && structuralChangeEvent.isHorizontalStructureChanged() && structuralChangeEvent.isVerticalStructureChanged()) {
// Assume everything changed
clearDataChanges();
} else if (structuralChangeEvent.isHorizontalStructureChanged() && structuralChangeEvent.getColumnDiffs() != null) {
if (this.keyHandler.updateOnHorizontalStructuralChange()) {
Collection<StructuralDiff> structuralDiffs = structuralChangeEvent.getColumnDiffs();
StructuralChangeEventHelper.handleColumnDelete(structuralDiffs, this.dataChanges, this.keyHandler);
StructuralChangeEventHelper.handleColumnInsert(structuralDiffs, this.dataChanges, this.keyHandler);
} else {
removeChangesForDeletedObjects();
}
} else if (structuralChangeEvent.isVerticalStructureChanged() && structuralChangeEvent.getRowDiffs() != null) {
if (this.keyHandler.updateOnVerticalStructuralChange()) {
Collection<StructuralDiff> structuralDiffs = structuralChangeEvent.getRowDiffs();
StructuralChangeEventHelper.handleRowDelete(structuralDiffs, this.dataChanges, this.keyHandler);
StructuralChangeEventHelper.handleRowInsert(structuralDiffs, this.dataChanges, this.keyHandler);
} else {
removeChangesForDeletedObjects();
}
}
rebuildPositionCollections();
}
super.handleLayerEvent(event);
}
use of org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand in project nebula.widgets.nattable by eclipse.
the class DataChangeLayer method discardDataChanges.
/**
* Discards the tracked data changes. In case temporary data storage is
* disabled, the applied changes are undone by restoring the previous values
* via dedicated {@link UpdateDataCommand}s.
*/
public void discardDataChanges() {
if (!this.temporaryDataStorage) {
// avoid handling of DataUpdateEvents that are caused by restoring
// the previous data states
this.handleDataUpdateEvents = false;
// old values
for (Map.Entry<Object, UpdateDataCommand> entry : this.dataChanges.entrySet()) {
getUnderlyingLayer().doCommand(getUpdateDataCommand(entry.getKey(), entry.getValue()));
}
this.handleDataUpdateEvents = true;
}
clearDataChanges();
fireLayerEvent(new VisualRefreshEvent(this));
}
use of org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand in project nebula.widgets.nattable by eclipse.
the class DataChangeLayer method saveDataChanges.
/**
* Saves the tracked data changes. In case temporary data storage is enabled
* this means the underlying data model is updated. Otherwise the stored
* data changes are simply cleared.
* <p>
* <b>Note:</b> In case temporary data storage is disabled and a custom save
* operation should be performed on save, a custom
* {@link SaveDataChangesCommandHandler} should be registered that first
* performs a custom action and afterwards calls this method to ensure a
* clear state in this layer.
* </p>
*/
public void saveDataChanges() {
if (this.temporaryDataStorage) {
for (Map.Entry<Object, UpdateDataCommand> entry : this.dataChanges.entrySet()) {
getUnderlyingLayer().doCommand(getUpdateDataCommand(entry.getKey(), entry.getValue()));
}
}
clearDataChanges();
fireLayerEvent(new VisualRefreshEvent(this));
}
use of org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand in project nebula.widgets.nattable by eclipse.
the class InternalPasteDataCommandHandler method doCommand.
@Override
protected boolean doCommand(PasteDataCommand command) {
if (this.clipboard.getCopiedCells() != null) {
preInternalPaste();
PositionCoordinate coord = this.selectionLayer.getSelectionAnchor();
int pasteColumn = coord.getColumnPosition();
int pasteRow = coord.getRowPosition();
for (ILayerCell[] cells : this.clipboard.getCopiedCells()) {
for (ILayerCell cell : cells) {
if (EditUtils.isCellEditable(this.selectionLayer, command.configRegistry, new PositionCoordinate(this.selectionLayer, pasteColumn, pasteRow))) {
this.selectionLayer.doCommand(new UpdateDataCommand(this.selectionLayer, pasteColumn, pasteRow, getPasteValue(cell, pasteColumn, pasteRow)));
}
pasteColumn++;
if (pasteColumn >= this.selectionLayer.getColumnCount()) {
break;
}
}
pasteRow++;
pasteColumn = coord.getColumnPosition();
}
postInternalPaste();
}
return true;
}
use of org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand in project nebula.widgets.nattable by eclipse.
the class ToggleCheckBoxColumnAction method run.
@Override
public void run(NatTable natTable, MouseEvent event) {
int sourceColumnPosition = natTable.getColumnPositionByX(event.x);
int columnPosition = LayerUtil.convertColumnPosition(natTable, sourceColumnPosition, this.bodyDataLayer);
int checkedCellsCount = this.columnHeaderCheckBoxPainter.getCheckedCellsCount(columnPosition, natTable.getConfigRegistry());
boolean targetState = checkedCellsCount < this.bodyDataLayer.getRowCount();
for (int rowPosition = 0; rowPosition < this.bodyDataLayer.getRowCount(); rowPosition++) {
this.bodyDataLayer.doCommand(new UpdateDataCommand(this.bodyDataLayer, columnPosition, rowPosition, targetState));
}
}
Aggregations