RowSynchronizer extends BaseSynchronizer<RowMetaData, RowMetaData, RowMetaData> { @Override public void moveRowsTo(final List<MoveRowToMetaData> metaData) throws VetoException { if (!handlesMoveRowsTo(metaData)) { return; } for (int idx = 0; idx < metaData.size(); idx++) { final MoveRowToMetaData md = metaData.get(idx); final int sourceRowIndex = md.getSourceRowIndex(); final int targetRowIndex = md.getTargetRowIndex(); final List<DTCellValue52> row = md.getRow(); if (targetRowIndex < sourceRowIndex) { model.getData().remove(sourceRowIndex); model.getData().add(targetRowIndex, row); } else if (targetRowIndex > sourceRowIndex) { model.getData().remove(sourceRowIndex - idx); model.getData().add(targetRowIndex - idx, row); } } }  @Override boolean handlesAppend(final MetaData metaData); @Override void append(final RowMetaData metaData); @Override boolean handlesInsert(final MetaData metaData); @Override void insert(final RowMetaData metaData); @Override boolean handlesUpdate(final MetaData metaData); @Override List<BaseColumnFieldDiff> update(final RowMetaData originalMetaData,
                                            final RowMetaData editedMetaData); @Override boolean handlesDelete(final MetaData metaData); @Override void delete(final RowMetaData metaData); @Override boolean handlesMoveColumnsTo(final List<? extends MetaData> metaData); @Override void moveColumnsTo(final List<MoveColumnToMetaData> metaData); @Override boolean handlesMoveRowsTo(final List<? extends MetaData> metaData); @Override void moveRowsTo(final List<MoveRowToMetaData> metaData);  }
@Test public void testMoveRowMoveUpTopBlock() throws VetoException { modelSynchronizer.appendRow(); modelSynchronizer.appendRow(); modelSynchronizer.appendRow(); final GridRow uiRow0 = uiModel.getRow(0); final GridRow uiRow1 = uiModel.getRow(1); final GridRow uiRow2 = uiModel.getRow(2); final List<DTCellValue52> row0 = model.getData().get(0); final List<DTCellValue52> row1 = model.getData().get(1); final List<DTCellValue52> row2 = model.getData().get(2); uiModel.moveRowsTo(0, new ArrayList<GridRow>() {{ add(uiRow2); }}); assertEquals(uiRow2, uiModel.getRow(0)); assertEquals(uiRow0, uiModel.getRow(1)); assertEquals(uiRow1, uiModel.getRow(2)); assertEquals(row2, model.getData().get(0)); assertEquals(row0, model.getData().get(1)); assertEquals(row1, model.getData().get(2)); }
@Test public void testMoveRowMoveUpMidBlock() throws VetoException { modelSynchronizer.appendRow(); modelSynchronizer.appendRow(); modelSynchronizer.appendRow(); final GridRow uiRow0 = uiModel.getRow(0); final GridRow uiRow1 = uiModel.getRow(1); final GridRow uiRow2 = uiModel.getRow(2); final List<DTCellValue52> row0 = model.getData().get(0); final List<DTCellValue52> row1 = model.getData().get(1); final List<DTCellValue52> row2 = model.getData().get(2); uiModel.moveRowsTo(1, new ArrayList<GridRow>() {{ add(uiRow2); }}); assertEquals(uiRow0, uiModel.getRow(0)); assertEquals(uiRow2, uiModel.getRow(1)); assertEquals(uiRow1, uiModel.getRow(2)); assertEquals(row0, model.getData().get(0)); assertEquals(row2, model.getData().get(1)); assertEquals(row1, model.getData().get(2)); }
@Test public void testMoveRowsMoveUp() throws VetoException { modelSynchronizer.appendRow(); modelSynchronizer.appendRow(); modelSynchronizer.appendRow(); final GridRow uiRow0 = uiModel.getRow(0); final GridRow uiRow1 = uiModel.getRow(1); final GridRow uiRow2 = uiModel.getRow(2); final List<DTCellValue52> row0 = model.getData().get(0); final List<DTCellValue52> row1 = model.getData().get(1); final List<DTCellValue52> row2 = model.getData().get(2); uiModel.moveRowsTo(0, new ArrayList<GridRow>() {{ add(uiRow1); add(uiRow2); }}); assertEquals(uiRow1, uiModel.getRow(0)); assertEquals(uiRow2, uiModel.getRow(1)); assertEquals(uiRow0, uiModel.getRow(2)); assertEquals(row1, model.getData().get(0)); assertEquals(row2, model.getData().get(1)); assertEquals(row0, model.getData().get(2)); }
@Test public void testMoveRowMoveDownEndBlock() throws VetoException { modelSynchronizer.appendRow(); modelSynchronizer.appendRow(); modelSynchronizer.appendRow(); final GridRow uiRow0 = uiModel.getRow(0); final GridRow uiRow1 = uiModel.getRow(1); final GridRow uiRow2 = uiModel.getRow(2); final List<DTCellValue52> row0 = model.getData().get(0); final List<DTCellValue52> row1 = model.getData().get(1); final List<DTCellValue52> row2 = model.getData().get(2); uiModel.moveRowsTo(2, new ArrayList<GridRow>() {{ add(uiRow0); }}); assertEquals(uiRow1, uiModel.getRow(0)); assertEquals(uiRow2, uiModel.getRow(1)); assertEquals(uiRow0, uiModel.getRow(2)); assertEquals(row1, model.getData().get(0)); assertEquals(row2, model.getData().get(1)); assertEquals(row0, model.getData().get(2)); }
@Test public void testMoveRowMoveDownMidBlock() throws VetoException { modelSynchronizer.appendRow(); modelSynchronizer.appendRow(); modelSynchronizer.appendRow(); final GridRow uiRow0 = uiModel.getRow(0); final GridRow uiRow1 = uiModel.getRow(1); final GridRow uiRow2 = uiModel.getRow(2); final List<DTCellValue52> row0 = model.getData().get(0); final List<DTCellValue52> row1 = model.getData().get(1); final List<DTCellValue52> row2 = model.getData().get(2); uiModel.moveRowsTo(1, new ArrayList<GridRow>() {{ add(uiRow0); }}); assertEquals(uiRow1, uiModel.getRow(0)); assertEquals(uiRow0, uiModel.getRow(1)); assertEquals(uiRow2, uiModel.getRow(2)); assertEquals(row1, model.getData().get(0)); assertEquals(row0, model.getData().get(1)); assertEquals(row2, model.getData().get(2)); }
@Test public void testMoveRowsMoveDown() throws VetoException { modelSynchronizer.appendRow(); modelSynchronizer.appendRow(); modelSynchronizer.appendRow(); final GridRow uiRow0 = uiModel.getRow(0); final GridRow uiRow1 = uiModel.getRow(1); final GridRow uiRow2 = uiModel.getRow(2); final List<DTCellValue52> row0 = model.getData().get(0); final List<DTCellValue52> row1 = model.getData().get(1); final List<DTCellValue52> row2 = model.getData().get(2); uiModel.moveRowsTo(2, new ArrayList<GridRow>() {{ add(uiRow0); add(uiRow1); }}); assertEquals(uiRow2, uiModel.getRow(0)); assertEquals(uiRow0, uiModel.getRow(1)); assertEquals(uiRow1, uiModel.getRow(2)); assertEquals(row2, model.getData().get(0)); assertEquals(row0, model.getData().get(1)); assertEquals(row1, model.getData().get(2)); }
@Test public void testMoveRowsMoveDownCheckRowNumbers() throws VetoException { modelSynchronizer.appendRow(); modelSynchronizer.appendRow(); modelSynchronizer.appendRow(); final GridRow uiRow0 = uiModel.getRow(0); final GridRow uiRow1 = uiModel.getRow(1); uiModel.moveRowsTo(2, new ArrayList<GridRow>() {{ add(uiRow0); add(uiRow1); }}); assertEquals(1, uiModel.getRow(0).getCells().get(0).getValue().getValue()); assertEquals(2, uiModel.getRow(1).getCells().get(0).getValue().getValue()); assertEquals(3, uiModel.getRow(2).getCells().get(0).getValue().getValue()); assertEquals(1, model.getData().get(0).get(0).getNumericValue()); assertEquals(2, model.getData().get(1).get(0).getNumericValue()); assertEquals(3, model.getData().get(2).get(0).getNumericValue()); }
@Test public void testMoveRowsMoveUpCheckRowNumbers() throws VetoException { modelSynchronizer.appendRow(); modelSynchronizer.appendRow(); modelSynchronizer.appendRow(); final GridRow uiRow1 = uiModel.getRow(1); final GridRow uiRow2 = uiModel.getRow(2); uiModel.moveRowsTo(0, new ArrayList<GridRow>() {{ add(uiRow1); add(uiRow2); }}); assertEquals(1, uiModel.getRow(0).getCells().get(0).getValue().getValue()); assertEquals(2, uiModel.getRow(1).getCells().get(0).getValue().getValue()); assertEquals(3, uiModel.getRow(2).getCells().get(0).getValue().getValue()); assertEquals(1, model.getData().get(0).get(0).getNumericValue()); assertEquals(2, model.getData().get(1).get(0).getNumericValue()); assertEquals(3, model.getData().get(2).get(0).getNumericValue()); }