Search in sources :

Example 16 with UIRepositoryObject

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);
    }
}
Also used : UIRepositoryDirectory(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryDirectory) RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) BindingConvertor(org.pentaho.ui.xul.binding.BindingConvertor) XulException(org.pentaho.ui.xul.XulException) ControllerInitializationException(org.pentaho.di.ui.repository.repositoryexplorer.ControllerInitializationException) UIObjectCreationException(org.pentaho.di.ui.repository.repositoryexplorer.model.UIObjectCreationException) KettleException(org.pentaho.di.core.exception.KettleException) Point(org.eclipse.swt.graphics.Point) UIRepositoryObject(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

UIRepositoryObject (org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject)16 KettleException (org.pentaho.di.core.exception.KettleException)8 ControllerInitializationException (org.pentaho.di.ui.repository.repositoryexplorer.ControllerInitializationException)8 UIRepositoryDirectory (org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryDirectory)8 ArrayList (java.util.ArrayList)7 UIRepositoryContent (org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryContent)7 XulException (org.pentaho.ui.xul.XulException)7 List (java.util.List)4 ILockObject (org.pentaho.di.ui.repository.pur.repositoryexplorer.ILockObject)4 XulComponent (org.pentaho.ui.xul.XulComponent)3 BindingConvertor (org.pentaho.ui.xul.binding.BindingConvertor)3 Repository (org.pentaho.di.repository.Repository)2 IAclObject (org.pentaho.di.ui.repository.pur.repositoryexplorer.IAclObject)2 IRevisionObject (org.pentaho.di.ui.repository.pur.repositoryexplorer.IRevisionObject)2 UIObjectCreationException (org.pentaho.di.ui.repository.repositoryexplorer.model.UIObjectCreationException)2 RepositoryFilePermission (org.pentaho.platform.api.repository2.unified.RepositoryFilePermission)2 XulMenuitem (org.pentaho.ui.xul.components.XulMenuitem)2 XulPromptBox (org.pentaho.ui.xul.components.XulPromptBox)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1