Search in sources :

Example 16 with VfsFileChooserDialog

use of org.pentaho.vfs.ui.VfsFileChooserDialog in project pentaho-kettle by pentaho.

the class VfsFileChooserControls method browseForFileInputPath.

protected void browseForFileInputPath() {
    try {
        String path = space.environmentSubstitute(wPath.getText());
        VfsFileChooserDialog fileChooserDialog;
        String fileName;
        if (path == null || path.length() == 0) {
            fileChooserDialog = getVfsFileChooserDialog(null, null);
            fileName = selectedVFSScheme.scheme + "://";
        } else {
            FileObject initialFile = getInitialFile(wPath.getText());
            FileObject rootFile = initialFile.getFileSystem().getRoot();
            fileChooserDialog = getVfsFileChooserDialog(rootFile, initialFile);
            fileName = null;
        }
        FileObject selectedFile = fileChooserDialog.open(getParent().getShell(), null, selectedVFSScheme.scheme, true, fileName, FILES_FILTERS, fileFilterNames, true, VfsFileChooserDialog.VFS_DIALOG_OPEN_FILE_OR_DIRECTORY, true, true);
        if (selectedFile != null) {
            String filePath = selectedFile.getURL().toString();
            if (!DEFAULT_LOCAL_PATH.equals(filePath)) {
                wPath.setText(filePath);
                updateLocation();
            }
        }
    } catch (KettleFileException | FileSystemException ex) {
        log.logError(ex.getMessage());
    }
}
Also used : KettleFileException(org.pentaho.di.core.exception.KettleFileException) FileSystemException(org.apache.commons.vfs2.FileSystemException) VfsFileChooserDialog(org.pentaho.vfs.ui.VfsFileChooserDialog) FileObject(org.apache.commons.vfs2.FileObject)

Example 17 with VfsFileChooserDialog

use of org.pentaho.vfs.ui.VfsFileChooserDialog in project pentaho-kettle by pentaho.

the class SimpleMappingDialog method selectFileTrans.

private void selectFileTrans() {
    String curFile = transMeta.environmentSubstitute(wPath.getText());
    FileObject root = null;
    String parentFolder = null;
    try {
        parentFolder = KettleVFS.getFileObject(transMeta.environmentSubstitute(transMeta.getFilename())).getParent().toString();
    } catch (Exception e) {
    // Take no action
    }
    try {
        root = KettleVFS.getFileObject(curFile != null ? curFile : Const.getUserHomeDirectory());
        VfsFileChooserDialog vfsFileChooser = Spoon.getInstance().getVfsFileChooserDialog(root.getParent(), root);
        FileObject file = vfsFileChooser.open(shell, null, Const.STRING_TRANS_FILTER_EXT, Const.getTransformationFilterNames(), VfsFileChooserDialog.VFS_DIALOG_OPEN_FILE);
        if (file == null) {
            return;
        }
        String fileName = file.getName().toString();
        if (fileName != null) {
            loadFileTrans(fileName);
            if (parentFolder != null && fileName.startsWith(parentFolder)) {
                fileName = fileName.replace(parentFolder, "${" + Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY + "}");
            }
            wPath.setText(fileName);
            specificationMethod = ObjectLocationSpecificationMethod.FILENAME;
        }
    } catch (IOException | KettleException e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "SimpleMappingDialog.ErrorLoadingTransformation.DialogTitle"), BaseMessages.getString(PKG, "SimpleMappingDialog.ErrorLoadingTransformation.DialogMessage"), e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) VfsFileChooserDialog(org.pentaho.vfs.ui.VfsFileChooserDialog) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) FileObject(org.apache.commons.vfs2.FileObject) IOException(java.io.IOException) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException)

Aggregations

VfsFileChooserDialog (org.pentaho.vfs.ui.VfsFileChooserDialog)17 FileObject (org.apache.commons.vfs2.FileObject)13 KettleException (org.pentaho.di.core.exception.KettleException)9 IOException (java.io.IOException)8 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)8 FileSystemException (org.apache.commons.vfs2.FileSystemException)5 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 ModifyEvent (org.eclipse.swt.events.ModifyEvent)3 ModifyListener (org.eclipse.swt.events.ModifyListener)3 ShellAdapter (org.eclipse.swt.events.ShellAdapter)3 ShellEvent (org.eclipse.swt.events.ShellEvent)3 FormAttachment (org.eclipse.swt.layout.FormAttachment)3 FormData (org.eclipse.swt.layout.FormData)3 FormLayout (org.eclipse.swt.layout.FormLayout)3 Button (org.eclipse.swt.widgets.Button)3 Display (org.eclipse.swt.widgets.Display)3 Event (org.eclipse.swt.widgets.Event)3 Label (org.eclipse.swt.widgets.Label)3 Listener (org.eclipse.swt.widgets.Listener)3