Search in sources :

Example 1 with VfsFileChooserDialog

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

the class JobEntryTalendJobExecDialog 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, "JobEntryTalendJobExec.Title"));
    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    // Filename line
    wlName = new Label(shell, SWT.RIGHT);
    wlName.setText(BaseMessages.getString(PKG, "JobEntryTalendJobExec.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);
    Control lastControl = wName;
    // Filename line
    wlFilename = new Label(shell, SWT.RIGHT);
    wlFilename.setText(BaseMessages.getString(PKG, "JobEntryTalendJobExec.Filename.Label"));
    props.setLook(wlFilename);
    fdlFilename = new FormData();
    fdlFilename.left = new FormAttachment(0, 0);
    fdlFilename.top = new FormAttachment(lastControl, margin);
    fdlFilename.right = new FormAttachment(middle, -margin);
    wlFilename.setLayoutData(fdlFilename);
    wbFilename = new Button(shell, 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(lastControl, 0);
    // fdbFilename.height = 22;
    wbFilename.setLayoutData(fdbFilename);
    wFilename = new TextVar(jobMeta, shell, 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(lastControl, margin);
    fdFilename.right = new FormAttachment(wbFilename, -margin);
    wFilename.setLayoutData(fdFilename);
    // 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();
            }
        }
    });
    lastControl = wFilename;
    // Filename line
    Label wlClassName = new Label(shell, SWT.RIGHT);
    wlClassName.setText(BaseMessages.getString(PKG, "JobEntryTalendJobExec.ClassName.Label"));
    props.setLook(wlClassName);
    FormData fdlClassName = new FormData();
    fdlClassName.left = new FormAttachment(0, 0);
    fdlClassName.right = new FormAttachment(middle, -margin);
    fdlClassName.top = new FormAttachment(lastControl, margin);
    wlClassName.setLayoutData(fdlClassName);
    wClassName = new TextVar(jobMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    wClassName.setToolTipText(BaseMessages.getString(PKG, "JobEntryTalendJobExec.ClassName.Tooltip"));
    props.setLook(wClassName);
    wClassName.addModifyListener(lsMod);
    FormData fdClassName = new FormData();
    fdClassName.left = new FormAttachment(middle, 0);
    fdClassName.top = new FormAttachment(lastControl, margin);
    fdClassName.right = new FormAttachment(100, 0);
    wClassName.setLayoutData(fdClassName);
    lastControl = wClassName;
    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, wClassName);
    // 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);
    wFilename.addSelectionListener(lsDef);
    // Detect X or ALT-F4 or something that kills this window...
    shell.addShellListener(new ShellAdapter() {

        public void shellClosed(ShellEvent e) {
            cancel();
        }
    });
    getData();
    BaseStepDialog.setSize(shell);
    shell.open();
    props.setDialogSize(shell, "JobEntryTalendJobExec.DialogSize");
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    return jobEntry;
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) 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) Control(org.eclipse.swt.widgets.Control) 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)

Example 2 with VfsFileChooserDialog

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

the class MetaInjectDialog method selectFileTrans.

private void selectFileTrans(boolean useVfs) {
    String curFile = transMeta.environmentSubstitute(wPath.getText());
    if (useVfs) {
        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, "SingleThreaderDialog.ErrorLoadingTransformation.DialogTitle"), BaseMessages.getString(PKG, "SingleThreaderDialog.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 3 with VfsFileChooserDialog

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

the class JobEntryCopyFilesDialog method getFileSelectionAdapter.

protected SelectionAdapter getFileSelectionAdapter() {
    return new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            FileObject selectedFile = null;
            try {
                // Get current file
                FileObject rootFile = null;
                FileObject initialFile = null;
                FileObject defaultInitialFile = null;
                String original = wFields.getActiveTableItem().getText(wFields.getActiveTableColumn());
                if (original != null) {
                    String fileName = jobMeta.environmentSubstitute(original);
                    if (fileName != null && !fileName.equals("")) {
                        try {
                            initialFile = KettleVFS.getFileObject(fileName);
                        } catch (KettleException ex) {
                            initialFile = KettleVFS.getFileObject("");
                        }
                        defaultInitialFile = KettleVFS.getFileObject("file:///c:/");
                        rootFile = initialFile.getFileSystem().getRoot();
                    } else {
                        defaultInitialFile = KettleVFS.getFileObject(Spoon.getInstance().getLastFileOpened());
                    }
                }
                if (rootFile == null) {
                    rootFile = defaultInitialFile.getFileSystem().getRoot();
                    initialFile = defaultInitialFile;
                }
                VfsFileChooserDialog fileChooserDialog = Spoon.getInstance().getVfsFileChooserDialog(rootFile, initialFile);
                fileChooserDialog.defaultInitialFile = defaultInitialFile;
                selectedFile = fileChooserDialog.open(shell, new String[] { "file" }, "file", true, null, new String[] { "*.*" }, FILETYPES, true, VfsFileChooserDialog.VFS_DIALOG_OPEN_FILE_OR_DIRECTORY, false, false);
                if (selectedFile != null) {
                    String url = selectedFile.getURL().toString();
                    wFields.getActiveTableItem().setText(wFields.getActiveTableColumn(), url);
                }
            } catch (KettleFileException ex) {
            } catch (FileSystemException ex) {
            }
        }
    };
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) FileSystemException(org.apache.commons.vfs2.FileSystemException) VfsFileChooserDialog(org.pentaho.vfs.ui.VfsFileChooserDialog) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FileObject(org.apache.commons.vfs2.FileObject)

Example 4 with VfsFileChooserDialog

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

the class MappingDialog 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, "MappingDialog.ErrorLoadingTransformation.DialogTitle"), BaseMessages.getString(PKG, "MappingDialog.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 5 with VfsFileChooserDialog

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

the class RepositoryVfsKettleLifecycleListener method onStart.

@Override
public void onStart(LifeEventHandler handler) throws LifecycleException {
    /*
     * Registers the UI for the VFS Browser
     */
    final Spoon spoon = spoonSupplier.get();
    spoon.getDisplay().asyncExec(new Runnable() {

        public void run() {
            VfsFileChooserDialog dialog = spoon.getVfsFileChooserDialog(null, null);
            RepositoryVfsProviderDialog hadoopVfsFileChooserDialog = new RepositoryVfsProviderDialog(RepositoryVfsProvider.SCHEME, "Repository VFS", dialog, SWT.NONE);
            dialog.addVFSUIPanel(hadoopVfsFileChooserDialog);
        }
    });
}
Also used : RepositoryVfsProviderDialog(org.pentaho.repositoryvfs.dialog.RepositoryVfsProviderDialog) VfsFileChooserDialog(org.pentaho.vfs.ui.VfsFileChooserDialog) Spoon(org.pentaho.di.ui.spoon.Spoon)

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