Search in sources :

Example 11 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)

Example 12 with VfsFileChooserDialog

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

the class BaseStreamingDialog method selectFile.

protected Optional<String> selectFile(TextVar fileWidget, String[] fileFilters) {
    String curFile = transMeta.environmentSubstitute(fileWidget.getText());
    FileObject root = null;
    try {
        root = KettleVFS.getFileObject(curFile != null ? curFile : Const.getUserHomeDirectory());
        VfsFileChooserDialog vfsFileChooser = Spoon.getInstance().getVfsFileChooserDialog(root.getParent(), root);
        FileObject file = vfsFileChooser.open(shell, null, fileFilters, Const.getTransformationFilterNames(), VfsFileChooserDialog.VFS_DIALOG_OPEN_FILE);
        if (file == null) {
            return Optional.empty();
        }
        String filePath = getRelativePath(file.getName().toString());
        fileWidget.setText(filePath);
        return Optional.ofNullable(filePath);
    } catch (IOException | KettleException e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "TransExecutorDialog.ErrorLoadingTransformation.DialogTitle"), BaseMessages.getString(PKG, "TransExecutorDialog.ErrorLoadingTransformation.DialogMessage"), e);
    }
    return Optional.empty();
}
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)

Example 13 with VfsFileChooserDialog

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

the class JobExecutorDialog method selectFileJob.

private void selectFileJob() {
    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_JOB_FILTER_EXT, Const.getJobFilterNames(), VfsFileChooserDialog.VFS_DIALOG_OPEN_FILE);
        if (file == null) {
            return;
        }
        String fileName = file.getName().toString();
        if (fileName != null) {
            loadFileJob(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, "JobExecutorDialog.ErrorLoadingJobformation.DialogTitle"), BaseMessages.getString(PKG, "JobExecutorDialog.ErrorLoadingJobformation.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)

Example 14 with VfsFileChooserDialog

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

the class JobEntryPGPVerifyDialog method open.

public JobEntryInterface open() {
    Shell parent = getParent();
    Display display = parent.getDisplay();
    shell = new Shell(parent, props.getJobsDialogStyle());
    props.setLook(shell);
    JobDialog.setShellImage(shell, jobEntry);
    ModifyListener lsMod = new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            jobEntry.setChanged();
        }
    };
    changed = jobEntry.hasChanged();
    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = Const.FORM_MARGIN;
    formLayout.marginHeight = Const.FORM_MARGIN;
    shell.setLayout(formLayout);
    shell.setText(BaseMessages.getString(PKG, "JobPGPVerify.Title"));
    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    // GPGLocation line
    wlName = new Label(shell, SWT.RIGHT);
    wlName.setText(BaseMessages.getString(PKG, "JobPGPVerify.Name.Label"));
    props.setLook(wlName);
    fdlName = new FormData();
    fdlName.left = new FormAttachment(0, 0);
    fdlName.right = new FormAttachment(middle, -margin);
    fdlName.top = new FormAttachment(0, margin);
    wlName.setLayoutData(fdlName);
    wName = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wName);
    wName.addModifyListener(lsMod);
    fdName = new FormData();
    fdName.left = new FormAttachment(middle, 0);
    fdName.top = new FormAttachment(0, margin);
    fdName.right = new FormAttachment(100, 0);
    wName.setLayoutData(fdName);
    // ////////////////////////
    // START OF SERVER SETTINGS GROUP///
    // /
    wSettings = new Group(shell, SWT.SHADOW_NONE);
    props.setLook(wSettings);
    wSettings.setText(BaseMessages.getString(PKG, "JobPGPVerify.Settings.Group.Label"));
    FormLayout SettingsgroupLayout = new FormLayout();
    SettingsgroupLayout.marginWidth = 10;
    SettingsgroupLayout.marginHeight = 10;
    wSettings.setLayout(SettingsgroupLayout);
    // GPGLocation line
    wlGPGLocation = new Label(wSettings, SWT.RIGHT);
    wlGPGLocation.setText(BaseMessages.getString(PKG, "JobPGPVerify.GPGLocation.Label"));
    props.setLook(wlGPGLocation);
    fdlGPGLocation = new FormData();
    fdlGPGLocation.left = new FormAttachment(0, 0);
    fdlGPGLocation.top = new FormAttachment(wName, margin);
    fdlGPGLocation.right = new FormAttachment(middle, -margin);
    wlGPGLocation.setLayoutData(fdlGPGLocation);
    wbGPGLocation = new Button(wSettings, SWT.PUSH | SWT.CENTER);
    props.setLook(wbGPGLocation);
    wbGPGLocation.setText(BaseMessages.getString(PKG, "System.Button.Browse"));
    fdbGPGLocation = new FormData();
    fdbGPGLocation.right = new FormAttachment(100, 0);
    fdbGPGLocation.top = new FormAttachment(wName, 0);
    wbGPGLocation.setLayoutData(fdbGPGLocation);
    wGPGLocation = new TextVar(jobMeta, wSettings, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wGPGLocation);
    wGPGLocation.addModifyListener(lsMod);
    fdGPGLocation = new FormData();
    fdGPGLocation.left = new FormAttachment(middle, 0);
    fdGPGLocation.top = new FormAttachment(wName, margin);
    fdGPGLocation.right = new FormAttachment(wbGPGLocation, -margin);
    wGPGLocation.setLayoutData(fdGPGLocation);
    // Filename line
    wlFilename = new Label(wSettings, SWT.RIGHT);
    wlFilename.setText(BaseMessages.getString(PKG, "JobPGPVerify.Filename.Label"));
    props.setLook(wlFilename);
    fdlFilename = new FormData();
    fdlFilename.left = new FormAttachment(0, 0);
    fdlFilename.top = new FormAttachment(wGPGLocation, margin);
    fdlFilename.right = new FormAttachment(middle, -margin);
    wlFilename.setLayoutData(fdlFilename);
    wbFilename = new Button(wSettings, SWT.PUSH | SWT.CENTER);
    props.setLook(wbFilename);
    wbFilename.setText(BaseMessages.getString(PKG, "System.Button.Browse"));
    fdbFilename = new FormData();
    fdbFilename.right = new FormAttachment(100, 0);
    fdbFilename.top = new FormAttachment(wGPGLocation, 0);
    wbFilename.setLayoutData(fdbFilename);
    wFilename = new TextVar(jobMeta, wSettings, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wFilename);
    wFilename.addModifyListener(lsMod);
    fdFilename = new FormData();
    fdFilename.left = new FormAttachment(middle, 0);
    fdFilename.top = new FormAttachment(wGPGLocation, margin);
    fdFilename.right = new FormAttachment(wbFilename, -margin);
    wFilename.setLayoutData(fdFilename);
    wluseDetachedSignature = new Label(wSettings, SWT.RIGHT);
    wluseDetachedSignature.setText(BaseMessages.getString(PKG, "JobPGPVerify.useDetachedSignature.Label"));
    props.setLook(wluseDetachedSignature);
    fdluseDetachedSignature = new FormData();
    fdluseDetachedSignature.left = new FormAttachment(0, 0);
    fdluseDetachedSignature.top = new FormAttachment(wFilename, margin);
    fdluseDetachedSignature.right = new FormAttachment(middle, -margin);
    wluseDetachedSignature.setLayoutData(fdluseDetachedSignature);
    wuseDetachedSignature = new Button(wSettings, SWT.CHECK);
    props.setLook(wuseDetachedSignature);
    wuseDetachedSignature.setToolTipText(BaseMessages.getString(PKG, "JobPGPVerify.useDetachedSignature.Tooltip"));
    fduseDetachedSignature = new FormData();
    fduseDetachedSignature.left = new FormAttachment(middle, 0);
    fduseDetachedSignature.top = new FormAttachment(wFilename, margin);
    fduseDetachedSignature.right = new FormAttachment(100, -margin);
    wuseDetachedSignature.setLayoutData(fduseDetachedSignature);
    wuseDetachedSignature.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            enableDetachedSignature();
        }
    });
    // DetachedFilename line
    wlDetachedFilename = new Label(wSettings, SWT.RIGHT);
    wlDetachedFilename.setText(BaseMessages.getString(PKG, "JobPGPVerify.DetachedFilename.Label"));
    props.setLook(wlDetachedFilename);
    fdlDetachedFilename = new FormData();
    fdlDetachedFilename.left = new FormAttachment(0, 0);
    fdlDetachedFilename.top = new FormAttachment(wuseDetachedSignature, margin);
    fdlDetachedFilename.right = new FormAttachment(middle, -margin);
    wlDetachedFilename.setLayoutData(fdlDetachedFilename);
    wbDetachedFilename = new Button(wSettings, SWT.PUSH | SWT.CENTER);
    props.setLook(wbDetachedFilename);
    wbDetachedFilename.setText(BaseMessages.getString(PKG, "System.Button.Browse"));
    fdbDetachedFilename = new FormData();
    fdbDetachedFilename.right = new FormAttachment(100, 0);
    fdbDetachedFilename.top = new FormAttachment(wuseDetachedSignature, 0);
    wbDetachedFilename.setLayoutData(fdbDetachedFilename);
    wDetachedFilename = new TextVar(jobMeta, wSettings, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wDetachedFilename);
    wDetachedFilename.addModifyListener(lsMod);
    fdDetachedFilename = new FormData();
    fdDetachedFilename.left = new FormAttachment(middle, 0);
    fdDetachedFilename.top = new FormAttachment(wuseDetachedSignature, margin);
    fdDetachedFilename.right = new FormAttachment(wbDetachedFilename, -margin);
    wDetachedFilename.setLayoutData(fdDetachedFilename);
    // Whenever something changes, set the tooltip to the expanded version:
    wDetachedFilename.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            wDetachedFilename.setToolTipText(jobMeta.environmentSubstitute(wDetachedFilename.getText()));
        }
    });
    wbDetachedFilename.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            try {
                FileObject DetachedFilename = null;
                try {
                    String curFile = wDetachedFilename.getText();
                    if (curFile.trim().length() > 0) {
                        DetachedFilename = KettleVFS.getInstance().getFileSystemManager().resolveFile(jobMeta.environmentSubstitute(wDetachedFilename.getText()));
                    } else {
                        DetachedFilename = KettleVFS.getInstance().getFileSystemManager().resolveFile(Const.getUserHomeDirectory());
                    }
                } catch (FileSystemException ex) {
                    DetachedFilename = KettleVFS.getInstance().getFileSystemManager().resolveFile(Const.getUserHomeDirectory());
                }
                VfsFileChooserDialog vfsFileChooser = Spoon.getInstance().getVfsFileChooserDialog(DetachedFilename.getParent(), DetachedFilename);
                FileObject selected = vfsFileChooser.open(shell, null, EXTENSIONS, FILETYPES, VfsFileChooserDialog.VFS_DIALOG_OPEN_FILE);
                wDetachedFilename.setText(selected != null ? selected.getURL().toString() : Const.EMPTY_STRING);
            } catch (FileSystemException ex) {
                ex.printStackTrace();
            }
        }
    });
    // Whenever something changes, set the tooltip to the expanded version:
    wFilename.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            wFilename.setToolTipText(jobMeta.environmentSubstitute(wFilename.getText()));
        }
    });
    wbFilename.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            try {
                FileObject fileName = null;
                try {
                    String curFile = wFilename.getText();
                    if (curFile.trim().length() > 0) {
                        fileName = KettleVFS.getInstance().getFileSystemManager().resolveFile(jobMeta.environmentSubstitute(wFilename.getText()));
                    } else {
                        fileName = KettleVFS.getInstance().getFileSystemManager().resolveFile(Const.getUserHomeDirectory());
                    }
                } catch (FileSystemException ex) {
                    fileName = KettleVFS.getInstance().getFileSystemManager().resolveFile(Const.getUserHomeDirectory());
                }
                VfsFileChooserDialog vfsFileChooser = Spoon.getInstance().getVfsFileChooserDialog(fileName.getParent(), fileName);
                FileObject selected = vfsFileChooser.open(shell, null, EXTENSIONS, FILETYPES, VfsFileChooserDialog.VFS_DIALOG_OPEN_FILE);
                wFilename.setText(selected != null ? selected.getURL().toString() : Const.EMPTY_STRING);
            } catch (FileSystemException ex) {
                ex.printStackTrace();
            }
        }
    });
    // Whenever something changes, set the tooltip to the expanded version:
    wGPGLocation.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            wGPGLocation.setToolTipText(jobMeta.environmentSubstitute(wGPGLocation.getText()));
        }
    });
    wbGPGLocation.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            try {
                FileObject fileName = null;
                try {
                    String curFile = wGPGLocation.getText();
                    if (curFile.trim().length() > 0) {
                        fileName = KettleVFS.getInstance().getFileSystemManager().resolveFile(jobMeta.environmentSubstitute(wGPGLocation.getText()));
                    } else {
                        fileName = KettleVFS.getInstance().getFileSystemManager().resolveFile(Const.getUserHomeDirectory());
                    }
                } catch (FileSystemException ex) {
                    fileName = KettleVFS.getInstance().getFileSystemManager().resolveFile(Const.getUserHomeDirectory());
                }
                VfsFileChooserDialog vfsFileChooser = Spoon.getInstance().getVfsFileChooserDialog(fileName.getParent(), fileName);
                FileObject selected = vfsFileChooser.open(shell, null, EXTENSIONS, FILETYPES, VfsFileChooserDialog.VFS_DIALOG_OPEN_FILE);
                wGPGLocation.setText(selected != null ? selected.getURL().toString() : Const.EMPTY_STRING);
            } catch (FileSystemException ex) {
                ex.printStackTrace();
            }
        }
    });
    fdSettings = new FormData();
    fdSettings.left = new FormAttachment(0, margin);
    fdSettings.top = new FormAttachment(wName, margin);
    fdSettings.right = new FormAttachment(100, -margin);
    wSettings.setLayoutData(fdSettings);
    // ///////////////////////////////////////////////////////////
    // / END OF Advanced SETTINGS GROUP
    // ///////////////////////////////////////////////////////////
    wOK = new Button(shell, SWT.PUSH);
    wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
    FormData fd = new FormData();
    fd.right = new FormAttachment(50, -10);
    fd.bottom = new FormAttachment(100, 0);
    fd.width = 100;
    wOK.setLayoutData(fd);
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
    fd = new FormData();
    fd.left = new FormAttachment(50, 10);
    fd.bottom = new FormAttachment(100, 0);
    fd.width = 100;
    wCancel.setLayoutData(fd);
    BaseStepDialog.positionBottomButtons(shell, new Button[] { wOK, wCancel }, margin, wSettings);
    // Add listeners
    lsCancel = new Listener() {

        public void handleEvent(Event e) {
            cancel();
        }
    };
    lsOK = new Listener() {

        public void handleEvent(Event e) {
            ok();
        }
    };
    wCancel.addListener(SWT.Selection, lsCancel);
    wOK.addListener(SWT.Selection, lsOK);
    lsDef = new SelectionAdapter() {

        public void widgetDefaultSelected(SelectionEvent e) {
            ok();
        }
    };
    wName.addSelectionListener(lsDef);
    wGPGLocation.addSelectionListener(lsDef);
    // Detect X or ALT-F4 or something that kills this window...
    shell.addShellListener(new ShellAdapter() {

        public void shellClosed(ShellEvent e) {
            cancel();
        }
    });
    getData();
    enableDetachedSignature();
    BaseStepDialog.setSize(shell);
    shell.open();
    props.setDialogSize(shell, "JobPGPVerifyDialogSize");
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    return jobEntry;
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) Group(org.eclipse.swt.widgets.Group) ShellAdapter(org.eclipse.swt.events.ShellAdapter) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) ShellEvent(org.eclipse.swt.events.ShellEvent) Text(org.eclipse.swt.widgets.Text) TextVar(org.pentaho.di.ui.core.widget.TextVar) Shell(org.eclipse.swt.widgets.Shell) ModifyEvent(org.eclipse.swt.events.ModifyEvent) FileSystemException(org.apache.commons.vfs2.FileSystemException) Button(org.eclipse.swt.widgets.Button) VfsFileChooserDialog(org.pentaho.vfs.ui.VfsFileChooserDialog) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Event(org.eclipse.swt.widgets.Event) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ShellEvent(org.eclipse.swt.events.ShellEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FileObject(org.apache.commons.vfs2.FileObject) FormAttachment(org.eclipse.swt.layout.FormAttachment) Display(org.eclipse.swt.widgets.Display)

Aggregations

VfsFileChooserDialog (org.pentaho.vfs.ui.VfsFileChooserDialog)14 FileObject (org.apache.commons.vfs2.FileObject)11 KettleException (org.pentaho.di.core.exception.KettleException)8 IOException (java.io.IOException)7 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)7 FileSystemException (org.apache.commons.vfs2.FileSystemException)4 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