Example usage for org.eclipse.jface.preference FileFieldEditor FileFieldEditor

List of usage examples for org.eclipse.jface.preference FileFieldEditor FileFieldEditor

Introduction

In this page you can find the example usage for org.eclipse.jface.preference FileFieldEditor FileFieldEditor.

Prototype

public FileFieldEditor(String name, String labelText, boolean enforceAbsolute, int validationStrategy,
        Composite parent) 

Source Link

Document

Creates a file field editor.

Usage

From source file:com.aptana.editor.js.preferences.NodePreferencePage.java

License:Open Source License

@Override
protected void createFieldEditors() {
    // Node Executable location
    FileFieldEditor fileEditor = new FileFieldEditor(IPreferenceConstants.NODEJS_EXECUTABLE_PATH,
            StringUtil.makeFormLabel(Messages.NodePreferencePage_LocationLabel), true,
            FileFieldEditor.VALIDATE_ON_KEY_STROKE, getFieldEditorParent()) {

        @Override//from ww w.ja v a 2 s.co  m
        protected boolean doCheckState() {
            // Now check that the executable is ok
            String text = getTextControl().getText();
            if (!StringUtil.isEmpty(text)) {
                IStatus status = getNodeService().acceptBinary(Path.fromOSString(text));
                if (!status.isOK()) {
                    setErrorMessage(status.getMessage());
                    return false;
                }
            }

            return true;
        }
    };
    addField(fileEditor);

    sfe = new StringFieldEditor("some_non_existent_pref_key", //$NON-NLS-1$
            StringUtil.makeFormLabel(Messages.NodePreferencePage_DetectedPathLabel),
            fep = getFieldEditorParent());
    addField(sfe);

    // Node Source location
    sourceEditor = new DirectoryFieldEditor(IPreferenceConstants.NODEJS_SOURCE_PATH,
            StringUtil.makeFormLabel(Messages.NodePreferencePage_SourceLocationLabel), getFieldEditorParent()) {
        @Override
        public int getNumberOfControls() {
            return super.getNumberOfControls() + 1;
        }

        @Override
        protected void doFillIntoGrid(Composite parent, int numColumns) {
            super.doFillIntoGrid(parent, numColumns - 1);
            createDownloadButton(parent);
            Text textControl = getTextControl();
            ((GridData) textControl.getLayoutData()).widthHint = convertHorizontalDLUsToPixels(textControl,
                    180);
        }

        @Override
        protected void adjustForNumColumns(int numColumns) {
            super.adjustForNumColumns(numColumns - 1);
        }

        @Override
        protected boolean doCheckState() {
            // Now check that the dir is ok
            String text = getTextControl().getText();
            if (!StringUtil.isEmpty(text)) {
                IPath path = Path.fromOSString(text);
                IStatus status = getNodeService().validateSourcePath(path);
                if (!status.isOK()) {
                    setErrorMessage(status.getMessage());
                    return false;
                }
            }

            return true;
        }

        // Create the NodeJS download button
        private Button createDownloadButton(Composite parent) {
            Button downloadBt = new Button(parent, SWT.PUSH);
            downloadBt.setText(Messages.NodePreferencePage_downloadButtonText);
            downloadBt.setFont(parent.getFont());
            GridData gd = GridDataFactory.fillDefaults().create();
            int widthHint = convertHorizontalDLUsToPixels(downloadBt, IDialogConstants.BUTTON_WIDTH);
            gd.widthHint = Math.max(widthHint, downloadBt.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
            downloadBt.setLayoutData(gd);
            downloadBt.addSelectionListener(new SelectionAdapter() {
                public void widgetSelected(SelectionEvent evt) {
                    downloadNodeJS();
                }
            });
            return downloadBt;
        }
    };
    addField(sourceEditor);
}

From source file:com.aptana.git.ui.internal.preferences.GitPreferencePage.java

License:Open Source License

@Override
protected void createFieldEditors() {
    // Git Executable location
    FileFieldEditor fileEditor = new FileFieldEditor(IPreferenceConstants.GIT_EXECUTABLE_PATH,
            Messages.GitExecutableLocationPage_LocationLabel, true, FileFieldEditor.VALIDATE_ON_KEY_STROKE,
            getFieldEditorParent()) {/*from w  ww .  j  ava  2s.  c  o  m*/
        @Override
        protected boolean checkState() {
            boolean ok = super.checkState();
            if (!ok)
                return ok;

            // Now check that the executable is ok
            String text = getTextControl().getText();
            if (text != null && text.trim().length() > 0) {
                if (!GitExecutable.acceptBinary(Path.fromOSString(text))) {
                    showErrorMessage(NLS.bind(Messages.GitExecutableLocationPage_InvalidLocationErrorMessage,
                            GitExecutable.MIN_GIT_VERSION));
                    return false;
                }
            }

            clearErrorMessage();
            return true;
        }
    };
    addField(fileEditor);

    // Git pull indicator
    addField(new BooleanFieldEditor(IPreferenceConstants.GIT_CALCULATE_PULL_INDICATOR,
            Messages.GitExecutableLocationPage_CalculatePullIndicatorLabel, getFieldEditorParent()));

    // Auto-attach to projects
    addField(new BooleanFieldEditor(IPreferenceConstants.AUTO_ATTACH_REPOS,
            Messages.GitExecutableLocationPage_AutoAttachProjectsLabel, getFieldEditorParent()));

    addField(new BooleanFieldEditor(IPreferenceConstants.IGNORE_NO_GIT,
            Messages.GitPreferencePage_IgnoreMissingGitLabel, getFieldEditorParent()));
}

From source file:com.arc.embeddedcdt.gui.RemoteGdbDebuggerPage.java

License:Open Source License

private void createTabItemComAshling(Composite subComp) {
    createTabItemComAshling = true;//from ww  w . ja va 2s  .co  m

    groupComAshling = SWTFactory.createGroup(subComp, externalToolsCombo.getItem(0), 3, 5,
            GridData.FILL_HORIZONTAL);
    final Composite compositeCom = SWTFactory.createComposite(groupComAshling, 3, 5, GridData.FILL_BOTH);

    // Path to Ashling binary
    ashlingBinaryPathEditor = new FileFieldEditor("ashlingBinaryPath", "Ashling binary path", false,
            StringButtonFieldEditor.VALIDATE_ON_KEY_STROKE, compositeCom);
    ashlingBinaryPathEditor.setStringValue(externalToolsAshlingPath);

    ashlingBinaryPathEditor.setPropertyChangeListener(new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty() == "field_editor_value") {
                externalToolsAshlingPath = (String) event.getNewValue();
                updateLaunchConfigurationDialog();
            }
        }
    });

    // Path to Ashling XMl file
    ashlingXmlPathEditor = new FileFieldEditor("ashlingXmlPathEditor", "Ashling XML File", false,
            StringButtonFieldEditor.VALIDATE_ON_KEY_STROKE, compositeCom);
    ashlingXmlPathEditor.setStringValue(ashlingXmlPath);

    ashlingXmlPathEditor.setPropertyChangeListener(new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty() == "field_editor_value") {
                ashlingXmlPath = (String) event.getNewValue();
                updateLaunchConfigurationDialog();
            }
        }
    });

    // Path to ashling target description file
    ashlingTdescXmlPathEditor = new FileFieldEditor("ashlingTdescXmlPath", "Target description XML file", false,
            StringButtonFieldEditor.VALIDATE_ON_KEY_STROKE, compositeCom);
    ashlingTdescXmlPathEditor.setStringValue(ashlingTdescPath);

    ashlingTdescXmlPathEditor.setPropertyChangeListener(new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty() == "field_editor_value") {
                ashlingTdescPath = (String) event.getNewValue();
                updateLaunchConfigurationDialog();
            }
        }
    });

    createJtagFrequencyCombo(compositeCom);

}

From source file:com.arc.embeddedcdt.gui.RemoteGdbDebuggerPage.java

License:Open Source License

private void createTabItemCom(Composite subComp) {
    createTabItemCom = true;//from  w w  w .j  a  va2 s . c  o m
    groupCom = SWTFactory.createGroup(subComp, externalToolsCombo.getItem(0), 3, 5, GridData.FILL_HORIZONTAL);
    final Composite compositeCom = SWTFactory.createComposite(groupCom, 3, 5, GridData.FILL_BOTH);

    // Path to OpenOCD binary
    openOcdBinPathEditor = new FileFieldEditor("openocdBinaryPathEditor", "OpenOCD executable", false,
            StringButtonFieldEditor.VALIDATE_ON_KEY_STROKE, compositeCom);
    openOcdBinPathEditor.setStringValue(openOcdBinaryPath);
    openOcdBinPathEditor.setPropertyChangeListener(new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty() == "field_editor_value") {
                openOcdBinaryPath = (String) event.getNewValue();
                if (ftdiDevice != FtdiDevice.CUSTOM) {
                    openOcdConfigurationPath = getOpenOcdConfigurationPath();
                    openOcdConfigurationPathEditor.setStringValue(openOcdConfigurationPath);
                }
                updateLaunchConfigurationDialog();
            }
        }
    });
    Label label = new Label(compositeCom, SWT.LEFT);
    label.setText("Development system:");
    ftdiDeviceCombo = new Combo(compositeCom, SWT.None | SWT.READ_ONLY);// 1-2 and 1-3

    GridData gridDataJtag = new GridData(GridData.BEGINNING);
    gridDataJtag.widthHint = 220;
    gridDataJtag.horizontalSpan = 2;
    ftdiDeviceCombo.setLayoutData(gridDataJtag);

    for (FtdiDevice i : FtdiDevice.values())
        ftdiDeviceCombo.add(i.toString());
    ftdiDeviceCombo.setText(ftdiDevice.toString());

    ftdiDeviceCombo.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent event) {
            Combo combo = (Combo) event.widget;
            ftdiDevice = FtdiDevice.fromString(combo.getText());

            if (ftdiDevice == FtdiDevice.CUSTOM)
                openOcdConfigurationPathEditor.setEnabled(true, compositeCom);
            else
                openOcdConfigurationPathEditor.setEnabled(false, compositeCom);

            if (ftdiDevice.getCores().size() <= 1)
                ftdiCoreCombo.setEnabled(false);
            else
                ftdiCoreCombo.setEnabled(true);

            updateFtdiCoreCombo();
            updateLaunchConfigurationDialog();
        }
    });

    Label coreLabel = new Label(compositeCom, SWT.LEFT);
    coreLabel.setText("Target Core");
    ftdiCoreCombo = new Combo(compositeCom, SWT.None | SWT.READ_ONLY);// 1-2 and 1-3
    ftdiCoreCombo.setLayoutData(gridDataJtag);

    if (ftdiDevice.getCores().size() <= 1)
        ftdiCoreCombo.setEnabled(false);
    else
        ftdiCoreCombo.setEnabled(true);

    updateFtdiCoreCombo();

    ftdiCoreCombo.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent event) {
            Combo combo = (Combo) event.widget;
            if (!combo.getText().isEmpty()) {
                ftdiCore = FtdiCore.fromString(combo.getText());
                if (ftdiDevice != FtdiDevice.CUSTOM) {
                    openOcdConfigurationPath = getOpenOcdConfigurationPath();
                    openOcdConfigurationPathEditor.setStringValue(openOcdConfigurationPath);
                }
            }
            updateLaunchConfigurationDialog();
        }
    });

    openOcdConfigurationPathEditor = new FileFieldEditor("openocdConfigurationPathEditor",
            "OpenOCD configuration file", false, StringButtonFieldEditor.VALIDATE_ON_KEY_STROKE, compositeCom);
    openOcdConfigurationPathEditor.setEnabled(false, compositeCom);
    openOcdConfigurationPathEditor.setStringValue(openOcdConfigurationPath);
    openOcdConfigurationPathEditor.setPropertyChangeListener(new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty() == "field_editor_value") {
                openOcdConfigurationPath = event.getNewValue().toString();
                updateLaunchConfigurationDialog();
            }
        }
    });

    if (openOcdConfigurationPathEditor != null) {
        if (!ftdiDeviceCombo.getText().equalsIgnoreCase(FtdiDevice.CUSTOM.toString())) {
            openOcdConfigurationPathEditor.setEnabled(false, compositeCom);
        } else {
            openOcdConfigurationPathEditor.setEnabled(true, compositeCom);
        }
    }
}

From source file:com.arc.embeddedcdt.gui.RemoteGdbDebuggerPage.java

License:Open Source License

private void createTabItemNsim(Composite subComp) {
    createTabItemNsim = true;/*from  w ww.j a v  a 2  s.  c  o m*/

    groupNsim = SWTFactory.createGroup(subComp, externalToolsCombo.getItem(0), 3, 5, GridData.FILL_HORIZONTAL);
    final Composite compositeNsim = SWTFactory.createComposite(groupNsim, 3, 5, GridData.FILL_BOTH);

    GridData gridData = new GridData();

    nsimBinaryPathEditor = new FileFieldEditor("nsimBinPath", "nSIM executable", false,
            StringButtonFieldEditor.VALIDATE_ON_KEY_STROKE, compositeNsim);

    nsimBinaryPathEditor.setStringValue(externalToolsNsimPath);
    nsimBinaryPathEditor.setPropertyChangeListener(new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty() == "field_editor_value") {
                externalToolsNsimPath = (String) event.getNewValue();
                updateLaunchConfigurationDialog();
            }
        }
    });

    launchTcfPropertiesButton = new Button(compositeNsim, SWT.CHECK); //$NON-NLS-1$ //6-3
    launchTcfPropertiesButton
            .setToolTipText("Pass specified TCF file to nSIM for parsing of nSIM properties (-tcf=path)");
    launchTcfPropertiesButton.setSelection(externalNsimTcfToolsEnabled);
    gridData = new GridData(SWT.BEGINNING);
    gridData.horizontalSpan = 3;
    launchTcfPropertiesButton.setLayoutData(gridData);
    launchTcfPropertiesButton.setText("Use TCF?");

    nsimTcfPathEditor = new FileFieldEditor("nsimTcfPath", "nSIM TCF path", false,
            StringButtonFieldEditor.VALIDATE_ON_KEY_STROKE, compositeNsim);
    nsimTcfPathEditor.setStringValue(nsimPropertiesFilesLast);
    nsimTcfPathEditor.setPropertyChangeListener(new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty() == "field_editor_value") {
                nsimPropertiesFilesLast = (String) event.getNewValue();
                updateLaunchConfigurationDialog();
            }
        }
    });
    nsimTcfPathEditor.setEnabled((externalNsimTcfToolsEnabled), compositeNsim);

    launchTcf = new Button(compositeNsim, SWT.CHECK); //$NON-NLS-1$ //6-3
    launchTcf.setToolTipText("-propsfile=path");
    launchTcf.setSelection(externalNsimPropertiesEnabled);
    gridData = new GridData(SWT.BEGINNING);
    gridData.horizontalSpan = 3;
    launchTcf.setLayoutData(gridData);
    launchTcf.setText("Use nSIM properties file?");
    nsimPropertiesPathEditor = new FileFieldEditor("nsimPropertiesPath", "nSIM properties file", false,
            StringButtonFieldEditor.VALIDATE_ON_KEY_STROKE, compositeNsim);
    nsimPropertiesPathEditor.setStringValue(nsimPropertiesFilesLast);
    nsimPropertiesPathEditor.setPropertyChangeListener(new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty() == "field_editor_value") {
                nsimPropertiesFilesLast = (String) event.getNewValue();
                updateLaunchConfigurationDialog();
            }
        }
    });

    nsimPropertiesPathEditor.setEnabled((externalNsimPropertiesEnabled), compositeNsim);

    launchTcf.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent event) {
            if (launchTcf.getSelection() == true) {
                externalNsimTcfToolsEnabled = true;
                nsimTcfPathEditor.setEnabled(true, compositeNsim);

            } else {
                externalNsimTcfToolsEnabled = false;
                launchTcfPropertiesButton.setSelection(false);
                nsimTcfPathEditor.setEnabled(false, compositeNsim);
            }
            updateLaunchConfigurationDialog();
        }

        public void widgetDefaultSelected(SelectionEvent event) {
        }

    });
    launchTcfPropertiesButton.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent event) {
            if (launchTcfPropertiesButton.getSelection() == true) {
                externalNsimPropertiesEnabled = true;
                nsimPropertiesPathEditor.setEnabled(true, compositeNsim);
            } else {
                externalNsimPropertiesEnabled = false;
                nsimPropertiesPathEditor.setEnabled(false, compositeNsim);
            }
            updateLaunchConfigurationDialog();
        }

        public void widgetDefaultSelected(SelectionEvent event) {
        }

    });

    // JIT

    gridData = new GridData(SWT.BEGINNING);
    gridData.horizontalSpan = 3;

    launchNsimJitProperties = new Button(compositeNsim, SWT.CHECK); //$NON-NLS-1$ //6-3
    launchNsimJitProperties.setSelection(externalNsimJitEnabled);
    launchNsimJitProperties.setText("JIT");
    launchNsimJitProperties
            .setToolTipText("Enable (1) or disable (0) JIT simulation mode (-p nsim_fast={0,1})");
    jitThreadSpinner = new Spinner(compositeNsim, SWT.NONE | SWT.BORDER);
    jitThreadSpinner.setToolTipText(
            "Specify number of threads to use in JIT simulation mode (-p nsim_fast-num-threads=N)");
    final Label jitLabel = new Label(compositeNsim, SWT.BEGINNING);
    jitLabel.setText("JIT threads");
    jitThreadSpinner.setValues(1, 1, 100, 10, 1, 0);

    launchNsimJitProperties.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent event) {
            if (launchNsimJitProperties.getSelection() == true) {
                externalNsimJitEnabled = true;
                jitLabel.setEnabled(true);
                jitThreadSpinner.setEnabled(true);

            } else {
                externalNsimJitEnabled = false;
                jitLabel.setEnabled(false);
                jitThreadSpinner.setEnabled(false);
            }
            updateLaunchConfigurationDialog();
        }

        public void widgetDefaultSelected(SelectionEvent event) {
        }

    });

    launchNsimJitProperties.setLayoutData(gridData);

    if (externalNsimJitEnabled == true) {
        jitLabel.setEnabled(true);
        jitThreadSpinner.setEnabled(true);
    } else if (externalNsimJitEnabled == false) {
        jitLabel.setEnabled(false);
        jitThreadSpinner.setEnabled(false);
    }

    if (!jitThread.equals("1"))
        jitThreadSpinner.setSelection(Integer.parseInt(jitThread));
    else
        jitThreadSpinner.setSelection(1);

    jitThreadSpinner.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent event) {
            jitThread = jitThreadSpinner.getText();
            updateLaunchConfigurationDialog();
        }
    });
    gridData = new GridData(SWT.BEGINNING);
    gridData.horizontalSpan = 2;
    jitLabel.setLayoutData(gridData);

    GridData gridDataNsim = new GridData(SWT.BEGINNING);
    gridDataNsim.horizontalSpan = 2;

    launchHostLinkProperties = new Button(compositeNsim, SWT.CHECK); //$NON-NLS-1$ //6-3
    launchHostLinkProperties.setToolTipText(
            "Enable or disable nSIM GNU host I/O support (-p nsim_emt={0,1}). The nsim_emt property works only if the application that is being simulated is compiled with the ARC GCC compiler.");
    launchHostLinkProperties.setSelection(externalNsimHostLinkToolsEnabled);
    launchHostLinkProperties.setText("GNU host I/O support");
    launchHostLinkProperties.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent event) {
            if (launchHostLinkProperties.getSelection() == true) {
                externalNsimHostLinkToolsEnabled = true;

            } else {
                externalNsimHostLinkToolsEnabled = false;
            }
            updateLaunchConfigurationDialog();
        }

        public void widgetDefaultSelected(SelectionEvent event) {
        }

    });

    launchHostLinkProperties.setLayoutData(gridDataNsim);

    launchMemoryExceptionProperties = new Button(compositeNsim, SWT.CHECK); //$NON-NLS-1$ //6-3
    launchMemoryExceptionProperties.setToolTipText(
            "Simulate (1) or break (0) on memory exception (-p memory_exception_interrupt={0,1})");
    launchMemoryExceptionProperties.setSelection(externalNsimMemoryExceptionToolsEnabled);
    launchMemoryExceptionProperties.setText("Memory Exception");
    launchMemoryExceptionProperties.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent event) {
            if (launchMemoryExceptionProperties.getSelection() == true) {
                externalNsimMemoryExceptionToolsEnabled = true;

            } else {
                externalNsimMemoryExceptionToolsEnabled = false;
            }
            updateLaunchConfigurationDialog();
        }

        public void widgetDefaultSelected(SelectionEvent event) {
        }

    });

    launchMemoryExceptionProperties.setLayoutData(gridDataNsim);

    launchEnableExceptionProperties = new Button(compositeNsim, SWT.CHECK); //$NON-NLS-1$ //6-3
    launchEnableExceptionProperties.setSelection(externalNsimEnableExceptionToolsEnabled);
    launchEnableExceptionProperties.setText("Enable Exception");
    launchEnableExceptionProperties
            .setToolTipText("Simulate (1) or break (0) on any exception (-p enable_exceptions={0,1})");
    launchEnableExceptionProperties.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent event) {
            if (launchEnableExceptionProperties.getSelection() == true) {
                externalNsimEnableExceptionToolsEnabled = true;

            } else {
                externalNsimEnableExceptionToolsEnabled = false;
            }
            updateLaunchConfigurationDialog();
        }

        public void widgetDefaultSelected(SelectionEvent event) {
        }

    });

    launchEnableExceptionProperties.setLayoutData(gridDataNsim);

    launchInvalidInstructionExceptionProperties = new Button(compositeNsim, SWT.CHECK); //$NON-NLS-1$ //6-3
    launchInvalidInstructionExceptionProperties.setToolTipText(
            "Simulate (1) or break (0) on invalid instruction exception (-p invalid_instruction_interrupt={0,1})");
    launchInvalidInstructionExceptionProperties.setSelection(launchExternalNsimInvalidInstructionException);
    launchInvalidInstructionExceptionProperties.setText("Invalid Instruction  Exception");
    launchInvalidInstructionExceptionProperties.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent event) {
            if (launchInvalidInstructionExceptionProperties.getSelection() == true) {
                launchExternalNsimInvalidInstructionException = true;

            } else {
                launchExternalNsimInvalidInstructionException = false;
            }
            updateLaunchConfigurationDialog();
        }

        public void widgetDefaultSelected(SelectionEvent event) {
        }

    });
    launchInvalidInstructionExceptionProperties.setLayoutData(gridDataNsim);

    workingDirectoryBlockNsim.createControl(compositeNsim);
}

From source file:net.ostis.scpdev.preferences.ScpEnviromentPreferencePage.java

License:Open Source License

protected void createFieldEditors() {
    useScCoreHomeField = new BooleanFieldEditor(PreferenceConstants.P_USE_SC_CORE_HOME,
            "Use enviroment variable SC_CORE_HOME for searching sc-core", getFieldEditorParent());
    sccoreDirField = new DirectoryFieldEditorOnKeyStroke(PreferenceConstants.P_SC_CORE_PATH,
            "SC-core root directory:", getFieldEditorParent());
    systemUIStartFileField = new FileFieldEditor(PreferenceConstants.P_SYSTEM_UI_PATH,
            "UI system path to start script:", true, StringFieldEditor.VALIDATE_ON_KEY_STROKE,
            getFieldEditorParent());//w ww  .  j  a va  2 s  .co m
    pythonExecutableField = new FileFieldEditor(PreferenceConstants.P_PYTHON_EXECUTABLE,
            "Path to python executable:", true, StringFieldEditor.VALIDATE_ON_KEY_STROKE,
            getFieldEditorParent());
    addField(useScCoreHomeField);
    addField(sccoreDirField);
    addField(systemUIStartFileField);
    addField(pythonExecutableField);
}

From source file:openbiomind.gui.preferences.OpenBiomindPreferencePage.java

License:Open Source License

/**
 * Creates the new file field editor.// w  w w.j  a v  a2 s .co  m
 * 
 * @param preferenceName the preference name
 * @param labelText the label text
 * @param fileExtensions the file extensions
 * @param emptyStringAllowed the empty string allowed
 * @param errorMessage the error message
 * 
 * @return the file field editor
 */
private FileFieldEditor createNewFileFieldEditor(final String preferenceName, final String labelText,
        final String[] fileExtensions, final boolean emptyStringAllowed, final String errorMessage) {
    final FileFieldEditor fileFieldEditor = new FileFieldEditor(preferenceName, labelText, true,
            StringFieldEditor.VALIDATE_ON_KEY_STROKE, getFieldEditorParent());
    fileFieldEditor.setFileExtensions(fileExtensions);
    fileFieldEditor.setEmptyStringAllowed(emptyStringAllowed);
    fileFieldEditor.setErrorMessage(errorMessage);
    return fileFieldEditor;
}

From source file:org.eclipse.gef4.dot.internal.ui.GraphvizPreferencePage.java

License:Open Source License

@Override
protected void createFieldEditors() {
    // this method will be invoked if the user clicks on the Graphviz
    // Preference Page for the first time

    FileFieldEditor fileFieldEditor = new FileFieldEditor(DOT_PATH_PREF_KEY, DOT_SELECT_SHORT, true,
            FileFieldEditor.VALIDATE_ON_KEY_STROKE, getFieldEditorParent()) {

        {//from   w  ww. ja  va  2s  . com
            setErrorMessage(INVALID_DOT_EXECUTABLE);
        }

        @Override
        public boolean isValid() {
            boolean isValid = super.isValid();
            String currentValue = getStringValue();
            if (!currentValue.isEmpty()) {
                isValid = isValid && isValidDotExecutable(currentValue);
            }
            return isValid;
        }

        @Override
        protected void refreshValidState() {
            super.refreshValidState();
            if (!isValid()) {
                showErrorMessage(getErrorMessage());
            }
            checkState();
        }

        @Override
        public boolean doCheckState() {
            String currentValue = getStringValue();
            if (!currentValue.isEmpty()) {
                return isValidDotExecutable(currentValue);
            }
            return super.doCheckState();
        }

        @Override
        public String changePressed() {
            // this method will be invoked if the user clicks on the
            // "Browse" button of the fileFieldEditor of the DOT Executable
            // path
            String dotExecutablePath = super.changePressed();
            if (dotExecutablePath == null) {
                // If the returned value is null, the currently displayed
                // value remains.
                return null;
            }
            adaptDotExportUI(dotExecutablePath);
            return dotExecutablePath;
        }
    };
    addField(fileFieldEditor);

    preferenceStore.addPropertyChangeListener(new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            // this method will be invoked if the user clicks on the
            // Apply/OK button of the Preference Page
            if (event.getProperty().equals(DOT_PATH_PREF_KEY)) {
                String dotExecutablePath = (String) event.getNewValue();
                adaptDotExportUI(dotExecutablePath);
            }
        }
    });

    String dotExecutablePath = getDotExecutablePath();
    addDotExportUI(dotExecutablePath);
}

From source file:org.emftools.emf2gv.processor.ui.preferences.EMF2GvPreferencePage.java

License:Open Source License

/**
 * Creates the field editors. Field editors are abstractions of the common
 * GUI blocks needed to manipulate various types of preferences. Each field
 * editor knows how to save and restore itself.
 *//* ww w . ja  va  2 s  . c  o m*/
public void createFieldEditors() {
    // Character set
    Set<String> charsetKeys = Charset.availableCharsets().keySet();
    String[][] charsets = new String[charsetKeys.size()][2];
    int i = 0;
    for (String charsetKey : charsetKeys) {
        charsets[i][0] = charsetKey;
        charsets[i][1] = charsetKey;
        i++;
    }
    ComboFieldEditor comboFieldEditor = new ComboFieldEditor(EMF2GvPreferenceConstants.P_GV_SOURCE_ENCODING,
            "&Graphviz source encoding :", charsets, getFieldEditorParent());
    addField(comboFieldEditor);

    // Dot path
    addField(new FileFieldEditor(EMF2GvPreferenceConstants.P_DOT_UTILITY_PATH, "&Dot utility path :", true,
            StringFieldEditor.VALIDATE_ON_KEY_STROKE, getFieldEditorParent()) {
        @Override
        protected boolean checkState() {
            String executablePath = getTextControl().getText();
            if (executablePath != null) {
                executablePath = executablePath.trim();
            }
            boolean valid = true;
            try {
                Runtime.getRuntime().exec(new String[] { executablePath, "-V" });
                clearErrorMessage();
            } catch (IOException e) {
                File file = new File(executablePath);
                if (!file.exists()) {
                    showErrorMessage("Specified executable file does not exist");
                } else {
                    showErrorMessage("Specified executable not seem to be runnable");
                }
                valid = false;
            }
            return valid;
        }
    });
}

From source file:org.jboss.tools.windup.ui.internal.launch.OptionsTab.java

License:Open Source License

private void createJREGroup(Composite parent) {

    //      parent = new Composite(parent, SWT.NONE);
    //      GridLayoutFactory.fillDefaults().numColumns(2).margins(0, 0).spacing(8, LayoutConstants.getSpacing().y).applyTo(parent);

    parent = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, false).indent(5, 0).applyTo(parent);

    jreEditor = new FileFieldEditor(IPreferenceConstants.WINDUP_JRE_HOME, Messages.WindupPreferenceJRE, true,
            StringFieldEditor.VALIDATE_ON_KEY_STROKE, parent) {

        private boolean isDefaultJrePresented = false;

        public Label getLabelControl(Composite parent) {
            CLabel label = new CLabel(parent, SWT.LEFT);
            Image jreImage = PDEPluginImages.DESC_JAVA_LIB_OBJ.createImage();
            label.setImage(jreImage);/*www  .j a  v  a2s.  c om*/
            label.setFont(parent.getFont());
            String text = getLabelText();
            if (text != null) {
                label.setText(text);
            }
            label.addDisposeListener(event -> {
                jreImage.dispose();
            });
            return null;
        }

        @Override
        protected void doStore() {
            configuration.setJreHome(getTextControl().getText().trim());
        }

        @Override
        public void store() {
            if (isDefaultJrePresented) {
                configuration.setJreHome(WindupRuntimePlugin.computeJRELocation());
            } else {
                doStore();
            }
        }

        protected void valueChanged() {
            setPresentsDefaultValue(false);
            boolean oldState = super.isValid();
            refreshValidState();

            if (isValid() != oldState) {
                fireStateChanged(IS_VALID, oldState, isValid());
            }

            String newValue = super.getTextControl().getText();
            if (!newValue.equals(oldValue)) {
                fireValueChanged(VALUE, oldValue, newValue);
                oldValue = newValue;
                store();
            }
        }

        @Override
        public void load() {
            isDefaultJrePresented = false;
            Text textControl = super.getTextControl();
            if (textControl != null) {
                String value = configuration.getJreHome();
                textControl.setText(value != null ? value : "");
                oldValue = value;
            }
            refreshValidState();
        }

        @Override
        public void loadDefault() {
            isDefaultJrePresented = true;
            Text textControl = super.getTextControl();
            if (textControl != null) {
                String value = WindupRuntimePlugin.computeJRELocation();
                textControl.setText(value);
            }
            refreshValidState();
            valueChanged();
        }

        @Override
        protected boolean checkState() {
            String msg = null;
            String path = getTextControl().getText();
            clearErrorMessage();
            if (path != null) {
                path = path.trim();
            } else {
                path = "";//$NON-NLS-1$
            }
            if (path.length() == 0) {
                return true;
            } else {
                File file = new File(path);
                if (file.isDirectory()) {
                    if (!file.isAbsolute()) {
                        msg = Messages.JRENotAbsolute;
                    }
                } else {
                    msg = Messages.InvalidJRELocation;
                }
            }
            if (msg != null) { // error
                showErrorMessage(msg);
                return false;
            }
            return true;
        }

        @Override
        protected String changePressed() {
            File f = new File(getTextControl().getText());
            if (!f.exists()) {
                f = null;
            }

            File d = promptJRE();
            if (d == null) {
                return null;
            }

            return d.getAbsolutePath();
        }
    };
    jreEditor.setEmptyStringAllowed(true);
}