use of org.eclipse.nebula.widgets.nattable.reorder.event.RowReorderEvent in project nebula.widgets.nattable by eclipse.
the class RowReorderLayerVisibleChangeTest method returnsCorrectPositionRectangleForMultiColumnReorderLeftCase.
@SuppressWarnings("boxing")
@Test
public /**
* Index 10 11 12 13 ... 20
* --------------------
* Position 0 1 2 3 ... 20
*/
void returnsCorrectPositionRectangleForMultiColumnReorderLeftCase() {
RowReorderLayer reorderLayer = new RowReorderLayer(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) {
RowReorderEvent multiReorder = (RowReorderEvent) event;
assertTrue(multiReorder.getChangedPositionRectangles().containsAll(expectedPositions));
}
});
// Reorder to beginning of grid
List<Integer> fromRowPositions = Arrays.asList(new Integer[] { 10, 11, 12, 13 });
reorderLayer.reorderMultipleRowPositions(fromRowPositions, 0);
// Reorder to middle of grid
expectedPositions.clear();
expectedPositions.add(new Rectangle(0, 10, 20, 10));
fromRowPositions = Arrays.asList(new Integer[] { 19, 18, 17, 16 });
reorderLayer.reorderMultipleRowPositions(fromRowPositions, 10);
// Reorder to end of grid
expectedPositions.clear();
expectedPositions.add(new Rectangle(0, 5, 20, 15));
fromRowPositions = Arrays.asList(new Integer[] { 5, 6, 7, 8 });
reorderLayer.reorderMultipleRowPositions(fromRowPositions, 10);
}
use of org.eclipse.nebula.widgets.nattable.reorder.event.RowReorderEvent in project nebula.widgets.nattable by eclipse.
the class RowReorderLayer method reorderRowPosition.
/**
* Reorders the row at the given from position to the <i>TOP</i> of the of
* the given to position.
*
* @param fromRowPosition
* row position to move
* @param toRowPosition
* position to move the row to
* @param reorderToTopEdge
* whether the move should be done above the given to position or
* not
*/
public void reorderRowPosition(int fromRowPosition, int toRowPosition, boolean reorderToTopEdge) {
moveRow(fromRowPosition, toRowPosition, reorderToTopEdge);
fireLayerEvent(new RowReorderEvent(this, fromRowPosition, toRowPosition, reorderToTopEdge));
}
use of org.eclipse.nebula.widgets.nattable.reorder.event.RowReorderEvent in project nebula.widgets.nattable by eclipse.
the class RowReorderLayerVisibleChangeTest method returnsCorrectPositionRectangleForMultiColumnReorderRightCase.
@SuppressWarnings("boxing")
@Test
public /**
* Index 2 3 0 1 ... 20
* --------------------
* Position 0 1 2 3 ... 20
*/
void returnsCorrectPositionRectangleForMultiColumnReorderRightCase() {
RowReorderLayer reorderLayer = new RowReorderLayer(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) {
RowReorderEvent multiReorder = (RowReorderEvent) event;
assertTrue(multiReorder.getChangedPositionRectangles().containsAll(expectedPositions));
}
});
// Reorder from beginning of grid
List<Integer> fromRowPositions = Arrays.asList(new Integer[] { 0, 1 });
reorderLayer.reorderMultipleRowPositions(fromRowPositions, 2);
// Reorder to middle of grid
expectedPositions.clear();
expectedPositions.add(new Rectangle(0, 5, 20, 15));
fromRowPositions = Arrays.asList(new Integer[] { 5, 6, 7, 8 });
reorderLayer.reorderMultipleRowPositions(fromRowPositions, 10);
// Reorder to end of grid
expectedPositions.clear();
expectedPositions.add(new Rectangle(0, 10, 20, 10));
fromRowPositions = Arrays.asList(new Integer[] { 10, 11, 12, 13 });
reorderLayer.reorderMultipleRowPositions(fromRowPositions, 19);
}
use of org.eclipse.nebula.widgets.nattable.reorder.event.RowReorderEvent in project nebula.widgets.nattable by eclipse.
the class RowReorderLayer method reorderMultipleRowPositions.
/**
* Reorders the rows at the given from positions to the <i>TOP</i> of the of
* the given to position.
*
* @param fromRowPositions
* row positions to move
* @param toRowPosition
* position to move the rows to
* @param reorderToTopEdge
* whether the move should be done above the given to position or
* not
*/
public void reorderMultipleRowPositions(List<Integer> fromRowPositions, int toRowPosition, boolean reorderToTopEdge) {
final int fromRowPositionsCount = fromRowPositions.size();
if (toRowPosition > fromRowPositions.get(fromRowPositionsCount - 1)) {
// Moving from top to bottom
int firstRowPosition = fromRowPositions.get(0);
for (int rowCount = 0; rowCount < fromRowPositionsCount; rowCount++) {
final int fromRowPosition = fromRowPositions.get(0);
moveRow(fromRowPosition, toRowPosition, reorderToTopEdge);
if (fromRowPosition < firstRowPosition) {
firstRowPosition = fromRowPosition;
}
}
} else if (toRowPosition < fromRowPositions.get(fromRowPositionsCount - 1)) {
// Moving from bottom to top
int targetRowPosition = toRowPosition;
for (Integer fromRowPosition : fromRowPositions) {
final int fromRowPositionInt = fromRowPosition;
moveRow(fromRowPositionInt, targetRowPosition++, reorderToTopEdge);
}
}
fireLayerEvent(new RowReorderEvent(this, fromRowPositions, toRowPosition, reorderToTopEdge));
}
Aggregations