Example usage for org.apache.commons.vfs FileObject getParent

List of usage examples for org.apache.commons.vfs FileObject getParent

Introduction

In this page you can find the example usage for org.apache.commons.vfs FileObject getParent.

Prototype

public FileObject getParent() throws FileSystemException;

Source Link

Document

Returns the folder that contains this file.

Usage

From source file:org.pentaho.di.trans.steps.exceloutput.ExcelOutput.java

private boolean createParentFolder(FileObject file) {
    boolean retval = true;
    // Check for parent folder
    FileObject parentfolder = null;
    try {/*from w  w  w .ja v  a 2s. c  om*/
        // Get parent folder
        parentfolder = file.getParent();
        if (parentfolder.exists()) {
            if (isDetailed()) {
                logDetailed(BaseMessages.getString(PKG, "ExcelOutput.Log.ParentFolderExist",
                        parentfolder.getName().toString()));
            }
        } else {
            if (isDetailed()) {
                logDetailed(BaseMessages.getString(PKG, "ExcelOutput.Log.ParentFolderNotExist",
                        parentfolder.getName().toString()));
            }
            if (meta.isCreateParentFolder()) {
                parentfolder.createFolder();
                if (isDetailed()) {
                    logDetailed(BaseMessages.getString(PKG, "ExcelOutput.Log.ParentFolderCreated",
                            parentfolder.getName().toString()));
                }
            } else {
                retval = false;
                logError(BaseMessages.getString(PKG, "ExcelOutput.Error.CanNotFoundParentFolder",
                        parentfolder.getName().toString(), file.getName().toString()));
            }
        }
    } catch (Exception e) {
        retval = false;
        logError(BaseMessages.getString(PKG, "ExcelOutput.Log.CouldNotCreateParentFolder",
                parentfolder.getName().toString()));
    } finally {
        if (parentfolder != null) {
            try {
                parentfolder.close();
            } catch (Exception ex) {
                // Ignore
            }
        }
    }
    return retval;
}

From source file:org.pentaho.di.trans.steps.gpload.GPLoad.java

/**
 * Returns the path to the pathToFile. It should be the same as what was passed but this method will check the file
 * system to see if the path is valid./*from www .  j  av  a2 s .  c  om*/
 * 
 * @param pathToFile
 *          Path to the file to verify.
 * @param exceptionMessage
 *          The message to use when the path is not provided.
 * @param checkExistence
 *          When true the path's existence will be verified.
 * @return
 * @throws KettleException
 */
private String getPath(String pathToFile, String exceptionMessage, boolean checkExistenceOfFile)
        throws KettleException {

    // Make sure the path is not empty
    if (Const.isEmpty(pathToFile)) {
        throw new KettleException(exceptionMessage);
    }

    // make sure the variable substitution is not empty
    pathToFile = environmentSubstitute(pathToFile).trim();
    if (Const.isEmpty(pathToFile)) {
        throw new KettleException(exceptionMessage);
    }

    FileObject fileObject = KettleVFS.getFileObject(pathToFile, getTransMeta());
    try {
        // we either check the existence of the file
        if (checkExistenceOfFile) {
            if (!fileObject.exists()) {
                throw new KettleException(
                        BaseMessages.getString(PKG, "GPLoad.Execption.FileDoesNotExist", pathToFile));
            }
        } else { // if the file does not have to exist, the parent, or source folder, does.
            FileObject parentFolder = fileObject.getParent();
            if (parentFolder.exists()) {
                return KettleVFS.getFilename(fileObject);
            } else {
                throw new KettleException(BaseMessages.getString(PKG, "GPLoad.Exception.DirectoryDoesNotExist",
                        parentFolder.getURL().getPath()));
            }

        }

        // if Windows is the OS
        if (Const.getOS().startsWith("Windows")) {
            return addQuotes(pathToFile);
        } else {
            return KettleVFS.getFilename(fileObject);
        }
    } catch (FileSystemException fsex) {
        throw new KettleException(
                BaseMessages.getString(PKG, "GPLoad.Exception.GPLoadCommandBuild", fsex.getMessage()));
    }
}

From source file:org.pentaho.di.trans.steps.script.ScriptAddedFunctions.java

public static String getParentFoldername(ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
        Object FunctionContext) {
    try {/*from w  w w .  ja v  a 2 s .  co  m*/
        if (ArgList.length == 1 && !isNull(ArgList[0]) && !isUndefined(ArgList[0])) {
            if (ArgList[0].equals(null)) {
                return null;
            }
            FileObject file = null;

            try {
                // Source file
                file = KettleVFS.getFileObject((String) ArgList[0]);
                String foldername = null;
                if (file.exists()) {
                    foldername = KettleVFS.getFilename(file.getParent());

                } else {
                    new RuntimeException("file [" + (String) ArgList[0] + "] can not be found!");
                }

                return foldername;
            } catch (IOException e) {
                throw new RuntimeException(
                        "The function call getParentFoldername throw an error : " + e.toString());
            } finally {
                if (file != null) {
                    try {
                        file.close();
                    } catch (Exception e) {
                        // Ignore errors
                    }
                }
            }

        } else {
            throw new RuntimeException("The function call getParentFoldername is not valid.");
        }
    } catch (Exception e) {
        throw new RuntimeException(e.toString());
    }
}

From source file:org.pentaho.di.trans.steps.scriptvalues_mod.ScriptValuesAddedFunctions.java

public static String getParentFoldername(Context actualContext, Scriptable actualObject, Object[] ArgList,
        Function FunctionContext) {
    try {//from w w w  . j a va  2s  .  co m
        if (ArgList.length == 1 && !isNull(ArgList[0]) && !isUndefined(ArgList[0])) {
            if (ArgList[0].equals(null)) {
                return null;
            }
            FileObject file = null;

            try {
                // Source file
                file = KettleVFS.getFileObject(Context.toString(ArgList[0]));
                String foldername = null;
                if (file.exists()) {
                    foldername = KettleVFS.getFilename(file.getParent());

                } else {
                    Context.reportRuntimeError("file [" + Context.toString(ArgList[0]) + "] can not be found!");
                }

                return foldername;
            } catch (IOException e) {
                throw Context.reportRuntimeError(
                        "The function call getParentFoldername throw an error : " + e.toString());
            } finally {
                if (file != null) {
                    try {
                        file.close();
                    } catch (Exception e) {
                        // Ignore errors
                    }
                }
            }

        } else {
            throw Context.reportRuntimeError("The function call getParentFoldername is not valid.");
        }
    } catch (Exception e) {
        throw Context.reportRuntimeError(e.toString());
    }
}

From source file:org.pentaho.di.trans.TransMeta.java

/**
 * Exports the specified objects to a flat-file system, adding content with filename keys to a set of definitions. The
 * supplied resource naming interface allows the object to name appropriately without worrying about those parts of
 * the implementation specific details./*from   w ww.j  a v a 2 s  .  c o m*/
 *
 * @param space
 *          the variable space to use
 * @param definitions
 * @param resourceNamingInterface
 * @param repository
 *          The repository to optionally load other resources from (to be converted to XML)
 * @param metaStore
 *          the metaStore in which non-kettle metadata could reside.
 *
 * @return the filename of the exported resource
 */
public String exportResources(VariableSpace space, Map<String, ResourceDefinition> definitions,
        ResourceNamingInterface resourceNamingInterface, Repository repository, IMetaStore metaStore)
        throws KettleException {

    try {
        // Handle naming for both repository and XML bases resources...
        //
        String baseName;
        String originalPath;
        String fullname;
        String extension = "ktr";
        if (Const.isEmpty(getFilename())) {
            // Assume repository...
            //
            originalPath = directory.getPath();
            baseName = getName();
            fullname = directory.getPath()
                    + (directory.getPath().endsWith(RepositoryDirectory.DIRECTORY_SEPARATOR) ? ""
                            : RepositoryDirectory.DIRECTORY_SEPARATOR)
                    + getName() + "." + extension; //
        } else {
            // Assume file
            //
            FileObject fileObject = KettleVFS.getFileObject(space.environmentSubstitute(getFilename()), space);
            originalPath = fileObject.getParent().getURL().toString();
            baseName = fileObject.getName().getBaseName();
            fullname = fileObject.getURL().toString();
        }

        String exportFileName = resourceNamingInterface.nameResource(baseName, originalPath, extension,
                ResourceNamingInterface.FileNamingType.TRANSFORMATION);
        ResourceDefinition definition = definitions.get(exportFileName);
        if (definition == null) {
            // If we do this once, it will be plenty :-)
            //
            TransMeta transMeta = (TransMeta) this.realClone(false);
            // transMeta.copyVariablesFrom(space);

            // Add used resources, modify transMeta accordingly
            // Go through the list of steps, etc.
            // These critters change the steps in the cloned TransMeta
            // At the end we make a new XML version of it in "exported"
            // format...

            // loop over steps, databases will be exported to XML anyway.
            //
            for (StepMeta stepMeta : transMeta.getSteps()) {
                stepMeta.exportResources(space, definitions, resourceNamingInterface, repository, metaStore);
            }

            // Change the filename, calling this sets internal variables
            // inside of the transformation.
            //
            transMeta.setFilename(exportFileName);

            // All objects get re-located to the root folder
            //
            transMeta.setRepositoryDirectory(new RepositoryDirectory());

            // Set a number of parameters for all the data files referenced so far...
            //
            Map<String, String> directoryMap = resourceNamingInterface.getDirectoryMap();
            if (directoryMap != null) {
                for (String directory : directoryMap.keySet()) {
                    String parameterName = directoryMap.get(directory);
                    transMeta.addParameterDefinition(parameterName, directory,
                            "Data file path discovered during export");
                }
            }

            // At the end, add ourselves to the map...
            //
            String transMetaContent = transMeta.getXML();

            definition = new ResourceDefinition(exportFileName, transMetaContent);

            // Also remember the original filename (if any), including variables etc.
            //
            if (Const.isEmpty(this.getFilename())) { // Repository
                definition.setOrigin(fullname);
            } else {
                definition.setOrigin(this.getFilename());
            }

            definitions.put(fullname, definition);
        }
        return exportFileName;
    } catch (FileSystemException e) {
        throw new KettleException(BaseMessages.getString(PKG,
                "TransMeta.Exception.ErrorOpeningOrValidatingTheXMLFile", getFilename()), e);
    } catch (KettleFileException e) {
        throw new KettleException(BaseMessages.getString(PKG,
                "TransMeta.Exception.ErrorOpeningOrValidatingTheXMLFile", getFilename()), e);
    }
}

From source file:org.pentaho.di.ui.job.entries.fileexists.JobEntryFileExistsDialog.java

public JobEntryInterface open() {
    Shell parent = getParent();//from w w w. j a v a 2  s.  co  m
    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, "JobFileExists.Title"));

    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;

    // Filename line
    wlName = new Label(shell, SWT.RIGHT);
    wlName.setText(BaseMessages.getString(PKG, "JobFileExists.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);

    // Filename line
    wlFilename = new Label(shell, SWT.RIGHT);
    wlFilename.setText(BaseMessages.getString(PKG, "JobFileExists.Filename.Label"));
    props.setLook(wlFilename);
    fdlFilename = new FormData();
    fdlFilename.left = new FormAttachment(0, 0);
    fdlFilename.top = new FormAttachment(wName, 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(wName, 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(wName, 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();
            }
        }
    });

    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, wFilename);
    // 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, "JobFileExistsDialogSize");
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    return jobEntry;
}

From source file:org.pentaho.di.ui.job.entries.pgpverify.JobEntryPGPVerifyDialog.java

public JobEntryInterface open() {
    Shell parent = getParent();//from   w  w w. j  a  va 2 s.co  m
    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;
}

From source file:org.pentaho.di.ui.job.entries.talendjobexec.JobEntryTalendJobExecDialog.java

public JobEntryInterface open() {
    Shell parent = getParent();//from  www  . j a  v a2 s  .c o  m
    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;
}

From source file:org.pentaho.di.ui.trans.steps.jobexecutor.JobExecutorDialog.java

private void selectFileJob() {
    String curFile = wFilename.getText();
    FileObject root = null;

    try {//from   www.j  a  va2 s.  c  o  m
        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.getJobFilterNames(), VfsFileChooserDialog.VFS_DIALOG_OPEN_FILE);
        if (file == null) {
            return;
        }
        String fname = null;

        fname = file.getURL().getFile();

        if (fname != null) {

            loadFileJob(fname);
            // PDI-11985 set filename for UI edit field. This will be saved later in xml
            // as a filename for JobMeta.
            wFilename.setText(fname);
            wJobname.setText(Const.NVL(executorJobMeta.getName(), ""));
            wDirectory.setText("");
            specificationMethod = ObjectLocationSpecificationMethod.FILENAME;
            setRadioButtons();
        }
    } catch (IOException e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "JobExecutorDialog.ErrorLoadingJob.DialogTitle"),
                BaseMessages.getString(PKG, "JobExecutorDialog.ErrorLoadingJob.DialogMessage"), e);
    } catch (KettleException e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "JobExecutorDialog.ErrorLoadingJob.DialogTitle"),
                BaseMessages.getString(PKG, "JobExecutorDialog.ErrorLoadingJob.DialogMessage"), e);
    }
}

From source file:org.pentaho.di.ui.trans.steps.mapping.MappingDialog.java

private void selectFileTrans() {
    String curFile = wFilename.getText();
    FileObject root;

    try {/*www . ja  v  a2 s .com*/
        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 fname;

        fname = file.getURL().getFile();

        if (fname != null) {

            loadFileTrans(fname);
            wFilename.setText(mappingTransMeta.getFilename());
            wTransname.setText(Const.NVL(mappingTransMeta.getName(), ""));
            wDirectory.setText("");
            setSpecificationMethod(ObjectLocationSpecificationMethod.FILENAME);
            setRadioButtons();
        }
    } catch (IOException e) {
        new ErrorDialog(shell,
                BaseMessages.getString(PKG, "MappingDialog.ErrorLoadingTransformation.DialogTitle"),
                BaseMessages.getString(PKG, "MappingDialog.ErrorLoadingTransformation.DialogMessage"), e);
    } catch (KettleException e) {
        new ErrorDialog(shell,
                BaseMessages.getString(PKG, "MappingDialog.ErrorLoadingTransformation.DialogTitle"),
                BaseMessages.getString(PKG, "MappingDialog.ErrorLoadingTransformation.DialogMessage"), e);
    }
}