use of org.eclipse.nebula.widgets.nattable.reorder.event.ColumnReorderEvent in project nebula.widgets.nattable by eclipse.
the class ColumnReorderLayerVisibleChangeTest method returnsCorrectPositionRectangleForMultiColumnReorderLeftCase.
@SuppressWarnings("boxing")
@Test
public /**
* Index 10 11 12 13 ... 20
* --------------------
* Position 0 1 2 3 ... 20
*/
void returnsCorrectPositionRectangleForMultiColumnReorderLeftCase() {
ColumnReorderLayer reorderLayer = new ColumnReorderLayer(new BaseDataLayerFixture(20, 20));
// Build expected cell positions to redraw
final Set<Rectangle> expectedPositions = new HashSet<Rectangle>();
expectedPositions.add(new Rectangle(0, 0, 20, 20));
reorderLayer.addLayerListener(new ILayerListener() {
@Override
public void handleLayerEvent(ILayerEvent event) {
ColumnReorderEvent multiReorder = (ColumnReorderEvent) event;
assertTrue(multiReorder.getChangedPositionRectangles().containsAll(expectedPositions));
}
});
// Reorder to beginning of grid
List<Integer> fromColumnPositions = Arrays.asList(new Integer[] { 10, 11, 12, 13 });
reorderLayer.reorderMultipleColumnPositions(fromColumnPositions, 0);
// Reorder to middle of grid
expectedPositions.clear();
expectedPositions.add(new Rectangle(10, 0, 10, 20));
fromColumnPositions = Arrays.asList(new Integer[] { 19, 18, 17, 16 });
reorderLayer.reorderMultipleColumnPositions(fromColumnPositions, 10);
// Reorder to end of grid
expectedPositions.clear();
expectedPositions.add(new Rectangle(5, 0, 15, 20));
fromColumnPositions = Arrays.asList(new Integer[] { 5, 6, 7, 8 });
reorderLayer.reorderMultipleColumnPositions(fromColumnPositions, 10);
}
use of org.eclipse.nebula.widgets.nattable.reorder.event.ColumnReorderEvent in project nebula.widgets.nattable by eclipse.
the class ColumnReorderLayerVisibleChangeTest method returnsCorrectPositionRectangleForMultiColumnReorderRightCase.
@SuppressWarnings("boxing")
@Test
public /**
* Index 2 3 0 1 ... 20
* --------------------
* Position 0 1 2 3 ... 20
*/
void returnsCorrectPositionRectangleForMultiColumnReorderRightCase() {
ColumnReorderLayer reorderLayer = new ColumnReorderLayer(new BaseDataLayerFixture(20, 20));
// Build expected cell positions to redraw
final Set<Rectangle> expectedPositions = new HashSet<Rectangle>();
expectedPositions.add(new Rectangle(0, 0, 20, 20));
reorderLayer.addLayerListener(new ILayerListener() {
@Override
public void handleLayerEvent(ILayerEvent event) {
ColumnReorderEvent multiReorder = (ColumnReorderEvent) event;
assertTrue(multiReorder.getChangedPositionRectangles().containsAll(expectedPositions));
}
});
// Reorder from beginning of grid
List<Integer> fromColumnPositions = Arrays.asList(new Integer[] { 0, 1 });
reorderLayer.reorderMultipleColumnPositions(fromColumnPositions, 2);
// Reorder to middle of grid
expectedPositions.clear();
expectedPositions.add(new Rectangle(5, 0, 15, 20));
fromColumnPositions = Arrays.asList(new Integer[] { 5, 6, 7, 8 });
reorderLayer.reorderMultipleColumnPositions(fromColumnPositions, 10);
// Reorder to end of grid
expectedPositions.clear();
expectedPositions.add(new Rectangle(10, 0, 10, 20));
fromColumnPositions = Arrays.asList(new Integer[] { 10, 11, 12, 13 });
reorderLayer.reorderMultipleColumnPositions(fromColumnPositions, 19);
}
use of org.eclipse.nebula.widgets.nattable.reorder.event.ColumnReorderEvent 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.reorder.event.ColumnReorderEvent 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.reorder.event.ColumnReorderEvent in project nebula.widgets.nattable by eclipse.
the class ColumnReorderLayer method reorderMultipleColumnPositions.
/**
* Reorders the given from-columns to the specified edge of the column to
* move to and fires a {@link ColumnReorderEvent}.
*
* @param fromColumnPositions
* column positions to move
* @param toColumnPosition
* position to move the columns to
* @param reorderToLeftEdge
* <code>true</code> if the columns should be moved to the left
* of the given column to move to, <code>false</code> if they
* should be positioned to the right
*/
public void reorderMultipleColumnPositions(List<Integer> fromColumnPositions, int toColumnPosition, boolean reorderToLeftEdge) {
// Moving from left to right
final int fromColumnPositionsCount = fromColumnPositions.size();
if (toColumnPosition > fromColumnPositions.get(fromColumnPositionsCount - 1)) {
int firstColumnPosition = fromColumnPositions.get(0).intValue();
for (int columnCount = 0; columnCount < fromColumnPositionsCount; columnCount++) {
final int fromColumnPosition = fromColumnPositions.get(0);
moveColumn(fromColumnPosition, toColumnPosition, reorderToLeftEdge);
if (fromColumnPosition < firstColumnPosition) {
firstColumnPosition = fromColumnPosition;
}
}
} else if (toColumnPosition < fromColumnPositions.get(fromColumnPositionsCount - 1).intValue()) {
// Moving from right to left
int targetColumnPosition = toColumnPosition;
for (Integer fromColumnPosition : fromColumnPositions) {
final int fromColumnPositionInt = fromColumnPosition.intValue();
moveColumn(fromColumnPositionInt, targetColumnPosition++, reorderToLeftEdge);
}
}
fireLayerEvent(new ColumnReorderEvent(this, fromColumnPositions, toColumnPosition, reorderToLeftEdge));
}
Aggregations