DataSetDefPreviewTable implements IsWidget { public void show(final DataSetDef dataSetDef, final Collection<DataColumnDef> columns, final DisplayerListener displayerListener) { clear(); if (dataSetDef != null) { final TableDisplayerSettingsBuilder settingsBuilder = DisplayerSettingsFactory.newTableSettings() .dataset(dataSetDef.getUUID()) .renderer(DefaultRenderer.UUID) .titleVisible(false) .tablePageSize(10) .tableOrderEnabled(true) .tableColumnPickerEnabled(false) .filterOn(true, false, false); if (columns != null && !columns.isEmpty()) { for (final DataColumnDef column : columns) { settingsBuilder.column(column.getId()); } } DataSetDef editCloneWithoutCacheSettings = dataSetDef.clone(); editCloneWithoutCacheSettings.setCacheEnabled(false); if (tableDisplayer != null) { tableDisplayer.close(); } DisplayerSettings settings = settingsBuilder.buildSettings(); tableDisplayer = displayerLocator.lookupDisplayer(settings); tableDisplayer.setDataSetHandler(new DataSetEditHandler(clientServices, settings.getDataSetLookup(), editCloneWithoutCacheSettings)); if (dataSetDef instanceof CSVDataSetDef) { CSVDataSetDef csvDataSetDef = (CSVDataSetDef) dataSetDef; tableDisplayer.addListener(new AbstractDisplayerListener() { @Override public void onDataLoaded(Displayer displayer) { configureColumnSettings(displayer, csvDataSetDef); } }); } draw(displayerListener); } } @Inject  DataSetDefPreviewTable(final DisplayerLocator displayerLocator,
                                  final DataSetClientServices clientServices,
                                  final View view); @PostConstruct void init(); @Override Widget asWidget(); void show(final DataSetDef dataSetDef, final Collection<DataColumnDef> columns,
                     final DisplayerListener displayerListener); void clear(); public View view; }
@Test public void testCSVConfig() throws Exception { DataSetDef dataSetDef = DataSetDefFactory.newCSVDataSetDef() .datePattern("dd/MM/yyyy") .numberPattern("#,###") .allColumns(true) .buildDef(); DataSet dataSet = DataSetFactory.newDataSetBuilder() .date("date") .number("number") .row(new Date(), 1d) .buildDataSet(); when(dataSetLookupServices.lookupDataSet(any(), any())).thenReturn(dataSet); tested.show(dataSetDef, null, displayerListener); ArgumentCaptor<Displayer> argumentCaptor = ArgumentCaptor.forClass(Displayer.class); verify(displayerListener).onDataLoaded(argumentCaptor.capture()); Displayer displayer = argumentCaptor.getValue(); DisplayerSettings settings = displayer.getDisplayerSettings(); assertEquals(settings.getColumnSettings("date").getValuePattern(), "dd/MM/yyyy"); assertEquals(settings.getColumnSettings("number").getValuePattern(), "#,###"); assertEquals(settings.isTableColumnPickerEnabled(), false); }
@Test public void testSQLConfig() throws Exception { DataSetDef dataSetDef = DataSetDefFactory.newSQLDataSetDef() .column("date", ColumnType.DATE) .column("number", ColumnType.NUMBER) .buildDef(); DataSet dataSet = DataSetFactory.newDataSetBuilder() .date("date") .number("number") .row(new Date(), 1d) .buildDataSet(); when(dataSetLookupServices.lookupDataSet(any(), any())).thenReturn(dataSet); tested.show(dataSetDef, null, displayerListener); ArgumentCaptor<Displayer> argumentCaptor = ArgumentCaptor.forClass(Displayer.class); verify(displayerListener).onDataLoaded(argumentCaptor.capture()); Displayer displayer = argumentCaptor.getValue(); DisplayerSettings settings = displayer.getDisplayerSettings(); assertFalse(settings.isTableColumnPickerEnabled()); assertEquals(settings.getTablePageSize(), 10); assertTrue(settings.isTableSortEnabled()); }