use of org.pentaho.ui.xul.binding.BindingConvertor in project pentaho-kettle by pentaho.
the class PermissionsController method createBindings.
protected void createBindings() {
super.createBindings();
// $NON-NLS-1$
fileFolderLabel = (XulLabel) document.getElementById("file-folder-name");
// $NON-NLS-1$
aclDeck = (XulDeck) document.getElementById("acl-deck");
// $NON-NLS-1$
inheritParentPermissionCheckbox = (XulCheckbox) document.getElementById("inherit-from-parent-permission-checkbox");
bf.setBindingType(Binding.Type.ONE_WAY);
BindingConvertor<List<UIRepositoryObject>, List<UIRepositoryObjectAcl>> securityBindingConverter = new BindingConvertor<List<UIRepositoryObject>, List<UIRepositoryObjectAcl>>() {
@Override
public List<UIRepositoryObjectAcl> sourceToTarget(List<UIRepositoryObject> ro) {
if (ro == null) {
return null;
}
if (ro.size() <= 0) {
return null;
}
setSelectedRepositoryObject(ro);
if (!hasManageAclAccess()) {
// disable everything
applyAclButton.setDisabled(true);
addAclButton.setDisabled(true);
removeAclButton.setDisabled(true);
inheritParentPermissionCheckbox.setDisabled(true);
manageAclCheckbox.setDisabled(true);
deleteCheckbox.setDisabled(true);
writeCheckbox.setDisabled(true);
readCheckbox.setDisabled(true);
viewAclsModel.setHasManageAclAccess(false);
} else {
applyAclButton.setDisabled(false);
inheritParentPermissionCheckbox.setDisabled(false);
viewAclsModel.setHasManageAclAccess(true);
}
viewAclsModel.setRemoveEnabled(false);
List<UIRepositoryObjectAcl> selectedAclList = Collections.emptyList();
// we've moved to a new file/folder; need to clear out what the model thinks is selected
viewAclsModel.setSelectedAclList(selectedAclList);
permissionsCheckboxHandler.updateCheckboxes(EnumSet.noneOf(RepositoryFilePermission.class));
UIRepositoryObject repoObject = ro.get(0);
try {
if (repoObject instanceof IAclObject) {
((IAclObject) repoObject).getAcls(viewAclsModel);
} else {
// $NON-NLS-1$
throw new IllegalStateException(BaseMessages.getString(PKG, "PermissionsController.NoAclSupport"));
}
fileFolderLabel.setValue(// $NON-NLS-1$
BaseMessages.getString(PKG, "AclTab.UserRolePermission", repoObject.getName()));
bf.setBindingType(Binding.Type.ONE_WAY);
// $NON-NLS-1$ //$NON-NLS-2$
bf.createBinding(viewAclsModel, "acls", userRoleList, "elements");
updateInheritFromParentPermission();
} catch (AccessDeniedException ade) {
if (mainController == null || !mainController.handleLostRepository(ade)) {
// $NON-NLS-1$
messageBox.setTitle(BaseMessages.getString(PKG, "Dialog.Error"));
// $NON-NLS-1$
messageBox.setAcceptLabel(BaseMessages.getString(PKG, "Dialog.Ok"));
messageBox.setMessage(BaseMessages.getString(PKG, "PermissionsController.UnableToGetAcls", repoObject.getName(), // $NON-NLS-1$
ade.getLocalizedMessage()));
messageBox.open();
}
} catch (Exception e) {
if (mainController == null || !mainController.handleLostRepository(e)) {
// $NON-NLS-1$
messageBox.setTitle(BaseMessages.getString(PKG, "Dialog.Error"));
// $NON-NLS-1$
messageBox.setAcceptLabel(BaseMessages.getString(PKG, "Dialog.Ok"));
messageBox.setMessage(BaseMessages.getString(PKG, "PermissionsController.UnableToGetAcls", repoObject.getName(), // $NON-NLS-1$
e.getLocalizedMessage()));
messageBox.open();
}
}
aclDeck.setSelectedIndex(ACL);
return viewAclsModel.getAcls();
}
@Override
public List<UIRepositoryObject> targetToSource(List<UIRepositoryObjectAcl> elements) {
return null;
}
};
// Binding between the selected repository objects and the user role list for acls
securityBinding = // $NON-NLS-1$ //$NON-NLS-2$
bf.createBinding(browseController, "repositoryObjects", userRoleList, "elements", securityBindingConverter);
securityBinding = // $NON-NLS-1$ //$NON-NLS-2$
bf.createBinding(browseController, "repositoryDirectories", userRoleList, "elements", securityBindingConverter);
bf.setBindingType(Binding.Type.BI_DIRECTIONAL);
// Binding Add Remove button to the inherit check box. If the checkbox is checked that disable add remove
// $NON-NLS-1$ //$NON-NLS-2$
bf.createBinding(viewAclsModel, "entriesInheriting", inheritParentPermissionCheckbox, "checked");
// Setting the default Deck to show no permission
aclDeck.setSelectedIndex(NO_ACL);
try {
if (securityBinding != null) {
securityBinding.fireSourceChanged();
}
} catch (Exception e) {
if (mainController == null || !mainController.handleLostRepository(e)) {
// convert to runtime exception so it bubbles up through the UI
throw new RuntimeException(e);
}
}
}
use of org.pentaho.ui.xul.binding.BindingConvertor in project pentaho-kettle by pentaho.
the class RepositoriesController method createBindings.
private void createBindings() {
loginDialog = (XulDialog) document.getElementById("repository-login-dialog");
repositoryEditButton = (XulButton) document.getElementById("repository-edit");
repositoryRemoveButton = (XulButton) document.getElementById("repository-remove");
username = (XulTextbox) document.getElementById("user-name");
userPassword = (XulTextbox) document.getElementById("user-password");
availableRepositories = (XulListbox) document.getElementById("available-repository-list");
showAtStartup = (XulCheckbox) document.getElementById("show-login-dialog-at-startup");
okButton = (XulButton) document.getElementById("repository-login-dialog_accept");
cancelButton = (XulButton) document.getElementById("repository-login-dialog_cancel");
bf.setBindingType(Binding.Type.BI_DIRECTIONAL);
bf.createBinding(loginModel, "username", username, "value");
bf.createBinding(loginModel, "password", userPassword, "value");
bf.createBinding(loginModel, "availableRepositories", availableRepositories, "elements");
bf.createBinding(loginModel, "selectedRepository", availableRepositories, "selectedItem");
bf.createBinding(loginModel, "showDialogAtStartup", showAtStartup, "checked");
bf.setBindingType(Binding.Type.ONE_WAY);
bf.createBinding(loginModel, "valid", okButton, "!disabled");
BindingConvertor<RepositoryMeta, Boolean> buttonConverter = new BindingConvertor<RepositoryMeta, Boolean>() {
@Override
public Boolean sourceToTarget(RepositoryMeta value) {
return (value == null);
}
@Override
public RepositoryMeta targetToSource(Boolean value) {
return null;
}
};
BindingConvertor<RepositoryMeta, Boolean> userpassConverter = new BindingConvertor<RepositoryMeta, Boolean>() {
@Override
public Boolean sourceToTarget(RepositoryMeta value) {
return (value == null) || !value.getRepositoryCapabilities().supportsUsers();
}
@Override
public RepositoryMeta targetToSource(Boolean value) {
return null;
}
};
bf.createBinding(loginModel, "selectedRepository", username, "disabled", userpassConverter);
bf.createBinding(loginModel, "selectedRepository", userPassword, "disabled", userpassConverter);
bf.createBinding(loginModel, "selectedRepository", repositoryEditButton, "disabled", buttonConverter);
bf.createBinding(loginModel, "selectedRepository", repositoryRemoveButton, "disabled", buttonConverter);
final Shell loginShell = (Shell) loginDialog.getRootObject();
helper = new RepositoriesHelper(loginModel, document, loginShell);
helper.setPreferredRepositoryName(preferredRepositoryName);
helper.getMetaData();
}
use of org.pentaho.ui.xul.binding.BindingConvertor in project data-access by pentaho.
the class CsvPhysicalStep method setBindings.
@Override
public void setBindings() {
// $NON-NLS-1$
uploadedFileTextBox = (XulTextbox) document.getElementById("uploadedFile");
// $NON-NLS-1$
csvTextPreview = (XulLabel) document.getElementById("csvTextPreview");
encodingTypeMenuList = (XulMenuList<String>) document.getElementById("encodingTypeMenuList");
encodingTypeMenuList.setElements(ENCODINGS);
BindingConvertor<Integer, Boolean> isFirstRowHeaderConverter = BindingConvertor.integer2Boolean();
bf.createBinding(datasourceModel.getModelInfo().getFileInfo(), CsvFileInfo.HEADER_ROWS_ATTRIBUTE, // $NON-NLS-1$
"isHeaderCheckBox", // $NON-NLS-1$
"checked", isFirstRowHeaderConverter);
// Binding convertor to between Delimiter and radio group selected value
BindingConvertor<String, String> delimiterBindingConvertor = new BindingConvertor<String, String>() {
public String sourceToTarget(String source) {
Delimiter delimiter = Delimiter.lookupValue(source);
if (delimiter != null) {
return Delimiter.lookupValue(source).getName();
} else {
return source;
}
}
public String targetToSource(String target) {
Delimiter delimiter = Delimiter.lookupName(target);
if (delimiter != null) {
return delimiter.getValue();
} else {
return target;
}
}
};
// add binding for the Delimiter to it's corresponding radio group
bf.createBinding(datasourceModel.getModelInfo().getFileInfo(), CsvFileInfo.DELIMITER_ATTRIBUTE, // $NON-NLS-1$
"delimiterRadioGroup", // $NON-NLS-1$
"value", delimiterBindingConvertor);
// Binding convertor to between Enclosure and radio group selected value
BindingConvertor<String, String> enclosureBindingConvertor = new BindingConvertor<String, String>() {
public String sourceToTarget(String source) {
Enclosure e = Enclosure.lookupValue(source);
if (e == null) {
e = Enclosure.NONE;
}
return e.getName();
}
public String targetToSource(String target) {
Enclosure e = Enclosure.lookupName(target);
if (e == Enclosure.NONE) {
return null;
} else {
return e.getValue();
}
}
};
// add binding for the Enclosure to it's corresponding radio group
bf.createBinding(datasourceModel.getModelInfo().getFileInfo(), CsvFileInfo.ENCLOSURE_ATTRIBUTE, // $NON-NLS-1$
"enclosureRadioGroup", // $NON-NLS-1$
"value", enclosureBindingConvertor);
// when the delimiter changes, we need to refresh the preview
datasourceModel.getModelInfo().getFileInfo().addPropertyChangeListener(CsvFileInfo.DELIMITER_ATTRIBUTE, new RefreshPreviewPropertyChangeListener());
// when the enclosure changes, we need to refresh the preview
datasourceModel.getModelInfo().getFileInfo().addPropertyChangeListener(CsvFileInfo.ENCLOSURE_ATTRIBUTE, new RefreshPreviewPropertyChangeListener());
// when the first-row-is-header flag changes, we need to refresh the preview
datasourceModel.getModelInfo().getFileInfo().addPropertyChangeListener(CsvFileInfo.HEADER_ROWS_ATTRIBUTE, new RefreshPreviewPropertyChangeListener());
uploadedFileTextBox.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals("value")) {
// set the defaults if none already selected
String delimiter = datasourceModel.getModelInfo().getFileInfo().getDelimiter();
if (delimiter == null || delimiter.equals("")) {
datasourceModel.getModelInfo().getFileInfo().setDelimiter(",");
datasourceModel.getModelInfo().getFileInfo().setHeaderRows(1);
}
String enclosure = datasourceModel.getModelInfo().getFileInfo().getEnclosure();
if (enclosure == null || enclosure.equals("")) {
datasourceModel.getModelInfo().getFileInfo().setEnclosure("\"");
}
syncModelInfo();
datasourceModel.getGuiStateModel().setDirty(true);
datasourceModel.getModelInfo().validate();
}
}
});
bf.setBindingType(Binding.Type.ONE_WAY);
// binding to set the first-row-is-header checkbox's enabled property based on the selectedItem in the filesList
bf.createBinding(uploadedFileTextBox, "value", "isHeaderCheckBox", "!disabled", BindingConvertor.object2Boolean());
// binding to set the delimiters enabled property based on the selectedItem in the filesList
bf.createBinding(uploadedFileTextBox, "value", "delimiterRadioGroup", "!disabled", BindingConvertor.object2Boolean());
// binding to set the enclosures enabled property based on the selectedItem in the filesList
bf.createBinding(uploadedFileTextBox, "value", "enclosureRadioGroup", "!disabled", BindingConvertor.object2Boolean());
bf.createBinding(datasourceModel.getModelInfo().getFileInfo(), "friendlyFilename", uploadedFileTextBox, // $NON-NLS-1$ //$NON-NLS-2$
"value");
bf.createBinding(uploadedFileTextBox, "value", "encodingTypeMenuList", "!disabled", BindingConvertor.object2Boolean());
BindingConvertor<String, String> encodingBindingConvertor = new BindingConvertor<String, String>() {
public String sourceToTarget(String source) {
return source;
}
public String targetToSource(String target) {
Collection<String> encodings = encodingTypeMenuList.getElements();
if (target != null && !encodings.contains(target)) {
encodings.add(target);
encodingTypeMenuList.setElements(encodings);
}
return target;
}
};
bf.setBindingType(Binding.Type.BI_DIRECTIONAL);
bf.createBinding(encodingTypeMenuList, "value", datasourceModel.getModelInfo().getFileInfo(), CsvFileInfo.ENCODING, // $NON-NLS-1$ //$NON-NLS-2$
encodingBindingConvertor);
RefreshPreviewPropertyChangeListener previewChangeListener = new RefreshPreviewPropertyChangeListener();
datasourceModel.getModelInfo().getFileInfo().addPropertyChangeListener(CsvFileInfo.ENCODING, previewChangeListener);
datasourceModel.getModelInfo().getFileInfo().addPropertyChangeListener(CsvFileInfo.TMP_FILENAME_ATTRIBUTE, previewChangeListener);
}
use of org.pentaho.ui.xul.binding.BindingConvertor in project data-access by pentaho.
the class WizardDatasourceController method init.
@Bindable
public void init() {
// $NON-NLS-1$
clearModelWarningDialog = (XulDialog) document.getElementById("clearModelWarningDialog");
// $NON-NLS-1$
csvDataTable = (XulTree) document.getElementById("csvDataTable");
// $NON-NLS-1$
modelDataTable = (XulTree) document.getElementById("modelDataTable");
// $NON-NLS-1$
errorDialog = (XulDialog) document.getElementById("errorDialog");
// $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$
csvDatasourceName = (XulTextbox) document.getElementById("datasourceName");
// $NON-NLS-1$
datasourceDialog = (XulDialog) document.getElementById("datasourceDialog");
// $NON-NLS-1$
okButton = (XulButton) document.getElementById("datasourceDialog_accept");
// $NON-NLS-1$
cancelButton = (XulButton) document.getElementById("datasourceDialog_cancel");
// $NON-NLS-1$
datasourceTabbox = (XulTabbox) document.getElementById("datasourceDialogTabbox");
bf.setBindingType(Binding.Type.ONE_WAY);
// $NON-NLS-1$ //$NON-NLS-2$
bf.createBinding(datasourceModel, "validated", okButton, "!disabled");
bf.setBindingType(Binding.Type.BI_DIRECTIONAL);
final Binding domainBinding = bf.createBinding(datasourceModel.getGuiStateModel(), "datasourceName", csvDatasourceName, // $NON-NLS-1$ //$NON-NLS-2$
"value");
// $NON-NLS-1$ //$NON-NLS-2$
bf.createBinding(datasourceModel, "datasourceName", csvDatasourceName, "value");
BindingConvertor<DatasourceType, Integer> tabIndexConvertor = new BindingConvertor<DatasourceType, Integer>() {
@Override
public Integer sourceToTarget(DatasourceType value) {
Integer returnValue = null;
if (DatasourceType.SQL == value) {
returnValue = 0;
} else if (DatasourceType.CSV == value) {
returnValue = 1;
} else if (DatasourceType.OLAP == value) {
return 2;
} else if (DatasourceType.NONE == value) {
return 0;
}
return returnValue;
}
@Override
public DatasourceType targetToSource(Integer value) {
DatasourceType type = null;
if (value == 0) {
type = DatasourceType.SQL;
} else if (value == 1) {
type = DatasourceType.CSV;
} else if (value == 2) {
type = DatasourceType.OLAP;
}
return type;
}
};
bf.createBinding(datasourceModel, "datasourceType", datasourceTabbox, "selectedIndex", // $NON-NLS-1$ //$NON-NLS-2$
tabIndexConvertor);
okButton.setDisabled(true);
initialize();
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();
}
}
use of org.pentaho.ui.xul.binding.BindingConvertor in project pentaho-kettle by pentaho.
the class XulDatabaseExplorerController method init.
public void init() {
SwtButton theAcceptButton = (SwtButton) this.document.getElementById("databaseExplorerDialog_accept");
SwtButton theCancelButton = (SwtButton) this.document.getElementById("databaseExplorerDialog_cancel");
if (this.isJustLook) {
theAcceptButton.setVisible(false);
theCancelButton.setLabel(BaseMessages.getString(getClass(), "DatabaseExplorer.Button.Ok"));
theAcceptButton.setDisabled(false);
} else {
theAcceptButton.setLabel(BaseMessages.getString(getClass(), "DatabaseExplorer.Button.Ok"));
theCancelButton.setLabel(BaseMessages.getString(getClass(), "DatabaseExplorer.Button.Cancel"));
theAcceptButton.setDisabled(true);
}
this.dbExplorerDialog = (SwtDialog) this.document.getElementById("databaseExplorerDialog");
createDatabaseNodes();
if (this.status != UiPostActionStatus.OK) {
// something goes dramatically wrong!
return;
}
this.bf.setDocument(super.document);
this.bf.setBindingType(Type.ONE_WAY);
this.expandCollapseButton = (XulButton) document.getElementById("expandCollapseButton");
this.databaseTree = (XulTree) document.getElementById("databaseTree");
this.databaseTreeBinding = bf.createBinding(this.model, "database", this.databaseTree, "elements");
bf.createBinding(model, "selectedNode", theAcceptButton, "disabled", new BindingConvertor<DatabaseExplorerNode, Boolean>() {
@Override
public Boolean sourceToTarget(DatabaseExplorerNode arg0) {
return (!isJustLook && (arg0 == null || !arg0.isTable()));
}
@Override
public DatabaseExplorerNode targetToSource(Boolean arg0) {
// TODO Auto-generated method stub
return null;
}
});
bf.setBindingType(Binding.Type.BI_DIRECTIONAL);
this.bf.createBinding(this.databaseTree, "selectedItems", this.model, "selectedNode", new BindingConvertor<List<DatabaseExplorerNode>, DatabaseExplorerNode>() {
@Override
public DatabaseExplorerNode sourceToTarget(List<DatabaseExplorerNode> arg0) {
if (arg0 == null || arg0.size() == 0) {
return null;
}
return arg0.get(0);
}
@Override
public List<DatabaseExplorerNode> targetToSource(DatabaseExplorerNode arg0) {
return Collections.singletonList(arg0);
}
});
BindingConvertor<DatabaseExplorerNode, Boolean> isDisabledConvertor = new BindingConvertor<DatabaseExplorerNode, Boolean>() {
public Boolean sourceToTarget(DatabaseExplorerNode value) {
return !(value != null && value.isTable());
}
public DatabaseExplorerNode targetToSource(Boolean value) {
return null;
}
};
bf.setBindingType(Binding.Type.ONE_WAY);
this.bf.createBinding(this.databaseTree, "selectedItem", "buttonMenuPopUp", "disabled", isDisabledConvertor);
this.bf.createBinding(this.databaseTree, "selectedItem", "buttonMenuPopUpImg", "disabled", isDisabledConvertor);
this.bf.createBinding(this.databaseTree, "selectedItem", "action_popup", "disabled", isDisabledConvertor);
fireBindings();
}
Aggregations