Search in sources :

Example 16 with BindingConvertor

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

the class FileImportController method init.

@Bindable
public void init() {
    bf = new GwtBindingFactory(document);
    // $NON-NLS-1$
    fileUpload = (XulFileUpload) document.getElementById("fileUpload");
    // $NON-NLS-1$
    datasourceDialog = (XulDialog) document.getElementById("fileImportEditorWindow");
    // $NON-NLS-1$
    errorLabel = (XulLabel) document.getElementById("errorLabel");
    // $NON-NLS-1$
    errorDialog = (XulDialog) document.getElementById("errorDialog");
    BindingConvertor<String, Boolean> isDisabledConvertor = new BindingConvertor<String, Boolean>() {

        @Override
        public Boolean sourceToTarget(String aValue) {
            return (aValue == null || "".equals(aValue));
        }

        @Override
        public String targetToSource(Boolean aValue) {
            return null;
        }
    };
    bf.createBinding("fileUpload", "selectedFile", "okButton", "disabled", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    isDisabledConvertor);
}
Also used : GwtBindingFactory(org.pentaho.ui.xul.gwt.binding.GwtBindingFactory) BindingConvertor(org.pentaho.ui.xul.binding.BindingConvertor) Bindable(org.pentaho.ui.xul.stereotype.Bindable)

Example 17 with BindingConvertor

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

the class DatasourceSelectionDialogController method internalInit.

private void internalInit() {
    try {
        // $NON-NLS-1$
        datasourceListbox = (XulListbox) safeGetElementById(document, "datasourceListbox");
        // $NON-NLS-1$
        datasourceSelectionDialog = (XulDialog) safeGetElementById(document, "datasourceSelectionDialog");
        removeDatasourceConfirmationDialog = (XulDialog) safeGetElementById(document, // $NON-NLS-1$
        "removeDatasourceConfirmationDialog");
        XulButton acceptButton = null;
        try {
            // $NON-NLS-1$
            acceptButton = (XulButton) safeGetElementById(document, "datasourceSelectionDialog_accept");
        } catch (Exception e) {
        // this might not be available
        }
        // $NON-NLS-1$
        addDatasourceButton = (XulButton) safeGetElementById(document, "addDatasource");
        // $NON-NLS-1$
        editDatasourceButton = (XulButton) safeGetElementById(document, "editDatasource");
        // $NON-NLS-1$
        removeDatasourceButton = (XulButton) safeGetElementById(document, "removeDatasource");
        manager = UIDatasourceServiceManager.getInstance();
        manager.getIds(new XulServiceCallback<List<IDatasourceInfo>>() {

            @Override
            public void success(List<IDatasourceInfo> infoList) {
                DatasourceSelectionDialogController.this.datasourceInfos = infoList;
            }

            @Override
            public void error(String message, Throwable error) {
            }
        });
        bf.setBindingType(Binding.Type.ONE_WAY);
        bf.createBinding(DatasourceSelectionDialogController.this.datasourceSelectionDialogModel, "logicalModelSummaries", datasourceListbox, // $NON-NLS-1$ //$NON-NLS-2$
        "elements");
        bf.setBindingType(Binding.Type.ONE_WAY);
        // $NON-NLS-1$
        bf.createBinding(// $NON-NLS-1$
        datasourceListbox, // $NON-NLS-1$
        "selectedIndex", DatasourceSelectionDialogController.this.datasourceSelectionDialogModel, // $NON-NLS-1$
        "selectedIndex");
        // setup binding to disable accept button until user selects a datasource
        bf.setBindingType(Binding.Type.ONE_WAY);
        if (acceptButton != null) {
            BindingConvertor<Integer, Boolean> acceptButtonConvertor = new BindingConvertor<Integer, Boolean>() {

                @Override
                public Boolean sourceToTarget(final Integer value) {
                    return value > -1;
                }

                @Override
                public Integer targetToSource(final Boolean value) {
                    throw new UnsupportedOperationException();
                }
            };
            bf.createBinding(DatasourceSelectionDialogController.this.datasourceSelectionDialogModel, "selectedIndex", // $NON-NLS-1$
            acceptButton, "!disabled", // $NON-NLS-1$
            acceptButtonConvertor);
        }
        // setup binding to disable remove datasource button until user selects a datasource
        bf.setBindingType(Binding.Type.ONE_WAY);
        BindingConvertor<Integer, Boolean> removeDatasourceButtonConvertor = new BindingConvertor<Integer, Boolean>() {

            @Override
            public Boolean sourceToTarget(final Integer value) {
                boolean active = false;
                if (value > -1) {
                    LogicalModelSummary summary = (LogicalModelSummary) datasourceListbox.getSelectedItem();
                    if (datasourceInfos.size() > 0) {
                        for (int i = 0; i < datasourceInfos.size(); i++) {
                            IDatasourceInfo datasourceInfo = datasourceInfos.get(i);
                            if (datasourceInfo.getId().equals(summary.getDomainId())) {
                                active = datasourceInfo.isEditable();
                                break;
                            }
                        }
                    }
                }
                return active && administrator;
            }

            @Override
            public Integer targetToSource(final Boolean value) {
                throw new UnsupportedOperationException();
            }
        };
        removeDatasourceButtonBinding = bf.createBinding(DatasourceSelectionDialogController.this.datasourceSelectionDialogModel, "selectedIndex", // $NON-NLS-1$
        removeDatasourceButton, "!disabled", // $NON-NLS-1$
        removeDatasourceButtonConvertor);
        BindingConvertor<Integer, Boolean> editDatasourceButtonConvertor = new BindingConvertor<Integer, Boolean>() {

            @Override
            public Boolean sourceToTarget(final Integer value) {
                boolean active = false;
                if (value > -1) {
                    LogicalModelSummary summary = (LogicalModelSummary) datasourceListbox.getSelectedItem();
                    if (datasourceInfos.size() > 0) {
                        for (int i = 0; i < datasourceInfos.size(); i++) {
                            IDatasourceInfo datasourceInfo = datasourceInfos.get(i);
                            if (datasourceInfo.getId().equals(summary.getDomainId())) {
                                active = datasourceInfo.isEditable();
                                break;
                            }
                        }
                    }
                }
                return active && administrator;
            }

            @Override
            public Integer targetToSource(final Boolean value) {
                throw new UnsupportedOperationException();
            }
        };
        editDatasourceButtonBinding = bf.createBinding(DatasourceSelectionDialogController.this.datasourceSelectionDialogModel, "selectedIndex", // $NON-NLS-1$
        editDatasourceButton, "!disabled", // $NON-NLS-1$
        editDatasourceButtonConvertor);
        datasourceListbox.setSelectedIndex(-1);
        // workaround for bug in some XulListbox implementations (doesn't fire event on setSelectedIndex call)
        DatasourceSelectionDialogController.this.datasourceSelectionDialogModel.setSelectedIndex(-1);
    } catch (Exception e) {
        e.printStackTrace();
        // $NON-NLS-1$
        showMessagebox("Error", e.getLocalizedMessage());
    }
}
Also used : BindingConvertor(org.pentaho.ui.xul.binding.BindingConvertor) XulException(org.pentaho.ui.xul.XulException) RequestException(com.google.gwt.http.client.RequestException) LogicalModelSummary(org.pentaho.platform.dataaccess.datasource.beans.LogicalModelSummary) XulButton(org.pentaho.ui.xul.components.XulButton) ArrayList(java.util.ArrayList) List(java.util.List) IDatasourceInfo(org.pentaho.platform.dataaccess.datasource.IDatasourceInfo)

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