Search in sources :

Example 56 with RepositoryDirectory

use of org.pentaho.di.repository.RepositoryDirectory in project pentaho-kettle by pentaho.

the class SelectDirectoryDialog method setTreeMenu.

public void setTreeMenu() {
    Menu mTree = null;
    // use SWT.SINGLE in wTree!!!!
    TreeItem[] ti = wTree.getSelection();
    if (ti.length == 1) {
        mTree = new Menu(wTree);
        /*
       * NEW Sub-directory
       */
        MenuItem miNew = new MenuItem(mTree, SWT.CASCADE);
        miNew.setText(BaseMessages.getString(PKG, "SelectDirectoryDialog.PopupMenu.Directory.New"));
        miNew.addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent e) {
                if (!readOnly) {
                    TreeItem ti = wTree.getSelection()[0];
                    String[] str = ConstUI.getTreeStrings(ti);
                    // 
                    // In which directory do we want create a subdirectory?
                    // 
                    RepositoryDirectoryInterface dir = repositoryTree.findDirectory(str);
                    if (dir != null) {
                        // 
                        // What's the name of the new directory?
                        // 
                        EnterStringDialog etd = new EnterStringDialog(shell, BaseMessages.getString(PKG, "SelectDirectoryDialog.Dialog.EnterDirectoryName.Title"), BaseMessages.getString(PKG, "SelectDirectoryDialog.Dialog.EnterDirectoryName.Message"), BaseMessages.getString(PKG, "SelectDirectoryDialog.Dialog.EnterDirectoryName.Default"));
                        String newdir = etd.open();
                        if (newdir != null) {
                            RepositoryDirectory subdir = new RepositoryDirectory(dir, newdir);
                            try {
                                rep.saveRepositoryDirectory(subdir);
                                dir.addSubdirectory(subdir);
                                TreeItem tiNew = new TreeItem(ti, SWT.NONE);
                                tiNew.setText(newdir);
                                tiNew.setImage(GUIResource.getInstance().getImageFolder());
                                wTree.setSelection(new TreeItem[] { tiNew });
                            } catch (Exception exception) {
                                new ErrorDialog(shell, BaseMessages.getString(PKG, "SelectDirectoryDialog.Dialog.UnableToCreateDirectory.Message"), BaseMessages.getString(PKG, "SelectDirectoryDialog.Dialog.UnableToCreateDirectory.Title"), exception);
                            }
                        }
                    } else {
                        MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
                        mb.setMessage(BaseMessages.getString(PKG, "SelectDirectoryDialog.Dialog.UnableToLocateDirectory.Message"));
                        mb.setText(BaseMessages.getString(PKG, "SelectDirectoryDialog.Dialog.UnableToLocateDirectory.Title"));
                        mb.open();
                    }
                } else {
                    MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
                    mb.setMessage(BaseMessages.getString(PKG, "SelectDirectoryDialog.Dialog.PermissionDenied.Message1") + (rep.getUserInfo() == null ? "" : rep.getUserInfo().getLogin()) + BaseMessages.getString(PKG, "SelectDirectoryDialog.Dialog.PermissionDenied.Message2"));
                    mb.setText(BaseMessages.getString(PKG, "SelectDirectoryDialog.Dialog.PermissionDenied.Title"));
                    mb.open();
                }
            }
        });
        /*
       * RENAME directory
       */
        MenuItem miRen = new MenuItem(mTree, SWT.CASCADE);
        miRen.setText(BaseMessages.getString(PKG, "SelectDirectoryDialog.PopupMenu.Directory.Rename"));
        miRen.addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent e) {
                if (!readOnly) {
                    TreeItem ti = wTree.getSelection()[0];
                    String[] str = ConstUI.getTreeStrings(ti);
                    RepositoryDirectoryInterface dir = repositoryTree.findDirectory(str);
                    if (dir != null) {
                        // 
                        // What's the new name of the directory?
                        // 
                        String oldName = dir.getName();
                        EnterStringDialog etd = new EnterStringDialog(shell, oldName, BaseMessages.getString(PKG, "SelectDirectoryDialog.Dialog.EnterDirectoryNewName.Message"), BaseMessages.getString(PKG, "SelectDirectoryDialog.Dialog.EnterDirectoryNewName.Title"));
                        String newName = etd.open();
                        if (newName != null && !newName.equals(oldName)) {
                            dir.setName(newName);
                            try {
                                rep.renameRepositoryDirectory(dir.getObjectId(), dir.getParent(), newName);
                                ti.setText(newName);
                                wTree.setSelection(ti);
                            } catch (Exception exception) {
                                new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryExplorerDialog.Directory.Rename.UnexpectedError.Message1") + oldName + "]" + Const.CR + BaseMessages.getString(PKG, "RepositoryExplorerDialog.Directory.Rename.UnexpectedError.Message2"), BaseMessages.getString(PKG, "RepositoryExplorerDialog.Directory.Rename.UnexpectedError.Title"), exception);
                            }
                        }
                    }
                }
            }
        });
        MenuItem miDel = new MenuItem(mTree, SWT.CASCADE);
        miDel.setText(BaseMessages.getString(PKG, "SelectDirectoryDialog.PopupMenu.Directory.Delete"));
        miDel.addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent e) {
                if (!readOnly) {
                    TreeItem ti = wTree.getSelection()[0];
                    String[] str = ConstUI.getTreeStrings(ti);
                    RepositoryDirectoryInterface dir = repositoryTree.findDirectory(str);
                    if (dir != null) {
                        try {
                            rep.deleteRepositoryDirectory(dir);
                            ti.dispose();
                        } catch (KettleException exception) {
                            new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryExplorerDialog.Directory.Delete.ErrorRemoving.Title"), BaseMessages.getString(PKG, "RepositoryExplorerDialog.Directory.Delete.ErrorRemoving.Message1"), exception);
                        }
                    }
                }
            }
        });
    }
    wTree.setMenu(mTree);
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleException(org.pentaho.di.core.exception.KettleException) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) TreeItem(org.eclipse.swt.widgets.TreeItem) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) MenuItem(org.eclipse.swt.widgets.MenuItem) EnterStringDialog(org.pentaho.di.ui.core.dialog.EnterStringDialog) KettleException(org.pentaho.di.core.exception.KettleException) MessageBox(org.eclipse.swt.widgets.MessageBox) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu)

Example 57 with RepositoryDirectory

use of org.pentaho.di.repository.RepositoryDirectory in project pentaho-kettle by pentaho.

the class SelectObjectDialog method refreshTree.

private void refreshTree() {
    try {
        wTree.removeAll();
        TreeItem ti = null;
        // display that on the UI otherwise we will hide it
        if (directoryTree.isRoot() && directoryTree.isVisible()) {
            ti = new TreeItem(wTree, SWT.NONE);
            ti.setImage(GUIResource.getInstance().getImageFolder());
            ti.setExpanded(true);
            RepositoryDirectoryUI.getTreeWithNames(ti, rep, dircolor, sortColumn, includeDeleted, ascending, showTrans, showJobs, directoryTree, filterString, pattern);
        } else {
            for (int i = 0; i < directoryTree.getNrSubdirectories(); i++) {
                RepositoryDirectory subdir = directoryTree.getSubdirectory(i);
                ti = new TreeItem(wTree, SWT.NONE);
                ti.setImage(GUIResource.getInstance().getImageFolder());
                RepositoryDirectoryUI.getTreeWithNames(ti, rep, dircolor, sortColumn, includeDeleted, ascending, showTrans, showJobs, subdir, filterString, pattern);
            }
        }
    } catch (KettleException e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "SelectObjectDialog.Dialog.UnexpectedError.Title"), BaseMessages.getString(PKG, "SelectObjectDialog.Dialog.UnexpectedError.Message"), e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) TreeItem(org.eclipse.swt.widgets.TreeItem) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog)

Aggregations

RepositoryDirectory (org.pentaho.di.repository.RepositoryDirectory)57 KettleException (org.pentaho.di.core.exception.KettleException)23 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)15 Test (org.junit.Test)14 TransMeta (org.pentaho.di.trans.TransMeta)11 LongObjectId (org.pentaho.di.repository.LongObjectId)10 ObjectId (org.pentaho.di.repository.ObjectId)9 KettleFileException (org.pentaho.di.core.exception.KettleFileException)8 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)8 Repository (org.pentaho.di.repository.Repository)8 RepositoryElementMetaInterface (org.pentaho.di.repository.RepositoryElementMetaInterface)8 ArrayList (java.util.ArrayList)7 StringObjectId (org.pentaho.di.repository.StringObjectId)7 FileSystemException (org.apache.commons.vfs2.FileSystemException)6 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)6 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)6 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)6 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)5 JobMeta (org.pentaho.di.job.JobMeta)5 TreeItem (org.eclipse.swt.widgets.TreeItem)4