use of org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject in project pentaho-kettle by pentaho.
the class BrowseController method createBindings.
protected void createBindings() {
shell = ((SwtDialog) document.getElementById("repository-explorer-dialog")).getShell();
folderTree = (XulTree) document.getElementById("folder-tree");
fileTable = (XulTree) document.getElementById("file-table");
if (!repositoryDirectory.isVisible()) {
folderTree.setHiddenrootnode(true);
} else {
folderTree.setHiddenrootnode(false);
}
BindingConvertor<List<?>, Boolean> checkIfMultipleItemsAreSelected = new BindingConvertor<List<?>, Boolean>() {
@Override
public Boolean sourceToTarget(List<?> value) {
return value != null && value.size() == 1 && value.get(0) != null;
}
@Override
public List<?> targetToSource(Boolean value) {
return null;
}
};
bf.setBindingType(Binding.Type.ONE_WAY);
bf.createBinding(fileTable, "selectedItems", "file-context-rename", "!disabled", checkIfMultipleItemsAreSelected);
bf.createBinding(fileTable, "selectedItems", this, "selectedFileItems");
// begin PDI-3326 hack
PropertyChangeListener childrenListener = new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
fireRepositoryDirectoryChange();
}
};
repositoryDirectory.addPropertyChangeListener("children", childrenListener);
// end PDI-3326 hack
directoryBinding = createDirectoryBinding();
// Bind the selected index from the folder tree to the list of repository objects in the file table.
bf.setBindingType(Binding.Type.ONE_WAY);
bf.createBinding(folderTree, "selectedItems", this, "selectedFolderItems");
bf.setBindingType(Binding.Type.ONE_WAY);
selectedItemsBinding = bf.createBinding(this, "selectedRepoDirChildren", fileTable, "elements");
// bindings can be added here in subclasses
doCreateBindings();
try {
// Fires the population of the repository tree of folders.
directoryBinding.fireSourceChanged();
} catch (Exception e) {
// convert to runtime exception so it bubbles up through the UI
throw new RuntimeException(e);
}
try {
// Set the initial selected directory as the users home directory
RepositoryDirectoryInterface homeDir = repository.getUserHomeDirectory();
int currentDir = 0;
String[] homePath = homeDir == null ? null : homeDir.getPathArray();
if (homePath != null) {
UIRepositoryDirectory tempRoot = repositoryDirectory;
// Check to see if the first item in homePath is the root directory
if (homePath.length > 0 && tempRoot.getName().equalsIgnoreCase(homePath[currentDir])) {
if (homePath.length == 1) {
// The home directory is home root
setSelectedFolderItems(Arrays.asList(tempRoot));
}
// We have used the first element. Increment to the next
currentDir++;
}
// Traverse the tree until we find our destination
for (; currentDir < homePath.length; currentDir++) {
for (UIRepositoryObject uiObj : tempRoot) {
if (uiObj instanceof UIRepositoryDirectory) {
if (uiObj.getName().equalsIgnoreCase(homePath[currentDir])) {
// We have a match. Let's move on to the next
tempRoot = (UIRepositoryDirectory) uiObj;
break;
}
}
}
}
// If we have traversed as many directories as there are in the path, we have found the directory
if (homePath.length == currentDir) {
setSelectedFolderItems(Arrays.asList(tempRoot));
folderTree.setSelectedItems(this.selectedFolderItems);
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations