Skip to content

Commit

Permalink
Take footer into account in column dnd-reorder (#16643)
Browse files Browse the repository at this point in the history
Change-Id: I0358d1b18f65d40325b6c1bc3f3e4d3b9249fb5f
  • Loading branch information
pleku committed Mar 4, 2015
1 parent de2172e commit 3abaa64
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 7 deletions.
14 changes: 8 additions & 6 deletions client/src/com/vaadin/client/widgets/Grid.java
Expand Up @@ -139,6 +139,8 @@
import com.vaadin.client.widget.grid.sort.SortOrder;
import com.vaadin.client.widgets.Escalator.AbstractRowContainer;
import com.vaadin.client.widgets.Grid.Editor.State;
import com.vaadin.client.widgets.Grid.StaticSection.StaticCell;
import com.vaadin.client.widgets.Grid.StaticSection.StaticRow;
import com.vaadin.shared.data.sort.SortDirection;
import com.vaadin.shared.ui.grid.GridConstants;
import com.vaadin.shared.ui.grid.GridStaticCellType;
Expand Down Expand Up @@ -3183,15 +3185,15 @@ private void calculatePossibleDropPositions() {
int leftBound = -1;
int rightBound = getColumnCount() + 1;

for (int r = 0; r < getHeaderRowCount(); r++) {
HeaderRow headerRow = getHeaderRow(r);
if (!headerRow.hasSpannedCells()) {
final List<StaticRow<?>> rows = new ArrayList<StaticRow<?>>();
rows.addAll(header.getRows());
rows.addAll(footer.getRows());
for (StaticRow<?> row : rows) {
if (!row.hasSpannedCells()) {
continue;
}
for (int c = frozenColumns; c < getColumnCount(); c++) {
HeaderCell cell = headerRow.getCell(getColumn(c));
assert cell != null : "Somehow got a null cell for row:cell "
+ r + ":" + c;
StaticCell cell = row.getCell(getColumn(c));
int colspan = cell.getColspan();
if (colspan <= 1) {
continue;
Expand Down
Expand Up @@ -236,7 +236,7 @@ public void testColumnReorder_anotherRowHasColumnHeadersSpanned_cantDropInsideSp
}

@Test
public void testColumnReorder_cellInsideASpannedHeader_cantBeDroppedOutsideSpannedArea() {
public void testColumnReorder_cellInsideSpannedHeader_cantBeDroppedOutsideSpannedArea() {
// given
toggleColumnReorder();
selectMenuPath("Component", "Header", "Append row");
Expand Down Expand Up @@ -353,6 +353,79 @@ public void testColumnReorder_cellsInsideTwoAdjacentSpannedHeaders_reorderingLim
assertColumnHeaderOrder(1, 3, 4, 5, 2);
}

@Test
public void testColumnReorder_footerHasSpannedCells_cantDropInside() {
// given
toggleColumnReorder();
selectMenuPath("Component", "Footer", "Append row");
selectMenuPath("Component", "Footer", "Row 1", "Join columns 1, 2");
assertColumnHeaderOrder(0, 1, 2, 3, 4);

// when
dragAndDropColumnHeader(0, 3, 1, 80);

// then
assertColumnHeaderOrder(0, 3, 1, 2, 4);
}

@Test
public void testColumnReorder_cellInsideASpannedFooter_cantBeDroppedOutsideSpannedArea() {
// given
toggleColumnReorder();
selectMenuPath("Component", "Footer", "Append row");
selectMenuPath("Component", "Footer", "Row 1", "Join columns 1, 2");
assertColumnHeaderOrder(0, 1, 2, 3, 4);

// when
dragAndDropColumnHeader(0, 2, 0, 20);

// then
assertColumnHeaderOrder(0, 2, 1, 3, 4);
}

@Test
public void testColumnReorder_cellInsideTwoCrossingSpanningFooters_cantTouchThis() {
// given
toggleColumnReorder();
selectMenuPath("Component", "Footer", "Append row");
selectMenuPath("Component", "Footer", "Append row");
selectMenuPath("Component", "Footer", "Row 1", "Join column cells 0, 1");
selectMenuPath("Component", "Footer", "Row 2", "Join columns 1, 2");
dragAndDropColumnHeader(0, 3, 0, 10);
assertColumnHeaderOrder(3, 0, 1, 2, 4);

// when
dragAndDropColumnHeader(0, 2, 0, 10);

// then
assertColumnHeaderOrder(3, 0, 1, 2, 4);
}

@Test
public void testColumnReorder_cellsInsideTwoAdjacentSpannedHeaderAndFooter_reorderingLimited() {
// given
toggleColumnReorder();
selectMenuPath("Component", "Header", "Append row");
selectMenuPath("Component", "Footer", "Append row");
selectMenuPath("Component", "Header", "Row 2", "Join columns 3, 4, 5");
dragAndDropColumnHeader(0, 0, 4, 80);
scrollGridHorizontallyTo(0);
dragAndDropColumnHeader(0, 1, 4, 80);
scrollGridHorizontallyTo(0);
selectMenuPath("Component", "Footer", "Row 1", "Join columns 1, 2");
assertColumnHeaderOrder(1, 3, 4, 5, 2);

// when then
dragAndDropColumnHeader(0, 1, 3, 80);
assertColumnHeaderOrder(1, 4, 3, 5, 2);

dragAndDropColumnHeader(0, 2, 4, 10);
assertColumnHeaderOrder(1, 4, 3, 5, 2);

dragAndDropColumnHeader(0, 2, 0, 10);
assertColumnHeaderOrder(1, 3, 4, 5, 2);
}

private void toggleColumnReorder() {
selectMenuPath("Component", "State", "Column Reordering");
}
Expand Down

0 comments on commit 3abaa64

Please sign in to comment.