Search in sources :

Example 11 with UIRepositoryObject

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

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

the class RevisionController method restoreRevision.

public void restoreRevision() {
    try {
        final Collection<UIRepositoryContent> content = fileTable.getSelectedItems();
        final UIRepositoryContent contentToRestore = content.iterator().next();
        Collection<UIRepositoryObjectRevision> versions = revisionTable.getSelectedItems();
        final UIRepositoryObjectRevision versionToRestore = versions.iterator().next();
        SwtConfirmBox confirmbox = promptCommitComment(document);
        if (contentToRestore instanceof ILockObject && ((ILockObject) contentToRestore).isLocked()) {
            // Cannot restore revision of locked content
            // $NON-NLS-1$
            messageBox.setTitle(BaseMessages.getString(PKG, "Dialog.Error"));
            // $NON-NLS-1$
            messageBox.setAcceptLabel(BaseMessages.getString(PKG, "Dialog.Ok"));
            // $NON-NLS-1$
            messageBox.setMessage(BaseMessages.getString(PKG, "RevisionsController.RestoreLockedFileNotAllowed"));
            messageBox.open();
            return;
        }
        confirmbox.addDialogCallback(new XulDialogCallback<String>() {

            public void onClose(XulComponent component, Status status, String value) {
                if (!status.equals(Status.CANCEL)) {
                    try {
                        if (contentToRestore instanceof IRevisionObject) {
                            ((IRevisionObject) contentToRestore).restoreRevision(versionToRestore, value);
                            List<UIRepositoryObject> objects = new ArrayList<UIRepositoryObject>();
                            objects.add(contentToRestore);
                            browseController.setRepositoryObjects(objects);
                        } else {
                            throw new IllegalStateException(BaseMessages.getString(PKG, // $NON-NLS-1$
                            "RevisionsController.RevisionsNotSupported"));
                        }
                    } catch (Exception e) {
                        if (mainController == null || !mainController.handleLostRepository(e)) {
                            // convert to runtime exception so it bubbles up through the UI
                            throw new RuntimeException(e);
                        }
                    }
                }
            }

            public void onError(XulComponent component, Throwable err) {
                if (mainController == null || !mainController.handleLostRepository(err)) {
                    throw new RuntimeException(err);
                }
            }
        });
        confirmbox.open();
    } catch (Exception e) {
        if (mainController == null || !mainController.handleLostRepository(e)) {
            throw new RuntimeException(new KettleException(e));
        }
    }
}
Also used : 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) SwtConfirmBox(org.pentaho.ui.xul.swt.tags.SwtConfirmBox) 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) ILockObject(org.pentaho.di.ui.repository.pur.repositoryexplorer.ILockObject) UIRepositoryObjectRevision(org.pentaho.di.ui.repository.pur.repositoryexplorer.model.UIRepositoryObjectRevision) ArrayList(java.util.ArrayList) List(java.util.List) XulComponent(org.pentaho.ui.xul.XulComponent)

Example 13 with UIRepositoryObject

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

the class TrashBrowseController method renameRepositoryObject.

@Override
protected void renameRepositoryObject(final UIRepositoryObject repoObject) throws XulException {
    // final Document doc = document;
    XulPromptBox prompt = promptForName(repoObject);
    prompt.addDialogCallback(new XulDialogCallback<String>() {

        public void onClose(XulComponent component, Status status, String value) {
            if (status == Status.ACCEPT) {
                final String newName = value;
                try {
                    repoObject.setName(newName);
                } catch (KettleException ke) {
                    if (ke.getCause() instanceof RepositoryObjectAccessException) {
                        moveDeletePrompt(ke, repoObject, new XulDialogCallback<Object>() {

                            public void onClose(XulComponent sender, Status returnCode, Object retVal) {
                                if (returnCode == Status.ACCEPT) {
                                    try {
                                        ((UIEERepositoryDirectory) repoObject).setName(newName, true);
                                    } catch (Exception e) {
                                        if (mainController == null || !mainController.handleLostRepository(e)) {
                                            displayExceptionMessage(BaseMessages.getString(PKG, e.getLocalizedMessage()));
                                        }
                                    }
                                }
                            }

                            public void onError(XulComponent sender, Throwable t) {
                                if (mainController == null || !mainController.handleLostRepository(t)) {
                                    throw new RuntimeException(t);
                                }
                            }
                        });
                    } else {
                        if (mainController == null || !mainController.handleLostRepository(ke)) {
                            throw new RuntimeException(ke);
                        }
                    }
                } catch (Exception e) {
                    if (mainController == null || !mainController.handleLostRepository(e)) {
                        // convert to runtime exception so it bubbles up through the UI
                        throw new RuntimeException(e);
                    }
                }
            }
        }

        public void onError(XulComponent component, Throwable err) {
            if (mainController == null || !mainController.handleLostRepository(err)) {
                throw new RuntimeException(err);
            }
        }
    });
    prompt.open();
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RepositoryObjectAccessException(org.pentaho.di.repository.pur.RepositoryObjectAccessException) XulPromptBox(org.pentaho.ui.xul.components.XulPromptBox) UIRepositoryObject(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject) IDeletedObject(org.pentaho.di.ui.repository.pur.services.ITrashService.IDeletedObject) XulComponent(org.pentaho.ui.xul.XulComponent) XulException(org.pentaho.ui.xul.XulException) KettleException(org.pentaho.di.core.exception.KettleException) RepositoryObjectAccessException(org.pentaho.di.repository.pur.RepositoryObjectAccessException) ControllerInitializationException(org.pentaho.di.ui.repository.repositoryexplorer.ControllerInitializationException)

Example 14 with UIRepositoryObject

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

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

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