Search in sources :

Example 11 with BindingConvertor

use of org.pentaho.ui.xul.binding.BindingConvertor in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceTestController method bindSelectedLogLevel.

private void bindSelectedLogLevel(BindingFactory bindingFactory) throws InvocationTargetException, XulException {
    Binding logBinding = bindingFactory.createBinding(model, "logLevel", logLevels, "selectedItem");
    logBinding.setBindingType(Binding.Type.BI_DIRECTIONAL);
    BindingConvertor logLevelConverter = new BindingConvertor<LogLevel, String>() {

        @Override
        public String sourceToTarget(LogLevel value) {
            return value.getDescription();
        }

        @Override
        public LogLevel targetToSource(String value) {
            for (LogLevel level : LogLevel.values()) {
                if (level.getDescription().equals(value)) {
                    return level;
                }
            }
            throw new IllegalArgumentException(String.format("'%s' does not correspond to a valid LogLevel value.", value));
        }
    };
    logBinding.setConversion(logLevelConverter);
    logBinding.initialize();
    logBinding.fireSourceChanged();
}
Also used : Binding(org.pentaho.ui.xul.binding.Binding) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) BindingConvertor(org.pentaho.ui.xul.binding.BindingConvertor) LogLevel(org.pentaho.di.core.logging.LogLevel)

Example 12 with BindingConvertor

use of org.pentaho.ui.xul.binding.BindingConvertor in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceTestController method bindSelectedMaxRows.

private void bindSelectedMaxRows(BindingFactory bindingFactory) throws InvocationTargetException, XulException {
    Binding binding = bindingFactory.createBinding(model, "maxRows", maxRows, "selectedItem");
    binding.setBindingType(Binding.Type.BI_DIRECTIONAL);
    BindingConvertor maxRowsConverter = new BindingConvertor<Integer, Integer>() {

        @Override
        public Integer sourceToTarget(Integer value) {
            return DataServiceTestModel.MAXROWS_CHOICES.indexOf(value);
        }

        @Override
        public Integer targetToSource(Integer value) {
            return DataServiceTestModel.MAXROWS_CHOICES.indexOf(value);
        }
    };
    binding.setConversion(maxRowsConverter);
    binding.initialize();
    binding.fireSourceChanged();
}
Also used : Binding(org.pentaho.ui.xul.binding.Binding) BindingConvertor(org.pentaho.ui.xul.binding.BindingConvertor)

Example 13 with BindingConvertor

use of org.pentaho.ui.xul.binding.BindingConvertor in project data-access by pentaho.

the class WizardRelationalDatasourceController method init.

@Bindable
public void init(final DatasourceModel datasourceModel) {
    this.datasourceModel = datasourceModel;
    bf = new GwtBindingFactory(document);
    // $NON-NLS-1$
    sampleDataTree = (XulTree) document.getElementById("relationalSampleDataTable");
    // $NON-NLS-1$
    aggregationEditorDialog = (XulDialog) document.getElementById("relationalAggregationEditorDialog");
    // $NON-NLS-1$
    sampleDataDialog = (XulDialog) document.getElementById("relationalSampleDataDialog");
    // $NON-NLS-1$
    errorDialog = (XulDialog) document.getElementById("errorDialog");
    // $NON-NLS-1$
    errorLabel = (XulLabel) document.getElementById("errorLabel");
    // $NON-NLS-1$
    applyQueryConfirmationDialog = (XulDialog) document.getElementById("applyQueryConfirmationDialog");
    // $NON-NLS-1$
    errorLabel = (XulLabel) document.getElementById("errorLabel");
    // $NON-NLS-1$
    successDialog = (XulDialog) document.getElementById("successDialog");
    // $NON-NLS-1$
    successLabel = (XulLabel) document.getElementById("successLabel");
    // $NON-NLS-1$
    datasourceName = (XulTextbox) document.getElementById("datasourceName");
    // $NON-NLS-1$
    connections = (XulListbox) document.getElementById("connectionList");
    // $NON-NLS-1$
    query = (XulTextbox) document.getElementById("query");
    // $NON-NLS-1$
    connectionDialog = (XulDialog) document.getElementById("connectionDialog");
    // $NON-NLS-1$
    previewResultsDialog = (XulDialog) document.getElementById("previewResultsDialog");
    // $NON-NLS-1$
    previewResultsTable = (XulTree) document.getElementById("previewResultsTable");
    // $NON-NLS-1$
    previewResultsTreeCols = (XulTreeCols) document.getElementById("previewResultsTreeCols");
    // $NON-NLS-1$
    previewLimit = (XulTextbox) document.getElementById("previewLimit");
    // $NON-NLS-1$
    editConnectionButton = (XulButton) document.getElementById("editConnection");
    // $NON-NLS-1$
    removeConnectionButton = (XulButton) document.getElementById("removeConnection");
    // $NON-NLS-1$
    editQueryButton = (XulButton) document.getElementById("editQuery");
    // $NON-NLS-1$
    previewButton = (XulButton) document.getElementById("preview");
    bf.setBindingType(Binding.Type.ONE_WAY);
    bf.createBinding(datasourceModel.getGuiStateModel(), "relationalPreviewValidated", previewButton, // $NON-NLS-1$ //$NON-NLS-2$
    "!disabled");
    List<Binding> bindingsThatNeedInitialized = new ArrayList<Binding>();
    BindingConvertor<IDatabaseConnection, Boolean> buttonConvertor = new BindingConvertor<IDatabaseConnection, Boolean>() {

        @Override
        public Boolean sourceToTarget(IDatabaseConnection value) {
            return !(value == null);
        }

        @Override
        public IDatabaseConnection targetToSource(Boolean value) {
            return null;
        }
    };
    bf.setBindingType(Binding.Type.ONE_WAY);
    final Binding domainBinding = bf.createBinding(datasourceModel.getGuiStateModel(), "connections", this, // $NON-NLS-1$ //$NON-NLS-2$
    "relationalConnections");
    // $NON-NLS-1$
    bf.createBinding(this, connectionNamesListProp, connections, "elements");
    bf.createBinding(datasourceModel, "selectedRelationalConnection", editConnectionButton, "!disabled", // $NON-NLS-1$ //$NON-NLS-2$
    buttonConvertor);
    bf.createBinding(datasourceModel, "selectedRelationalConnection", removeConnectionButton, "!disabled", // $NON-NLS-1$ //$NON-NLS-2$
    buttonConvertor);
    bf.setBindingType(Binding.Type.BI_DIRECTIONAL);
    bf.createBinding(datasourceModel, "selectedRelationalConnection", connections, "selectedIndex", new // $NON-NLS-1$ //$NON-NLS-2$
    BindingConvertor<IDatabaseConnection, Integer>() {

        @Override
        public Integer sourceToTarget(IDatabaseConnection connection) {
            if (connection != null) {
                return datasourceModel.getGuiStateModel().getConnectionIndex(connection);
            }
            return -1;
        }

        @Override
        public IDatabaseConnection targetToSource(Integer value) {
            if (value >= 0) {
                return datasourceModel.getGuiStateModel().getConnections().get(value);
            }
            return null;
        }
    });
    bf.setBindingType(Binding.Type.BI_DIRECTIONAL);
    bf.createBinding(datasourceModel.getGuiStateModel(), "previewLimit", previewLimit, // $NON-NLS-1$ //$NON-NLS-2$
    "value");
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(datasourceModel, "query", query, "value");
    try {
        // Fires the population of the model listbox. This cascades down to the categories and columns. In essence, this
        // call initializes the entire UI.
        domainBinding.fireSourceChanged();
    } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
    }
    for (Binding b : bindingsThatNeedInitialized) {
        try {
            b.fireSourceChanged();
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
    }
}
Also used : Binding(org.pentaho.ui.xul.binding.Binding) GwtBindingFactory(org.pentaho.ui.xul.gwt.binding.GwtBindingFactory) ArrayList(java.util.ArrayList) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) BindingConvertor(org.pentaho.ui.xul.binding.BindingConvertor) XulException(org.pentaho.ui.xul.XulException) Bindable(org.pentaho.ui.xul.stereotype.Bindable)

Example 14 with BindingConvertor

use of org.pentaho.ui.xul.binding.BindingConvertor in project data-access by pentaho.

the class StageDataStep method generateDataTypeDisplay_horizontal.

private void generateDataTypeDisplay_horizontal() {
    // $NON-NLS-1$
    XulTree tree = (XulTree) document.getElementById("csvModelDataTable");
    tree.setRows(datasourceModel.getModelInfo().getColumns().length);
    bf.setBindingType(Binding.Type.ONE_WAY);
    tree.setBindingProvider(new FactoryBasedBindingProvider(bf) {

        @Override
        public BindingConvertor getConvertor(XulEventSource source, String prop1, XulEventSource target, String prop2) {
            if (source instanceof ColumnInfo) {
                if (prop1.equals("length") || prop1.equals("precision")) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    return BindingConvertor.integer2String();
                } else if (prop1.equals("include") && prop2.equals("value")) {
                    // this is the binding from the cell to the value of the checkbox
                    return null;
                } else if (prop1.equals("include")) {
                    // this binding is from the model to the checkbox
                    return BindingConvertor.boolean2String();
                } else if (prop1.equals("availableDataTypes")) {
                    // $NON-NLS-1$
                    return new BindingConvertor<List, Vector>() {

                        @SuppressWarnings("unchecked")
                        public Vector sourceToTarget(List value) {
                            return new Vector(value);
                        }

                        @SuppressWarnings("unchecked")
                        public List targetToSource(Vector value) {
                            return new ArrayList(value);
                        }
                    };
                } else if (prop1.equals("formatStrings")) {
                    // $NON-NLS-1$
                    return new BindingConvertor<List, Vector>() {

                        @SuppressWarnings("unchecked")
                        public Vector sourceToTarget(List value) {
                            return new Vector(value);
                        }

                        @SuppressWarnings("unchecked")
                        public List targetToSource(Vector value) {
                            return new ArrayList(value);
                        }
                    };
                } else if (prop1.equals("dataType") && prop2.equals("selectedIndex")) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    return new BindingConvertor<DataType, Integer>() {

                        @Override
                        public Integer sourceToTarget(DataType value) {
                            List<DataType> types = ColumnInfo.getAvailableDataTypes();
                            for (int i = 0; i < types.size(); i++) {
                                if (types.get(i).equals(value)) {
                                    return i;
                                }
                            }
                            return 0;
                        }

                        @Override
                        public DataType targetToSource(Integer value) {
                            return ColumnInfo.getAvailableDataTypes().get(value);
                        }
                    };
                } else if (prop1.equals("formatStringsDisabled")) {
                    return null;
                } else {
                    return BindingConvertor.string2String();
                }
            } else {
                return null;
            }
        }
    });
    tree.setElements(Arrays.asList(datasourceModel.getModelInfo().getColumns()));
    if (datasourceModel.getModelInfo().getColumns().length > 0) {
        tree.setSelectedRows(new int[] { 0 });
    }
    tree.update();
}
Also used : FactoryBasedBindingProvider(org.pentaho.ui.xul.binding.FactoryBasedBindingProvider) XulTree(org.pentaho.ui.xul.containers.XulTree) ArrayList(java.util.ArrayList) ColumnInfo(org.pentaho.platform.dataaccess.datasource.wizard.models.ColumnInfo) BindingConvertor(org.pentaho.ui.xul.binding.BindingConvertor) DataType(org.pentaho.metadata.model.concept.types.DataType) ArrayList(java.util.ArrayList) List(java.util.List) Vector(java.util.Vector) XulEventSource(org.pentaho.ui.xul.XulEventSource)

Example 15 with BindingConvertor

use of org.pentaho.ui.xul.binding.BindingConvertor in project data-access by pentaho.

the class JoinDefinitionsStep method setBindings.

public void setBindings() {
    BindingFactory bf = new GwtBindingFactory(document);
    bf.createBinding(this.joinGuiModel.getLeftTables(), "children", this.leftTables, "elements");
    bf.createBinding(this.joinGuiModel.getRightTables(), "children", this.rightTables, "elements");
    bf.createBinding(this.leftTables, "selectedItem", this.joinGuiModel, "leftJoinTable");
    bf.createBinding(this.rightTables, "selectedItem", this.joinGuiModel, "rightJoinTable");
    bf.createBinding(this.joinGuiModel.getJoins(), "children", this.joinsList, "elements");
    bf.createBinding(this.joinsList, "selectedItem", this.joinGuiModel, "selectedJoin");
    bf.createBinding(this.leftTables, "selectedItem", this.leftKeyFieldList, "elements", new TableSelectionConvertor(this.leftTables));
    bf.createBinding(this.rightTables, "selectedItem", this.rightKeyFieldList, "elements", new TableSelectionConvertor(this.rightTables));
    this.leftKeyFieldBinding = bf.createBinding(this.leftKeyFieldList, "selectedIndex", this.joinGuiModel, "leftKeyField", new BindingConvertor<Integer, JoinFieldModel>() {

        @Override
        public JoinFieldModel sourceToTarget(final Integer index) {
            JoinTableModel joinTable = joinGuiModel.getLeftJoinTable();
            if (joinTable != null) {
                List<JoinFieldModel> fields = joinTable.getFields();
                if (index == -1 || fields.isEmpty()) {
                    return null;
                }
                return fields.get(index);
            }
            return null;
        }

        @Override
        public Integer targetToSource(final JoinFieldModel value) {
            return null;
        }
    });
    this.rightKeyFieldBinding = bf.createBinding(this.rightKeyFieldList, "selectedIndex", this.joinGuiModel, "rightKeyField", new BindingConvertor<Integer, JoinFieldModel>() {

        @Override
        public JoinFieldModel sourceToTarget(final Integer index) {
            JoinTableModel joinTable = joinGuiModel.getRightJoinTable();
            if (joinTable != null) {
                List<JoinFieldModel> fields = joinTable.getFields();
                if (index == -1 || fields.isEmpty()) {
                    return null;
                }
                return fields.get(index);
            }
            return null;
        }

        @Override
        public Integer targetToSource(final JoinFieldModel value) {
            return null;
        }
    });
}
Also used : JoinTableModel(org.pentaho.agilebi.modeler.models.JoinTableModel) GwtBindingFactory(org.pentaho.ui.xul.gwt.binding.GwtBindingFactory) JoinFieldModel(org.pentaho.agilebi.modeler.models.JoinFieldModel) BindingConvertor(org.pentaho.ui.xul.binding.BindingConvertor) BindingFactory(org.pentaho.ui.xul.binding.BindingFactory) GwtBindingFactory(org.pentaho.ui.xul.gwt.binding.GwtBindingFactory)

Aggregations

BindingConvertor (org.pentaho.ui.xul.binding.BindingConvertor)17 ArrayList (java.util.ArrayList)10 List (java.util.List)9 Binding (org.pentaho.ui.xul.binding.Binding)5 KettleException (org.pentaho.di.core.exception.KettleException)4 ControllerInitializationException (org.pentaho.di.ui.repository.repositoryexplorer.ControllerInitializationException)4 XulException (org.pentaho.ui.xul.XulException)4 UIRepositoryObjectAcl (org.pentaho.di.ui.repository.pur.repositoryexplorer.model.UIRepositoryObjectAcl)3 UIRepositoryObject (org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject)3 GwtBindingFactory (org.pentaho.ui.xul.gwt.binding.GwtBindingFactory)3 Bindable (org.pentaho.ui.xul.stereotype.Bindable)3 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 PropertyChangeListener (java.beans.PropertyChangeListener)2 IAclObject (org.pentaho.di.ui.repository.pur.repositoryexplorer.IAclObject)2 AccessDeniedException (org.pentaho.di.ui.repository.repositoryexplorer.AccessDeniedException)2 UIObjectCreationException (org.pentaho.di.ui.repository.repositoryexplorer.model.UIObjectCreationException)2 UIRepositoryDirectory (org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryDirectory)2 RequestException (com.google.gwt.http.client.RequestException)1 Vector (java.util.Vector)1 Point (org.eclipse.swt.graphics.Point)1