MetaDataColumnSynchronizer extends BaseColumnSynchronizer<BaseColumnSynchronizer.ColumnMetaData, BaseColumnSynchronizer.ColumnMetaData, BaseColumnSynchronizer.ColumnMetaData> { @Override public void moveColumnsTo(final List<MoveColumnToMetaData> metaData) throws VetoException { if (!handlesMoveColumnsTo(metaData)) { return; } final MoveColumnToMetaData md = metaData.get(0); final MetadataCol52 modelColumn = (MetadataCol52) md.getColumn(); final List<MetadataCol52> modelMetaDataColumns = model.getMetadataCols(); final int modelMetaDataColumnCount = modelMetaDataColumns.size(); if (modelMetaDataColumnCount == 0) { throw new ModelSynchronizer.MoveVetoException(); } final List<BaseColumn> allModelColumns = model.getExpandedColumns(); final int minColumnIndex = allModelColumns.indexOf(modelMetaDataColumns.get(0)); final int maxColumnIndex = allModelColumns.indexOf(modelMetaDataColumns.get(modelMetaDataColumnCount - 1)); final int targetColumnIndex = md.getTargetColumnIndex(); final int sourceColumnIndex = md.getSourceColumnIndex(); if (targetColumnIndex < minColumnIndex || targetColumnIndex > maxColumnIndex) { throw new ModelSynchronizer.MoveVetoException(); } moveModelData(targetColumnIndex, sourceColumnIndex, sourceColumnIndex); modelMetaDataColumns.remove(modelColumn); modelMetaDataColumns.add(targetColumnIndex - minColumnIndex, modelColumn); }  @Override boolean handlesAppend(final MetaData metaData); @Override void append(final BaseColumnSynchronizer.ColumnMetaData metaData); @Override boolean handlesUpdate(final MetaData metaData); @Override List<BaseColumnFieldDiff> update(final BaseColumnSynchronizer.ColumnMetaData originalMetaData,
                                            final BaseColumnSynchronizer.ColumnMetaData editedMetaData); @Override boolean handlesDelete(final MetaData metaData); @Override void delete(final BaseColumnSynchronizer.ColumnMetaData metaData); @Override boolean handlesMoveColumnsTo(final List<? extends MetaData> metaData); @Override void moveColumnsTo(final List<MoveColumnToMetaData> metaData);  }
@Test public void testMoveColumnsTo_MoveLeft() throws VetoException { final MetadataCol52 column1 = new MetadataCol52(); column1.setMetadata("metadata1"); final MetadataCol52 column2 = new MetadataCol52(); column2.setMetadata("metadata2"); final MetadataCol52 column3 = new MetadataCol52(); column3.setMetadata("metadata3"); modelSynchronizer.appendColumn(column1); modelSynchronizer.appendColumn(column2); modelSynchronizer.appendColumn(column3); modelSynchronizer.appendRow(); uiModel.setCellValue(0, 3, new BaseGridCellValue<String>("metadata1")); uiModel.setCellValue(0, 4, new BaseGridCellValue<String>("metadata2")); uiModel.setCellValue(0, 5, new BaseGridCellValue<String>("metadata3")); final GridColumn<?> uiModelColumn1_1 = uiModel.getColumns().get(3); final GridColumn<?> uiModelColumn2_1 = uiModel.getColumns().get(4); final GridColumn<?> uiModelColumn3_1 = uiModel.getColumns().get(5); assertTestMoveColumnsTo(column1, column2, column3, uiModelColumn1_1, uiModelColumn2_1, uiModelColumn3_1); uiModel.moveColumnsTo(3, new ArrayList<GridColumn<?>>() {{ add(uiModelColumn2_1); add(uiModelColumn3_1); }}); final GridColumn<?> uiModelColumn1_2 = uiModel.getColumns().get(3); final GridColumn<?> uiModelColumn2_2 = uiModel.getColumns().get(4); final GridColumn<?> uiModelColumn3_2 = uiModel.getColumns().get(5); assertTestMoveColumnsTo(column1, column2, column3, uiModelColumn1_2, uiModelColumn2_2, uiModelColumn3_2); }
@Test public void testMoveColumnsTo_MoveRight() throws VetoException { final MetadataCol52 column1 = new MetadataCol52(); column1.setMetadata("metadata1"); final MetadataCol52 column2 = new MetadataCol52(); column2.setMetadata("metadata2"); final MetadataCol52 column3 = new MetadataCol52(); column3.setMetadata("metadata3"); modelSynchronizer.appendColumn(column1); modelSynchronizer.appendColumn(column2); modelSynchronizer.appendColumn(column3); modelSynchronizer.appendRow(); uiModel.setCellValue(0, 3, new BaseGridCellValue<String>("metadata1")); uiModel.setCellValue(0, 4, new BaseGridCellValue<String>("metadata2")); uiModel.setCellValue(0, 5, new BaseGridCellValue<String>("metadata3")); final GridColumn<?> uiModelColumn1_1 = uiModel.getColumns().get(3); final GridColumn<?> uiModelColumn2_1 = uiModel.getColumns().get(4); final GridColumn<?> uiModelColumn3_1 = uiModel.getColumns().get(5); assertTestMoveColumnsTo(column1, column2, column3, uiModelColumn1_1, uiModelColumn2_1, uiModelColumn3_1); uiModel.moveColumnsTo(5, new ArrayList<GridColumn<?>>() {{ add(uiModelColumn1_1); add(uiModelColumn2_1); }}); final GridColumn<?> uiModelColumn1_2 = uiModel.getColumns().get(3); final GridColumn<?> uiModelColumn2_2 = uiModel.getColumns().get(4); final GridColumn<?> uiModelColumn3_2 = uiModel.getColumns().get(5); assertTestMoveColumnsTo(column1, column2, column3, uiModelColumn1_2, uiModelColumn2_2, uiModelColumn3_2); }