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);
}
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());
}
}
Aggregations