Search in sources :

Example 1 with FileDialogOperation

use of org.pentaho.di.ui.core.FileDialogOperation in project pentaho-kettle by pentaho.

the class RepositoryOpenSaveExtensionPoint method callExtensionPoint.

@Override
public void callExtensionPoint(LogChannelInterface logChannelInterface, Object o) throws KettleException {
    FileDialogOperation fileDialogOperation = (FileDialogOperation) o;
    PropsUI propsUI = propsUISupplier.get();
    String startingDir = null;
    if (fileDialogOperation.getRepository() == null) {
        String username = getRepository().getUserInfo() != null ? getRepository().getUserInfo().getLogin() : "";
        String repoAndUser = getRepository().getName() + ":" + username;
        List<LastUsedFile> lastUsedFileList = propsUI.getLastUsedRepoFiles().getOrDefault(repoAndUser, Collections.emptyList());
        startingDir = getStartingDir(fileDialogOperation, lastUsedFileList);
    } else {
        startingDir = fileDialogOperation.getStartDir();
    }
    RepositoryOpenSaveDialog repositoryOpenSaveDialog = new RepositoryOpenSaveDialog(spoonSupplier.get().getShell(), WIDTH, HEIGHT);
    repositoryOpenSaveDialog.open(fileDialogOperation.getRepository(), startingDir, fileDialogOperation.getCommand(), fileDialogOperation.getTitle(), fileDialogOperation.getFilter(), fileDialogOperation.getOrigin(), fileDialogOperation.getFilename(), fileDialogOperation.getFileType());
    if (!Utils.isEmpty(repositoryOpenSaveDialog.getObjectName())) {
        RepositoryObject repositoryObject = new RepositoryObject();
        repositoryObject.setObjectId(repositoryOpenSaveDialog::getObjectId);
        repositoryObject.setName(repositoryOpenSaveDialog.getObjectName());
        repositoryObject.setRepositoryDirectory(getRepository().findDirectory(repositoryOpenSaveDialog.getObjectDirectory()));
        repositoryObject.setObjectType(repositoryOpenSaveDialog.getObjectType().equals(TRANSFORMATION) ? RepositoryObjectType.TRANSFORMATION : RepositoryObjectType.JOB);
        fileDialogOperation.setRepositoryObject(repositoryObject);
    }
}
Also used : RepositoryObject(org.pentaho.di.repository.RepositoryObject) RepositoryOpenSaveDialog(org.pentaho.repo.dialog.RepositoryOpenSaveDialog) LastUsedFile(org.pentaho.di.core.LastUsedFile) FileDialogOperation(org.pentaho.di.ui.core.FileDialogOperation) PropsUI(org.pentaho.di.ui.core.PropsUI)

Example 2 with FileDialogOperation

use of org.pentaho.di.ui.core.FileDialogOperation in project pentaho-kettle by pentaho.

the class Spoon method saveToRepository.

public boolean saveToRepository(EngineMetaInterface meta, boolean ask_name) throws KettleException {
    if (log.isDetailed()) {
        // "Save to repository..."
        // 
        log.logDetailed(BaseMessages.getString(PKG, "Spoon.Log.SaveToRepository"));
    }
    if (rep != null) {
        // If the repository directory is root then get the default save directory
        if (meta.getRepositoryDirectory() == null || meta.getRepositoryDirectory().isRoot()) {
            meta.setRepositoryDirectory(rep.getDefaultSaveDirectory(meta));
        }
        if (ask_name) {
            try {
                String fileType = meta.getFileType().equals(LastUsedFile.FILE_TYPE_TRANSFORMATION) ? FileDialogOperation.TRANSFORMATION : FileDialogOperation.JOB;
                FileDialogOperation fileDialogOperation = new FileDialogOperation(FileDialogOperation.SAVE, FileDialogOperation.ORIGIN_SPOON);
                fileDialogOperation.setFileType(fileType);
                fileDialogOperation.setStartDir(meta.getRepositoryDirectory().getPath());
                // Set the filename so it can be used as the default filename in the save dialog
                fileDialogOperation.setFilename(meta.getFilename());
                ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.SpoonOpenSaveRepository.id, fileDialogOperation);
                if (fileDialogOperation.getRepositoryObject() != null) {
                    RepositoryObject repositoryObject = (RepositoryObject) fileDialogOperation.getRepositoryObject();
                    meta.setRepositoryDirectory(repositoryObject.getRepositoryDirectory());
                    meta.setName(repositoryObject.getName());
                    delegates.tabs.renameTabs();
                    return saveToRepositoryConfirmed(meta);
                }
            } catch (KettleException ke) {
            // Ignore
            }
        } else {
            return saveToRepositoryConfirmed(meta);
        }
    } else {
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
        // "There is no repository connection available."
        mb.setMessage(BaseMessages.getString(PKG, "Spoon.Dialog.NoRepositoryConnection.Message"));
        // "No repository available."
        mb.setText(BaseMessages.getString(PKG, "Spoon.Dialog.NoRepositoryConnection.Title"));
        mb.open();
    }
    return false;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RepositoryObject(org.pentaho.di.repository.RepositoryObject) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) FileDialogOperation(org.pentaho.di.ui.core.FileDialogOperation) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 3 with FileDialogOperation

use of org.pentaho.di.ui.core.FileDialogOperation in project pentaho-kettle by pentaho.

the class JobEntryExportRepositoryDialog method displaydirectoryList.

private void displaydirectoryList() {
    RepositoriesMeta repositoriesMeta = null;
    RepositoryMeta repositoryMeta = null;
    Repository repos = null;
    try {
        repositoriesMeta = new RepositoriesMeta();
        repositoriesMeta.readData();
        repositoryMeta = repositoriesMeta.findRepository(jobMeta.environmentSubstitute(wRepositoryname.getText()));
        if (repositoryMeta == null) {
            // Can not find repository
            displayMsg(BaseMessages.getString(PKG, "JobExportRepository.Error.CanNotFindRep"), BaseMessages.getString(PKG, "JobExportRepository.Error.CanNotFindRepMsg", wRepositoryname.getText()), true);
        }
        repos = PluginRegistry.getInstance().loadClass(RepositoryPluginType.class, repositoryMeta, Repository.class);
        repos.init(repositoryMeta);
        try {
            repos.connect(jobMeta.environmentSubstitute(wUserName.getText()), jobMeta.environmentSubstitute(wPassword.getText()));
        } catch (Exception e) {
            displayMsg(BaseMessages.getString(PKG, "JobExportRepository.Error.CanNotConnect"), BaseMessages.getString(PKG, "JobExportRepository.Error.CanNotConnectMsg", wRepositoryname.getText()), true);
        }
        if (repos.isConnected()) {
            try {
                FileDialogOperation fileDialogOperation = new FileDialogOperation(FileDialogOperation.SELECT_FOLDER, FileDialogOperation.ORIGIN_SPOON);
                fileDialogOperation.setTitle(BaseMessages.getString(PKG, "JobExportRepository.SelectDirectoryDialog.Title"));
                fileDialogOperation.setFilter(null);
                fileDialogOperation.setRepository(repos);
                if (!Utils.isEmpty(wFoldername.getText())) {
                    fileDialogOperation.setStartDir(wFoldername.getText());
                }
                ExtensionPointHandler.callExtensionPoint(null, KettleExtensionPoint.SpoonOpenSaveRepository.id, fileDialogOperation);
                if (fileDialogOperation.getRepositoryObject() != null) {
                    String path = ((RepositoryObject) fileDialogOperation.getRepositoryObject()).getRepositoryDirectory().getPath();
                    wFoldername.setText(path);
                }
            } catch (KettleException e) {
            // Do Nothing
            }
        }
    } catch (Exception e) {
        displayMsg(BaseMessages.getString(PKG, "System.Dialog.Error.Title"), BaseMessages.getString(PKG, "JobExportRepository.ErrorGettingFolderds.DialogMessage") + Const.CR + ":" + e.getMessage(), true);
    } finally {
        if (repos != null) {
            repos.disconnect();
            repos = null;
        }
        if (repositoryMeta != null) {
            repositoryMeta = null;
        }
        repositoriesMeta.clear();
    }
}
Also used : RepositoryMeta(org.pentaho.di.repository.RepositoryMeta) KettleException(org.pentaho.di.core.exception.KettleException) JobEntryExportRepository(org.pentaho.di.job.entries.exportrepository.JobEntryExportRepository) Repository(org.pentaho.di.repository.Repository) RepositoryPluginType(org.pentaho.di.core.plugins.RepositoryPluginType) RepositoriesMeta(org.pentaho.di.repository.RepositoriesMeta) KettleException(org.pentaho.di.core.exception.KettleException) FileDialogOperation(org.pentaho.di.ui.core.FileDialogOperation)

Example 4 with FileDialogOperation

use of org.pentaho.di.ui.core.FileDialogOperation in project pentaho-kettle by pentaho.

the class DialogHelper method selectRepositoryObject.

public static RepositoryObject selectRepositoryObject(String filter, LogChannel log) {
    try {
        FileDialogOperation fileDialogOperation = new FileDialogOperation(FileDialogOperation.OPEN, FileDialogOperation.ORIGIN_OTHER);
        if (!Utils.isEmpty(filter)) {
            fileDialogOperation.setFilter(filter);
        }
        ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.SpoonOpenSaveRepository.id, fileDialogOperation);
        return (RepositoryObject) fileDialogOperation.getRepositoryObject();
    } catch (KettleException ke) {
    // Ignore
    }
    return null;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RepositoryObject(org.pentaho.di.repository.RepositoryObject) FileDialogOperation(org.pentaho.di.ui.core.FileDialogOperation)

Example 5 with FileDialogOperation

use of org.pentaho.di.ui.core.FileDialogOperation in project pentaho-kettle by pentaho.

the class Spoon method openFile.

public void openFile(boolean importfile) {
    try {
        SpoonPerspective activePerspective = SpoonPerspectiveManager.getInstance().getActivePerspective();
        // 
        if (!importfile) {
            if (activePerspective instanceof SpoonPerspectiveOpenSaveInterface) {
                ((SpoonPerspectiveOpenSaveInterface) activePerspective).open();
                return;
            }
        }
        String activePerspectiveId = activePerspective.getId();
        boolean etlPerspective = activePerspectiveId.equals(MainSpoonPerspective.ID);
        if (rep == null || importfile || !etlPerspective) {
            // Load from XML
            FileDialog dialog = new FileDialog(shell, SWT.OPEN);
            LinkedHashSet<String> extensions = new LinkedHashSet<>();
            LinkedHashSet<String> extensionNames = new LinkedHashSet<>();
            StringBuilder allExtensions = new StringBuilder();
            for (FileListener l : fileListeners) {
                for (String ext : l.getSupportedExtensions()) {
                    extensions.add("*." + ext);
                    allExtensions.append("*.").append(ext).append(";");
                }
                Collections.addAll(extensionNames, l.getFileTypeDisplayNames(Locale.getDefault()));
            }
            extensions.add("*");
            extensionNames.add(BaseMessages.getString(PKG, "Spoon.Dialog.OpenFile.AllFiles"));
            String[] exts = new String[extensions.size() + 1];
            exts[0] = allExtensions.toString();
            System.arraycopy(extensions.toArray(new String[extensions.size()]), 0, exts, 1, extensions.size());
            String[] extNames = new String[extensionNames.size() + 1];
            extNames[0] = BaseMessages.getString(PKG, "Spoon.Dialog.OpenFile.AllTypes");
            System.arraycopy(extensionNames.toArray(new String[extensionNames.size()]), 0, extNames, 1, extensionNames.size());
            dialog.setFilterExtensions(exts);
            setFilterPath(dialog);
            String filename = dialog.open();
            if (filename != null) {
                if (importfile) {
                    if (activePerspective instanceof SpoonPerspectiveOpenSaveInterface) {
                        ((SpoonPerspectiveOpenSaveInterface) activePerspective).importFile(filename);
                        return;
                    }
                }
                lastDirOpened = dialog.getFilterPath();
                openFile(filename, importfile);
            }
        } else {
            try {
                FileDialogOperation fileDialogOperation = new FileDialogOperation(FileDialogOperation.OPEN, FileDialogOperation.ORIGIN_SPOON);
                ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.SpoonOpenSaveRepository.id, fileDialogOperation);
                if (fileDialogOperation.getRepositoryObject() != null) {
                    RepositoryObject repositoryObject = (RepositoryObject) fileDialogOperation.getRepositoryObject();
                    loadObjectFromRepository(repositoryObject.getObjectId(), repositoryObject.getObjectType(), null);
                }
            } catch (Exception e) {
            // Ignore
            }
        }
    } catch (KettleRepositoryLostException krle) {
        new ErrorDialog(getShell(), BaseMessages.getString(PKG, "Spoon.Error"), krle.getPrefaceMessage(), krle);
        this.closeRepository();
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) RepositoryObject(org.pentaho.di.repository.RepositoryObject) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) KettleRepositoryLostException(org.pentaho.di.repository.KettleRepositoryLostException) SWTException(org.eclipse.swt.SWTException) KettleRowException(org.pentaho.di.core.exception.KettleRowException) FileSystemException(org.apache.commons.vfs2.FileSystemException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleAuthException(org.pentaho.di.core.exception.KettleAuthException) KettleRepositoryLostException(org.pentaho.di.repository.KettleRepositoryLostException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) LifecycleException(org.pentaho.di.core.lifecycle.LifecycleException) KettleMissingPluginsException(org.pentaho.di.core.exception.KettleMissingPluginsException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) KettleException(org.pentaho.di.core.exception.KettleException) MalformedURLException(java.net.MalformedURLException) KettlePropertiesFileDialog(org.pentaho.di.ui.core.dialog.KettlePropertiesFileDialog) FileDialog(org.eclipse.swt.widgets.FileDialog) FileDialogOperation(org.pentaho.di.ui.core.FileDialogOperation)

Aggregations

FileDialogOperation (org.pentaho.di.ui.core.FileDialogOperation)5 KettleException (org.pentaho.di.core.exception.KettleException)4 RepositoryObject (org.pentaho.di.repository.RepositoryObject)4 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)2 MalformedURLException (java.net.MalformedURLException)1 LinkedHashSet (java.util.LinkedHashSet)1 FileSystemException (org.apache.commons.vfs2.FileSystemException)1 SWTException (org.eclipse.swt.SWTException)1 FileDialog (org.eclipse.swt.widgets.FileDialog)1 MessageBox (org.eclipse.swt.widgets.MessageBox)1 LastUsedFile (org.pentaho.di.core.LastUsedFile)1 KettleAuthException (org.pentaho.di.core.exception.KettleAuthException)1 KettleFileException (org.pentaho.di.core.exception.KettleFileException)1 KettleMissingPluginsException (org.pentaho.di.core.exception.KettleMissingPluginsException)1 KettleRowException (org.pentaho.di.core.exception.KettleRowException)1 KettleValueException (org.pentaho.di.core.exception.KettleValueException)1 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)1 LifecycleException (org.pentaho.di.core.lifecycle.LifecycleException)1 RepositoryPluginType (org.pentaho.di.core.plugins.RepositoryPluginType)1 JobEntryExportRepository (org.pentaho.di.job.entries.exportrepository.JobEntryExportRepository)1