Search in sources :

Example 11 with StructuralDiff

use of org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff in project nebula.widgets.nattable by eclipse.

the class ColumnHideShowLayer method handleLayerEvent.

@Override
public void handleLayerEvent(ILayerEvent event) {
    if (event instanceof IStructuralChangeEvent) {
        IStructuralChangeEvent structuralChangeEvent = (IStructuralChangeEvent) event;
        if (structuralChangeEvent.isHorizontalStructureChanged()) {
            Collection<StructuralDiff> columnDiffs = structuralChangeEvent.getColumnDiffs();
            if (columnDiffs != null && !columnDiffs.isEmpty() && !StructuralChangeEventHelper.isReorder(columnDiffs)) {
                StructuralChangeEventHelper.handleColumnDelete(columnDiffs, this.underlyingLayer, this.hiddenColumnIndexes, false);
                StructuralChangeEventHelper.handleColumnInsert(columnDiffs, this.underlyingLayer, this.hiddenColumnIndexes, false);
            }
        }
    }
    super.handleLayerEvent(event);
}
Also used : IStructuralChangeEvent(org.eclipse.nebula.widgets.nattable.layer.event.IStructuralChangeEvent) StructuralDiff(org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff)

Example 12 with StructuralDiff

use of org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff in project nebula.widgets.nattable by eclipse.

the class RowHideShowLayer method handleLayerEvent.

@Override
public void handleLayerEvent(ILayerEvent event) {
    if (event instanceof IStructuralChangeEvent) {
        IStructuralChangeEvent structuralChangeEvent = (IStructuralChangeEvent) event;
        if (structuralChangeEvent.isVerticalStructureChanged()) {
            Collection<StructuralDiff> rowDiffs = structuralChangeEvent.getRowDiffs();
            if (rowDiffs != null && !rowDiffs.isEmpty() && !StructuralChangeEventHelper.isReorder(rowDiffs)) {
                StructuralChangeEventHelper.handleRowDelete(rowDiffs, this.underlyingLayer, this.hiddenRowIndexes, false);
                StructuralChangeEventHelper.handleRowInsert(rowDiffs, this.underlyingLayer, this.hiddenRowIndexes, false);
            }
        }
    }
    super.handleLayerEvent(event);
}
Also used : IStructuralChangeEvent(org.eclipse.nebula.widgets.nattable.layer.event.IStructuralChangeEvent) StructuralDiff(org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff)

Example 13 with StructuralDiff

use of org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff in project nebula.widgets.nattable by eclipse.

the class HideRowPositionsEvent method getRowDiffs.

@Override
public Collection<StructuralDiff> getRowDiffs() {
    Collection<StructuralDiff> rowDiffs = new ArrayList<StructuralDiff>(getRowPositionRanges().size());
    for (Range range : getRowPositionRanges()) {
        StructuralDiff diff = new StructuralDiff(DiffTypeEnum.DELETE, range, new Range(range.start, range.start));
        rowDiffs.add(diff);
    }
    return rowDiffs;
}
Also used : StructuralDiff(org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff) ArrayList(java.util.ArrayList) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range)

Example 14 with StructuralDiff

use of org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff in project nebula.widgets.nattable by eclipse.

the class ShowColumnPositionsEvent method getColumnDiffs.

@Override
public Collection<StructuralDiff> getColumnDiffs() {
    Collection<StructuralDiff> columnDiffs = new ArrayList<StructuralDiff>(getColumnPositionRanges().size());
    int offset = 0;
    for (Range range : getColumnPositionRanges()) {
        columnDiffs.add(new StructuralDiff(DiffTypeEnum.ADD, new Range(range.start - offset, range.start - offset), range));
        offset += range.size();
    }
    return columnDiffs;
}
Also used : StructuralDiff(org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff) ArrayList(java.util.ArrayList) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range)

Example 15 with StructuralDiff

use of org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff in project nebula.widgets.nattable by eclipse.

the class ColumnReorderEvent method getColumnDiffs.

@Override
public Collection<StructuralDiff> getColumnDiffs() {
    Collection<StructuralDiff> columnDiffs = new ArrayList<StructuralDiff>();
    Collection<Range> beforeFromColumnPositionRanges = getBeforeFromColumnPositionRanges();
    final int beforeToColumnPosition = (this.reorderToLeftEdge) ? this.beforeToColumnPosition : (this.beforeToColumnPosition + 1);
    int afterAddColumnPosition = beforeToColumnPosition;
    for (Range beforeFromColumnPositionRange : beforeFromColumnPositionRanges) {
        if (beforeFromColumnPositionRange.start < beforeToColumnPosition) {
            afterAddColumnPosition -= Math.min(beforeFromColumnPositionRange.end, beforeToColumnPosition) - beforeFromColumnPositionRange.start;
        } else {
            break;
        }
    }
    int cumulativeAddSize = 0;
    for (Range beforeFromColumnPositionRange : beforeFromColumnPositionRanges) {
        cumulativeAddSize += beforeFromColumnPositionRange.size();
    }
    int offset = 0;
    for (Range beforeFromColumnPositionRange : beforeFromColumnPositionRanges) {
        int afterDeleteColumnPosition = beforeFromColumnPositionRange.start - offset;
        if (afterAddColumnPosition < afterDeleteColumnPosition) {
            afterDeleteColumnPosition += cumulativeAddSize;
        }
        columnDiffs.add(new StructuralDiff(DiffTypeEnum.DELETE, beforeFromColumnPositionRange, new Range(afterDeleteColumnPosition, afterDeleteColumnPosition)));
        offset += beforeFromColumnPositionRange.size();
    }
    Range beforeAddRange = new Range(beforeToColumnPosition, beforeToColumnPosition);
    offset = 0;
    for (Range beforeFromColumnPositionRange : beforeFromColumnPositionRanges) {
        int size = beforeFromColumnPositionRange.size();
        columnDiffs.add(new StructuralDiff(DiffTypeEnum.ADD, beforeAddRange, new Range(afterAddColumnPosition + offset, afterAddColumnPosition + offset + size)));
        offset += size;
    }
    return columnDiffs;
}
Also used : StructuralDiff(org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff) ArrayList(java.util.ArrayList) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range)

Aggregations

StructuralDiff (org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff)28 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)23 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)9 IStructuralChangeEvent (org.eclipse.nebula.widgets.nattable.layer.event.IStructuralChangeEvent)5 ColumnReorderEvent (org.eclipse.nebula.widgets.nattable.reorder.event.ColumnReorderEvent)4 Serializable (java.io.Serializable)2 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)2 IUniqueIndexLayer (org.eclipse.nebula.widgets.nattable.layer.IUniqueIndexLayer)2 NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)2 LayerListenerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 PositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)1 UpdateDataCommand (org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand)1 DataUpdateEvent (org.eclipse.nebula.widgets.nattable.edit.event.DataUpdateEvent)1 ColumnHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand)1