Example usage for org.eclipse.jface.preference FieldEditor getLabelControl

List of usage examples for org.eclipse.jface.preference FieldEditor getLabelControl

Introduction

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

Prototype

public Label getLabelControl(Composite parent) 

Source Link

Document

Returns this field editor's label component.

Usage

From source file:net.mldonkey.g2gui.view.pref.MLDonkeyOptions.java

License:Open Source License

private void setupEditor( FieldEditor e, String optionHelp ) {
    e.setPreferencePage( this );
    e.setPreferenceStore( getPreferenceStore() );
    e.getLabelControl( parent ).setToolTipText( optionHelp );
    e.load();//w  w w.  ja v a 2  s .  c o m
    addField( e );
}

From source file:org.csstudio.diirt.util.preferences.BasePreferencePage.java

License:Open Source License

/**
 * Add the given {@code editor} field to this page. The editor's
 * caption foreground will be updated when the editor's value changes.
 *
 * @param fieldEditor The {@link FieldEditor} to be added and updated.
 * @param parent The {@link Composite} owning the given {@code editor}.
 * @param canBeDefaulted {@code true} if the given {@code editor} can be
 *            restored to its default value.
 * @param defaultGetter The {@link Supplier} of the editor's default value.
 *            Can be {@code null} if the editor's caption foreground
 *            should not be updated when the editor's value changes.
 * @param storedGetter The {@link Supplier} of the editor's stored value.
 *            Can be {@code null} if the editor's caption foreground
 *            should not be initially updated.
 * @param listener Called when a field editor fires a value property change.
 *//*from   w w w. j  a  v a 2 s .  co  m*/
protected void addField(FieldEditor fieldEditor, Composite parent, boolean canBeDefaulted,
        Supplier<Object> defaultGetter, Supplier<Object> storedGetter, IPropertyChangeListener listener) {

    final IPreferenceStore store = getPreferenceStore();
    final Editor editor = new Editor(fieldEditor, parent, canBeDefaulted, defaultGetter, storedGetter);

    fieldEditor.getLabelControl(parent).setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
    fieldEditor.setPage(this);
    fieldEditor.setPreferenceStore(store);
    fieldEditor.load();
    fieldEditor.setPropertyChangeListener(e -> {
        if (FieldEditor.VALUE.equals(e.getProperty())) {

            if (storedGetter != null) {
                editor.setRestartRequired(!Objects.equals(e.getNewValue(), storedGetter.get()));
            }

            editor.updateCaptionColor(e.getNewValue());

            if (listener != null) {
                listener.propertyChange(e);
            }

        }
    });

    editor.updateCaptionColor();
    editors.put(fieldEditor, editor);

    if (PREF_CONFIGURATION_DIRECTORY.equals(fieldEditor.getPreferenceName())) {
        directoryEditor = editor;
    }

}

From source file:org.csstudio.diirt.util.preferences.BasePreferencePage.java

License:Open Source License

/**
 * Updates the color of the given {@code editor}'s caption, depending on
 * the current value compared with the default one. If they are equals, the
 * caption foreground color will be {@link SWT#COLOR_WIDGET_FOREGROUND},
 * otherwise {@link SWT#COLOR_BLUE}./*  w  w w.  j  a v  a 2  s  . com*/
 *
 * @param editor The {@link FieldEditor} whose caption's color must be
 *            updated.
 * @param parent The {@link Composite} owning the given {@code editor}.
 * @param defaultValue The {@code editor}'s default value.
 * @param currentValue The {@code editor}'s current value.
 */
protected void updateCaptionColor(final FieldEditor editor, final Composite parent, Object defaultValue,
        Object currentValue) {

    final Color captionColor = Objects.equals(defaultValue, currentValue)
            ? SWTResourceManager.getColor(SWT.COLOR_WIDGET_FOREGROUND)
            : SWTResourceManager.getColor(SWT.COLOR_BLUE);

    Display.getDefault().asyncExec(() -> {

        Label l = editor.getLabelControl(parent);

        if (!l.isDisposed()) {
            l.setForeground(captionColor);
        }

    });

}

From source file:org.csstudio.diirt.util.preferences.BasePreferencePage.java

License:Open Source License

/**
 * Updates the color of the given {@code editor}'s caption, depending on
 * the current {@code error} value. If {@code false}, the caption foreground
 * color will be {@link SWT#COLOR_WIDGET_FOREGROUND}, otherwise
 * {@link SWT#COLOR_RED}.//from w w  w.j av  a2  s. c o  m
 *
 * @param editor The {@link FieldEditor} whose caption's color must be
 *            updated.
 * @param parent The {@link Composite} owning the given {@code editor}.
 * @param error {@code true} if the caption must be colored in
 *            {@link SWT#COLOR_RED}.
 * @param tooltip The tooltip assigned to the {@code editor}'s caption.
 */
protected void updateCaptionColor(final Composite parent, final FieldEditor editor, boolean error,
        final String tooltip) {

    final Color captionColor = error ? SWTResourceManager.getColor(SWT.COLOR_RED)
            : SWTResourceManager.getColor(SWT.COLOR_WIDGET_FOREGROUND);

    Display.getDefault().asyncExec(() -> {

        Label l = editor.getLabelControl(parent);

        if (!l.isDisposed()) {
            l.setForeground(captionColor);
            l.setToolTipText(tooltip);
        }

    });

}

From source file:org.ebayopensource.turmeric.eclipse.repositorysystem.ui.pref.CustomRadioGroupFieldEditor.java

License:Open Source License

/**
 * Gets the radio box control./*from  w  w w  . j  a  v a 2 s.  co m*/
 *
 * @param parent the parent
 * @return the radio box control
 */
public Composite getRadioBoxControl(Composite parent) {
    if (chooseArea != null) {
        checkParent(chooseArea, parent);
        return chooseArea;
    }
    createChooseArea(parent);
    Font font = parent.getFont();
    radioButtons = new Button[labelsAndValues.length];
    for (int i = 0; i < labelsAndValues.length; i++) {
        final Button radio = new Button(chooseArea, SWT.RADIO | SWT.LEFT);
        radioButtons[i] = radio;
        String[] labelAndValue = labelsAndValues[i];
        radio.setText(labelAndValue[0]);
        radio.setData(labelAndValue[1]);
        radio.setFont(font);
        radio.setEnabled(organizations.size() > 1);
        radio.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent event) {
                CustomRadioGroupFieldEditor.this.clearErrorMessage();
                String oldValue = value;
                value = (String) event.widget.getData();
                setPresentsDefaultValue(false);
                setSubButtonsEnabled(value);
                fireValueChanged(VALUE, oldValue, value);
            }
        });

        final Composite composite = new Composite(chooseArea, SWT.NONE);
        final GridLayout layout = new GridLayout(1, true);
        composite.setLayout(layout);
        List<Button> buttons = new ArrayList<Button>();
        subButtons.put(labelAndValue[1], buttons);
        for (String orgId : organizations.get(labelAndValue[1]).keySet()) {
            final Button radio1 = new Button(composite, SWT.RADIO | SWT.LEFT);
            GridData data = new GridData();
            data.horizontalIndent = 30;
            radio1.setLayoutData(data);
            radio1.setText(organizations.get(labelAndValue[1]).get(orgId));
            radio1.setData(orgId);
            radio1.setFont(font);
            radio1.setEnabled(organizations.get(labelAndValue[1]).size() > 1);
            radio1.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent event) {
                    CustomRadioGroupFieldEditor.this.clearErrorMessage();
                    String oldValue = subValue;
                    subValue = (String) event.widget.getData();
                    setPresentsDefaultValue(false);
                    fireValueChanged(SUB_VALUE, oldValue, subValue);
                }
            });
            buttons.add(radio1);
        }

        final Composite panel = new Composite(chooseArea, SWT.NONE);
        GridData data = new GridData(GridData.FILL_HORIZONTAL);
        data.horizontalSpan = numColumns;
        panel.setLayoutData(data);
        panel.setLayout(new GridLayout(2, false));
        final FieldEditor fieldEditor = createChoiceSubFieldEditor(panel, radio);
        if (fieldEditor != null) {
            Label label = fieldEditor.getLabelControl(panel);
            data = new GridData();
            data.horizontalIndent = 15;
            label.setLayoutData(data);
            subFieldEditors.put(fieldEditor, panel);
            fieldEditor.setEnabled(radio.getText().equals(getPreferenceStore().getString(getPreferenceName())),
                    panel);
            radio.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetDefaultSelected(SelectionEvent e) {
                    widgetSelected(e);
                }

                @Override
                public void widgetSelected(SelectionEvent e) {
                    setSubFieldEditorEnabled(false);
                    fieldEditor.setEnabled(radio.getSelection(), panel);
                    fieldEditor.setFocus();
                }

            });
        }
    }
    chooseArea.addDisposeListener(new DisposeListener() {
        @Override
        public void widgetDisposed(DisposeEvent event) {
            chooseArea = null;
            radioButtons = null;
        }
    });

    return chooseArea;
}

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/* www.  ja v  a2s .  c o  m*/
    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.wesnoth.preferences.AbstractPreferencePage.java

License:Open Source License

/**
 * Adds the specified field editor with the specified tooltip
 * /*from   ww  w . j av a  2 s. c o  m*/
 * @param editor
 * @param tooltip
 */
protected void addField(FieldEditor editor, String tooltip) {
    editor.getLabelControl(getFieldEditorParent()).setToolTipText(tooltip);
    super.addField(editor);
}