Search in sources :

Example 11 with UIRepositoryDirectory

use of org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryDirectory in project pentaho-kettle by pentaho.

the class RepositoryLockController method repositoryDirectoryHasLockedObject.

private boolean repositoryDirectoryHasLockedObject(DropEvent event, UIRepositoryDirectory dir) throws KettleException {
    if (areAnyRepositoryObjectsLocked(event, dir.getRepositoryObjects())) {
        return true;
    }
    for (UIRepositoryObject ro : dir.getChildren()) {
        if (ro instanceof UIRepositoryDirectory) {
            UIRepositoryDirectory directory = (UIRepositoryDirectory) ro;
            repositoryDirectoryHasLockedObject(event, directory);
        }
    }
    return false;
}
Also used : UIRepositoryObject(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject) UIRepositoryDirectory(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryDirectory)

Example 12 with UIRepositoryDirectory

use of org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryDirectory in project pentaho-kettle by pentaho.

the class RevisionController method createBindings.

private void createBindings() {
    // $NON-NLS-1$
    filePropertiesTabbox = (XulTabbox) document.getElementById("file-properties-tabs");
    // $NON-NLS-1$
    historyTab = (XulTab) document.getElementById("history");
    // $NON-NLS-1$
    revisionTable = (XulTree) document.getElementById("revision-table");
    // $NON-NLS-1$
    folderTree = (XulTree) document.getElementById("folder-tree");
    // $NON-NLS-1$
    fileTable = (XulTree) document.getElementById("file-table");
    // Hide the history tab if versioning is off
    historyTab.setVisible(false);
    bf.setBindingType(Binding.Type.ONE_WAY);
    BindingConvertor<int[], Boolean> forButtons = new BindingConvertor<int[], Boolean>() {

        @Override
        public Boolean sourceToTarget(int[] value) {
            return value != null && !(value.length <= 0);
        }

        @Override
        public int[] targetToSource(Boolean value) {
            return null;
        }
    };
    Binding openButtonBinding = // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    bf.createBinding(revisionTable, "selectedRows", OPEN_REVISION_BUTTON, "!disabled", forButtons);
    Binding restoreButtonBinding = // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    bf.createBinding(revisionTable, "selectedRows", RESTORE_REVISION_BUTTON, "!disabled", forButtons);
    bf.setBindingType(Binding.Type.ONE_WAY);
    // $NON-NLS-1$  //$NON-NLS-2$
    bf.createBinding(folderTree, "selectedItems", this, "historyTabVisibility");
    // $NON-NLS-1$ //$NON-NLS-2$
    revisionBinding = bf.createBinding(this, "revisionObjects", revisionTable, "elements");
    revisionBinding = // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(// $NON-NLS-1$ //$NON-NLS-2$
    browseController, // $NON-NLS-1$ //$NON-NLS-2$
    "repositoryItems", // $NON-NLS-1$ //$NON-NLS-2$
    this, // $NON-NLS-1$ //$NON-NLS-2$
    "revisionObjects", new BindingConvertor<List<UIRepositoryObject>, UIRepositoryObjectRevisions>() {

        private void disableButtons() {
            document.getElementById(OPEN_REVISION_BUTTON).setDisabled(true);
            document.getElementById(RESTORE_REVISION_BUTTON).setDisabled(true);
        }

        @Override
        public UIRepositoryObjectRevisions sourceToTarget(List<UIRepositoryObject> ro) {
            if (ro == null || ro.isEmpty() || !masterVersioningEnabled) {
                return new UIRepositoryObjectRevisions();
            }
            if (ro.get(0) instanceof UIRepositoryDirectory) {
                historyTab.setVisible(false);
                filePropertiesTabbox.setSelectedIndex(0);
                disableButtons();
                return null;
            }
            UIRepositoryObjectRevisions revisions = null;
            try {
                UIRepositoryContent rc = (UIRepositoryContent) ro.get(0);
                if (rc instanceof IRevisionObject) {
                    Boolean versioningEnabled = ((IRevisionObject) rc).getVersioningEnabled();
                    // Show/hide the Verison History tab
                    historyTab.setVisible(versioningEnabled);
                    if (!versioningEnabled) {
                        return new UIRepositoryObjectRevisions();
                    }
                    Boolean versionCommentEnabled = ((IRevisionObject) rc).getVersionCommentEnabled();
                    // Show/Hide the version comment column
                    setRevisionTableColumns(versionCommentEnabled);
                    revisions = ((IRevisionObject) rc).getRevisions();
                } else {
                    throw new IllegalStateException(BaseMessages.getString(PKG, // $NON-NLS-1$
                    "RevisionsController.RevisionsNotSupported"));
                }
            } catch (KettleException e) {
                if (mainController == null || !mainController.handleLostRepository(e)) {
                    // convert to runtime exception so it bubbles up through the UI
                    throw new RuntimeException(e);
                }
            }
            return revisions;
        }

        @Override
        public List<UIRepositoryObject> targetToSource(UIRepositoryObjectRevisions elements) {
            return null;
        }
    });
    try {
        openButtonBinding.fireSourceChanged();
        restoreButtonBinding.fireSourceChanged();
        revisionBinding.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);
        }
    }
}
Also used : Binding(org.pentaho.ui.xul.binding.Binding) UIRepositoryDirectory(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryDirectory) KettleException(org.pentaho.di.core.exception.KettleException) IRevisionObject(org.pentaho.di.ui.repository.pur.repositoryexplorer.IRevisionObject) UIRepositoryContent(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryContent) BindingConvertor(org.pentaho.ui.xul.binding.BindingConvertor) XulException(org.pentaho.ui.xul.XulException) KettleException(org.pentaho.di.core.exception.KettleException) ControllerInitializationException(org.pentaho.di.ui.repository.repositoryexplorer.ControllerInitializationException) UIRepositoryObject(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject) UIRepositoryObjectRevisions(org.pentaho.di.ui.repository.pur.repositoryexplorer.model.UIRepositoryObjectRevisions) ArrayList(java.util.ArrayList) List(java.util.List)

Example 13 with UIRepositoryDirectory

use of org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryDirectory in project pentaho-kettle by pentaho.

the class BrowseController method onDrop.

public void onDrop(DropEvent event) {
    boolean result = false;
    try {
        List<Object> dirList = new ArrayList<Object>();
        List<UIRepositoryObject> moveList = new ArrayList<UIRepositoryObject>();
        UIRepositoryDirectory targetDirectory = null;
        if (event.getDropParent() != null && event.getDropParent() instanceof UIRepositoryDirectory) {
            targetDirectory = (UIRepositoryDirectory) event.getDropParent();
            if (event.getDataTransfer().getData().size() > 0) {
                for (Object o : event.getDataTransfer().getData()) {
                    if (o instanceof UIRepositoryObject) {
                        moveList.add((UIRepositoryObject) o);
                        // Make sure only Folders are copied to the Directory Tree
                        if (o instanceof UIRepositoryDirectory) {
                            dirList.add(o);
                        }
                        result = true;
                    }
                }
            }
        }
        if (result == true) {
            List<UIRepositoryObject> collisionObjects = new ArrayList<UIRepositoryObject>();
            // Check for overwriting
            for (UIRepositoryObject newChild : moveList) {
                for (UIRepositoryObject currChild : targetDirectory.getRepositoryObjects()) {
                    if ((currChild instanceof UIRepositoryDirectory) && (newChild instanceof UIRepositoryDirectory) && (currChild.getName().equalsIgnoreCase(newChild.getName()))) {
                        messageBox.setTitle(BaseMessages.getString(PKG, "Dialog.Error"));
                        messageBox.setAcceptLabel(BaseMessages.getString(PKG, "Dialog.Ok"));
                        messageBox.setMessage(BaseMessages.getString(PKG, "BrowseController.UnableToMove.DirectoryAlreadyExists", currChild.getPath()));
                        messageBox.open();
                        result = false;
                        break;
                    } else if (!(currChild instanceof UIRepositoryDirectory) && (currChild.getType().equalsIgnoreCase(newChild.getType())) && (currChild.getName().equalsIgnoreCase(newChild.getName()))) {
                        collisionObjects.add(currChild);
                    }
                }
                if (!result) {
                    break;
                }
            }
            // Prompt to overwrite
            if (result && collisionObjects.size() > 0) {
                FileOverwriteDialogController fileOverwriteDialog = FileOverwriteDialogController.getInstance(getXulDomContainer().getOuterContext() instanceof Shell ? (Shell) getXulDomContainer().getOuterContext() : null, collisionObjects);
                fileOverwriteDialog.show();
                if (fileOverwriteDialog.isOverwriteFiles()) {
                    // Delete the files before moving
                    for (UIRepositoryObject o : collisionObjects) {
                        o.delete();
                    }
                } else {
                    // We are not moving the files
                    result = false;
                }
            }
            // Make sure we are still moving the files
            if (result) {
                moveFiles(moveList, targetDirectory);
                // Set UI objects to appear in folder directory
                event.getDataTransfer().setData(dirList);
            }
        }
    } catch (Exception e) {
        if (mainController == null || !mainController.handleLostRepository(e)) {
            result = false;
            event.setAccepted(false);
            messageBox.setTitle(BaseMessages.getString(PKG, "Dialog.Error"));
            messageBox.setAcceptLabel(BaseMessages.getString(PKG, "Dialog.Ok"));
            messageBox.setMessage(BaseMessages.getString(PKG, "BrowseController.UnableToMove", e.getLocalizedMessage()));
            messageBox.open();
        }
    }
    event.setAccepted(result);
}
Also used : UIRepositoryObject(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject) UIRepositoryDirectory(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryDirectory) Shell(org.eclipse.swt.widgets.Shell) ArrayList(java.util.ArrayList) UIRepositoryObject(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject) 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)

Example 14 with UIRepositoryDirectory

use of org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryDirectory in project pentaho-kettle by pentaho.

the class BrowseController method renameContent.

public void renameContent() throws Exception {
    try {
        Collection<UIRepositoryContent> content = fileTable.getSelectedItems();
        UIRepositoryObject contentToRename = content.iterator().next();
        renameRepositoryObject(contentToRename);
        if (contentToRename instanceof UIRepositoryDirectory) {
            directoryBinding.fireSourceChanged();
        }
        selectedItemsBinding.fireSourceChanged();
    } catch (Throwable th) {
        if (mainController == null || !mainController.handleLostRepository(th)) {
            messageBox.setTitle(BaseMessages.getString(PKG, "Dialog.Error"));
            messageBox.setAcceptLabel(BaseMessages.getString(PKG, "Dialog.Ok"));
            messageBox.setMessage(BaseMessages.getString(PKG, th.getLocalizedMessage()));
            messageBox.open();
        }
    }
}
Also used : UIRepositoryObject(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject) UIRepositoryDirectory(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryDirectory) UIRepositoryContent(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryContent)

Example 15 with UIRepositoryDirectory

use of org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryDirectory 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

UIRepositoryDirectory (org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryDirectory)16 UIRepositoryObject (org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject)10 KettleException (org.pentaho.di.core.exception.KettleException)9 ControllerInitializationException (org.pentaho.di.ui.repository.repositoryexplorer.ControllerInitializationException)7 XulException (org.pentaho.ui.xul.XulException)7 ArrayList (java.util.ArrayList)5 UIObjectCreationException (org.pentaho.di.ui.repository.repositoryexplorer.model.UIObjectCreationException)5 UIRepositoryContent (org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryContent)5 List (java.util.List)2 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)2 ILockObject (org.pentaho.di.ui.repository.pur.repositoryexplorer.ILockObject)2 Binding (org.pentaho.ui.xul.binding.Binding)2 BindingConvertor (org.pentaho.ui.xul.binding.BindingConvertor)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 Callable (java.util.concurrent.Callable)1 Point (org.eclipse.swt.graphics.Point)1 Shell (org.eclipse.swt.widgets.Shell)1 Before (org.junit.Before)1 ObjectId (org.pentaho.di.repository.ObjectId)1