Example usage for org.eclipse.jface.preference PreferenceStore setDefault

List of usage examples for org.eclipse.jface.preference PreferenceStore setDefault

Introduction

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

Prototype

@Override
    public void setDefault(String name, boolean value) 

Source Link

Usage

From source file:com.android.ddms.PrefsDialog.java

License:Apache License

private static void setDefaults(String homeDir) {
    PreferenceStore prefStore = mStore.getPreferenceStore();

    prefStore.setDefault(PREFS_DEBUG_PORT_BASE, DdmPreferences.DEFAULT_DEBUG_PORT_BASE);

    prefStore.setDefault(PREFS_SELECTED_DEBUG_PORT, DdmPreferences.DEFAULT_SELECTED_DEBUG_PORT);

    prefStore.setDefault(PREFS_USE_ADBHOST, DdmPreferences.DEFAULT_USE_ADBHOST);
    prefStore.setDefault(PREFS_ADBHOST_VALUE, DdmPreferences.DEFAULT_ADBHOST_VALUE);

    prefStore.setDefault(PREFS_DEFAULT_THREAD_UPDATE, true);
    prefStore.setDefault(PREFS_DEFAULT_HEAP_UPDATE, false);
    prefStore.setDefault(PREFS_THREAD_REFRESH_INTERVAL, DdmUiPreferences.DEFAULT_THREAD_REFRESH_INTERVAL);

    prefStore.setDefault("textSaveDir", homeDir); //$NON-NLS-1$
    prefStore.setDefault("imageSaveDir", homeDir); //$NON-NLS-1$

    prefStore.setDefault(PREFS_LOG_LEVEL, "info"); //$NON-NLS-1$

    prefStore.setDefault(PREFS_TIMEOUT, DdmPreferences.DEFAULT_TIMEOUT);
    prefStore.setDefault(PREFS_PROFILER_BUFFER_SIZE_MB, DdmPreferences.DEFAULT_PROFILER_BUFFER_SIZE_MB);

    // choose a default font for the text output
    FontData fdat = new FontData("Courier", 10, SWT.NORMAL); //$NON-NLS-1$
    prefStore.setDefault("textOutputFont", fdat.toString()); //$NON-NLS-1$

    // layout information.
    prefStore.setDefault(SHELL_X, 100);//from ww  w  .  j ava  2s  .  c o m
    prefStore.setDefault(SHELL_Y, 100);
    prefStore.setDefault(SHELL_WIDTH, 800);
    prefStore.setDefault(SHELL_HEIGHT, 600);

    prefStore.setDefault(EXPLORER_SHELL_X, 50);
    prefStore.setDefault(EXPLORER_SHELL_Y, 50);

    prefStore.setDefault(SHOW_NATIVE_HEAP, false);
}

From source file:com.aptana.internal.ui.text.spelling.SpellingConfigurationBlock.java

License:Open Source License

/**
 * Creates the encoding field editor.//from  w w  w  . j a va 2s . co  m
 * 
 * @param composite
 *            the parent composite
 * @param allControls
 *            list with all controls
 * @since 3.3
 */
private void createEncodingFieldEditor(Composite composite, List allControls) {
    final Label filler = new Label(composite, SWT.NONE);
    final GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gd.horizontalSpan = 4;
    filler.setLayoutData(gd);

    // Label label = new Label(composite, SWT.NONE);
    // label
    // .setText(PreferencesMessages.SpellingPreferencePage_encoding_label);
    // label.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    // allControls.add(label);

    // fEncodingEditorParent = new Composite(composite, SWT.NONE);
    // GridLayout layout = new GridLayout(2, false);
    // layout.marginWidth = 0;
    // layout.marginHeight = 0;
    // fEncodingEditorParent.setLayout(layout);
    // gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    // gd.horizontalSpan = 3;
    // fEncodingEditorParent.setLayoutData(gd);

    //fEncodingEditor= new EncodingFieldEditor(PREF_SPELLING_USER_DICTIONARY_ENCODING.getName(), "", null, fEncodingEditorParent); //$NON-NLS-1$

    final PreferenceStore store = new PreferenceStore();
    // String defaultEncoding= ResourcesPlugin.getEncoding();
    store.setDefault(PREF_SPELLING_USER_DICTIONARY_ENCODING.getName(), Charset.defaultCharset().name());
    final String encoding = this.getValue(PREF_SPELLING_USER_DICTIONARY_ENCODING);
    if ((encoding != null) && (encoding.length() > 0)) {
        store.setValue(PREF_SPELLING_USER_DICTIONARY_ENCODING.getName(), encoding);
    }

    // fEncodingEditor.setPreferenceStore(store);

    // Redirect status messages from the field editor to the status change
    // listener
    final DialogPage fakePage = new DialogPage() {
        public void createControl(Composite c) {
        }

        public void setErrorMessage(String newMessage) {
            final StatusInfo status = new StatusInfo();
            if (newMessage != null) {
                status.setError(newMessage);
            }
            SpellingConfigurationBlock.this.fEncodingFieldEditorStatus = status;
            SpellingConfigurationBlock.this.fContext.statusChanged(
                    StatusUtil.getMostSevere(new IStatus[] { SpellingConfigurationBlock.this.fThresholdStatus,
                            SpellingConfigurationBlock.this.fFileStatus,
                            SpellingConfigurationBlock.this.fEncodingFieldEditorStatus }));
        }
    };
    // fEncodingEditor.setPage(fakePage);
    //      
    // fEncodingEditor.load();
    //      
    // if (encoding == null || encoding.equals(defaultEncoding) ||
    // encoding.length() == 0)
    // fEncodingEditor.loadDefault();

}

From source file:eclipse.spellchecker.preferences.SpellingConfigurationBlock.java

License:Open Source License

/**
 * Creates the encoding field editor.//from   w ww .  ja va2 s.c o m
 *
 * @param composite the parent composite
 * @param allControls list with all controls
 * @since 3.3
 */
private void createEncodingFieldEditor(Composite composite, List<Control> allControls) {
    Label filler = new Label(composite, SWT.NONE);
    GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gd.horizontalSpan = 4;
    filler.setLayoutData(gd);

    Label label = new Label(composite, SWT.NONE);
    label.setText(PreferencesMessages.SpellingPreferencePage_encoding_label);
    label.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    allControls.add(label);

    fEncodingEditorParent = new Composite(composite, SWT.NONE);
    GridLayout layout = new GridLayout(2, false);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    fEncodingEditorParent.setLayout(layout);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gd.horizontalSpan = 3;
    fEncodingEditorParent.setLayoutData(gd);

    fEncodingEditor = new EncodingFieldEditor(PREF_SPELLING_USER_DICTIONARY_ENCODING.getName(), "", null, //$NON-NLS-1$
            fEncodingEditorParent);

    PreferenceStore store = new PreferenceStore();
    String defaultEncoding = ResourcesPlugin.getEncoding();
    store.setDefault(PREF_SPELLING_USER_DICTIONARY_ENCODING.getName(), defaultEncoding);
    String encoding = getValue(PREF_SPELLING_USER_DICTIONARY_ENCODING);
    if (encoding != null && encoding.length() > 0)
        store.setValue(PREF_SPELLING_USER_DICTIONARY_ENCODING.getName(), encoding);

    fEncodingEditor.setPreferenceStore(store);

    // Redirect status messages from the field editor to the status change listener
    DialogPage fakePage = new DialogPage() {
        public void createControl(Composite c) {
        }

        @Override
        public void setErrorMessage(String newMessage) {
            StatusInfo status = new StatusInfo();
            if (newMessage != null)
                status.setError(newMessage);
            fEncodingFieldEditorStatus = status;
            fContext.statusChanged(StatusUtil.getMostSevere(
                    new IStatus[] { fThresholdStatus, fFileStatus, fEncodingFieldEditorStatus }));
        }
    };
    fEncodingEditor.setPage(fakePage);

    fEncodingEditor.load();

    if (encoding == null || encoding.equals(defaultEncoding) || encoding.length() == 0)
        fEncodingEditor.loadDefault();

}

From source file:mpj_express_debugger.JavaMPJConnectTab.java

License:Open Source License

/**
 * Update the argument area to show the selected connector's arguments
 *//*from   ww w  .ja v a  2 s  .c  o  m*/
private void handleConnectorComboModified() {
    int index = fConnectorCombo.getSelectionIndex();
    if ((index < 0) || (index >= fConnectors.length)) {
        return;
    }
    IVMConnector vm = fConnectors[index];
    if (vm.equals(fConnector)) {
        return; // selection did not change
    }
    fConnector = vm;
    try {
        fArgumentMap = vm.getDefaultArguments();
    } catch (CoreException e) {
        JDIDebugUIPlugin.statusDialog(LauncherMessages.JavaConnectTab_Unable_to_display_connection_arguments__2,
                e.getStatus());
        return;
    }

    // Dispose of any current child widgets in the tab holder area
    Control[] children = fArgumentComposite.getChildren();
    for (int i = 0; i < children.length; i++) {
        children[i].dispose();
    }
    fFieldEditorMap.clear();
    PreferenceStore store = new PreferenceStore();
    // create editors
    Iterator keys = vm.getArgumentOrder().iterator();
    while (keys.hasNext()) {
        String key = (String) keys.next();
        Connector.Argument arg = (Connector.Argument) fArgumentMap.get(key);
        FieldEditor field = null;
        if (arg instanceof Connector.IntegerArgument) {
            store.setDefault(arg.name(), ((Connector.IntegerArgument) arg).intValue());
            field = new IntegerFieldEditor(arg.name(), arg.label(), fArgumentComposite);
        } else if (arg instanceof Connector.SelectedArgument) {
            List choices = ((Connector.SelectedArgument) arg).choices();
            String[][] namesAndValues = new String[choices.size()][2];
            Iterator iter = choices.iterator();
            int count = 0;
            while (iter.hasNext()) {
                String choice = (String) iter.next();
                namesAndValues[count][0] = choice;
                namesAndValues[count][1] = choice;
                count++;
            }
            store.setDefault(arg.name(), arg.value());
            field = new ComboFieldEditor(arg.name(), arg.label(), namesAndValues, fArgumentComposite);
        } else if (arg instanceof Connector.StringArgument) {
            store.setDefault(arg.name(), arg.value());
            field = new StringFieldEditor(arg.name(), arg.label(), fArgumentComposite);
        } else if (arg instanceof Connector.BooleanArgument) {
            store.setDefault(arg.name(), ((Connector.BooleanArgument) arg).booleanValue());
            field = new BooleanFieldEditor(arg.name(), arg.label(), fArgumentComposite);
        }
        if (field != null) {
            field.setPreferenceStore(store);
            field.loadDefault();
            field.setPropertyChangeListener(this);
            fFieldEditorMap.put(key, field);
        }
    }
    fArgumentComposite.getParent().getParent().layout();
    fArgumentComposite.layout(true);
    updateLaunchConfigurationDialog();
}

From source file:net.certiv.fluentmark.spell.SpellingConfigurationBlock.java

License:Open Source License

/**
 * Creates the encoding field editor.//from  ww w. java  2s  .  c  o  m
 *
 * @param composite the parent composite
 * @param string list with all controls
 */
private void encodingControl(Composite composite, String text) {

    Label label = new Label(composite, SWT.NONE);
    label.setText(text);
    label.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));

    fEncodingEditorParent = new Composite(composite, SWT.NONE);
    GridLayout layout = new GridLayout(2, false);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    fEncodingEditorParent.setLayout(layout);
    GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gd.horizontalSpan = 3;
    gd.horizontalIndent += SwtUtil.getIndent();
    fEncodingEditorParent.setLayoutData(gd);

    encEditor = new EncodingFieldEditor(SPELLING_USER_DICTIONARY_ENCODING, "", null, fEncodingEditorParent); //$NON-NLS-1$

    PreferenceStore store = new PreferenceStore();
    String defaultEncoding = ResourcesPlugin.getEncoding();
    store.setDefault(SPELLING_USER_DICTIONARY_ENCODING, defaultEncoding);
    String encoding = store.getString(SPELLING_USER_DICTIONARY_ENCODING);
    if (encoding != null && encoding.length() > 0)
        store.setValue(SPELLING_USER_DICTIONARY_ENCODING, encoding);

    encEditor.setPreferenceStore(store);

    // Redirect status messages from the field editor to the status change listener
    DialogPage fakePage = new DialogPage() {

        @Override
        public void createControl(Composite c) {
        }

        @Override
        public void setErrorMessage(String newMessage) {
            StatusInfo status = new StatusInfo();
            if (newMessage != null)
                status.setError(newMessage);
            fEncodingFieldEditorStatus = status;
            fContext.statusChanged(StatusUtil.getMostSevere(
                    new IStatus[] { fThresholdStatus, fFileStatus, fEncodingFieldEditorStatus }));
        }
    };
    encEditor.setPage(fakePage);
    encEditor.load();
    if (encoding == null || encoding.equals(defaultEncoding) || encoding.length() == 0) {
        encEditor.loadDefault();
    }
}

From source file:net.sourceforge.eclipsetrader.core.CorePlugin.java

License:Open Source License

/**
 * Log4j configurator/* w ww  .ja  va2 s .  co  m*/
 */
public void configureLogging() {
    try {
        PreferenceStore preferences = new PreferenceStore();

        // Set the default values from extension registry
        IExtensionRegistry registry = Platform.getExtensionRegistry();
        IExtensionPoint extensionPoint = registry
                .getExtensionPoint(CorePlugin.LOGGER_PREFERENCES_EXTENSION_POINT);
        IConfigurationElement[] members = extensionPoint.getConfigurationElements();
        for (int i = 0; i < members.length; i++) {
            IConfigurationElement element = members[i];
            if (element.getName().equals("logger")) //$NON-NLS-1$
            {
                if (element.getAttribute("defaultValue") != null) //$NON-NLS-1$
                {
                    String[] item = element.getAttribute("name").split(";"); //$NON-NLS-1$ //$NON-NLS-2$
                    for (int x = 0; x < item.length; x++)
                        preferences.setDefault("log4j.logger." + item[x], element.getAttribute("defaultValue")); //$NON-NLS-1$ //$NON-NLS-2$
                }
            }
        }

        // Set the default values from the bundle's properties file
        try {
            URL url = CorePlugin.getDefault().getBundle().getResource("log4j.properties"); //$NON-NLS-1$
            Properties properties = new Properties();
            properties.load(url.openStream());
            for (Iterator iter = properties.keySet().iterator(); iter.hasNext();) {
                String key = (String) iter.next();
                preferences.setDefault(key, (String) properties.get(key));
            }

            // Read the values from the user's configuration
            File file = CorePlugin.getDefault().getStateLocation().append("log4j.properties").toFile(); //$NON-NLS-1$
            if (file.exists())
                preferences.load(new FileInputStream(file));
        } catch (Exception e) {
            CorePlugin.logException(e);
        }

        // Configure log4j
        Properties properties = new Properties();
        String[] names = preferences.preferenceNames();
        for (int i = 0; i < names.length; i++)
            properties.put(names[i], preferences.getString(names[i]));
        PropertyConfigurator.configure(properties);
    } catch (Exception e) {
        BasicConfigurator.configure();
        logException(e);
    }
}

From source file:net.sourceforge.eclipsetrader.trading.internal.WatchlistTableViewer.java

License:Open Source License

public void updateView() {
    int index;// w  ww .j  a v  a 2 s  .  c om
    TableColumn tableColumn;

    String[] items = getView().getPreferenceStore().getString(WatchlistView.PREFS_SORTING).split(";");
    if (items.length != 2)
        items = new String[] { "", "0" };
    sortDirection = new Integer(items[1]).intValue();

    index = 1;
    for (Iterator iter = getView().getWatchlist().getColumns().iterator(); iter.hasNext();) {
        WatchlistColumn column = (WatchlistColumn) iter.next();
        String name = "";
        int style = SWT.LEFT;
        Image image = null;

        ILabelProvider provider = ColumnRegistry.createLabelProvider(column.getId());
        if (provider != null) {
            LogFactory.getLog(getClass()).debug("Adding column [" + column.getId() + "]");
            name = ColumnRegistry.getName(column.getId());
            style = ColumnRegistry.getOrientation(column.getId());

            if (provider instanceof ITableLabelProvider) {
                name = ((ITableLabelProvider) provider).getColumnText(getView().getWatchlist(), index);
                image = ((ITableLabelProvider) provider).getColumnImage(getView().getWatchlist(), index);
            }
        } else
            LogFactory.getLog(getClass()).warn("Missing column [" + column.getId() + "]");

        if (index < table.getColumnCount()) {
            tableColumn = table.getColumn(index);
            tableColumn.setAlignment(style);
            if (tableColumn.getData("labelProvider") != null)
                ((ILabelProvider) tableColumn.getData("labelProvider")).dispose();
        } else {
            tableColumn = new EditableTableColumn(table, style);
            tableColumn.addControlListener(columnControlListener);
            tableColumn.addDisposeListener(new DisposeListener() {
                public void widgetDisposed(DisposeEvent e) {
                    if (e.widget.getData("labelProvider") != null)
                        ((ILabelProvider) e.widget.getData("labelProvider")).dispose();
                }
            });
            tableColumn.addSelectionListener(columnSelectionListener);
        }
        tableColumn.setText(name);
        tableColumn.setImage(image);
        tableColumn.setData(column);
        tableColumn.setData("labelProvider", provider);

        if (column.getId().equals(items[0]))
            sortColumn = index;

        index++;
    }

    while (index < table.getColumnCount())
        table.getColumn(index).dispose();

    list = new ArrayList(getView().getWatchlist().getItems());
    if (sortColumn >= 1 && sortColumn < table.getColumnCount()) {
        table.setSortColumn(table.getColumn(sortColumn));
        table.setSortDirection(sortDirection == 0 ? SWT.UP : SWT.DOWN);
        Collections.sort(list, comparator);
    } else {
        table.setSortColumn(null);
        sortColumn = -1;
        sortDirection = 0;
    }

    updateTableContents();

    PreferenceStore preferences = getView().getPreferenceStore();
    for (int i = 1; i < table.getColumnCount(); i++) {
        WatchlistColumn column = (WatchlistColumn) table.getColumn(i).getData();
        preferences.setDefault(column.getId() + ".width", -1);
        int size = preferences.getInt(column.getId() + ".width");
        if (size != -1)
            table.getColumn(i).setWidth(size);
        else
            table.getColumn(i).pack();
    }
    if ("gtk".equals(SWT.getPlatform()))
        table.getColumn(table.getColumnCount() - 1).pack();
}

From source file:org.bc.eclipse.hadoop.debug.JavaRetryConnectTab.java

License:Open Source License

/**
 * Update the argument area to show the selected connector's arguments
 *///from w w  w .j  a v a 2s  .  co  m
private void handleConnectorComboModified() {
    int index = fConnectorCombo.getSelectionIndex();
    if ((index < 0) || (index >= fConnectors.length)) {
        return;
    }
    IVMConnector vm = fConnectors[index];
    if (vm.equals(fConnector)) {
        return; // selection did not change
    }
    fConnector = vm;
    try {
        fArgumentMap = vm.getDefaultArguments();
    } catch (CoreException e) {
        JDIDebugUIPlugin.statusDialog(LauncherMessages.JavaConnectTab_Unable_to_display_connection_arguments__2,
                e.getStatus());
        return;
    }

    // Dispose of any current child widgets in the tab holder area
    Control[] children = fArgumentComposite.getChildren();
    for (int i = 0; i < children.length; i++) {
        children[i].dispose();
    }
    fFieldEditorMap.clear();
    PreferenceStore store = new PreferenceStore();
    // create editors
    Iterator<String> keys = vm.getArgumentOrder().iterator();
    while (keys.hasNext()) {
        String key = keys.next();
        Connector.Argument arg = fArgumentMap.get(key);
        FieldEditor field = null;
        if (arg instanceof Connector.IntegerArgument) {
            store.setDefault(arg.name(), ((Connector.IntegerArgument) arg).intValue());
            field = new IntegerFieldEditor(arg.name(), arg.label(), fArgumentComposite);
        } else if (arg instanceof Connector.SelectedArgument) {
            List<String> choices = ((Connector.SelectedArgument) arg).choices();
            String[][] namesAndValues = new String[choices.size()][2];
            Iterator<String> iter = choices.iterator();
            int count = 0;
            while (iter.hasNext()) {
                String choice = iter.next();
                namesAndValues[count][0] = choice;
                namesAndValues[count][1] = choice;
                count++;
            }
            store.setDefault(arg.name(), arg.value());
            field = new ComboFieldEditor(arg.name(), arg.label(), namesAndValues, fArgumentComposite);
        } else if (arg instanceof Connector.StringArgument) {
            store.setDefault(arg.name(), arg.value());
            field = new StringFieldEditor(arg.name(), arg.label(), fArgumentComposite);
        } else if (arg instanceof Connector.BooleanArgument) {
            store.setDefault(arg.name(), ((Connector.BooleanArgument) arg).booleanValue());
            field = new BooleanFieldEditor(arg.name(), arg.label(), fArgumentComposite);
        }
        if (field != null) {
            field.setPreferenceStore(store);
            field.loadDefault();
            field.setPropertyChangeListener(this);
            fFieldEditorMap.put(key, field);
        }
    }
    fArgumentComposite.getParent().getParent().layout();
    fArgumentComposite.layout(true);
    updateLaunchConfigurationDialog();
}

From source file:org.eclipse.cdt.debug.internal.ui.preferences.CDebugPreferencePage.java

License:Open Source License

/**
 * Set the values of the component widgets based on the values in the preference store
 *///from w  ww .  ja va 2s. c o m
private void setValues() {
    // Set the number format combo boxes.
    fVariableFormatCombo
            .select(getFormatIndex(Platform.getPreferencesService().getInt(CDebugCorePlugin.PLUGIN_ID,
                    ICDebugConstants.PREF_DEFAULT_VARIABLE_FORMAT, ICDIFormat.NATURAL, null)));
    fExpressionFormatCombo
            .select(getFormatIndex(Platform.getPreferencesService().getInt(CDebugCorePlugin.PLUGIN_ID,
                    ICDebugConstants.PREF_DEFAULT_EXPRESSION_FORMAT, ICDIFormat.NATURAL, null)));
    fRegisterFormatCombo
            .select(getFormatIndex(Platform.getPreferencesService().getInt(CDebugCorePlugin.PLUGIN_ID,
                    ICDebugConstants.PREF_DEFAULT_REGISTER_FORMAT, ICDIFormat.NATURAL, null)));

    // Set the charset editors.

    // Create a temporary preference store.
    PreferenceStore ps = new PreferenceStore();

    // Get the default charset and the default wide charset.
    String defaultCharset = DefaultScope.INSTANCE.getNode(CDebugCorePlugin.PLUGIN_ID)
            .get(ICDebugConstants.PREF_DEBUG_CHARSET, null);
    if (defaultCharset != null) {
        ps.setDefault(ICDebugConstants.PREF_DEBUG_CHARSET, defaultCharset);
    }
    String defaultWideCharset = DefaultScope.INSTANCE.getNode(CDebugCorePlugin.PLUGIN_ID)
            .get(ICDebugConstants.PREF_DEBUG_WIDE_CHARSET, null);
    if (defaultWideCharset != null) {
        ps.setDefault(ICDebugConstants.PREF_DEBUG_WIDE_CHARSET, defaultWideCharset);
    }

    // Get the charset and the wide charset. If they're unset, use the default instead.
    // Note that we have to call the setValue() function of the PreferenceStore even if we
    // want to use the default. This is to ensure proper display of the encoding field editor.
    String charset = InstanceScope.INSTANCE.getNode(CDebugCorePlugin.PLUGIN_ID)
            .get(ICDebugConstants.PREF_DEBUG_CHARSET, null);
    if (charset != null) {
        ps.setValue(ICDebugConstants.PREF_DEBUG_CHARSET, charset);
    } else if (defaultCharset != null) {
        ps.setValue(ICDebugConstants.PREF_DEBUG_CHARSET, defaultCharset);
    }
    String wideCharset = InstanceScope.INSTANCE.getNode(CDebugCorePlugin.PLUGIN_ID)
            .get(ICDebugConstants.PREF_DEBUG_WIDE_CHARSET, null);
    if (wideCharset != null) {
        ps.setValue(ICDebugConstants.PREF_DEBUG_WIDE_CHARSET, wideCharset);
    } else if (defaultWideCharset != null) {
        ps.setValue(ICDebugConstants.PREF_DEBUG_WIDE_CHARSET, defaultWideCharset);
    }

    // Initialize the encoding field editors with the values from the preference store.
    fCharsetEditor.setPreferenceStore(ps);
    fCharsetEditor.load();
    fWideCharsetEditor.setPreferenceStore(ps);
    fWideCharsetEditor.load();

    // Tell the encoding field editors to check the "Default" option if we're currently using the default values.
    if (charset == null) {
        fCharsetEditor.loadDefault();
    }
    if (wideCharset == null) {
        fWideCharsetEditor.loadDefault();
    }

    // Set the values for the remaining preferences.
    fShowBinarySourceFilesButton.setSelection(Platform.getPreferencesService().getBoolean(CCorePlugin.PLUGIN_ID,
            CCorePreferenceConstants.SHOW_SOURCE_FILES_IN_BINARIES, true, null));
}

From source file:org.eclipse.cdt.internal.ui.preferences.SpellingConfigurationBlock.java

License:Open Source License

/**
 * Creates the encoding field editor./*from w ww.  j  a v a2s . c o  m*/
 * 
 * @param composite the parent composite
 * @param allControls list with all controls
 */
private void createEncodingFieldEditor(Composite composite, List<Control> allControls) {
    Label filler = new Label(composite, SWT.NONE);
    GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gd.horizontalSpan = 4;
    filler.setLayoutData(gd);

    Label label = new Label(composite, SWT.NONE);
    label.setText(PreferencesMessages.SpellingPreferencePage_encoding_label);
    label.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    allControls.add(label);

    fEncodingEditorParent = new Composite(composite, SWT.NONE);
    GridLayout layout = new GridLayout(2, false);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    fEncodingEditorParent.setLayout(layout);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gd.horizontalSpan = 3;
    fEncodingEditorParent.setLayoutData(gd);

    fEncodingEditor = new EncodingFieldEditor(PREF_SPELLING_USER_DICTIONARY_ENCODING.getName(), "", null, //$NON-NLS-1$
            fEncodingEditorParent);

    PreferenceStore store = new PreferenceStore();
    String defaultEncoding = ResourcesPlugin.getEncoding();
    store.setDefault(PREF_SPELLING_USER_DICTIONARY_ENCODING.getName(), defaultEncoding);
    String encoding = getValue(PREF_SPELLING_USER_DICTIONARY_ENCODING);
    if (encoding != null && encoding.length() > 0)
        store.setValue(PREF_SPELLING_USER_DICTIONARY_ENCODING.getName(), encoding);

    fEncodingEditor.setPreferenceStore(store);

    // Redirect status messages from the field editor to the status change listener  
    DialogPage fakePage = new DialogPage() {
        @Override
        public void createControl(Composite c) {
        }

        @Override
        public void setErrorMessage(String newMessage) {
            StatusInfo status = new StatusInfo();
            if (newMessage != null)
                status.setError(newMessage);
            fEncodingFieldEditorStatus = status;
            fContext.statusChanged(StatusUtil.getMostSevere(
                    new IStatus[] { fThresholdStatus, fFileStatus, fEncodingFieldEditorStatus }));
        }
    };
    fEncodingEditor.setPage(fakePage);

    fEncodingEditor.load();

    if (encoding == null || encoding.equals(defaultEncoding) || encoding.length() == 0)
        fEncodingEditor.loadDefault();
}