use of org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff in project nebula.widgets.nattable by eclipse.
the class ResizeEventDiffTest method testConvertToLocal.
@Test
public void testConvertToLocal() {
this.event.convertToLocal(this.viewportLayer);
Collection<StructuralDiff> columnDiffs = this.event.getColumnDiffs();
Assert.assertNotNull(columnDiffs);
Assert.assertEquals(1, columnDiffs.size());
Assert.assertEquals(new StructuralDiff(DiffTypeEnum.CHANGE, new Range(0, 1), new Range(0, 1)), columnDiffs.iterator().next());
}
use of org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff in project nebula.widgets.nattable by eclipse.
the class MultiColumnReorderEventDiffTest method testReorderLeftColumnDiffs.
/**
* + - - - before: 0 1 2 3 4 5 6 7 8 9 10 after: 0 1 7 8 9 2 3 4 5 6 10 + +
* + -
*/
@Test
public void testReorderLeftColumnDiffs() {
this.event = new ColumnReorderEvent(this.dataLayer, Arrays.asList(new Integer[] { 7, 8, 9 }), 2, true);
Collection<StructuralDiff> columnDiffs = this.event.getColumnDiffs();
Assert.assertNotNull(columnDiffs);
Assert.assertEquals(2, columnDiffs.size());
Iterator<StructuralDiff> iterator = columnDiffs.iterator();
Assert.assertEquals(new StructuralDiff(DiffTypeEnum.DELETE, new Range(7, 10), new Range(10, 10)), iterator.next());
Assert.assertEquals(new StructuralDiff(DiffTypeEnum.ADD, new Range(2, 2), new Range(2, 5)), iterator.next());
}
use of org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff in project nebula.widgets.nattable by eclipse.
the class MultiColumnReorderEventDiffTest method testReorderRightColumnDiffs.
/**
* - - - + before: 0 1 2 3 4 5 6 7 8 after: 0 1 5 6 2 3 4 7 8 - + + +
*/
@Test
public void testReorderRightColumnDiffs() {
this.event = new ColumnReorderEvent(this.dataLayer, Arrays.asList(new Integer[] { 2, 3, 4 }), 7, true);
Collection<StructuralDiff> columnDiffs = this.event.getColumnDiffs();
Assert.assertNotNull(columnDiffs);
Assert.assertEquals(2, columnDiffs.size());
Iterator<StructuralDiff> iterator = columnDiffs.iterator();
Assert.assertEquals(new StructuralDiff(DiffTypeEnum.DELETE, new Range(2, 5), new Range(2, 2)), iterator.next());
Assert.assertEquals(new StructuralDiff(DiffTypeEnum.ADD, new Range(7, 7), new Range(4, 7)), iterator.next());
}
use of org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff in project nebula.widgets.nattable by eclipse.
the class RenameColumnHelper method handleStructuralChanges.
/**
* Handle the given collection of {@link StructuralDiff} objects to update
* the indexes of the renamed column labels.
*
* @param columnDiffs
* The {@link StructuralDiff}s to handle
* @since 1.4
*/
public void handleStructuralChanges(Collection<StructuralDiff> columnDiffs) {
// the number of all deleted columns that don't have a corresponding
// index anymore (last column cases)
List<Integer> toRemove = new ArrayList<Integer>();
for (StructuralDiff columnDiff : columnDiffs) {
if (columnDiff.getDiffType() != null && columnDiff.getDiffType().equals(DiffTypeEnum.DELETE)) {
Range beforePositionRange = columnDiff.getBeforePositionRange();
for (int i = beforePositionRange.start; i < beforePositionRange.end; i++) {
int index = i;
if (index >= 0)
toRemove.add(index);
}
}
}
// remove the column indexes that are deleted
for (Integer r : toRemove) {
this.renamedColumnsLabelsByIndex.remove(r);
}
// modify column indexes regarding the deleted columns
List<Integer> indices = new ArrayList<Integer>(this.renamedColumnsLabelsByIndex.keySet());
Collections.sort(indices);
Map<Integer, String> modified = new TreeMap<Integer, String>();
for (Integer column : indices) {
// check number of removed indexes that are lower than the current
// one
int deletedBefore = 0;
for (Integer removed : toRemove) {
if (removed < column) {
deletedBefore++;
}
}
int modColumn = column - deletedBefore;
if (modColumn >= 0)
modified.put(modColumn, this.renamedColumnsLabelsByIndex.get(column));
}
this.renamedColumnsLabelsByIndex.clear();
this.renamedColumnsLabelsByIndex.putAll(modified);
for (StructuralDiff columnDiff : columnDiffs) {
if (columnDiff.getDiffType() != null && columnDiff.getDiffType().equals(DiffTypeEnum.ADD)) {
indices = new ArrayList<Integer>(this.renamedColumnsLabelsByIndex.keySet());
Collections.sort(indices);
Range beforePositionRange = columnDiff.getBeforePositionRange();
Range afterPositionRange = columnDiff.getAfterPositionRange();
Map<Integer, String> modifiedColumns = new TreeMap<Integer, String>();
int beforeIndex = this.columnHeaderLayer.getColumnIndexByPosition(beforePositionRange.start);
for (Integer column : indices) {
if (column >= beforeIndex) {
modifiedColumns.put(column + (afterPositionRange.end - afterPositionRange.start), this.renamedColumnsLabelsByIndex.get(column));
} else {
modifiedColumns.put(column, this.renamedColumnsLabelsByIndex.get(column));
}
}
this.renamedColumnsLabelsByIndex.clear();
this.renamedColumnsLabelsByIndex.putAll(modifiedColumns);
}
}
}
use of org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff 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);
}
Aggregations