Example usage for org.eclipse.jface.preference StringFieldEditor getTextControl

List of usage examples for org.eclipse.jface.preference StringFieldEditor getTextControl

Introduction

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

Prototype

public Text getTextControl(Composite parent) 

Source Link

Document

Returns this field editor's text control.

Usage

From source file:org.csstudio.opibuilder.preferences.OPIRuntimePreferencePage.java

License:Open Source License

@Override
protected void createFieldEditors() {
    final Composite parent = getFieldEditorParent();

    macrosEditor = new StringTableFieldEditor(PreferencesHelper.RUN_MACROS, "Macros: ", parent,
            new String[] { "Name", "Value" }, new boolean[] { true, true },
            new MacroEditDialog(parent.getShell()), new int[] { 120, 120 }) {

        @Override/*from   w w  w. j  a v a  2  s .c  o m*/
        public boolean isValid() {
            String reason;
            for (String[] row : items) {
                reason = Verifier.checkElementName(row[0]);
                if (reason != null) {
                    wrongMacroName = row[0];
                    return false;
                }
            }
            return true;
        }

        @Override
        protected void doStore() {
            if (!isValid())
                return;
            super.doStore();
        }

        @Override
        protected void doFillIntoGrid(Composite parent, int numColumns) {
            super.doFillIntoGrid(parent, numColumns);
            tableEditor.getTableViewer().getTable().addKeyListener(new KeyAdapter() {
                @Override
                public void keyReleased(KeyEvent e) {
                    boolean valid = isValid();
                    fireStateChanged(IS_VALID, !valid, valid);
                }
            });
            tableEditor.getTableViewer().getTable().addFocusListener(new FocusListener() {

                @Override
                public void focusLost(FocusEvent e) {
                    boolean valid = isValid();
                    fireStateChanged(IS_VALID, !valid, valid);
                }

                @Override
                public void focusGained(FocusEvent e) {
                    boolean valid = isValid();
                    fireStateChanged(IS_VALID, !valid, valid);
                }
            });
        }

    };
    addField(macrosEditor);

    IntegerFieldEditor guiRefreshCycleEditor = new IntegerFieldEditor(PreferencesHelper.OPI_GUI_REFRESH_CYCLE,
            "OPI GUI Refresh Cycle (ms)", parent);
    guiRefreshCycleEditor.setValidRange(10, 5000);
    guiRefreshCycleEditor.getTextControl(parent)
            .setToolTipText("The fastest refresh cycle for OPI GUI in millisecond");
    addField(guiRefreshCycleEditor);

    IntegerFieldEditor pulsingMinorPeriodFieldEditor = new IntegerFieldEditor(
            PreferencesHelper.PULSING_ALARM_MINOR_PERIOD,
            "Time period of MINOR alarm if pulsing alarm selected (ms)", parent);
    pulsingMinorPeriodFieldEditor.setValidRange(100, 10000);
    pulsingMinorPeriodFieldEditor.getTextControl(parent)
            .setToolTipText("If the pulsing alarm box is checked for a widget that monitors a PV, "
                    + "then what is the time period of the pulse with the PV is in MINOR alarm severity");
    addField(pulsingMinorPeriodFieldEditor);

    IntegerFieldEditor pulsingMajorPeriodFieldEditor = new IntegerFieldEditor(
            PreferencesHelper.PULSING_ALARM_MAJOR_PERIOD,
            "Time period of MAJOR alarm if pulsing alarm selected (ms)", parent);
    pulsingMajorPeriodFieldEditor.setValidRange(100, 10000);
    pulsingMajorPeriodFieldEditor.getTextControl(parent)
            .setToolTipText("If the pulsing alarm box is checked for a widget that monitors a PV, "
                    + "then what is the time period of the pulse with the PV is in MAJOR alarm severity");
    addField(pulsingMajorPeriodFieldEditor);

    String[] allPVFactories = SimplePVLayer.getAllPVFactoryExtensions();
    String[][] entries = new String[allPVFactories.length][2];
    for (int i = 0; i < allPVFactories.length; i++) {
        entries[i][0] = allPVFactories[i];
        entries[i][1] = allPVFactories[i];
    }
    ComboFieldEditor pvConnectionLayerEditor = new ComboFieldEditor(PreferencesHelper.PV_CONNECTION_LAYER,
            "PV Connection Layer", entries, parent);
    addField(pvConnectionLayerEditor);

    ComboFieldEditor popupConsoleEditor = new ComboFieldEditor(PreferencesHelper.POPUP_CONSOLE,
            "Console Popup Level",
            new String[][] { { "Error, Warning and Info", ConsolePopupLevel.ALL.toString() },
                    { "Only Info", ConsolePopupLevel.ONLY_INFO.toString() },
                    { "Don't Popup", ConsolePopupLevel.NO_POP.toString() } },
            parent);
    addField(popupConsoleEditor);

    StringFieldEditor pythonPathEditor = new StringFieldEditor(PreferencesHelper.PYTHON_PATH, "PYTHONPATH",
            parent);
    pythonPathEditor.getTextControl(parent).setToolTipText("The path to search python modules");
    addField(pythonPathEditor);

    BooleanFieldEditor showCompactModeDialogEditor = new BooleanFieldEditor(
            PreferencesHelper.SHOW_COMPACT_MODE_DIALOG, "Show tip dialog about how to exit compact mode",
            parent);
    addField(showCompactModeDialogEditor);

    BooleanFieldEditor showFullScreenDialogEditor = new BooleanFieldEditor(
            PreferencesHelper.SHOW_FULLSCREEN_DIALOG, "Show tip dialog about how to exit fullscreen", parent);
    addField(showFullScreenDialogEditor);

    BooleanFieldEditor startWindowInCompactEditor = new BooleanFieldEditor(
            PreferencesHelper.START_WINDOW_IN_COMPACT_MODE, "Start application window in compact mode.",
            parent);
    addField(startWindowInCompactEditor);

    BooleanFieldEditor startWindowInFullScreen = new BooleanFieldEditor(
            PreferencesHelper.START_WINDOW_IN_FULL_SCREEN_MODE, "Start application window in full screen mode.",
            parent);
    addField(startWindowInFullScreen);

    BooleanFieldEditor showStatusLineInCompactMode = new BooleanFieldEditor(
            PreferencesHelper.SHOW_STATUS_LINE_IN_FULL_COMPACT_MODE, "Show status line in compact mode.",
            parent);
    addField(showStatusLineInCompactMode);

    BooleanFieldEditor showStatusLineInFullScreenMode = new BooleanFieldEditor(
            PreferencesHelper.SHOW_STATUS_LINE_IN_FULL_SCREEN_MODE, "Show status line in full screen mode.",
            parent);
    addField(showStatusLineInFullScreenMode);
}

From source file:org.csstudio.utility.ldap.ui.preference.PreferencePage.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./*  w  w  w. j  av a  2s  .  c om*/
 */
@Override
public void createFieldEditors() {
    addField(new StringFieldEditor(LdapPreference.URL.getKeyAsString(),
            Messages.getString("PreferencePage.URL"), getFieldEditorParent())); //$NON-NLS-1$
    addField(new StringFieldEditor(LdapPreference.USER_DN.getKeyAsString(),
            Messages.getString("PreferencePage.DN"), getFieldEditorParent())); //$NON-NLS-1$

    final StringFieldEditor sfeP = new StringFieldEditor(LdapPreference.USER_PASSWORD.getKeyAsString(),
            Messages.getString("PreferencePage.PASS"), getFieldEditorParent()); //$NON-NLS-1$

    sfeP.getTextControl(getFieldEditorParent()).setEchoChar('*');
    addField(sfeP);

    addField(new StringFieldEditor(LdapPreference.SECURITY_PROTOCOL.getKeyAsString(),
            Messages.getString("PreferencePage.SECURITY_PROTOCOL"), getFieldEditorParent())); //$NON-NLS-1$

    addField(new StringFieldEditor(LdapPreference.SECURITY_AUTH.getKeyAsString(),
            Messages.getString("PreferencePage.SECURITY_AUTHENTICATION"), getFieldEditorParent())); //$NON-NLS-1$

}

From source file:org.csstudio.utility.nameSpaceSearch.preference.PreferencePage.java

License:Open Source License

@Override
protected void createFieldEditors() {
    addField(new StringFieldEditor(RECORD.getNodeTypeName(),
            Messages.getString(Messages.PreferencePage_RECORD_ATTRIBUTE), getFieldEditorParent()));
    final StringFieldEditor searchRoot = new StringFieldEditor(
            UNIT.getNodeTypeName() + "=" + UNIT.getUnitTypeValue(),
            Messages.getString(Messages.PreferencePage_SEARCH_ROOT), getFieldEditorParent());

    searchRoot.getTextControl(getFieldEditorParent())
            .setToolTipText(Messages.getString(Messages.PreferencePage_SEARCH_ROOT_TOOL_TIP));
    addField(searchRoot);//from  w  ww  .  j a  v a 2 s  .  co m

}

From source file:org.csstudio.utility.tine.ui.perference.PreferencePage.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 . j ava2  s  .c  om*/
 */
@Override
public void createFieldEditors() {
    final StringFieldEditor pathSFE = new StringFieldEditor(PreferenceConstants.TINE_CONFIG_PATH,
            Messages.getString("Tine.PreferencePage.Path"), getFieldEditorParent());
    pathSFE.getTextControl(getFieldEditorParent())
            .setToolTipText(Messages.getString("Tine.PreferencePage.Path.ToolTip"));
    addField(pathSFE); //$NON-NLS-1$
}

From source file:org.dawb.tango.extensions.editors.preferences.CalibrationPreferences.java

License:Open Source License

@Override
protected void createFieldEditors() {

    editors = new ArrayList<StringFieldEditor>(7);

    this.use = new BooleanFieldEditor(CalibrationConstants.USE, "Use calibration", getFieldEditorParent());
    addField(use);/* w w w  .j  a v  a 2s. c  o m*/

    StringFieldEditor expr = new StringFieldEditor(CalibrationConstants.EXPR, "Calibration Expression",
            getFieldEditorParent());
    expr.getLabelControl(getFieldEditorParent()).setToolTipText(
            "Expression to use in calibration, the variable p is used for pixel value and p0 for the first pixel.");
    addField(expr);
    editors.add(expr);
    expr.getTextControl(getFieldEditorParent())
            .setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE));
    new Label(getFieldEditorParent(), SWT.SEPARATOR | SWT.HORIZONTAL);
    new Label(getFieldEditorParent(), SWT.SEPARATOR | SWT.HORIZONTAL);

    addField(new LabelFieldEditor("Coefficients:", getFieldEditorParent()));
    StringFieldEditor a = new StringFieldEditor(CalibrationConstants.A, "a", getFieldEditorParent());
    a.getLabelControl(getFieldEditorParent())
            .setToolTipText("Coefficient a used in the calibration expression.");
    addField(a);
    editors.add(a);

    StringFieldEditor b = new StringFieldEditor(CalibrationConstants.B, "b", getFieldEditorParent());
    b.getLabelControl(getFieldEditorParent())
            .setToolTipText("Coefficient b used in the calibration expression.");
    addField(b);
    editors.add(b);

    StringFieldEditor c = new StringFieldEditor(CalibrationConstants.C, "c", getFieldEditorParent());
    c.getLabelControl(getFieldEditorParent())
            .setToolTipText("Coefficient c used in the calibration expression.");
    addField(c);
    editors.add(c);

    StringFieldEditor d = new StringFieldEditor(CalibrationConstants.D, "d", getFieldEditorParent());
    d.getLabelControl(getFieldEditorParent())
            .setToolTipText("Coefficient d used in the calibration expression.");
    addField(d);
    editors.add(d);

    updateEnabled(Activator.getDefault().getPreferenceStore().getBoolean(CalibrationConstants.USE));

    new Label(getFieldEditorParent(), SWT.SEPARATOR | SWT.HORIZONTAL);
    new Label(getFieldEditorParent(), SWT.SEPARATOR | SWT.HORIZONTAL);
    addField(new LabelFieldEditor("", getFieldEditorParent()));
    addField(new StringFieldEditor(CalibrationConstants.LABEL, "X-axis label", getFieldEditorParent()));
}

From source file:org.ebayopensource.turmeric.eclipse.maven.ui.preferences.TurmericSOAConfigPrefPage.java

License:Open Source License

@Override
protected void createFieldEditors() {
    final IPreferenceStore prefStore = TurmericSOAConfigPrefInitializer.getPreferenceStore();
    final Composite composite = getFieldEditorParent();

    try {/*w ww  .  ja v a  2 s.  co  m*/
        final Group group = new Group(composite, SWT.SHADOW_ETCHED_IN);
        group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        GridLayout layout = new GridLayout(2, false);
        group.setLayout(layout);
        group.setText("Framework Version Configurations");
        final ISOAOrganizationProvider orgProvider = GlobalRepositorySystem.instanceOf()
                .getActiveRepositorySystem().getActiveOrganizationProvider();
        String soatoolsId = orgProvider.getSOAFrameworkLibraryIdentifier(SOAFrameworkLibrary.SOATOOLS);
        final ArtifactMetadata metadata = MavenEclipseUtil.artifactMetadata(soatoolsId);

        BooleanFieldEditor overwriteEditor = new BooleanFieldEditor(
                TurmericSOAConfigPrefInitializer.PREF_KEY_OVERWRITE_PREFERRED_VERSOIN,
                "Overwrite Preferred Version", group) {

            @Override
            protected void valueChanged(boolean oldValue, boolean newValue) {
                enableVersionEditor(newValue);
                super.valueChanged(oldValue, newValue);
            }

            private void enableVersionEditor(boolean newValue) {
                if (preferredVerEditor != null) {
                    preferredVerEditor.setEnabled(newValue, group);
                    if (newValue == true && StringUtils.isBlank(preferredVerEditor.getStringValue())) {
                        TurmericSOAConfigPrefPage.this.setErrorMessage("preferred version must not be empty");
                        preferredVerEditor.setErrorMessage("preferred version must not be empty");
                    }
                }
            }

            @Override
            protected void doLoadDefault() {

                super.doLoadDefault();
                enableVersionEditor(getBooleanValue());
            }
        };
        addField(overwriteEditor);
        final Collection<String> versions = new TreeSet<String>();
        if (metadata != null) {
            for (Artifact artifact : MavenCoreUtils.mavenEclipseAPI()
                    .findArtifactByNameAndGroup(metadata.getArtifactId(), metadata.getGroupId())) {
                versions.add(artifact.getVersion());
            }
        }

        final String minVersion = orgProvider.getMinimumRequiredTurmericFrameworkVersion();
        this.preferredVerEditor = new StringFieldEditor(
                TurmericSOAConfigPrefInitializer.PREF_KEY_TURMERIC_PREFERRED_VERSOIN,
                "Preferred Turmeric Version:", group) {

            @Override
            protected boolean doCheckState() {
                if (VersionUtil.compare(getStringValue(), minVersion) < 0) {
                    this.setErrorMessage("Preferred version must be equal to or greater than " + minVersion);
                    return false;
                }
                return super.doCheckState();
            }

        };
        this.preferredVerEditor.setEmptyStringAllowed(false);
        this.preferredVerEditor.setValidateStrategy(StringFieldEditor.VALIDATE_ON_KEY_STROKE);

        addField(preferredVerEditor);

        if (versions.isEmpty() == false) {
            Text verText = this.preferredVerEditor.getTextControl(group);
            new AutoCompleteField(verText, new TextContentAdapter(), versions.toArray(new String[0]));
        }

        this.preferredVerEditor.setEnabled(
                prefStore.getBoolean(TurmericSOAConfigPrefInitializer.PREF_KEY_OVERWRITE_PREFERRED_VERSOIN),
                group);

        prefStore.setValue(TurmericSOAConfigPrefInitializer.PREF_KEY_MINIMUM_REQUIRED_VERSOIN, minVersion);
        prefStore.setDefault(TurmericSOAConfigPrefInitializer.PREF_KEY_MINIMUM_REQUIRED_VERSOIN, minVersion);
        StringFieldEditor text = new StringFieldEditor(
                TurmericSOAConfigPrefInitializer.PREF_KEY_MINIMUM_REQUIRED_VERSOIN, "Minimum Required Version:",
                group);
        text.getTextControl(group).setEditable(false);
        text.setStringValue(orgProvider.getMinimumRequiredTurmericFrameworkVersion());
        addField(text);
    } catch (Exception e) {
        logger.error(e);
        UIUtil.showErrorDialog(e);
    }
}

From source file:org.ebayopensource.turmeric.eclipse.services.ui.properties.SOAServiceDependenciesPage.java

License:Open Source License

private String getText(StringFieldEditor stringFieldEditor) {
    return stringFieldEditor.getTextControl(editorParentMap.get(stringFieldEditor)).getText();
}

From source file:org.eclipse.cdt.codan.internal.ui.widgets.ParametersComposite.java

License:Open Source License

/**
 * @param parent// w  ww.  ja va2s  .  co m
 * @param problem
 * @param style
 */
public ParametersComposite(Composite parent, final IProblem problem) {
    super(parent, SWT.NONE);
    if (problem == null)
        throw new NullPointerException();
    this.setLayout(new GridLayout(2, false));
    this.problem = problem;
    this.prefStore = new PreferenceStore();
    page = new FieldEditorPreferencePage(FieldEditorPreferencePage.GRID) {
        @Override
        protected void createFieldEditors() {
            noDefaultAndApplyButton();
            ((GridLayout) getFieldEditorParent().getLayout()).numColumns = 2;
            addField(new BooleanFieldEditor(PREF_ENABLED, CodanUIMessages.ParametersComposite_IsEnabled,
                    getFieldEditorParent()));
            String[][] entries = {
                    { CodanSeverity.Error.toTranslatableString(), CodanSeverity.Error.toString() }, //
                    { CodanSeverity.Warning.toTranslatableString(), CodanSeverity.Warning.toString() }, //
                    { CodanSeverity.Info.toTranslatableString(), CodanSeverity.Info.toString() }, //
                    { NO_CHANGE, NO_CHANGE }, //
            };
            addField(new ComboFieldEditor(PREF_SEVERITY, CodanUIMessages.ParametersComposite_Severity, entries,
                    getFieldEditorParent()));
            StringFieldEditor messagePatternEditor = new StringFieldEditor(PREF_MESSAGE,
                    CodanUIMessages.ParametersComposite_MessagePattern, getFieldEditorParent());
            // We are using read-only text field for message pattern to allow copy to clipboard.
            makeUneditable(messagePatternEditor);
            addField(messagePatternEditor);
            IProblemPreference pref = problem.getPreference();
            createFieldEditorsForParameters(pref);
        }

        private void makeUneditable(StringFieldEditor editor) {
            /*
             * Here we are doing 2 things to make a text control "uneditable":
             * 1. 'setUneditable(false)' the problem with with just doing this is that
             *    the background of the text control doesn't change, and it looks like
             *    an editable one. This is confusing to the user.
             * 2. Getting the background of a label control and applying it
             *    to the "uneditable" text control. This way it is easier to figure out that
             *    the contents of the text control cannot be changed.
             * Why not just setEnable(false)? Because it changes the text of the text control
             * to light gray, making it difficult to read. Also, users cannot select and copy
             * text from a disabled text field.
             */
            Color background = editor.getLabelControl(getFieldEditorParent()).getBackground();
            Text text = editor.getTextControl(getFieldEditorParent());
            text.setBackground(background);
            text.setEditable(false);
        }

        @Override
        protected Control createContents(Composite parent) {
            return super.createContents(parent);
        }

        /**
         * @param info
         */
        private void createFieldEditorsForParameters(final IProblemPreference info) {
            if (info == null)
                return;
            if (info.getKey() == FileScopeProblemPreference.KEY)
                return; // skip the scope
            if (info.getKey() == LaunchModeProblemPreference.KEY)
                return; // skip the launch
            switch (info.getType()) {
            case TYPE_STRING: {
                StringFieldEditor fe = new StringFieldEditor(info.getQualifiedKey(), info.getLabel(),
                        getFieldEditorParent());
                addField(fe);
                break;
            }
            case TYPE_BOOLEAN: {
                BooleanFieldEditor fe = new BooleanFieldEditor(info.getQualifiedKey(), info.getLabel(),
                        getFieldEditorParent());
                addField(fe);
                break;
            }
            case TYPE_LIST:
                ListEditor le = new ListEditor(info.getQualifiedKey(), info.getLabel(),
                        getFieldEditorParent()) {
                    @Override
                    protected String[] parseString(String stringList) {
                        ListProblemPreference list = (ListProblemPreference) info;
                        IProblemPreference[] childDescriptors = list.getChildDescriptors();
                        if (childDescriptors.length == 0)
                            return new String[0];
                        String res[] = new String[childDescriptors.length];
                        for (int i = 0; i < childDescriptors.length; i++) {
                            IProblemPreference item = childDescriptors[i];
                            res[i] = String.valueOf(item.getValue());
                        }
                        return res;
                    }

                    @Override
                    protected String getNewInputObject() {
                        ListProblemPreference list = (ListProblemPreference) info;
                        String label = list.getChildDescriptor().getLabel();
                        InputDialog dialog = new InputDialog(getShell(),
                                CodanUIMessages.ParametersComposite_NewValue, label, "", null); //$NON-NLS-1$
                        if (dialog.open() == Window.OK) {
                            return dialog.getValue();
                        }
                        return null;
                    }

                    @Override
                    protected String createList(String[] items) {
                        ListProblemPreference list = (ListProblemPreference) info.clone();
                        list.clear();
                        for (int i = 0; i < items.length; i++) {
                            String val = items[i];
                            list.addChildValue(val);
                        }
                        return list.exportValue();
                    }
                };
                addField(le);
                break;
            case TYPE_MAP:
                IProblemPreference[] childrenDescriptor = ((IProblemPreferenceCompositeDescriptor) info)
                        .getChildDescriptors();
                for (int i = 0; i < childrenDescriptor.length; i++) {
                    IProblemPreference desc = childrenDescriptor[i];
                    createFieldEditorsForParameters(desc);
                }
                break;
            case TYPE_CUSTOM: {
                StringFieldEditor fe = new StringFieldEditor(info.getQualifiedKey(), info.getLabel(),
                        getFieldEditorParent());
                addField(fe);
                break;
            }
            case TYPE_FILE: {
                FileFieldEditor fe = new FileFieldEditor(info.getQualifiedKey(), info.getLabel(),
                        getFieldEditorParent());
                addField(fe);
                break;
            }
            default:
                throw new UnsupportedOperationException(info.getType().toString());
            }
        }
    };
    load(problem);
    page.setPreferenceStore(prefStore);
    page.createControl(parent);
    page.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
}

From source file:org.eclipse.cdt.managedbuilder.ui.properties.BuildOptionSettingsUI.java

License:Open Source License

@Override
protected void createFieldEditors() {
    // true if the user selected "Display tool option tips at a fixed location" in Preferences AND
    // and we are displaying the tool tip box on this page because one or more option has non-empty tool tip.
    boolean pageHasToolTipBox = isToolTipBoxNeeded();

    // Get the preference store for the build settings
    super.createFieldEditors();
    // Iterate over the options in the category and create a field editor
    // for each//from   w ww . j  a v  a  2 s . com
    Object[][] options = category.getOptions(fInfo, optionHolder);

    for (int index = 0; index < options.length; ++index) {
        // Get the option
        IHoldsOptions holder = (IHoldsOptions) options[index][0];
        if (holder == null)
            break; //  The array may not be full
        IOption opt = (IOption) options[index][1];

        // check to see if the option has an applicability calculator
        IOptionApplicability applicabilityCalculator = opt.getApplicabilityCalculator();
        IBuildObject config = fInfo;

        if (applicabilityCalculator == null || applicabilityCalculator.isOptionVisible(config, holder, opt)) {

            String optId = getToolSettingsPrefStore().getOptionId(opt);
            final String nameStr = opt.getName();
            String tipStr = opt.getToolTip();
            String contextId = opt.getContextId();

            if (pageHasToolTipBox && (tipStr == null || tipStr.trim().length() == 0)) {
                tipStr = Messages.BuildOptionSettingsUI_0;
            }

            try {
                // Figure out which type the option is and add a proper field
                // editor for it
                Composite fieldEditorParent = getFieldEditorParent();
                FieldEditor fieldEditor = null;

                String customFieldEditorId = opt.getFieldEditorId();
                if (customFieldEditorId != null) {
                    fieldEditor = createCustomFieldEditor(customFieldEditorId);
                    if (fieldEditor != null) {
                        ICustomBuildOptionEditor customFieldEditor = (ICustomBuildOptionEditor) fieldEditor;
                        if (customFieldEditor.init(opt, opt.getFieldEditorExtraArgument(), optId,
                                fieldEditorParent)) {
                            Control[] toolTipSources = customFieldEditor.getToolTipSources();
                            if (toolTipSources != null) {
                                for (Control control : toolTipSources) {
                                    if (pageHasToolTipBox) {
                                        control.setData(new TipInfo(nameStr, tipStr));
                                        control.addListener(selectAction, tipSetListener);
                                    } else {
                                        control.setToolTipText(tipStr);
                                    }
                                }
                            }
                        } else {
                            fieldEditor = null;
                        }
                    }
                }

                if (fieldEditor == null) {
                    switch (opt.getValueType()) {
                    case IOption.STRING: {
                        StringFieldEditor stringField;

                        // If browsing is set, use a field editor that has a
                        // browse button of the appropriate type.
                        switch (opt.getBrowseType()) {
                        case IOption.BROWSE_DIR: {
                            stringField = new DirectoryFieldEditor(optId, nameStr, fieldEditorParent);
                            if (opt.getBrowseFilterPath() != null) {
                                try {
                                    String filterPath = ManagedBuildManager.getBuildMacroProvider()
                                            .resolveValue(opt.getBrowseFilterPath(), null, null,
                                                    IBuildMacroProvider.CONTEXT_OPTION,
                                                    opt.getOptionContextData(holder));
                                    ((DirectoryFieldEditor) stringField).setFilterPath(new File(filterPath));
                                } catch (BuildMacroException bmx) {
                                    ManagedBuilderUIPlugin.log(bmx);
                                }
                            }
                        }
                            break;

                        case IOption.BROWSE_FILE: {
                            stringField = new FileFieldEditor(optId, nameStr, fieldEditorParent) {
                                /**
                                 * Do not perform validity check on the file name due to losing focus,
                                 * see http://bugs.eclipse.org/289448
                                 */
                                @Override
                                protected boolean checkState() {
                                    clearErrorMessage();
                                    return true;
                                }
                            };
                            if (opt.getBrowseFilterPath() != null) {
                                try {
                                    String filterPath = ManagedBuildManager.getBuildMacroProvider()
                                            .resolveValue(opt.getBrowseFilterPath(), null, null,
                                                    IBuildMacroProvider.CONTEXT_OPTION,
                                                    opt.getOptionContextData(holder));
                                    ((FileFieldEditor) stringField).setFilterPath(new File(filterPath));
                                } catch (BuildMacroException bmx) {
                                    ManagedBuilderUIPlugin.log(bmx);
                                }
                            }
                            ((FileFieldEditor) stringField).setFileExtensions(opt.getBrowseFilterExtensions());
                        }
                            break;

                        case IOption.BROWSE_NONE: {
                            final StringFieldEditorM local = new StringFieldEditorM(optId, nameStr,
                                    fieldEditorParent);
                            stringField = local;
                            local.getTextControl().addModifyListener(new ModifyListener() {
                                @Override
                                public void modifyText(ModifyEvent e) {
                                    local.valueChanged();
                                }
                            });
                        }
                            break;

                        default: {
                            throw new BuildException(null);
                        }
                        }
                        Label label = stringField.getLabelControl(fieldEditorParent);
                        Text text = stringField.getTextControl(fieldEditorParent);
                        if (pageHasToolTipBox) {
                            label.setData(new TipInfo(nameStr, tipStr));
                            label.addListener(selectAction, tipSetListener);
                            text.setData(new TipInfo(nameStr, tipStr));
                            text.addListener(selectAction, tipSetListener);
                        } else {
                            label.setToolTipText(tipStr);
                            text.setToolTipText(tipStr);
                        }
                        if (!contextId.equals(AbstractPage.EMPTY_STR)) {
                            PlatformUI.getWorkbench().getHelpSystem().setHelp(text, contextId);
                        }
                        fieldEditor = stringField;
                    }
                        break;

                    case IOption.BOOLEAN: {
                        fieldEditor = new TriStateBooleanFieldEditor(optId, nameStr, tipStr, fieldEditorParent,
                                contextId, ohs, curr);
                        // tipStr is handled in TriStateBooleanFieldEditor constructor
                    }
                        break;

                    case IOption.ENUMERATED: {
                        String selId = opt.getSelectedEnum();
                        String sel = opt.getEnumName(selId);

                        // Get all applicable values for this enumerated Option, But display
                        // only the enumerated values that are valid (static set of enumerated values defined
                        // in the plugin.xml file) in the UI Combobox. This refrains the user from selecting an
                        // invalid value and avoids issuing an error message.
                        String[] enumNames = opt.getApplicableValues();
                        Vector<String> enumValidList = new Vector<String>();
                        for (int i = 0; i < enumNames.length; ++i) {
                            if (opt.getValueHandler().isEnumValueAppropriate(config, opt.getOptionHolder(), opt,
                                    opt.getValueHandlerExtraArgument(), enumNames[i])) {
                                enumValidList.add(enumNames[i]);
                            }
                        }
                        String[] enumValidNames = new String[enumValidList.size()];
                        enumValidList.copyInto(enumValidNames);

                        // if (displayFixedTip==false), tooltip was already set in BuildOptionComboFieldEditor constructor.
                        String tooltipHoverStr = displayFixedTip ? null : tipStr;
                        fieldEditor = new BuildOptionComboFieldEditor(optId, nameStr, tooltipHoverStr,
                                contextId, enumValidNames, sel, fieldEditorParent);

                        if (pageHasToolTipBox) {
                            Combo combo = ((BuildOptionComboFieldEditor) fieldEditor).getComboControl();
                            Label label = fieldEditor.getLabelControl(fieldEditorParent);
                            combo.setData(new TipInfo(nameStr, tipStr));
                            combo.addListener(selectAction, tipSetListener);
                            label.setData(new TipInfo(nameStr, tipStr));
                            label.addListener(selectAction, tipSetListener);
                        }
                    }
                        break;

                    case IOption.TREE:
                        fieldEditor = new TreeBrowseFieldEditor(optId, nameStr, fieldEditorParent, nameStr, opt,
                                contextId);
                        ((StringButtonFieldEditor) fieldEditor).setChangeButtonText("..."); //$NON-NLS-1$

                        if (pageHasToolTipBox) {
                            Text text = ((StringButtonFieldEditor) fieldEditor)
                                    .getTextControl(fieldEditorParent);
                            Label label = fieldEditor.getLabelControl(fieldEditorParent);
                            text.setData(new TipInfo(nameStr, tipStr));
                            text.addListener(selectAction, tipSetListener);
                            label.setData(new TipInfo(nameStr, tipStr));
                            label.addListener(selectAction, tipSetListener);
                        }
                        break;

                    case IOption.INCLUDE_PATH:
                    case IOption.STRING_LIST:
                    case IOption.PREPROCESSOR_SYMBOLS:
                    case IOption.LIBRARIES:
                    case IOption.OBJECTS:
                    case IOption.INCLUDE_FILES:
                    case IOption.LIBRARY_PATHS:
                    case IOption.LIBRARY_FILES:
                    case IOption.MACRO_FILES:
                    case IOption.UNDEF_INCLUDE_PATH:
                    case IOption.UNDEF_PREPROCESSOR_SYMBOLS:
                    case IOption.UNDEF_INCLUDE_FILES:
                    case IOption.UNDEF_LIBRARY_PATHS:
                    case IOption.UNDEF_LIBRARY_FILES:
                    case IOption.UNDEF_MACRO_FILES: {
                        // if (displayFixedTip==false), tooltip was already set in FileListControlFieldEditor constructor.
                        String tooltipHoverStr = displayFixedTip ? null : tipStr;
                        fieldEditor = new FileListControlFieldEditor(optId, nameStr, tooltipHoverStr, contextId,
                                fieldEditorParent, opt.getBrowseType());
                        if (opt.getBrowseFilterPath() != null) {
                            try {
                                String filterPath = ManagedBuildManager.getBuildMacroProvider().resolveValue(
                                        opt.getBrowseFilterPath(), null, null,
                                        IBuildMacroProvider.CONTEXT_OPTION, opt.getOptionContextData(holder));
                                ((FileListControlFieldEditor) fieldEditor).setFilterPath(filterPath);
                            } catch (BuildMacroException bmx) {
                                ManagedBuilderUIPlugin.log(bmx);
                            }
                        }
                        ((FileListControlFieldEditor) fieldEditor)
                                .setFilterExtensions(opt.getBrowseFilterExtensions());

                        if (pageHasToolTipBox) {
                            Label label = fieldEditor.getLabelControl(fieldEditorParent);
                            label.setData(new TipInfo(nameStr, tipStr));
                            label.addListener(selectAction, tipSetListener);
                        }
                    }
                        break;

                    default:
                        throw new BuildException(null);
                    }
                }

                setFieldEditorEnablement(holder, opt, applicabilityCalculator, fieldEditor, fieldEditorParent);

                addField(fieldEditor);
                fieldsMap.put(optId, fieldEditor);
                fieldEditorsToParentMap.put(fieldEditor, fieldEditorParent);

            } catch (BuildException e) {
            }
        }
    }
}

From source file:org.eclipse.dirigible.ide.db.preferences.DatabaseAttributesPreferencePage.java

License:Open Source License

@Override
protected void createFieldEditors() {
    Text text = null;//from w ww  .ja  v  a2  s .c o  m

    StringFieldEditor databaseProductNameField = new StringFieldEditor(CommonParameters.DATABASE_PRODUCT_NAME,
            "&Product Name:", getFieldEditorParent());
    text = databaseProductNameField.getTextControl(getFieldEditorParent());
    text.setEditable(false);
    text.setText(CommonParameters.getDatabaseProductName() != null ? CommonParameters.getDatabaseProductName()
            : DatabasePreferencePage.N_A);
    addField(databaseProductNameField);

    StringFieldEditor databaseProductVersionField = new StringFieldEditor(
            CommonParameters.DATABASE_PRODUCT_VERSION, "&Product Version:", getFieldEditorParent());
    text = databaseProductVersionField.getTextControl(getFieldEditorParent());
    text.setEditable(false);
    text.setText(
            CommonParameters.getDatabaseProductVersion() != null ? CommonParameters.getDatabaseProductVersion()
                    : DatabasePreferencePage.N_A);
    addField(databaseProductVersionField);

    StringFieldEditor databaseMinorVersionField = new StringFieldEditor(CommonParameters.DATABASE_MINOR_VERSION,
            "&Minor Version:", getFieldEditorParent());
    text = databaseMinorVersionField.getTextControl(getFieldEditorParent());
    text.setEditable(false);
    text.setText(CommonParameters.get(CommonParameters.DATABASE_MINOR_VERSION) != null
            ? CommonParameters.get(CommonParameters.DATABASE_MINOR_VERSION)
            : DatabasePreferencePage.N_A);
    addField(databaseMinorVersionField);

    StringFieldEditor databaseMajorVersionField = new StringFieldEditor(CommonParameters.DATABASE_MAJOR_VERSION,
            "&Major Version:", getFieldEditorParent());
    text = databaseMajorVersionField.getTextControl(getFieldEditorParent());
    text.setEditable(false);
    text.setText(CommonParameters.get(CommonParameters.DATABASE_MAJOR_VERSION) != null
            ? CommonParameters.get(CommonParameters.DATABASE_MAJOR_VERSION)
            : DatabasePreferencePage.N_A);
    addField(databaseMajorVersionField);

}