Search in sources :

Example 1 with TableColumn

use of org.activityinfo.model.analysis.TableColumn in project activityinfo by bedatadriven.

the class TableViewModelTest method test.

@Test
public void test() {
    TableModel tableModel = ImmutableTableModel.builder().formId(setup.getSurveyForm().getFormId()).build();
    TableViewModel viewModel = new TableViewModel(setup.getFormStore(), tableModel);
    Connection<EffectiveTableModel> view = setup.connect(viewModel.getEffectiveTable());
    EffectiveTableModel effectiveTableModel = view.assertLoaded();
    EffectiveTableColumn nameColumn = effectiveTableModel.getColumns().get(0);
    assertThat(nameColumn.getLabel(), equalTo("Respondent Name"));
    // Now verify that we can update the column label
    view.resetChangeCounter();
    TableColumn updatedColumn = ImmutableTableColumn.builder().from(nameColumn.getModel()).label("MY column").build();
    viewModel.update(ImmutableTableModel.builder().from(tableModel).columns(Arrays.asList(updatedColumn)).build());
    setup.runScheduled();
    // Should receive a change event...
    view.assertChanged();
    EffectiveTableModel updatedModel = view.assertLoaded();
    assertThat(updatedModel.getColumns().get(0).getLabel(), equalTo("MY column"));
}
Also used : TableColumn(org.activityinfo.model.analysis.TableColumn) ImmutableTableColumn(org.activityinfo.model.analysis.ImmutableTableColumn) TableModel(org.activityinfo.model.analysis.TableModel) ImmutableTableModel(org.activityinfo.model.analysis.ImmutableTableModel) Test(org.junit.Test)

Example 2 with TableColumn

use of org.activityinfo.model.analysis.TableColumn in project activityinfo by bedatadriven.

the class TableViewModelTest method testSubFormExport.

@Test
public void testSubFormExport() {
    IncidentForm incidentForm = setup.getCatalog().getIncidentForm();
    TableModel tableModel = ImmutableTableModel.builder().formId(incidentForm.getFormId()).addColumns(ImmutableTableColumn.builder().label("My PCODE").formula(IncidentForm.PROTECTION_CODE_FIELD_ID.asString()).build()).build();
    TableViewModel viewModel = new TableViewModel(setup.getFormStore(), tableModel);
    Connection<TableModel> exportModel = setup.connect(viewModel.computeExportModel(Observable.just(ReferralSubForm.FORM_ID), Observable.just(ExportScope.SELECTED)));
    System.out.println(Json.stringify(exportModel.assertLoaded().toJson(), 2));
    assertThat(exportModel.assertLoaded().getFormId(), equalTo(ReferralSubForm.FORM_ID));
    assertThat(exportModel.assertLoaded().getColumns(), hasSize(3));
    TableColumn firstColumn = exportModel.assertLoaded().getColumns().get(0);
    assertThat(firstColumn.getLabel(), equalTo(Optional.of("My PCODE")));
    assertThat(firstColumn.getFormula(), equalTo(new CompoundExpr(new SymbolNode(ColumnModel.PARENT_SYMBOL), IncidentForm.PROTECTION_CODE_FIELD_ID).asExpression()));
}
Also used : CompoundExpr(org.activityinfo.model.formula.CompoundExpr) SymbolNode(org.activityinfo.model.formula.SymbolNode) TableColumn(org.activityinfo.model.analysis.TableColumn) ImmutableTableColumn(org.activityinfo.model.analysis.ImmutableTableColumn) TableModel(org.activityinfo.model.analysis.TableModel) ImmutableTableModel(org.activityinfo.model.analysis.ImmutableTableModel) IncidentForm(org.activityinfo.store.testing.IncidentForm) Test(org.junit.Test)

Example 3 with TableColumn

use of org.activityinfo.model.analysis.TableColumn in project activityinfo by bedatadriven.

the class TableViewModel method updateColumnWidth.

@Override
public void updateColumnWidth(String columnId, int newWidth) {
    TableModel model = this.tableModel.get();
    List<TableColumn> updatedColumns = new ArrayList<>();
    for (TableColumn column : model.getColumns()) {
        if (column.getId().equals(columnId)) {
            updatedColumns.add(ImmutableTableColumn.builder().from(column).width(newWidth).build());
        } else {
            updatedColumns.add(column);
        }
    }
    tableModel.updateIfNotSame(ImmutableTableModel.builder().from(model).columns(updatedColumns).build());
}
Also used : ArrayList(java.util.ArrayList) TableColumn(org.activityinfo.model.analysis.TableColumn) ImmutableTableColumn(org.activityinfo.model.analysis.ImmutableTableColumn) TableModel(org.activityinfo.model.analysis.TableModel) ImmutableTableModel(org.activityinfo.model.analysis.ImmutableTableModel)

Aggregations

ImmutableTableColumn (org.activityinfo.model.analysis.ImmutableTableColumn)3 ImmutableTableModel (org.activityinfo.model.analysis.ImmutableTableModel)3 TableColumn (org.activityinfo.model.analysis.TableColumn)3 TableModel (org.activityinfo.model.analysis.TableModel)3 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 CompoundExpr (org.activityinfo.model.formula.CompoundExpr)1 SymbolNode (org.activityinfo.model.formula.SymbolNode)1 IncidentForm (org.activityinfo.store.testing.IncidentForm)1