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

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

Introduction

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

Prototype

public void setFocus() 

Source Link

Document

Sets the focus to this field editor.

Usage

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

License:Open Source License

/**
 * Gets the radio box control./* w  w w .  j av  a 2  s  .c om*/
 *
 * @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.talend.core.prefs.ui.CorePreferencePage.java

License:Open Source License

@Override
    protected void checkState() {
        super.checkState();
        int size = fields.size();
        if (size > 0) {
            for (int i = 0; i < size; i++) {
                FieldEditor editor = fields.get(i);
                if (!editor.isValid()) {
                    editor.setFocus();
                }//from  ww  w.  ja  v a2 s .co  m
            }
        }
    }