Search in sources :

Example 1 with AbstractModelList

use of org.pentaho.ui.xul.util.AbstractModelList in project data-access by pentaho.

the class MultitableGuiModel method populateJoinGuiModel.

public void populateJoinGuiModel(Domain domain, MultiTableDatasourceDTO dto, List tables) {
    this.selectedTables.clear();
    // Populate "selectedTables" from availableTables using logicalRelationships.
    AbstractModelList<JoinTableModel> selectedTablesList = new AbstractModelList<JoinTableModel>();
    if (dto != null) {
        for (String selectedTable : dto.getSelectedTables()) {
            this.selectTable(selectedTable, selectedTablesList, tables);
        }
        this.selectedTables.addAll(selectedTablesList);
        // Populates joins.
        this.computeJoins(dto);
        // Populate fact table.
        if (dto.isDoOlap()) {
            for (JoinTableModel table : this.selectedTables) {
                if (tablesAreEqual(table.getName(), dto.getSchemaModel().getFactTable().getName())) {
                    this.setFactTable(table);
                    break;
                }
            }
        }
    }
    // Populate available tables discarding selected tables.
    this.processAvailableTables(tables);
    if (domain != null) {
        // Existing joinTableModels will not have fields. We can add these from the domain.
        this.addFieldsToTables(domain, this.availableTables);
    }
}
Also used : JoinTableModel(org.pentaho.agilebi.modeler.models.JoinTableModel) AbstractModelList(org.pentaho.ui.xul.util.AbstractModelList) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString)

Example 2 with AbstractModelList

use of org.pentaho.ui.xul.util.AbstractModelList in project data-access by pentaho.

the class TablesSelectionStep method setBindings.

public void setBindings() {
    BindingFactory bf = new GwtBindingFactory(document);
    bf.createBinding(this.joinGuiModel.getAvailableTables(), "children", this.availableTables, "elements");
    bf.createBinding(this.joinGuiModel.getSelectedTables(), "children", this.selectedTables, "elements");
    bf.createBinding(this.joinGuiModel.getSelectedTables(), "children", this.factTables, "elements", new BindingConvertor<AbstractModelList<JoinTableModel>, Collection<JoinTableModel>>() {

        @Override
        public Collection<JoinTableModel> sourceToTarget(AbstractModelList<JoinTableModel> list) {
            List<JoinTableModel> tables = new ArrayList<JoinTableModel>();
            tables.addAll(list.asList());
            JoinTableModel emptyOption = new JoinTableModel();
            emptyOption.setName(MessageHandler.getString("multitable.SELECT_TABLE"));
            // Empty option must be always 0.
            tables.add(0, emptyOption);
            return tables;
        }

        @Override
        public AbstractModelList<JoinTableModel> targetToSource(final Collection<JoinTableModel> list) {
            return null;
        }
    });
    bf.createBinding(this.joinGuiModel, "schemas", this.schemas, "elements", new BindingConvertor<List<String>, Collection<String>>() {

        @Override
        public Collection<String> sourceToTarget(List<String> list) {
            List<String> tables = new ArrayList<String>();
            tables.addAll(list);
            return tables;
        }

        @Override
        public List<String> targetToSource(final Collection<String> list) {
            return null;
        }
    });
    bf.createBinding(this.factTables, "selectedIndex", this.joinGuiModel, "factTable", new BindingConvertor<Integer, JoinTableModel>() {

        @Override
        public JoinTableModel sourceToTarget(final Integer index) {
            if (index == -1) {
                return null;
            }
            // Index 0 represents [select table] option.
            // To be valid index must not be 0.
            checkValidState();
            int i = (int) index;
            i--;
            return i < 0 ? null : joinGuiModel.getSelectedTables().get(i);
        }

        @Override
        public Integer targetToSource(final JoinTableModel value) {
            return joinGuiModel.getSelectedTables().indexOf(value);
        }
    });
    // use a binding to handle the visibility state of the schema type radio group
    try {
        bf.createBinding(joinGuiModel, "doOlap", "factTableVbox", "visible").fireSourceChanged();
    } catch (Exception e) {
        e.printStackTrace();
        mtdatasource.displayErrors(new JoinError(e.getMessage(), e.getMessage()));
    }
}
Also used : XulException(org.pentaho.ui.xul.XulException) JoinTableModel(org.pentaho.agilebi.modeler.models.JoinTableModel) GwtBindingFactory(org.pentaho.ui.xul.gwt.binding.GwtBindingFactory) Collection(java.util.Collection) AbstractModelList(org.pentaho.ui.xul.util.AbstractModelList) XulMenuList(org.pentaho.ui.xul.components.XulMenuList) ArrayList(java.util.ArrayList) List(java.util.List) AbstractModelList(org.pentaho.ui.xul.util.AbstractModelList) BindingFactory(org.pentaho.ui.xul.binding.BindingFactory) GwtBindingFactory(org.pentaho.ui.xul.gwt.binding.GwtBindingFactory)

Aggregations

JoinTableModel (org.pentaho.agilebi.modeler.models.JoinTableModel)2 AbstractModelList (org.pentaho.ui.xul.util.AbstractModelList)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 LocalizedString (org.pentaho.metadata.model.concept.types.LocalizedString)1 XulException (org.pentaho.ui.xul.XulException)1 BindingFactory (org.pentaho.ui.xul.binding.BindingFactory)1 XulMenuList (org.pentaho.ui.xul.components.XulMenuList)1 GwtBindingFactory (org.pentaho.ui.xul.gwt.binding.GwtBindingFactory)1