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

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

Introduction

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

Prototype

public FileName getName();

Source Link

Document

Returns the name of this file.

Usage

From source file:org.pentaho.di.ui.job.AbstractJobEntryController.java

/**
 * Browse for a file or directory with the VFS Browser.
 * //from w w  w . ja v  a2  s . c  o  m
 * @param root
 *          Root object
 * @param initial
 *          Initial file or folder the browser should open to
 * @param dialogMode
 *          Mode to open dialog in: e.g.
 *          {@link org.pentaho.vfs.ui .VfsFileChooserDialog#VFS_DIALOG_OPEN_FILE_OR_DIRECTORY}
 * @param schemeRestriction
 *          Scheme to limit the user to browsing from
 * @param defaultScheme
 *          Scheme to select by default in the selection dropdown
 * @return The selected file object, {@code null} if no object is selected
 * @throws org.pentaho.di.core.exception.KettleFileException
 *           Error accessing the root file using the initial file, when {@code root} is not provided
 */
protected FileObject browseVfs(FileObject root, FileObject initial, int dialogMode, String schemeRestriction,
        String defaultScheme, boolean showFileScheme) throws KettleFileException {

    if (initial == null) {
        initial = KettleVFS.getFileObject(Spoon.getInstance().getLastFileOpened());
    }
    if (root == null) {
        try {
            root = initial.getFileSystem().getRoot();
        } catch (FileSystemException e) {
            throw new KettleFileException(e);
        }
    }

    VfsFileChooserHelper fileChooserHelper = new VfsFileChooserHelper(getShell(),
            Spoon.getInstance().getVfsFileChooserDialog(root, initial), jobEntry);
    fileChooserHelper.setDefaultScheme(defaultScheme);
    fileChooserHelper.setSchemeRestriction(schemeRestriction);
    fileChooserHelper.setShowFileScheme(showFileScheme);
    try {
        return fileChooserHelper.browse(getFileFilters(), getFileFilterNames(), initial.getName().getURI(),
                dialogMode);
    } catch (KettleException e) {
        throw new KettleFileException(e);
    } catch (FileSystemException e) {
        throw new KettleFileException(e);
    }

}

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

public JobEntryInterface open() {
    Shell parent = getParent();//from   w  w  w.j  av  a2  s .com
    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();
        }
    };
    backupChanged = jobEntry.hasChanged();

    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = Const.FORM_MARGIN;
    formLayout.marginHeight = Const.FORM_MARGIN;

    shell.setLayout(formLayout);
    shell.setText(BaseMessages.getString(PKG, "JobJob.Title"));

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

    // Name line
    wlName = new Label(shell, SWT.RIGHT);
    wlName.setText(BaseMessages.getString(PKG, "JobJob.Name.Label"));
    props.setLook(wlName);
    FormData fdlName = new FormData();
    fdlName.left = new FormAttachment(0, 0);
    fdlName.top = new FormAttachment(0, 0);
    fdlName.right = new FormAttachment(middle, -margin);
    wlName.setLayoutData(fdlName);

    wName = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wName);
    wName.addModifyListener(lsMod);
    FormData fdName = new FormData();
    fdName.top = new FormAttachment(0, 0);
    fdName.left = new FormAttachment(middle, 0);
    fdName.right = new FormAttachment(100, 0);
    wName.setLayoutData(fdName);

    CTabFolder wTabFolder = new CTabFolder(shell, SWT.BORDER);
    props.setLook(wTabFolder, Props.WIDGET_STYLE_TAB);

    // Specification
    //
    CTabItem wSpecTab = new CTabItem(wTabFolder, SWT.NONE);
    wSpecTab.setText(BaseMessages.getString(PKG, "JobJob.Specification.Group.Label"));

    ScrolledComposite wSSpec = new ScrolledComposite(wTabFolder, SWT.V_SCROLL | SWT.H_SCROLL);
    wSSpec.setLayout(new FillLayout());

    Composite wSpec = new Composite(wSSpec, SWT.SHADOW_NONE);
    props.setLook(wSpec);

    FormLayout specLayout = new FormLayout();
    specLayout.marginWidth = Const.FORM_MARGIN;
    specLayout.marginHeight = Const.FORM_MARGIN;
    wSpec.setLayout(specLayout);

    // The specify by filename option...
    //
    Group gFilename = new Group(wSpec, SWT.SHADOW_ETCHED_IN);
    props.setLook(gFilename);
    FormLayout gFileLayout = new FormLayout();
    gFileLayout.marginWidth = Const.FORM_MARGIN;
    gFileLayout.marginHeight = Const.FORM_MARGIN;
    gFilename.setLayout(gFileLayout);

    radioFilename = new Button(gFilename, SWT.RADIO);
    props.setLook(radioFilename);
    radioFilename.setText(BaseMessages.getString(PKG, "JobJob.JobFile.Label"));
    FormData fdRadioFilename = new FormData();
    fdRadioFilename.top = new FormAttachment(0, 0);
    fdRadioFilename.left = new FormAttachment(0, 0);
    fdRadioFilename.right = new FormAttachment(middle, -margin);
    radioFilename.setLayoutData(fdRadioFilename);
    radioFilename.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent arg0) {
            specificationMethod = ObjectLocationSpecificationMethod.FILENAME;
            setRadioButtons();
        }
    });

    wbFilename = new Button(gFilename, SWT.PUSH | SWT.CENTER);
    props.setLook(wbFilename);
    wbFilename.setImage(GUIResource.getInstance().getImageJobGraph());
    wbFilename.setToolTipText(BaseMessages.getString(PKG, "JobJob.SelectJob.Tooltip"));
    FormData fdbFilename = new FormData();
    fdbFilename.top = new FormAttachment(0, 0);
    fdbFilename.right = new FormAttachment(100, 0);
    wbFilename.setLayoutData(fdbFilename);

    wFilename = new TextVar(jobMeta, gFilename, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wFilename);
    wFilename.addModifyListener(lsMod);
    FormData fdFilename = new FormData();
    fdFilename.top = new FormAttachment(0, 0);
    fdFilename.left = new FormAttachment(middle, 0);
    fdFilename.right = new FormAttachment(wbFilename, -margin);
    wFilename.setLayoutData(fdFilename);
    wFilename.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent arg0) {
            specificationMethod = ObjectLocationSpecificationMethod.FILENAME;
            setRadioButtons();
        }
    });

    FormData fdgFilename = new FormData();
    fdgFilename.top = new FormAttachment(0, 0);
    fdgFilename.left = new FormAttachment(0, 0);
    fdgFilename.right = new FormAttachment(100, 0);
    gFilename.setLayoutData(fdgFilename);

    // The repository : specify by name radio option...
    //
    Group gByName = new Group(wSpec, SWT.SHADOW_ETCHED_IN);
    props.setLook(gByName);
    FormLayout gByNameLayout = new FormLayout();
    gByNameLayout.marginWidth = Const.FORM_MARGIN;
    gByNameLayout.marginHeight = Const.FORM_MARGIN;
    gByName.setLayout(gByNameLayout);

    radioByName = new Button(gByName, SWT.RADIO);
    props.setLook(radioByName);
    radioByName.setText(BaseMessages.getString(PKG, "JobJob.NameOfJob.Label"));
    FormData fdRadioByName = new FormData();
    fdRadioByName.top = new FormAttachment(0, 0);
    fdRadioByName.left = new FormAttachment(0, 0);
    fdRadioByName.right = new FormAttachment(middle, -margin);
    radioByName.setLayoutData(fdRadioByName);
    radioByName.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent arg0) {
            specificationMethod = ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME;
            setRadioButtons();
        }
    });

    wbJobname = new Button(gByName, SWT.PUSH | SWT.CENTER);
    props.setLook(wbJobname);
    wbJobname.setImage(GUIResource.getInstance().getImageJobGraph());
    wbJobname.setToolTipText(BaseMessages.getString(PKG, "JobJob.SelectJobRep.Tooltip"));
    FormData fdbJobname = new FormData();
    fdbJobname.top = new FormAttachment(0, 0);
    fdbJobname.right = new FormAttachment(100, 0);
    wbJobname.setLayoutData(fdbJobname);

    wJobname = new TextVar(jobMeta, gByName, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wJobname);
    wJobname.addModifyListener(lsMod);
    FormData fdJobname = new FormData();
    fdJobname.top = new FormAttachment(0, 0);
    fdJobname.left = new FormAttachment(middle, 0);
    fdJobname.right = new FormAttachment(wbJobname, -margin);
    wJobname.setLayoutData(fdJobname);

    wDirectory = new TextVar(jobMeta, gByName, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wDirectory);
    wDirectory.addModifyListener(lsMod);
    FormData fdDirectory = new FormData();
    fdDirectory.top = new FormAttachment(wJobname, margin * 2);
    fdDirectory.left = new FormAttachment(middle, 0);
    fdDirectory.right = new FormAttachment(100, 0);
    wDirectory.setLayoutData(fdDirectory);

    FormData fdgByName = new FormData();
    fdgByName.top = new FormAttachment(gFilename, margin);
    fdgByName.left = new FormAttachment(0, 0);
    fdgByName.right = new FormAttachment(100, 0);
    gByName.setLayoutData(fdgByName);

    // The specify by filename option...
    //
    Group gByReference = new Group(wSpec, SWT.SHADOW_ETCHED_IN);
    props.setLook(gByReference);
    FormLayout gByReferenceLayout = new FormLayout();
    gByReferenceLayout.marginWidth = Const.FORM_MARGIN;
    gByReferenceLayout.marginHeight = Const.FORM_MARGIN;
    gByReference.setLayout(gByReferenceLayout);

    radioByReference = new Button(gByReference, SWT.RADIO);
    props.setLook(radioByReference);
    radioByReference.setText(BaseMessages.getString(PKG, "JobJob.JobByReference.Label"));
    FormData fdRadioByReference = new FormData();
    fdRadioByReference.top = new FormAttachment(0, 0);
    fdRadioByReference.left = new FormAttachment(0, 0);
    fdRadioByReference.right = new FormAttachment(middle, -margin);
    radioByReference.setLayoutData(fdRadioByReference);
    radioByReference.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent arg0) {
            specificationMethod = ObjectLocationSpecificationMethod.REPOSITORY_BY_REFERENCE;
            setRadioButtons();
        }
    });

    wbByReference = new Button(gByReference, SWT.PUSH | SWT.CENTER);
    props.setLook(wbByReference);
    wbByReference.setImage(GUIResource.getInstance().getImageJobGraph());
    wbByReference.setToolTipText(BaseMessages.getString(PKG, "JobJob.SelectJob.Tooltip"));
    FormData fdbByReference = new FormData();
    fdbByReference.top = new FormAttachment(0, 0);
    fdbByReference.right = new FormAttachment(100, 0);
    wbByReference.setLayoutData(fdbByReference);

    wByReference = new Text(gByReference, SWT.SINGLE | SWT.LEFT | SWT.BORDER | SWT.READ_ONLY);
    props.setLook(wByReference);
    wByReference.addModifyListener(lsMod);
    FormData fdByReference = new FormData();
    fdByReference.top = new FormAttachment(0, 0);
    fdByReference.left = new FormAttachment(middle, 0);
    fdByReference.right = new FormAttachment(wbByReference, -margin);
    wByReference.setLayoutData(fdByReference);

    FormData fdgByReference = new FormData();
    fdgByReference.top = new FormAttachment(gByName, margin);
    fdgByReference.left = new FormAttachment(0, 0);
    fdgByReference.right = new FormAttachment(100, 0);
    gByReference.setLayoutData(fdgByReference);

    wNewJob = new Button(wSpec, SWT.PUSH);
    wNewJob.setText(BaseMessages.getString(PKG, "JobJob.NewJobButton.Label"));
    FormData fdNewJob = new FormData();
    fdNewJob.bottom = new FormAttachment(100, -margin);
    fdNewJob.left = new FormAttachment(wByReference, 0, SWT.CENTER);
    wNewJob.setLayoutData(fdNewJob);
    wNewJob.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent event) {
            newJob();
        }
    });

    wSpec.pack();
    Rectangle bounds = wSpec.getBounds();

    wSSpec.setContent(wSpec);
    wSSpec.setExpandHorizontal(true);
    wSSpec.setExpandVertical(true);
    wSSpec.setMinWidth(bounds.width);
    wSSpec.setMinHeight(bounds.height);

    wSpecTab.setControl(wSSpec);

    FormData fdSpec = new FormData();
    fdSpec.left = new FormAttachment(0, 0);
    fdSpec.top = new FormAttachment(0, 0);
    fdSpec.right = new FormAttachment(100, 0);
    fdSpec.bottom = new FormAttachment(100, 0);
    wSpec.setLayoutData(fdSpec);

    // Advanced
    //
    CTabItem wAdvancedTab = new CTabItem(wTabFolder, SWT.NONE);
    wAdvancedTab.setText(BaseMessages.getString(PKG, "JobJob.Advanced.Group.Label"));

    ScrolledComposite wSAdvanced = new ScrolledComposite(wTabFolder, SWT.V_SCROLL | SWT.H_SCROLL);
    wSAdvanced.setLayout(new FillLayout());

    wAdvanced = new Composite(wSAdvanced, SWT.SHADOW_NONE);
    props.setLook(wAdvanced);

    FormLayout advancedLayout = new FormLayout();
    advancedLayout.marginWidth = Const.FORM_MARGIN;
    advancedLayout.marginHeight = Const.FORM_MARGIN;
    wAdvanced.setLayout(advancedLayout);

    wlPrevious = new Label(wAdvanced, SWT.RIGHT);
    wlPrevious.setText(BaseMessages.getString(PKG, "JobJob.Previous.Label"));
    props.setLook(wlPrevious);
    fdlPrevious = new FormData();
    fdlPrevious.left = new FormAttachment(0, 0);
    fdlPrevious.top = new FormAttachment(0, 0);
    fdlPrevious.right = new FormAttachment(middle, -margin);
    wlPrevious.setLayoutData(fdlPrevious);
    wPrevious = new Button(wAdvanced, SWT.CHECK);
    props.setLook(wPrevious);
    wPrevious.setSelection(jobEntry.argFromPrevious);
    wPrevious.setToolTipText(BaseMessages.getString(PKG, "JobJob.Previous.Tooltip"));
    fdPrevious = new FormData();
    fdPrevious.left = new FormAttachment(middle, 0);
    fdPrevious.top = new FormAttachment(0, 0);
    fdPrevious.right = new FormAttachment(100, 0);
    wPrevious.setLayoutData(fdPrevious);
    wPrevious.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            jobEntry.setChanged();
        }
    });

    wlPrevToParams = new Label(wAdvanced, SWT.RIGHT);
    wlPrevToParams.setText(BaseMessages.getString(PKG, "JobJob.PrevToParams.Label"));
    props.setLook(wlPrevToParams);
    fdlPrevToParams = new FormData();
    fdlPrevToParams.left = new FormAttachment(0, 0);
    fdlPrevToParams.top = new FormAttachment(wPrevious, margin * 3);
    fdlPrevToParams.right = new FormAttachment(middle, -margin);
    wlPrevToParams.setLayoutData(fdlPrevToParams);
    wPrevToParams = new Button(wAdvanced, SWT.CHECK);
    props.setLook(wPrevToParams);
    wPrevToParams.setSelection(jobEntry.paramsFromPrevious);
    wPrevToParams.setToolTipText(BaseMessages.getString(PKG, "JobJob.PrevToParams.Tooltip"));
    fdPrevToParams = new FormData();
    fdPrevToParams.left = new FormAttachment(middle, 0);
    fdPrevToParams.top = new FormAttachment(wPrevious, margin * 3);
    fdPrevToParams.right = new FormAttachment(100, 0);
    wPrevToParams.setLayoutData(fdPrevToParams);
    wPrevToParams.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            jobEntry.setChanged();
        }
    });

    wlEveryRow = new Label(wAdvanced, SWT.RIGHT);
    wlEveryRow.setText(BaseMessages.getString(PKG, "JobJob.ExecForEveryInputRow.Label"));
    props.setLook(wlEveryRow);
    fdlEveryRow = new FormData();
    fdlEveryRow.left = new FormAttachment(0, 0);
    fdlEveryRow.top = new FormAttachment(wPrevToParams, margin * 3);
    fdlEveryRow.right = new FormAttachment(middle, -margin);
    wlEveryRow.setLayoutData(fdlEveryRow);
    wEveryRow = new Button(wAdvanced, SWT.CHECK);
    props.setLook(wEveryRow);
    wEveryRow.setSelection(jobEntry.execPerRow);
    wEveryRow.setToolTipText(BaseMessages.getString(PKG, "JobJob.ExecForEveryInputRow.Tooltip"));
    fdEveryRow = new FormData();
    fdEveryRow.left = new FormAttachment(middle, 0);
    fdEveryRow.top = new FormAttachment(wPrevToParams, margin * 3);
    fdEveryRow.right = new FormAttachment(100, 0);
    wEveryRow.setLayoutData(fdEveryRow);
    wEveryRow.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            jobEntry.execPerRow = !jobEntry.execPerRow;
            jobEntry.setChanged();
        }
    });

    // The remote slave server
    wlSlaveServer = new Label(wAdvanced, SWT.RIGHT);
    wlSlaveServer.setText(BaseMessages.getString(PKG, "JobJob.SlaveServer.Label"));
    wlSlaveServer.setToolTipText(BaseMessages.getString(PKG, "JobJob.SlaveServer.ToolTip"));
    props.setLook(wlSlaveServer);
    fdlSlaveServer = new FormData();
    fdlSlaveServer.left = new FormAttachment(0, 0);
    fdlSlaveServer.right = new FormAttachment(middle, -margin);
    fdlSlaveServer.top = new FormAttachment(wEveryRow, margin);
    wlSlaveServer.setLayoutData(fdlSlaveServer);
    wSlaveServer = new ComboVar(jobMeta, wAdvanced, SWT.SINGLE | SWT.BORDER);
    wSlaveServer.setItems(SlaveServer.getSlaveServerNames(jobMeta.getSlaveServers()));
    wSlaveServer.setToolTipText(BaseMessages.getString(PKG, "JobJob.SlaveServer.ToolTip"));
    props.setLook(wSlaveServer);
    fdSlaveServer = new FormData();
    fdSlaveServer.left = new FormAttachment(middle, 0);
    fdSlaveServer.top = new FormAttachment(wEveryRow, margin);
    fdSlaveServer.right = new FormAttachment(100, 0);
    wSlaveServer.setLayoutData(fdSlaveServer);
    wSlaveServer.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            setActive();
        }
    });

    // Pass the export of this job as an export to the slave server
    //
    wlPassExport = new Label(wAdvanced, SWT.RIGHT);
    wlPassExport.setText(BaseMessages.getString(PKG, "JobJob.PassExportToSlave.Label"));
    props.setLook(wlPassExport);
    fdlPassExport = new FormData();
    fdlPassExport.left = new FormAttachment(0, 0);
    fdlPassExport.top = new FormAttachment(wSlaveServer, margin);
    fdlPassExport.right = new FormAttachment(middle, -margin);
    wlPassExport.setLayoutData(fdlPassExport);
    wPassExport = new Button(wAdvanced, SWT.CHECK);
    props.setLook(wPassExport);
    fdPassExport = new FormData();
    fdPassExport.left = new FormAttachment(middle, 0);
    fdPassExport.top = new FormAttachment(wSlaveServer, margin);
    fdPassExport.right = new FormAttachment(100, 0);
    wPassExport.setLayoutData(fdPassExport);

    // Wait for the remote transformation to finish?
    //
    wlWaitingToFinish = new Label(wAdvanced, SWT.RIGHT);
    wlWaitingToFinish.setText(BaseMessages.getString(PKG, "JobJob.WaitToFinish.Label"));
    props.setLook(wlWaitingToFinish);
    fdlWaitingToFinish = new FormData();
    fdlWaitingToFinish.left = new FormAttachment(0, 0);
    fdlWaitingToFinish.top = new FormAttachment(wPassExport, margin);
    fdlWaitingToFinish.right = new FormAttachment(middle, -margin);
    wlWaitingToFinish.setLayoutData(fdlWaitingToFinish);
    wWaitingToFinish = new Button(wAdvanced, SWT.CHECK);
    props.setLook(wWaitingToFinish);
    fdWaitingToFinish = new FormData();
    fdWaitingToFinish.left = new FormAttachment(middle, 0);
    fdWaitingToFinish.top = new FormAttachment(wPassExport, margin);
    fdWaitingToFinish.right = new FormAttachment(100, 0);
    wWaitingToFinish.setLayoutData(fdWaitingToFinish);
    wWaitingToFinish.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            setActive();
        }
    });

    // Follow a local abort remotely?
    //
    wlFollowingAbortRemotely = new Label(wAdvanced, SWT.RIGHT);
    wlFollowingAbortRemotely.setText(BaseMessages.getString(PKG, "JobJob.AbortRemote.Label"));
    props.setLook(wlFollowingAbortRemotely);
    fdlFollowingAbortRemotely = new FormData();
    fdlFollowingAbortRemotely.left = new FormAttachment(0, 0);
    fdlFollowingAbortRemotely.top = new FormAttachment(wWaitingToFinish, margin);
    fdlFollowingAbortRemotely.right = new FormAttachment(middle, -margin);
    wlFollowingAbortRemotely.setLayoutData(fdlFollowingAbortRemotely);
    wFollowingAbortRemotely = new Button(wAdvanced, SWT.CHECK);
    props.setLook(wFollowingAbortRemotely);
    fdFollowingAbortRemotely = new FormData();
    fdFollowingAbortRemotely.left = new FormAttachment(middle, 0);
    fdFollowingAbortRemotely.top = new FormAttachment(wWaitingToFinish, margin);
    fdFollowingAbortRemotely.right = new FormAttachment(100, 0);
    wFollowingAbortRemotely.setLayoutData(fdFollowingAbortRemotely);

    // Expand the job on the remote server, make the sub-jobs and transformations visible
    //
    wlExpandRemote = new Label(wAdvanced, SWT.RIGHT);
    wlExpandRemote.setText(BaseMessages.getString(PKG, "JobEntryJobDialog.ExpandRemoteOnSlave.Label"));
    props.setLook(wlExpandRemote);
    fdlExpandRemote = new FormData();
    fdlExpandRemote.left = new FormAttachment(0, 0);
    fdlExpandRemote.top = new FormAttachment(wFollowingAbortRemotely, margin);
    fdlExpandRemote.right = new FormAttachment(middle, -margin);
    wlExpandRemote.setLayoutData(fdlExpandRemote);
    wExpandRemote = new Button(wAdvanced, SWT.CHECK);
    props.setLook(wExpandRemote);
    fdExpandRemote = new FormData();
    fdExpandRemote.left = new FormAttachment(middle, 0);
    fdExpandRemote.top = new FormAttachment(wFollowingAbortRemotely, margin);
    fdExpandRemote.right = new FormAttachment(100, 0);
    wExpandRemote.setLayoutData(fdExpandRemote);

    wAdvanced.pack();
    bounds = wAdvanced.getBounds();

    wSAdvanced.setContent(wAdvanced);
    wSAdvanced.setExpandHorizontal(true);
    wSAdvanced.setExpandVertical(true);
    wSAdvanced.setMinWidth(bounds.width);
    wSAdvanced.setMinHeight(bounds.height);

    wAdvancedTab.setControl(wSAdvanced);

    // Logging
    //
    CTabItem wLoggingTab = new CTabItem(wTabFolder, SWT.NONE);
    wLoggingTab.setText(BaseMessages.getString(PKG, "JobJob.LogSettings.Group.Label"));

    ScrolledComposite wSLogging = new ScrolledComposite(wTabFolder, SWT.V_SCROLL | SWT.H_SCROLL);
    wSLogging.setLayout(new FillLayout());

    wLogging = new Composite(wSLogging, SWT.SHADOW_NONE);
    props.setLook(wLogging);

    FormLayout groupLayout = new FormLayout();
    groupLayout.marginWidth = Const.FORM_MARGIN;
    groupLayout.marginHeight = Const.FORM_MARGIN;

    wLogging.setLayout(groupLayout);

    Label wlForceSeparateLogging = new Label(wLogging, SWT.RIGHT);
    wlForceSeparateLogging.setText(BaseMessages.getString(PKG, "JobEntryJobDialog.ForceSeparateLogging.Label"));
    props.setLook(wlForceSeparateLogging);
    FormData fdlForceSeparateLogging = new FormData();
    fdlForceSeparateLogging.left = new FormAttachment(0, 0);
    fdlForceSeparateLogging.top = new FormAttachment(0, margin);
    fdlForceSeparateLogging.right = new FormAttachment(middle, -margin);
    wlForceSeparateLogging.setLayoutData(fdlForceSeparateLogging);
    wForceSeparateLogging = new Button(wLogging, SWT.CHECK);
    props.setLook(wForceSeparateLogging);
    wForceSeparateLogging
            .setToolTipText(BaseMessages.getString(PKG, "JobEntryJobDialog.ForceSeparateLogging.Tooltip"));
    FormData fdForceSeparateLogging = new FormData();
    fdForceSeparateLogging.left = new FormAttachment(middle, 0);
    fdForceSeparateLogging.top = new FormAttachment(0, margin);
    fdForceSeparateLogging.right = new FormAttachment(100, 0);
    wForceSeparateLogging.setLayoutData(fdForceSeparateLogging);

    // Set the logfile?
    //
    wlSetLogfile = new Label(wLogging, SWT.RIGHT);
    wlSetLogfile.setText(BaseMessages.getString(PKG, "JobJob.Specify.Logfile.Label"));
    props.setLook(wlSetLogfile);
    fdlSetLogfile = new FormData();
    fdlSetLogfile.left = new FormAttachment(0, 0);
    fdlSetLogfile.top = new FormAttachment(wForceSeparateLogging, margin);
    fdlSetLogfile.right = new FormAttachment(middle, -margin);
    wlSetLogfile.setLayoutData(fdlSetLogfile);
    wSetLogfile = new Button(wLogging, SWT.CHECK);
    props.setLook(wSetLogfile);
    fdSetLogfile = new FormData();
    fdSetLogfile.left = new FormAttachment(middle, 0);
    fdSetLogfile.top = new FormAttachment(wForceSeparateLogging, margin);
    fdSetLogfile.right = new FormAttachment(100, 0);
    wSetLogfile.setLayoutData(fdSetLogfile);
    wSetLogfile.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            setActive();
        }
    });

    // Append logfile?
    wlAppendLogfile = new Label(wLogging, SWT.RIGHT);
    wlAppendLogfile.setText(BaseMessages.getString(PKG, "JobJob.Append.Logfile.Label"));
    props.setLook(wlAppendLogfile);
    fdlAppendLogfile = new FormData();
    fdlAppendLogfile.left = new FormAttachment(0, 0);
    fdlAppendLogfile.top = new FormAttachment(wSetLogfile, margin);
    fdlAppendLogfile.right = new FormAttachment(middle, -margin);
    wlAppendLogfile.setLayoutData(fdlAppendLogfile);
    wAppendLogfile = new Button(wLogging, SWT.CHECK);
    wAppendLogfile.setToolTipText(BaseMessages.getString(PKG, "JobJob.Append.Logfile.Tooltip"));
    props.setLook(wAppendLogfile);
    fdAppendLogfile = new FormData();
    fdAppendLogfile.left = new FormAttachment(middle, 0);
    fdAppendLogfile.top = new FormAttachment(wSetLogfile, margin);
    fdAppendLogfile.right = new FormAttachment(100, 0);
    wAppendLogfile.setLayoutData(fdAppendLogfile);
    wAppendLogfile.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
        }
    });

    // Set the logfile path + base-name
    wlLogfile = new Label(wLogging, SWT.RIGHT);
    wlLogfile.setText(BaseMessages.getString(PKG, "JobJob.NameOfLogfile.Label"));
    props.setLook(wlLogfile);
    fdlLogfile = new FormData();
    fdlLogfile.left = new FormAttachment(0, 0);
    fdlLogfile.top = new FormAttachment(wAppendLogfile, margin);
    fdlLogfile.right = new FormAttachment(middle, -margin);
    wlLogfile.setLayoutData(fdlLogfile);

    wbLogFilename = new Button(wLogging, SWT.PUSH | SWT.CENTER);
    props.setLook(wbLogFilename);
    wbLogFilename.setText(BaseMessages.getString(PKG, "JobJob.Browse.Label"));
    fdbLogFilename = new FormData();
    fdbLogFilename.top = new FormAttachment(wAppendLogfile, margin);
    fdbLogFilename.right = new FormAttachment(100, 0);
    wbLogFilename.setLayoutData(fdbLogFilename);

    wLogfile = new TextVar(jobMeta, wLogging, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    wLogfile.setText("");
    props.setLook(wLogfile);
    fdLogfile = new FormData();
    fdLogfile.left = new FormAttachment(middle, 0);
    fdLogfile.top = new FormAttachment(wAppendLogfile, margin);
    fdLogfile.right = new FormAttachment(wbLogFilename, -margin);
    wLogfile.setLayoutData(fdLogfile);

    // create parent folder?
    wlCreateParentFolder = new Label(wLogging, SWT.RIGHT);
    wlCreateParentFolder.setText(BaseMessages.getString(PKG, "JobJob.Logfile.CreateParentFolder.Label"));
    props.setLook(wlCreateParentFolder);
    fdlCreateParentFolder = new FormData();
    fdlCreateParentFolder.left = new FormAttachment(0, 0);
    fdlCreateParentFolder.top = new FormAttachment(wLogfile, margin);
    fdlCreateParentFolder.right = new FormAttachment(middle, -margin);
    wlCreateParentFolder.setLayoutData(fdlCreateParentFolder);
    wCreateParentFolder = new Button(wLogging, SWT.CHECK);
    wCreateParentFolder
            .setToolTipText(BaseMessages.getString(PKG, "JobJob.Logfile.CreateParentFolder.Tooltip"));
    props.setLook(wCreateParentFolder);
    fdCreateParentFolder = new FormData();
    fdCreateParentFolder.left = new FormAttachment(middle, 0);
    fdCreateParentFolder.top = new FormAttachment(wLogfile, margin);
    fdCreateParentFolder.right = new FormAttachment(100, 0);
    wCreateParentFolder.setLayoutData(fdCreateParentFolder);
    wCreateParentFolder.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
        }
    });

    // Set the logfile filename extention
    wlLogext = new Label(wLogging, SWT.RIGHT);
    wlLogext.setText(BaseMessages.getString(PKG, "JobJob.LogfileExtension.Label"));
    props.setLook(wlLogext);
    fdlLogext = new FormData();
    fdlLogext.left = new FormAttachment(0, 0);
    fdlLogext.top = new FormAttachment(wCreateParentFolder, margin);
    fdlLogext.right = new FormAttachment(middle, -margin);
    wlLogext.setLayoutData(fdlLogext);
    wLogext = new TextVar(jobMeta, wLogging, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    wLogext.setText("");
    props.setLook(wLogext);
    fdLogext = new FormData();
    fdLogext.left = new FormAttachment(middle, 0);
    fdLogext.top = new FormAttachment(wCreateParentFolder, margin);
    fdLogext.right = new FormAttachment(100, 0);
    wLogext.setLayoutData(fdLogext);

    // Add date to logfile name?
    wlAddDate = new Label(wLogging, SWT.RIGHT);
    wlAddDate.setText(BaseMessages.getString(PKG, "JobJob.Logfile.IncludeDate.Label"));
    props.setLook(wlAddDate);
    fdlAddDate = new FormData();
    fdlAddDate.left = new FormAttachment(0, 0);
    fdlAddDate.top = new FormAttachment(wLogext, margin);
    fdlAddDate.right = new FormAttachment(middle, -margin);
    wlAddDate.setLayoutData(fdlAddDate);
    wAddDate = new Button(wLogging, SWT.CHECK);
    props.setLook(wAddDate);
    fdAddDate = new FormData();
    fdAddDate.left = new FormAttachment(middle, 0);
    fdAddDate.top = new FormAttachment(wLogext, margin);
    fdAddDate.right = new FormAttachment(100, 0);
    wAddDate.setLayoutData(fdAddDate);

    // Add time to logfile name?
    wlAddTime = new Label(wLogging, SWT.RIGHT);
    wlAddTime.setText(BaseMessages.getString(PKG, "JobJob.Logfile.IncludeTime.Label"));
    props.setLook(wlAddTime);
    fdlAddTime = new FormData();
    fdlAddTime.left = new FormAttachment(0, 0);
    fdlAddTime.top = new FormAttachment(wAddDate, margin);
    fdlAddTime.right = new FormAttachment(middle, -margin);
    wlAddTime.setLayoutData(fdlAddTime);
    wAddTime = new Button(wLogging, SWT.CHECK);
    props.setLook(wAddTime);
    fdAddTime = new FormData();
    fdAddTime.left = new FormAttachment(middle, 0);
    fdAddTime.top = new FormAttachment(wAddDate, margin);
    fdAddTime.right = new FormAttachment(100, 0);
    wAddTime.setLayoutData(fdAddTime);

    wlLoglevel = new Label(wLogging, SWT.RIGHT);
    wlLoglevel.setText(BaseMessages.getString(PKG, "JobJob.Loglevel.Label"));
    props.setLook(wlLoglevel);
    fdlLoglevel = new FormData();
    fdlLoglevel.left = new FormAttachment(0, 0);
    fdlLoglevel.right = new FormAttachment(middle, -margin);
    fdlLoglevel.top = new FormAttachment(wAddTime, margin);
    wlLoglevel.setLayoutData(fdlLoglevel);
    wLoglevel = new CCombo(wLogging, SWT.SINGLE | SWT.READ_ONLY | SWT.BORDER);
    wLoglevel.setItems(LogLevel.getLogLevelDescriptions());
    props.setLook(wLoglevel);
    fdLoglevel = new FormData();
    fdLoglevel.left = new FormAttachment(middle, 0);
    fdLoglevel.top = new FormAttachment(wAddTime, margin);
    fdLoglevel.right = new FormAttachment(100, 0);
    wLoglevel.setLayoutData(fdLoglevel);

    fdLogging = new FormData();
    fdLogging.left = new FormAttachment(0, margin);
    fdLogging.top = new FormAttachment(wbFilename, margin);
    fdLogging.right = new FormAttachment(100, -margin);
    wLogging.setLayoutData(fdLogging);

    wLogging.pack();
    bounds = wLogging.getBounds();

    wSLogging.setContent(wLogging);
    wSLogging.setExpandHorizontal(true);
    wSLogging.setExpandVertical(true);
    wSLogging.setMinWidth(bounds.width);
    wSLogging.setMinHeight(bounds.height);

    wLoggingTab.setControl(wSLogging);

    // Arguments
    //
    CTabItem wFieldTab = new CTabItem(wTabFolder, SWT.NONE);
    wFieldTab.setText(BaseMessages.getString(PKG, "JobJob.Fields.Argument.Label"));

    FormLayout fieldLayout = new FormLayout();
    fieldLayout.marginWidth = Const.MARGIN;
    fieldLayout.marginHeight = Const.MARGIN;

    Composite wFieldComp = new Composite(wTabFolder, SWT.NONE);
    props.setLook(wFieldComp);
    wFieldComp.setLayout(fieldLayout);

    final int FieldsCols = 1;
    int rows = jobEntry.arguments == null ? 1
            : (jobEntry.arguments.length == 0 ? 0 : jobEntry.arguments.length);
    final int FieldsRows = rows;

    ColumnInfo[] colinf = new ColumnInfo[FieldsCols];
    colinf[0] = new ColumnInfo(BaseMessages.getString(PKG, "JobJob.Fields.Argument.Label"),
            ColumnInfo.COLUMN_TYPE_TEXT, false);
    colinf[0].setUsingVariables(true);

    wFields = new TableView(jobMeta, wFieldComp, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, colinf,
            FieldsRows, lsMod, props);

    FormData fdFields = new FormData();
    fdFields.left = new FormAttachment(0, 0);
    fdFields.top = new FormAttachment(0, margin);
    fdFields.right = new FormAttachment(100, 0);
    fdFields.bottom = new FormAttachment(100, 0);
    wFields.setLayoutData(fdFields);

    FormData fdFieldsComp = new FormData();
    fdFieldsComp.left = new FormAttachment(0, 0);
    fdFieldsComp.top = new FormAttachment(0, 0);
    fdFieldsComp.right = new FormAttachment(100, 0);
    fdFieldsComp.bottom = new FormAttachment(100, 0);
    wFieldComp.setLayoutData(fdFieldsComp);

    wFieldComp.layout();
    wFieldTab.setControl(wFieldComp);

    // The parameters tab
    CTabItem wParametersTab = new CTabItem(wTabFolder, SWT.NONE);
    wParametersTab.setText(BaseMessages.getString(PKG, "JobJob.Fields.Parameters.Label"));

    fieldLayout = new FormLayout();
    fieldLayout.marginWidth = Const.MARGIN;
    fieldLayout.marginHeight = Const.MARGIN;

    Composite wParameterComp = new Composite(wTabFolder, SWT.NONE);
    props.setLook(wParameterComp);
    wParameterComp.setLayout(fieldLayout);

    // Pass all parameters down
    //
    wlPassParams = new Label(wParameterComp, SWT.RIGHT);
    wlPassParams.setText(BaseMessages.getString(PKG, "JobJob.PassAllParameters.Label"));
    props.setLook(wlPassParams);
    fdlPassParams = new FormData();
    fdlPassParams.left = new FormAttachment(0, 0);
    fdlPassParams.top = new FormAttachment(0, 0);
    fdlPassParams.right = new FormAttachment(middle, -margin);
    wlPassParams.setLayoutData(fdlPassParams);
    wPassParams = new Button(wParameterComp, SWT.CHECK);
    props.setLook(wPassParams);
    fdPassParams = new FormData();
    fdPassParams.left = new FormAttachment(middle, 0);
    fdPassParams.top = new FormAttachment(0, 0);
    fdPassParams.right = new FormAttachment(100, 0);
    wPassParams.setLayoutData(fdPassParams);

    wbGetParams = new Button(wParameterComp, SWT.PUSH);
    wbGetParams.setText(BaseMessages.getString(PKG, "JobJob.GetParameters.Button.Label"));
    FormData fdGetParams = new FormData();
    fdGetParams.top = new FormAttachment(wPassParams, margin);
    fdGetParams.right = new FormAttachment(100, 0);
    wbGetParams.setLayoutData(fdGetParams);
    wbGetParams.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent arg0) {
            getParameters(null); // null: reload file from specification
        }
    });

    final int parameterRows = jobEntry.parameters == null ? 0 : jobEntry.parameters.length;

    colinf = new ColumnInfo[] {
            new ColumnInfo(BaseMessages.getString(PKG, "JobJob.Parameters.Parameter.Label"),
                    ColumnInfo.COLUMN_TYPE_TEXT, false),
            new ColumnInfo(BaseMessages.getString(PKG, "JobJob.Parameters.ColumnName.Label"),
                    ColumnInfo.COLUMN_TYPE_TEXT, false),
            new ColumnInfo(BaseMessages.getString(PKG, "JobJob.Parameters.Value.Label"),
                    ColumnInfo.COLUMN_TYPE_TEXT, false), };
    colinf[2].setUsingVariables(true);

    wParameters = new TableView(jobMeta, wParameterComp, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, colinf,
            parameterRows, lsMod, props);

    FormData fdParameters = new FormData();
    fdParameters.left = new FormAttachment(0, 0);
    fdParameters.top = new FormAttachment(wPassParams, margin);
    fdParameters.right = new FormAttachment(wbGetParams, -margin);
    fdParameters.bottom = new FormAttachment(100, 0);
    wParameters.setLayoutData(fdParameters);

    FormData fdParametersComp = new FormData();
    fdParametersComp.left = new FormAttachment(0, 0);
    fdParametersComp.top = new FormAttachment(0, 0);
    fdParametersComp.right = new FormAttachment(100, 0);
    fdParametersComp.bottom = new FormAttachment(100, 0);
    wParameterComp.setLayoutData(fdParametersComp);

    wParameterComp.layout();
    wParametersTab.setControl(wParameterComp);

    FormData fdTabFolder = new FormData();
    fdTabFolder.left = new FormAttachment(0, 0);
    fdTabFolder.top = new FormAttachment(wName, margin * 3);
    fdTabFolder.right = new FormAttachment(100, 0);
    fdTabFolder.bottom = new FormAttachment(100, -50);
    wTabFolder.setLayoutData(fdTabFolder);

    wTabFolder.setSelection(0);

    // Some buttons
    wOK = new Button(shell, SWT.PUSH);
    wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));

    BaseStepDialog.positionBottomButtons(shell, new Button[] { wOK, wCancel }, margin, wTabFolder);

    // Add listeners
    lsCancel = new Listener() {
        public void handleEvent(Event e) {
            cancel();
        }
    };
    lsOK = new Listener() {
        public void handleEvent(Event e) {
            ok();
        }
    };

    wOK.addListener(SWT.Selection, lsOK);
    wCancel.addListener(SWT.Selection, lsCancel);

    lsDef = new SelectionAdapter() {
        public void widgetDefaultSelected(SelectionEvent e) {
            ok();
        }
    };
    wName.addSelectionListener(lsDef);
    wFilename.addSelectionListener(lsDef);

    wbJobname.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            selectJob();
        }
    });

    wbFilename.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            pickFileVFS();
        }
    });

    wbByReference.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            selectJobByReference();
        }
    });

    wbLogFilename.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {

            FileDialog dialog = new FileDialog(shell, SWT.SAVE);
            dialog.setFilterExtensions(new String[] { "*.txt", "*.log", "*" });
            dialog.setFilterNames(FILE_FILTERLOGNAMES);

            if (wLogfile.getText() != null) {
                dialog.setFileName(jobMeta.environmentSubstitute(wLogfile.getText()));
            }

            if (dialog.open() != null) {
                wLogfile.setText(dialog.getFilterPath() + Const.FILE_SEPARATOR + dialog.getFileName());
                String filename = dialog.getFilterPath() + Const.FILE_SEPARATOR + dialog.getFileName();
                FileObject file = null;
                try {
                    file = KettleVFS.getFileObject(filename);
                    // Set file extension ..
                    wLogext.setText(file.getName().getExtension());
                    // Set filename without extension ...
                    wLogfile.setText(wLogfile.getText().substring(0,
                            wLogfile.getText().length() - wLogext.getText().length() - 1));
                } catch (Exception ex) {
                    // Ignore
                }
                if (file != null) {
                    try {
                        file.close();
                    } catch (IOException ex) { /* Ignore */
                    }
                }
            }

        }
    });

    // Detect [X] or ALT-F4 or something that kills this window...
    shell.addShellListener(new ShellAdapter() {
        public void shellClosed(ShellEvent e) {
            cancel();
        }
    });

    getData();
    setActive();

    BaseStepDialog.setSize(shell);

    shell.open();
    props.setDialogSize(shell, "JobJobDialogSize");
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    return jobEntry;
}

From source file:org.pentaho.di.ui.job.entries.oozie.OozieJobExecutorJobEntryController.java

/**
 * Open the VFS file browser to allow for selection of the workflow job properties configuration file.
 *//*from   w  w w. j a  v a  2s.c o  m*/
@Bindable
public void browseWorkflowConfig() {
    FileObject path = null;
    try {
        path = KettleVFS.getFileObject(
                jobEntry.getVariableSpace().environmentSubstitute(getConfig().getOozieWorkflowConfig()));
    } catch (Exception e) {
        // Ignore, use null (default VFS browse path)
    }
    try {
        FileObject exportDir = browseVfs(null, path, VfsFileChooserDialog.VFS_DIALOG_OPEN_DIRECTORY, null,
                "file", true);
        if (exportDir != null) {
            getConfig().setOozieWorkflowConfig(exportDir.getName().getURI());
        }
    } catch (KettleFileException e) {
        getJobEntry().logError(BaseMessages.getString(OozieJobExecutorJobEntry.class, ERROR_BROWSING_DIRECTORY),
                e);
    }
}

From source file:org.pentaho.di.ui.job.entries.sqoop.AbstractSqoopJobEntryController.java

protected FileObject getInitialFile(String path) throws FileSystemException {
    if (Const.isEmpty(path)) {
        path = "/";
    }/*  w  w  w .  j  a  v  a 2 s.co  m*/

    NamedCluster namedCluster = NamedClusterManager.getInstance()
            .getNamedClusterByName(selectedNamedCluster.getName(), Spoon.getInstance().getMetaStore());
    if (namedCluster == null) {
        return null;
    }
    if (namedCluster.isMapr()) {
        path = HadoopSpoonPlugin.MAPRFS_SCHEME + "://" + path;
    } else {
        path = NamedClusterManager.getInstance().processURLsubstitution(selectedNamedCluster.getName(), path,
                HadoopSpoonPlugin.HDFS_SCHEME, Spoon.getInstance().getMetaStore(), jobEntry);
    }

    FileObject initialFile = null;

    if (path != null) {
        String fileName = jobEntry.environmentSubstitute(path);
        if (fileName != null && !fileName.equals("")) {
            try {
                initialFile = KettleVFS.getFileObject(fileName);
                if (namedCluster.isMapr()) {
                    if (!initialFile.getName().getScheme().startsWith(HadoopSpoonPlugin.MAPRFS_SCHEME)) {
                        return null;
                    }
                } else if (!initialFile.getName().getScheme().startsWith(HadoopSpoonPlugin.HDFS_SCHEME)) {
                    return null;
                }
            } catch (Exception ex) {
                return null;
            }
        }
    }

    return initialFile;
}

From source file:org.pentaho.di.ui.job.entries.sqoop.SqoopExportJobEntryController.java

public void browseForExportDirectory() {
    FileObject path = null;/*from  www . j a  v  a 2 s.  c  om*/
    // TODO Build proper URL for path
    // path = resolveFile(getConfig().getExportDir());
    try {
        FileObject exportDir = browseVfs(null, path, VfsFileChooserDialog.VFS_DIALOG_OPEN_DIRECTORY,
                HadoopSpoonPlugin.HDFS_SCHEME, HadoopSpoonPlugin.HDFS_SCHEME, false);
        if (exportDir != null) {
            getConfig().setExportDir(exportDir.getName().getPath());
        }
    } catch (KettleFileException e) {
        getJobEntry().logError(BaseMessages.getString(AbstractSqoopJobEntry.class, "ErrorBrowsingDirectory"),
                e);
    }
}

From source file:org.pentaho.di.ui.job.entries.sqoop.SqoopImportJobEntryController.java

public void browseForTargetDirectory() {
    FileObject path = null;// w ww . j av a  2s. c  o  m
    // TODO Build proper URL for path
    // path = resolveFile(getConfig().getExportDir());

    try {
        FileObject targetDir = browseVfs(null, path, VfsFileChooserDialog.VFS_DIALOG_OPEN_DIRECTORY,
                HadoopSpoonPlugin.HDFS_SCHEME, HadoopSpoonPlugin.HDFS_SCHEME, false);
        if (targetDir != null) {
            getConfig().setTargetDir(targetDir.getName().getPath());
        }
    } catch (KettleFileException e) {
        getJobEntry().logError(BaseMessages.getString(AbstractSqoopJobEntry.class, "ErrorBrowsingDirectory"),
                e);
    }
}

From source file:org.pentaho.di.ui.job.entries.trans.JobEntryTransDialog.java

public JobEntryInterface open() {
    Shell parent = getParent();//from  w  ww  .  j  a  va 2s .c  om
    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();
        }
    };
    backupChanged = jobEntry.hasChanged();

    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = Const.FORM_MARGIN;
    formLayout.marginHeight = Const.FORM_MARGIN;

    shell.setLayout(formLayout);
    shell.setText(BaseMessages.getString(PKG, "JobTrans.Header"));

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

    // Name line
    wlName = new Label(shell, SWT.RIGHT);
    wlName.setText(BaseMessages.getString(PKG, "JobTrans.JobStep.Label"));
    props.setLook(wlName);
    fdlName = new FormData();
    fdlName.left = new FormAttachment(0, 0);
    fdlName.top = new FormAttachment(0, 0);
    fdlName.right = new FormAttachment(middle, -margin);
    wlName.setLayoutData(fdlName);

    wName = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wName);
    wName.addModifyListener(lsMod);
    fdName = new FormData();
    fdName.top = new FormAttachment(0, 0);
    fdName.left = new FormAttachment(middle, 0);
    fdName.right = new FormAttachment(100, 0);
    wName.setLayoutData(fdName);

    CTabFolder wTabFolder = new CTabFolder(shell, SWT.BORDER);
    props.setLook(wTabFolder, Props.WIDGET_STYLE_TAB);

    // Specification
    //
    CTabItem wSpecTab = new CTabItem(wTabFolder, SWT.NONE);
    wSpecTab.setText(BaseMessages.getString(PKG, "JobTrans.Specification.Group.Label"));

    ScrolledComposite wSSpec = new ScrolledComposite(wTabFolder, SWT.V_SCROLL | SWT.H_SCROLL);
    wSSpec.setLayout(new FillLayout());

    wSpec = new Composite(wSSpec, SWT.SHADOW_NONE);
    props.setLook(wSpec);

    FormLayout specLayout = new FormLayout();
    specLayout.marginWidth = Const.FORM_MARGIN;
    specLayout.marginHeight = Const.FORM_MARGIN;
    wSpec.setLayout(specLayout);

    // The specify by filename option...
    //
    Group gFilename = new Group(wSpec, SWT.SHADOW_ETCHED_IN);
    props.setLook(gFilename);
    FormLayout gFileLayout = new FormLayout();
    gFileLayout.marginWidth = Const.FORM_MARGIN;
    gFileLayout.marginHeight = Const.FORM_MARGIN;
    gFilename.setLayout(gFileLayout);

    radioFilename = new Button(gFilename, SWT.RADIO);
    props.setLook(radioFilename);
    radioFilename.setText(BaseMessages.getString(PKG, "JobTrans.TransformationFile.Label"));
    FormData fdRadioFilename = new FormData();
    fdRadioFilename.top = new FormAttachment(0, 0);
    fdRadioFilename.left = new FormAttachment(0, 0);
    fdRadioFilename.right = new FormAttachment(middle, -margin);
    radioFilename.setLayoutData(fdRadioFilename);
    radioFilename.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent arg0) {
            specificationMethod = ObjectLocationSpecificationMethod.FILENAME;
            setRadioButtons();
        }
    });

    wbFilename = new Button(gFilename, SWT.PUSH | SWT.CENTER);
    props.setLook(wbFilename);
    wbFilename.setImage(GUIResource.getInstance().getImageTransGraph());
    wbFilename.setToolTipText(BaseMessages.getString(PKG, "JobTrans.SelectTrans.Tooltip"));
    FormData fdbFilename = new FormData();
    fdbFilename.top = new FormAttachment(0, 0);
    fdbFilename.right = new FormAttachment(100, 0);
    wbFilename.setLayoutData(fdbFilename);

    wFilename = new TextVar(jobMeta, gFilename, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wFilename);
    wFilename.addModifyListener(lsMod);
    FormData fdFilename = new FormData();
    fdFilename.top = new FormAttachment(0, 0);
    fdFilename.left = new FormAttachment(middle, 0);
    fdFilename.right = new FormAttachment(wbFilename, -margin);
    wFilename.setLayoutData(fdFilename);
    wFilename.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent arg0) {
            specificationMethod = ObjectLocationSpecificationMethod.FILENAME;
            setRadioButtons();
        }
    });

    FormData fdgFilename = new FormData();
    fdgFilename.top = new FormAttachment(0, 0);
    fdgFilename.left = new FormAttachment(0, 0);
    fdgFilename.right = new FormAttachment(100, 0);
    gFilename.setLayoutData(fdgFilename);

    // The repository : specify by name radio option...
    //
    Group gByName = new Group(wSpec, SWT.SHADOW_ETCHED_IN);
    props.setLook(gByName);
    FormLayout gByNameLayout = new FormLayout();
    gByNameLayout.marginWidth = Const.FORM_MARGIN;
    gByNameLayout.marginHeight = Const.FORM_MARGIN;
    gByName.setLayout(gByNameLayout);

    radioByName = new Button(gByName, SWT.RADIO);
    props.setLook(radioByName);
    radioByName.setText(BaseMessages.getString(PKG, "JobTrans.NameOfTransformation.Label"));
    FormData fdRadioByName = new FormData();
    fdRadioByName.top = new FormAttachment(0, 0);
    fdRadioByName.left = new FormAttachment(0, 0);
    fdRadioByName.right = new FormAttachment(middle, -margin);
    radioByName.setLayoutData(fdRadioByName);
    radioByName.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent arg0) {
            specificationMethod = ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME;
            setRadioButtons();
        }
    });

    wbTransname = new Button(gByName, SWT.PUSH | SWT.CENTER);
    props.setLook(wbTransname);
    wbTransname.setImage(GUIResource.getInstance().getImageTransGraph());
    wbTransname.setToolTipText(BaseMessages.getString(PKG, "JobTrans.SelectTransRep.Tooltip"));
    FormData fdbTransname = new FormData();
    fdbTransname.top = new FormAttachment(0, 0);
    fdbTransname.right = new FormAttachment(100, 0);
    wbTransname.setLayoutData(fdbTransname);

    wTransname = new TextVar(jobMeta, gByName, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wTransname);
    wTransname.addModifyListener(lsMod);
    FormData fdTransname = new FormData();
    fdTransname.top = new FormAttachment(0, 0);
    fdTransname.left = new FormAttachment(middle, 0);
    fdTransname.right = new FormAttachment(wbTransname, -margin);
    wTransname.setLayoutData(fdTransname);

    wDirectory = new TextVar(jobMeta, gByName, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wDirectory);
    wDirectory.addModifyListener(lsMod);
    FormData fdDirectory = new FormData();
    fdDirectory.top = new FormAttachment(wTransname, margin * 2);
    fdDirectory.left = new FormAttachment(middle, 0);
    fdDirectory.right = new FormAttachment(100, 0);
    wDirectory.setLayoutData(fdDirectory);

    FormData fdgByName = new FormData();
    fdgByName.top = new FormAttachment(gFilename, margin);
    fdgByName.left = new FormAttachment(0, 0);
    fdgByName.right = new FormAttachment(100, 0);
    gByName.setLayoutData(fdgByName);

    // The specify by filename option...
    //

    Group gByReference = new Group(wSpec, SWT.SHADOW_ETCHED_IN);
    props.setLook(gByReference);
    FormLayout gByReferenceLayout = new FormLayout();
    gByReferenceLayout.marginWidth = Const.FORM_MARGIN;
    gByReferenceLayout.marginHeight = Const.FORM_MARGIN;
    gByReference.setLayout(gByReferenceLayout);

    radioByReference = new Button(gByReference, SWT.RADIO);
    props.setLook(radioByReference);
    radioByReference.setText(BaseMessages.getString(PKG, "JobTrans.TransformationByReference.Label"));
    FormData fdRadioByReference = new FormData();
    fdRadioByReference.top = new FormAttachment(0, 0);
    fdRadioByReference.left = new FormAttachment(0, 0);
    fdRadioByReference.right = new FormAttachment(middle, -margin);
    radioByReference.setLayoutData(fdRadioByReference);
    radioByReference.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent arg0) {
            specificationMethod = ObjectLocationSpecificationMethod.REPOSITORY_BY_REFERENCE;
            setRadioButtons();
        }
    });

    wbByReference = new Button(gByReference, SWT.PUSH | SWT.CENTER);
    props.setLook(wbByReference);
    wbByReference.setImage(GUIResource.getInstance().getImageTransGraph());
    wbByReference.setToolTipText(BaseMessages.getString(PKG, "JobTrans.SelectTrans.Tooltip"));
    FormData fdbByReference = new FormData();
    fdbByReference.top = new FormAttachment(0, 0);
    fdbByReference.right = new FormAttachment(100, 0);
    wbByReference.setLayoutData(fdbByReference);

    wByReference = new Text(gByReference, SWT.SINGLE | SWT.LEFT | SWT.BORDER | SWT.READ_ONLY);
    props.setLook(wByReference);
    wByReference.addModifyListener(lsMod);
    FormData fdByReference = new FormData();
    fdByReference.top = new FormAttachment(0, 0);
    fdByReference.left = new FormAttachment(middle, 0);
    fdByReference.right = new FormAttachment(wbByReference, -margin);
    wByReference.setLayoutData(fdByReference);

    FormData fdgByReference = new FormData();
    fdgByReference.top = new FormAttachment(gByName, margin);
    fdgByReference.left = new FormAttachment(0, 0);
    fdgByReference.right = new FormAttachment(100, 0);
    gByReference.setLayoutData(fdgByReference);

    wNewTrans = new Button(wSpec, SWT.PUSH);
    wNewTrans.setText(BaseMessages.getString(PKG, "JobTrans.NewTransButton.Label"));
    FormData fdNewTrans = new FormData();
    fdNewTrans.bottom = new FormAttachment(100, -margin);
    fdNewTrans.left = new FormAttachment(wByReference, 0, SWT.CENTER);
    wNewTrans.setLayoutData(fdNewTrans);
    wNewTrans.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent event) {
            newTransformation();
        }
    });

    wSpec.pack();
    Rectangle bounds = wSpec.getBounds();

    wSSpec.setContent(wSpec);
    wSSpec.setExpandHorizontal(true);
    wSSpec.setExpandVertical(true);
    wSSpec.setMinWidth(bounds.width);
    wSSpec.setMinHeight(bounds.height);

    wSpecTab.setControl(wSSpec);

    fdSpec = new FormData();
    fdSpec.left = new FormAttachment(0, 0);
    fdSpec.top = new FormAttachment(0, 0);
    fdSpec.right = new FormAttachment(100, 0);
    fdSpec.bottom = new FormAttachment(100, 0);
    wSpec.setLayoutData(fdSpec);

    // Advanced
    //
    CTabItem wAdvancedTab = new CTabItem(wTabFolder, SWT.NONE);
    wAdvancedTab.setText(BaseMessages.getString(PKG, "JobTrans.Advanced.Group.Label"));

    ScrolledComposite wSAdvanced = new ScrolledComposite(wTabFolder, SWT.V_SCROLL | SWT.H_SCROLL);
    wSAdvanced.setLayout(new FillLayout());

    wAdvanced = new Composite(wSAdvanced, SWT.SHADOW_NONE);
    props.setLook(wAdvanced);

    FormLayout advancedLayout = new FormLayout();
    advancedLayout.marginWidth = Const.FORM_MARGIN;
    advancedLayout.marginHeight = Const.FORM_MARGIN;
    wAdvanced.setLayout(advancedLayout);

    wlPrevious = new Label(wAdvanced, SWT.RIGHT);
    wlPrevious.setText(BaseMessages.getString(PKG, "JobTrans.Previous.Label"));
    props.setLook(wlPrevious);
    FormData fdlPrevious = new FormData();
    fdlPrevious.left = new FormAttachment(0, 0);
    fdlPrevious.top = new FormAttachment(0, 0);
    fdlPrevious.right = new FormAttachment(middle, -margin);
    wlPrevious.setLayoutData(fdlPrevious);
    wPrevious = new Button(wAdvanced, SWT.CHECK);
    props.setLook(wPrevious);
    wPrevious.setSelection(jobEntry.argFromPrevious);
    wPrevious.setToolTipText(BaseMessages.getString(PKG, "JobTrans.Previous.Tooltip"));
    FormData fdPrevious = new FormData();
    fdPrevious.left = new FormAttachment(middle, 0);
    fdPrevious.top = new FormAttachment(0, 0);
    fdPrevious.right = new FormAttachment(100, 0);
    wPrevious.setLayoutData(fdPrevious);
    wPrevious.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            wFields.setEnabled(!jobEntry.argFromPrevious);
        }
    });

    wlPrevToParams = new Label(wAdvanced, SWT.RIGHT);
    wlPrevToParams.setText(BaseMessages.getString(PKG, "JobTrans.PrevToParams.Label"));
    props.setLook(wlPrevToParams);
    FormData fdlPrevToParams = new FormData();
    fdlPrevToParams.left = new FormAttachment(0, 0);
    fdlPrevToParams.top = new FormAttachment(wPrevious, margin * 3);
    fdlPrevToParams.right = new FormAttachment(middle, -margin);
    wlPrevToParams.setLayoutData(fdlPrevToParams);
    wPrevToParams = new Button(wAdvanced, SWT.CHECK);
    props.setLook(wPrevToParams);
    wPrevToParams.setSelection(jobEntry.paramsFromPrevious);
    wPrevToParams.setToolTipText(BaseMessages.getString(PKG, "JobTrans.PrevToParams.Tooltip"));
    FormData fdPrevToParams = new FormData();
    fdPrevToParams.left = new FormAttachment(middle, 0);
    fdPrevToParams.top = new FormAttachment(wPrevious, margin * 3);
    fdPrevToParams.right = new FormAttachment(100, 0);
    wPrevToParams.setLayoutData(fdPrevToParams);
    wPrevToParams.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            jobEntry.setChanged();
        }
    });

    wlEveryRow = new Label(wAdvanced, SWT.RIGHT);
    wlEveryRow.setText(BaseMessages.getString(PKG, "JobTrans.ExecForEveryInputRow.Label"));
    props.setLook(wlEveryRow);
    FormData fdlEveryRow = new FormData();
    fdlEveryRow.left = new FormAttachment(0, 0);
    fdlEveryRow.top = new FormAttachment(wPrevToParams, margin);
    fdlEveryRow.right = new FormAttachment(middle, -margin);
    wlEveryRow.setLayoutData(fdlEveryRow);
    wEveryRow = new Button(wAdvanced, SWT.CHECK);
    props.setLook(wEveryRow);
    wEveryRow.setToolTipText(BaseMessages.getString(PKG, "JobTrans.ExecForEveryInputRow.Tooltip"));
    FormData fdEveryRow = new FormData();
    fdEveryRow.left = new FormAttachment(middle, 0);
    fdEveryRow.top = new FormAttachment(wPrevToParams, margin);
    fdEveryRow.right = new FormAttachment(100, 0);
    wEveryRow.setLayoutData(fdEveryRow);

    // Clear the result rows before executing the transformation?
    //
    wlClearRows = new Label(wAdvanced, SWT.RIGHT);
    wlClearRows.setText(BaseMessages.getString(PKG, "JobTrans.ClearResultList.Label"));
    props.setLook(wlClearRows);
    FormData fdlClearRows = new FormData();
    fdlClearRows.left = new FormAttachment(0, 0);
    fdlClearRows.top = new FormAttachment(wEveryRow, margin);
    fdlClearRows.right = new FormAttachment(middle, -margin);
    wlClearRows.setLayoutData(fdlClearRows);
    wClearRows = new Button(wAdvanced, SWT.CHECK);
    props.setLook(wClearRows);
    FormData fdClearRows = new FormData();
    fdClearRows.left = new FormAttachment(middle, 0);
    fdClearRows.top = new FormAttachment(wEveryRow, margin);
    fdClearRows.right = new FormAttachment(100, 0);
    wClearRows.setLayoutData(fdClearRows);

    // Clear the result files before executing the transformation?
    //
    wlClearFiles = new Label(wAdvanced, SWT.RIGHT);
    wlClearFiles.setText(BaseMessages.getString(PKG, "JobTrans.ClearResultFiles.Label"));
    props.setLook(wlClearFiles);
    FormData fdlClearFiles = new FormData();
    fdlClearFiles.left = new FormAttachment(0, 0);
    fdlClearFiles.top = new FormAttachment(wClearRows, margin);
    fdlClearFiles.right = new FormAttachment(middle, -margin);
    wlClearFiles.setLayoutData(fdlClearFiles);
    wClearFiles = new Button(wAdvanced, SWT.CHECK);
    props.setLook(wClearFiles);
    FormData fdClearFiles = new FormData();
    fdClearFiles.left = new FormAttachment(middle, 0);
    fdClearFiles.top = new FormAttachment(wClearRows, margin);
    fdClearFiles.right = new FormAttachment(100, 0);
    wClearFiles.setLayoutData(fdClearFiles);

    // Clear the result rows before executing the transformation?
    //
    wlCluster = new Label(wAdvanced, SWT.RIGHT);
    wlCluster.setText(BaseMessages.getString(PKG, "JobTrans.RunTransInCluster.Label"));
    props.setLook(wlCluster);
    FormData fdlCluster = new FormData();
    fdlCluster.left = new FormAttachment(0, 0);
    fdlCluster.top = new FormAttachment(wClearFiles, margin);
    fdlCluster.right = new FormAttachment(middle, -margin);
    wlCluster.setLayoutData(fdlCluster);
    wCluster = new Button(wAdvanced, SWT.CHECK);
    props.setLook(wCluster);
    FormData fdCluster = new FormData();
    fdCluster.left = new FormAttachment(middle, 0);
    fdCluster.top = new FormAttachment(wClearFiles, margin);
    fdCluster.right = new FormAttachment(100, 0);
    wCluster.setLayoutData(fdCluster);
    wCluster.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            setActive();
        }
    });

    // Log clustering logging results locally?
    //
    wlLogRemoteWork = new Label(wAdvanced, SWT.RIGHT);
    wlLogRemoteWork.setText(BaseMessages.getString(PKG, "JobTrans.LogRemoteWork.Label"));
    props.setLook(wlLogRemoteWork);
    FormData fdlLogRemoteWork = new FormData();
    fdlLogRemoteWork.left = new FormAttachment(0, 0);
    fdlLogRemoteWork.top = new FormAttachment(wCluster, margin);
    fdlLogRemoteWork.right = new FormAttachment(middle, -margin);
    wlLogRemoteWork.setLayoutData(fdlLogRemoteWork);
    wLogRemoteWork = new Button(wAdvanced, SWT.CHECK);
    props.setLook(wLogRemoteWork);
    FormData fdLogRemoteWork = new FormData();
    fdLogRemoteWork.left = new FormAttachment(middle, 0);
    fdLogRemoteWork.top = new FormAttachment(wCluster, margin);
    fdLogRemoteWork.right = new FormAttachment(100, 0);
    wLogRemoteWork.setLayoutData(fdLogRemoteWork);

    // The remote slave server
    //
    wlSlaveServer = new Label(wAdvanced, SWT.RIGHT);
    wlSlaveServer.setText(BaseMessages.getString(PKG, "JobTrans.SlaveServer.Label"));
    wlSlaveServer.setToolTipText(BaseMessages.getString(PKG, "JobTrans.SlaveServer.ToolTip"));
    props.setLook(wlSlaveServer);
    FormData fdlSlaveServer = new FormData();
    fdlSlaveServer.left = new FormAttachment(0, 0);
    fdlSlaveServer.right = new FormAttachment(middle, -margin);
    fdlSlaveServer.top = new FormAttachment(wLogRemoteWork, margin);
    wlSlaveServer.setLayoutData(fdlSlaveServer);
    wSlaveServer = new ComboVar(jobMeta, wAdvanced, SWT.SINGLE | SWT.BORDER);
    wSlaveServer.setItems(SlaveServer.getSlaveServerNames(jobMeta.getSlaveServers()));
    wSlaveServer.setToolTipText(BaseMessages.getString(PKG, "JobTrans.SlaveServer.ToolTip"));
    props.setLook(wSlaveServer);
    FormData fdSlaveServer = new FormData();
    fdSlaveServer.left = new FormAttachment(middle, 0);
    fdSlaveServer.top = new FormAttachment(wLogRemoteWork, margin);
    fdSlaveServer.right = new FormAttachment(100, 0);
    wSlaveServer.setLayoutData(fdSlaveServer);
    wSlaveServer.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            setActive();
        }
    });

    // Wait for the remote transformation to finish?
    //
    wlWaitingToFinish = new Label(wAdvanced, SWT.RIGHT);
    wlWaitingToFinish.setText(BaseMessages.getString(PKG, "JobTrans.WaitToFinish.Label"));
    props.setLook(wlWaitingToFinish);
    FormData fdlWaitingToFinish = new FormData();
    fdlWaitingToFinish.left = new FormAttachment(0, 0);
    fdlWaitingToFinish.top = new FormAttachment(wSlaveServer, margin);
    fdlWaitingToFinish.right = new FormAttachment(middle, -margin);
    wlWaitingToFinish.setLayoutData(fdlWaitingToFinish);
    wWaitingToFinish = new Button(wAdvanced, SWT.CHECK);
    props.setLook(wWaitingToFinish);
    FormData fdWaitingToFinish = new FormData();
    fdWaitingToFinish.left = new FormAttachment(middle, 0);
    fdWaitingToFinish.top = new FormAttachment(wSlaveServer, margin);
    fdWaitingToFinish.right = new FormAttachment(100, 0);
    wWaitingToFinish.setLayoutData(fdWaitingToFinish);
    wWaitingToFinish.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            setActive();
        }
    });

    // Follow a local abort remotely?
    //
    wlFollowingAbortRemotely = new Label(wAdvanced, SWT.RIGHT);
    wlFollowingAbortRemotely.setText(BaseMessages.getString(PKG, "JobTrans.AbortRemote.Label"));
    props.setLook(wlFollowingAbortRemotely);
    FormData fdlFollowingAbortRemotely = new FormData();
    fdlFollowingAbortRemotely.left = new FormAttachment(0, 0);
    fdlFollowingAbortRemotely.top = new FormAttachment(wWaitingToFinish, margin);
    fdlFollowingAbortRemotely.right = new FormAttachment(middle, -margin);
    wlFollowingAbortRemotely.setLayoutData(fdlFollowingAbortRemotely);
    wFollowingAbortRemotely = new Button(wAdvanced, SWT.CHECK);
    props.setLook(wFollowingAbortRemotely);
    FormData fdFollowingAbortRemotely = new FormData();
    fdFollowingAbortRemotely.left = new FormAttachment(middle, 0);
    fdFollowingAbortRemotely.top = new FormAttachment(wWaitingToFinish, margin);
    fdFollowingAbortRemotely.right = new FormAttachment(100, 0);
    wFollowingAbortRemotely.setLayoutData(fdFollowingAbortRemotely);

    FormData fdAdvanced = new FormData();
    fdAdvanced.left = new FormAttachment(0, 0);
    fdAdvanced.top = new FormAttachment(0, 0);
    fdAdvanced.right = new FormAttachment(100, 0);
    fdAdvanced.bottom = new FormAttachment(100, 0);
    wAdvanced.setLayoutData(fdAdvanced);

    wAdvanced.pack();
    bounds = wAdvanced.getBounds();

    wSAdvanced.setContent(wAdvanced);
    wSAdvanced.setExpandHorizontal(true);
    wSAdvanced.setExpandVertical(true);
    wSAdvanced.setMinWidth(bounds.width);
    wSAdvanced.setMinHeight(bounds.height);

    wAdvancedTab.setControl(wSAdvanced);

    // Logging
    //
    CTabItem wLoggingTab = new CTabItem(wTabFolder, SWT.NONE);
    wLoggingTab.setText(BaseMessages.getString(PKG, "JobTrans.LogSettings.Group.Label"));

    ScrolledComposite wSLogging = new ScrolledComposite(wTabFolder, SWT.V_SCROLL | SWT.H_SCROLL);
    wSLogging.setLayout(new FillLayout());

    wLogging = new Composite(wSLogging, SWT.SHADOW_NONE);
    props.setLook(wLogging);

    FormLayout groupLayout = new FormLayout();
    groupLayout.marginWidth = Const.FORM_MARGIN;
    groupLayout.marginHeight = Const.FORM_MARGIN;

    wLogging.setLayout(groupLayout);

    // Set the logfile?
    wlSetLogfile = new Label(wLogging, SWT.RIGHT);
    wlSetLogfile.setText(BaseMessages.getString(PKG, "JobTrans.Specify.Logfile.Label"));
    props.setLook(wlSetLogfile);
    FormData fdlSetLogfile = new FormData();
    fdlSetLogfile.left = new FormAttachment(0, 0);
    fdlSetLogfile.top = new FormAttachment(0, margin);
    fdlSetLogfile.right = new FormAttachment(middle, -margin);
    wlSetLogfile.setLayoutData(fdlSetLogfile);
    wSetLogfile = new Button(wLogging, SWT.CHECK);
    props.setLook(wSetLogfile);
    FormData fdSetLogfile = new FormData();
    fdSetLogfile.left = new FormAttachment(middle, 0);
    fdSetLogfile.top = new FormAttachment(0, margin);
    fdSetLogfile.right = new FormAttachment(100, 0);
    wSetLogfile.setLayoutData(fdSetLogfile);
    wSetLogfile.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            setActive();
        }
    });
    // Append the logfile?
    wlAppendLogfile = new Label(wLogging, SWT.RIGHT);
    wlAppendLogfile.setText(BaseMessages.getString(PKG, "JobTrans.Append.Logfile.Label"));
    props.setLook(wlAppendLogfile);
    FormData fdlAppendLogfile = new FormData();
    fdlAppendLogfile.left = new FormAttachment(0, 0);
    fdlAppendLogfile.top = new FormAttachment(wSetLogfile, margin);
    fdlAppendLogfile.right = new FormAttachment(middle, -margin);
    wlAppendLogfile.setLayoutData(fdlAppendLogfile);
    wAppendLogfile = new Button(wLogging, SWT.CHECK);
    wAppendLogfile.setToolTipText(BaseMessages.getString(PKG, "JobTrans.Append.Logfile.Tooltip"));
    props.setLook(wAppendLogfile);
    FormData fdAppendLogfile = new FormData();
    fdAppendLogfile.left = new FormAttachment(middle, 0);
    fdAppendLogfile.top = new FormAttachment(wSetLogfile, margin);
    fdAppendLogfile.right = new FormAttachment(100, 0);
    wAppendLogfile.setLayoutData(fdAppendLogfile);
    wAppendLogfile.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
        }
    });

    // Set the logfile path + base-name
    wlLogfile = new Label(wLogging, SWT.RIGHT);
    wlLogfile.setText(BaseMessages.getString(PKG, "JobTrans.NameOfLogfile.Label"));
    props.setLook(wlLogfile);
    FormData fdlLogfile = new FormData();
    fdlLogfile.left = new FormAttachment(0, 0);
    fdlLogfile.top = new FormAttachment(wAppendLogfile, margin);
    fdlLogfile.right = new FormAttachment(middle, -margin);
    wlLogfile.setLayoutData(fdlLogfile);

    wbLogFilename = new Button(wLogging, SWT.PUSH | SWT.CENTER);
    props.setLook(wbLogFilename);
    wbLogFilename.setText(BaseMessages.getString(PKG, "JobTrans.Browse.Label"));
    fdbLogFilename = new FormData();
    fdbLogFilename.top = new FormAttachment(wAppendLogfile, margin);
    fdbLogFilename.right = new FormAttachment(100, 0);
    wbLogFilename.setLayoutData(fdbLogFilename);

    wLogfile = new TextVar(jobMeta, wLogging, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    wLogfile.setText("");
    props.setLook(wLogfile);
    FormData fdLogfile = new FormData();
    fdLogfile.left = new FormAttachment(middle, 0);
    fdLogfile.top = new FormAttachment(wAppendLogfile, margin);
    fdLogfile.right = new FormAttachment(wbLogFilename, -margin);
    wLogfile.setLayoutData(fdLogfile);

    // create parent folder?
    wlCreateParentFolder = new Label(wLogging, SWT.RIGHT);
    wlCreateParentFolder.setText(BaseMessages.getString(PKG, "JobTrans.Logfile.CreateParentFolder.Label"));
    props.setLook(wlCreateParentFolder);
    fdlCreateParentFolder = new FormData();
    fdlCreateParentFolder.left = new FormAttachment(0, 0);
    fdlCreateParentFolder.top = new FormAttachment(wLogfile, margin);
    fdlCreateParentFolder.right = new FormAttachment(middle, -margin);
    wlCreateParentFolder.setLayoutData(fdlCreateParentFolder);
    wCreateParentFolder = new Button(wLogging, SWT.CHECK);
    wCreateParentFolder
            .setToolTipText(BaseMessages.getString(PKG, "JobTrans.Logfile.CreateParentFolder.Tooltip"));
    props.setLook(wCreateParentFolder);
    fdCreateParentFolder = new FormData();
    fdCreateParentFolder.left = new FormAttachment(middle, 0);
    fdCreateParentFolder.top = new FormAttachment(wLogfile, margin);
    fdCreateParentFolder.right = new FormAttachment(100, 0);
    wCreateParentFolder.setLayoutData(fdCreateParentFolder);
    wCreateParentFolder.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
        }
    });

    // Set the logfile filename extention
    wlLogext = new Label(wLogging, SWT.RIGHT);
    wlLogext.setText(BaseMessages.getString(PKG, "JobTrans.LogfileExtension.Label"));
    props.setLook(wlLogext);
    FormData fdlLogext = new FormData();
    fdlLogext.left = new FormAttachment(0, 0);
    fdlLogext.top = new FormAttachment(wCreateParentFolder, margin);
    fdlLogext.right = new FormAttachment(middle, -margin);
    wlLogext.setLayoutData(fdlLogext);
    wLogext = new TextVar(jobMeta, wLogging, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    wLogext.setText("");
    props.setLook(wLogext);
    FormData fdLogext = new FormData();
    fdLogext.left = new FormAttachment(middle, 0);
    fdLogext.top = new FormAttachment(wCreateParentFolder, margin);
    fdLogext.right = new FormAttachment(100, 0);
    wLogext.setLayoutData(fdLogext);

    // Add date to logfile name?
    wlAddDate = new Label(wLogging, SWT.RIGHT);
    wlAddDate.setText(BaseMessages.getString(PKG, "JobTrans.Logfile.IncludeDate.Label"));
    props.setLook(wlAddDate);
    FormData fdlAddDate = new FormData();
    fdlAddDate.left = new FormAttachment(0, 0);
    fdlAddDate.top = new FormAttachment(wLogext, margin);
    fdlAddDate.right = new FormAttachment(middle, -margin);
    wlAddDate.setLayoutData(fdlAddDate);
    wAddDate = new Button(wLogging, SWT.CHECK);
    props.setLook(wAddDate);
    FormData fdAddDate = new FormData();
    fdAddDate.left = new FormAttachment(middle, 0);
    fdAddDate.top = new FormAttachment(wLogext, margin);
    fdAddDate.right = new FormAttachment(100, 0);
    wAddDate.setLayoutData(fdAddDate);

    // Add time to logfile name?
    wlAddTime = new Label(wLogging, SWT.RIGHT);
    wlAddTime.setText(BaseMessages.getString(PKG, "JobTrans.Logfile.IncludeTime.Label"));
    props.setLook(wlAddTime);
    FormData fdlAddTime = new FormData();
    fdlAddTime.left = new FormAttachment(0, 0);
    fdlAddTime.top = new FormAttachment(wlAddDate, margin);
    fdlAddTime.right = new FormAttachment(middle, -margin);
    wlAddTime.setLayoutData(fdlAddTime);
    wAddTime = new Button(wLogging, SWT.CHECK);
    props.setLook(wAddTime);
    FormData fdAddTime = new FormData();
    fdAddTime.left = new FormAttachment(middle, 0);
    fdAddTime.top = new FormAttachment(wlAddDate, margin);
    fdAddTime.right = new FormAttachment(100, 0);
    wAddTime.setLayoutData(fdAddTime);

    wlLoglevel = new Label(wLogging, SWT.RIGHT);
    wlLoglevel.setText(BaseMessages.getString(PKG, "JobTrans.Loglevel.Label"));
    props.setLook(wlLoglevel);
    FormData fdlLoglevel = new FormData();
    fdlLoglevel.left = new FormAttachment(0, 0);
    fdlLoglevel.right = new FormAttachment(middle, -margin);
    fdlLoglevel.top = new FormAttachment(wAddTime, margin);
    wlLoglevel.setLayoutData(fdlLoglevel);
    wLoglevel = new CCombo(wLogging, SWT.SINGLE | SWT.READ_ONLY | SWT.BORDER);
    wLoglevel.setItems(LogLevel.getLogLevelDescriptions());
    props.setLook(wLoglevel);
    FormData fdLoglevel = new FormData();
    fdLoglevel.left = new FormAttachment(middle, 0);
    fdLoglevel.top = new FormAttachment(wAddTime, margin);
    fdLoglevel.right = new FormAttachment(100, 0);
    wLoglevel.setLayoutData(fdLoglevel);

    FormData fdLogging = new FormData();
    fdLogging.left = new FormAttachment(0, 0);
    fdLogging.top = new FormAttachment(0, 0);
    fdLogging.right = new FormAttachment(100, 0);
    fdLogging.bottom = new FormAttachment(100, 0);
    wLogging.setLayoutData(fdLogging);

    wLogging.pack();
    bounds = wLogging.getBounds();

    wSLogging.setContent(wLogging);
    wSLogging.setExpandHorizontal(true);
    wSLogging.setExpandVertical(true);
    wSLogging.setMinWidth(bounds.width);
    wSLogging.setMinHeight(bounds.height);

    wLoggingTab.setControl(wSLogging);

    // Arguments
    //
    CTabItem wFieldTab = new CTabItem(wTabFolder, SWT.NONE);
    wFieldTab.setText(BaseMessages.getString(PKG, "JobTrans.Fields.Argument.Label"));

    FormLayout fieldLayout = new FormLayout();
    fieldLayout.marginWidth = Const.MARGIN;
    fieldLayout.marginHeight = Const.MARGIN;

    Composite wFieldComp = new Composite(wTabFolder, SWT.NONE);
    props.setLook(wFieldComp);
    wFieldComp.setLayout(fieldLayout);

    final int FieldsCols = 1;
    int rows = jobEntry.arguments == null ? 1
            : (jobEntry.arguments.length == 0 ? 0 : jobEntry.arguments.length);
    final int FieldsRows = rows;

    ColumnInfo[] colinf = new ColumnInfo[FieldsCols];
    colinf[0] = new ColumnInfo(BaseMessages.getString(PKG, "JobTrans.Fields.Argument.Label"),
            ColumnInfo.COLUMN_TYPE_TEXT, false);
    colinf[0].setUsingVariables(true);

    wFields = new TableView(jobMeta, wFieldComp, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, colinf,
            FieldsRows, lsMod, props);

    FormData fdFields = new FormData();
    fdFields.left = new FormAttachment(0, 0);
    fdFields.top = new FormAttachment(0, margin);
    fdFields.right = new FormAttachment(100, 0);
    fdFields.bottom = new FormAttachment(100, 0);
    wFields.setLayoutData(fdFields);

    FormData fdFieldsComp = new FormData();
    fdFieldsComp.left = new FormAttachment(0, 0);
    fdFieldsComp.top = new FormAttachment(0, 0);
    fdFieldsComp.right = new FormAttachment(100, 0);
    fdFieldsComp.bottom = new FormAttachment(100, 0);
    wFieldComp.setLayoutData(fdFieldsComp);

    wFieldComp.layout();
    wFieldTab.setControl(wFieldComp);

    // The parameters tab
    CTabItem wParametersTab = new CTabItem(wTabFolder, SWT.NONE);
    wParametersTab.setText(BaseMessages.getString(PKG, "JobTrans.Fields.Parameters.Label"));

    fieldLayout = new FormLayout();
    fieldLayout.marginWidth = Const.MARGIN;
    fieldLayout.marginHeight = Const.MARGIN;

    Composite wParameterComp = new Composite(wTabFolder, SWT.NONE);
    props.setLook(wParameterComp);
    wParameterComp.setLayout(fieldLayout);

    // Pass all parameters down
    //
    wlPassParams = new Label(wParameterComp, SWT.RIGHT);
    wlPassParams.setText(BaseMessages.getString(PKG, "JobTrans.PassAllParameters.Label"));
    props.setLook(wlPassParams);
    FormData fdlPassParams = new FormData();
    fdlPassParams.left = new FormAttachment(0, 0);
    fdlPassParams.top = new FormAttachment(0, 0);
    fdlPassParams.right = new FormAttachment(middle, -margin);
    wlPassParams.setLayoutData(fdlPassParams);
    wPassParams = new Button(wParameterComp, SWT.CHECK);
    props.setLook(wPassParams);
    FormData fdPassParams = new FormData();
    fdPassParams.left = new FormAttachment(middle, 0);
    fdPassParams.top = new FormAttachment(0, 0);
    fdPassParams.right = new FormAttachment(100, 0);
    wPassParams.setLayoutData(fdPassParams);

    wbGetParams = new Button(wParameterComp, SWT.PUSH);
    wbGetParams.setText(BaseMessages.getString(PKG, "JobTrans.GetParameters.Button.Label"));
    FormData fdGetParams = new FormData();
    fdGetParams.top = new FormAttachment(wPassParams, margin);
    fdGetParams.right = new FormAttachment(100, 0);
    wbGetParams.setLayoutData(fdGetParams);
    wbGetParams.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent arg0) {
            getParameters(null); // force reload from file specification
        }
    });

    final int parameterRows = jobEntry.parameters != null ? jobEntry.parameters.length : 0;

    colinf = new ColumnInfo[] {
            new ColumnInfo(BaseMessages.getString(PKG, "JobTrans.Parameters.Parameter.Label"),
                    ColumnInfo.COLUMN_TYPE_TEXT, false),
            new ColumnInfo(BaseMessages.getString(PKG, "JobTrans.Parameters.ColumnName.Label"),
                    ColumnInfo.COLUMN_TYPE_TEXT, false),
            new ColumnInfo(BaseMessages.getString(PKG, "JobTrans.Parameters.Value.Label"),
                    ColumnInfo.COLUMN_TYPE_TEXT, false), };
    colinf[2].setUsingVariables(true);

    wParameters = new TableView(jobMeta, wParameterComp, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, colinf,
            parameterRows, lsMod, props);

    FormData fdParameters = new FormData();
    fdParameters.left = new FormAttachment(0, 0);
    fdParameters.top = new FormAttachment(wPassParams, margin);
    fdParameters.right = new FormAttachment(wbGetParams, -margin);
    fdParameters.bottom = new FormAttachment(100, 0);
    wParameters.setLayoutData(fdParameters);

    FormData fdParametersComp = new FormData();
    fdParametersComp.left = new FormAttachment(0, 0);
    fdParametersComp.top = new FormAttachment(0, 0);
    fdParametersComp.right = new FormAttachment(100, 0);
    fdParametersComp.bottom = new FormAttachment(100, 0);
    wParameterComp.setLayoutData(fdParametersComp);

    wParameterComp.layout();
    wParametersTab.setControl(wParameterComp);

    FormData fdTabFolder = new FormData();
    fdTabFolder.left = new FormAttachment(0, 0);
    fdTabFolder.top = new FormAttachment(wName, margin * 3);
    fdTabFolder.right = new FormAttachment(100, 0);
    fdTabFolder.bottom = new FormAttachment(100, -50);
    wTabFolder.setLayoutData(fdTabFolder);

    wTabFolder.setSelection(0);

    // Some buttons
    wOK = new Button(shell, SWT.PUSH);
    wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));

    BaseStepDialog.positionBottomButtons(shell, new Button[] { wOK, wCancel }, margin, wTabFolder);

    // Add listeners
    lsCancel = new Listener() {
        public void handleEvent(Event e) {
            cancel();
        }
    };
    lsOK = new Listener() {
        public void handleEvent(Event e) {
            ok();
        }
    };

    wOK.addListener(SWT.Selection, lsOK);
    wCancel.addListener(SWT.Selection, lsCancel);

    lsDef = new SelectionAdapter() {
        public void widgetDefaultSelected(SelectionEvent e) {
            ok();
        }
    };
    wName.addSelectionListener(lsDef);
    wFilename.addSelectionListener(lsDef);

    wbTransname.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            selectTransformation();
        }
    });

    wbFilename.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            pickFileVFS();
        }
    });

    wbByReference.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            selectTransformationByReference();
        }
    });

    wbLogFilename.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {

            FileDialog dialog = new FileDialog(shell, SWT.SAVE);
            dialog.setFilterExtensions(new String[] { "*.txt", "*'.log", "*" });
            dialog.setFilterNames(FILE_FILTERLOGNAMES);

            if (wLogfile.getText() != null) {
                dialog.setFileName(jobMeta.environmentSubstitute(wLogfile.getText()));
            }

            if (dialog.open() != null) {
                wLogfile.setText(dialog.getFilterPath() + Const.FILE_SEPARATOR + dialog.getFileName());
                String filename = dialog.getFilterPath() + Const.FILE_SEPARATOR + dialog.getFileName();
                FileObject file = null;
                try {
                    file = KettleVFS.getFileObject(filename);
                    // Set file extension ..
                    wLogext.setText(file.getName().getExtension());
                    // Set filename without extension ...
                    wLogfile.setText(wLogfile.getText().substring(0,
                            wLogfile.getText().length() - wLogext.getText().length() - 1));
                } catch (Exception ex) {
                    // Ignore
                }
                if (file != null) {
                    try {
                        file.close();
                    } catch (IOException ex) { /* Ignore */
                    }
                }
            }

        }
    });

    // Detect [X] or ALT-F4 or something that kills this window...
    shell.addShellListener(new ShellAdapter() {
        public void shellClosed(ShellEvent e) {
            cancel();
        }
    });

    getData();
    setActive();

    BaseStepDialog.setSize(shell);

    shell.open();
    props.setDialogSize(shell, "JobTransDialogSize");
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    return jobEntry;
}

From source file:org.pentaho.di.ui.spoon.Spoon.java

public void openFileVFSFile() {
    FileObject initialFile;/*from ww  w  . j a  v  a  2s.c o  m*/
    FileObject rootFile;
    try {
        initialFile = KettleVFS.getFileObject(getLastFileOpened());
        rootFile = initialFile.getFileSystem().getRoot();
    } catch (Exception e) {
        String message = Const.getStackTracker(e);
        new ErrorDialog(shell, BaseMessages.getString(PKG, "Spoon.Error"), message, e);

        return;
    }

    FileObject selectedFile = getVfsFileChooserDialog(rootFile, initialFile).open(shell, null,
            Const.STRING_TRANS_AND_JOB_FILTER_EXT, Const.getTransformationAndJobFilterNames(),
            VfsFileChooserDialog.VFS_DIALOG_OPEN_FILE);
    if (selectedFile != null) {
        setLastFileOpened(selectedFile.getName().getFriendlyURI());
        openFile(selectedFile.getName().getFriendlyURI(), false);
    }
}

From source file:org.pentaho.di.ui.spoon.Spoon.java

public boolean saveXMLFileToVfs(EngineMetaInterface meta) {
    if (log.isBasic()) {
        log.logBasic("Save file as...");
    }//from   ww  w. j  av  a  2  s . co  m

    FileObject rootFile;
    FileObject initialFile;
    try {
        initialFile = KettleVFS.getFileObject(getLastFileOpened());
        rootFile = KettleVFS.getFileObject(getLastFileOpened()).getFileSystem().getRoot();
    } catch (Exception e) {
        MessageBox messageDialog = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
        messageDialog.setText("Error");
        messageDialog.setMessage(e.getMessage());
        messageDialog.open();
        return false;
    }

    String filename = null;
    FileObject selectedFile = getVfsFileChooserDialog(rootFile, initialFile).open(shell, "Untitled",
            Const.STRING_TRANS_AND_JOB_FILTER_EXT, Const.getTransformationAndJobFilterNames(),
            VfsFileChooserDialog.VFS_DIALOG_SAVEAS);
    if (selectedFile != null) {
        filename = selectedFile.getName().getFriendlyURI();
    }

    String[] extensions = meta.getFilterExtensions();
    if (filename != null) {
        // Is the filename ending on .ktr, .xml?
        boolean ending = false;
        for (int i = 0; i < extensions.length - 1; i++) {
            if (filename.endsWith(extensions[i].substring(1))) {
                ending = true;
            }
        }
        if (filename.endsWith(meta.getDefaultExtension())) {
            ending = true;
        }
        if (!ending) {
            filename += '.' + meta.getDefaultExtension();
        }
        // See if the file already exists...
        int id = SWT.YES;
        try {
            FileObject f = KettleVFS.getFileObject(filename);
            if (f.exists()) {
                MessageBox mb = new MessageBox(shell, SWT.NO | SWT.YES | SWT.ICON_WARNING);
                // "This file already exists.  Do you want to overwrite it?"
                mb.setMessage(BaseMessages.getString(PKG, "Spoon.Dialog.PromptOverwriteFile.Message"));
                mb.setText(BaseMessages.getString(PKG, "Spoon.Dialog.PromptOverwriteFile.Title"));
                id = mb.open();
            }
        } catch (Exception e) {
            // TODO do we want to show an error dialog here? My first guess
            // is not, but we might.
        }
        if (id == SWT.YES) {
            save(meta, filename, false);
        }
    }
    return false;
}

From source file:org.pentaho.di.ui.trans.steps.hadoopfileinput.HadoopFileInputDialog.java

private List<String> getFirst(int nrlines, boolean skipHeaders) throws KettleException {
    TextFileInputMeta meta = new TextFileInputMeta();
    getInfo(meta);/*w w w .j  a  v  a  2s  . c om*/
    FileInputList textFileList = meta.getTextFileList(transMeta);

    InputStream fi = null;
    InputStream f = null;
    StringBuilder lineStringBuilder = new StringBuilder(256);
    int fileFormatType = meta.getFileFormatTypeNr();

    List<String> retval = new ArrayList<String>();

    if (textFileList.nrOfFiles() > 0) {
        FileObject file = textFileList.getFile(0);
        try {
            fi = KettleVFS.getInputStream(file);

            CompressionProvider provider = CompressionProviderFactory.getInstance()
                    .createCompressionProviderInstance(meta.getFileCompression());
            f = provider.createInputStream(fi);

            InputStreamReader reader;
            if (meta.getEncoding() != null && meta.getEncoding().length() > 0) {
                reader = new InputStreamReader(f, meta.getEncoding());
            } else {
                reader = new InputStreamReader(f);
            }

            int linenr = 0;
            int maxnr = nrlines + (meta.hasHeader() ? meta.getNrHeaderLines() : 0);

            if (skipHeaders) {
                // Skip the header lines first if more then one, it helps us position
                if (meta.isLayoutPaged() && meta.getNrLinesDocHeader() > 0) {
                    int skipped = 0;
                    String line = TextFileInput.getLine(log, reader, fileFormatType, lineStringBuilder);
                    while (line != null && skipped < meta.getNrLinesDocHeader() - 1) {
                        skipped++;
                        line = TextFileInput.getLine(log, reader, fileFormatType, lineStringBuilder);
                    }
                }

                // Skip the header lines first if more then one, it helps us position
                if (meta.hasHeader() && meta.getNrHeaderLines() > 0) {
                    int skipped = 0;
                    String line = TextFileInput.getLine(log, reader, fileFormatType, lineStringBuilder);
                    while (line != null && skipped < meta.getNrHeaderLines() - 1) {
                        skipped++;
                        line = TextFileInput.getLine(log, reader, fileFormatType, lineStringBuilder);
                    }
                }
            }

            String line = TextFileInput.getLine(log, reader, fileFormatType, lineStringBuilder);
            while (line != null && (linenr < maxnr || nrlines == 0)) {
                retval.add(line);
                linenr++;
                line = TextFileInput.getLine(log, reader, fileFormatType, lineStringBuilder);
            }
        } catch (Exception e) {
            throw new KettleException(
                    BaseMessages.getString(BASE_PKG, "TextFileInputDialog.Exception.ErrorGettingFirstLines",
                            "" + nrlines, file.getName().getURI()),
                    e);
        } finally {
            try {
                f.close();
            } catch (Exception e) {
                // Ignore errors
            }
        }
    }

    return retval;
}