Search in sources :

Example 6 with XulButton

use of org.pentaho.ui.xul.components.XulButton 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

XulButton (org.pentaho.ui.xul.components.XulButton)6 RequestException (com.google.gwt.http.client.RequestException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IDatasourceInfo (org.pentaho.platform.dataaccess.datasource.IDatasourceInfo)1 LogicalModelSummary (org.pentaho.platform.dataaccess.datasource.beans.LogicalModelSummary)1 XulException (org.pentaho.ui.xul.XulException)1 BindingConvertor (org.pentaho.ui.xul.binding.BindingConvertor)1 XulTextbox (org.pentaho.ui.xul.components.XulTextbox)1