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

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

Introduction

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

Prototype

public PreferenceStore() 

Source Link

Document

Creates an empty preference store.

Usage

From source file:org.eclipse.ui.texteditor.ChangeEncodingAction.java

License:Open Source License

public void run() {
    final IResource resource = getResource();
    final Shell parentShell = getTextEditor().getSite().getShell();
    final IEncodingSupport encodingSupport = getEncodingSupport();
    if (resource == null && encodingSupport == null) {
        MessageDialog.openInformation(parentShell, fDialogTitle,
                TextEditorMessages.ChangeEncodingAction_message_noEncodingSupport);
        return;//w  ww .  jav  a  2 s  .  c om
    }

    Dialog dialog = new Dialog(parentShell) {
        private AbstractEncodingFieldEditor fEncodingEditor;
        private IPreferenceStore store = null;

        /*
         * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
         */
        protected void configureShell(Shell newShell) {
            super.configureShell(newShell);
            newShell.setText(fDialogTitle);
        }

        /*
         * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
         */
        protected Control createDialogArea(Composite parent) {
            Composite composite = (Composite) super.createDialogArea(parent);

            composite = new Composite(composite, SWT.NONE);
            GridLayout layout = new GridLayout();
            layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
            layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
            layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
            layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
            composite.setLayout(layout);

            GridData data = new GridData(GridData.FILL_BOTH);
            composite.setLayoutData(data);
            composite.setFont(parent.getFont());

            DialogPage page = new MessageDialogPage(composite) {
                public void setErrorMessage(String newMessage) {
                    super.setErrorMessage(newMessage);
                    setButtonEnabledState(IDialogConstants.OK_ID, newMessage == null);
                    setButtonEnabledState(APPLY_ID, newMessage == null);
                }

                private void setButtonEnabledState(int id, boolean state) {
                    Button button = getButton(id);
                    if (button != null)
                        button.setEnabled(state);
                }
            };

            if (resource != null) {
                fEncodingEditor = new ResourceEncodingFieldEditor("", composite, resource, null); //$NON-NLS-1$
                fEncodingEditor.setPage(page);
                fEncodingEditor.load();
            } else {
                fEncodingEditor = new EncodingFieldEditor(ENCODING_PREF_KEY, "", null, composite); //$NON-NLS-1$
                store = new PreferenceStore();
                String defaultEncoding = encodingSupport.getDefaultEncoding();
                store.setDefault(ENCODING_PREF_KEY, defaultEncoding);
                String encoding = encodingSupport.getEncoding();
                if (encoding != null)
                    store.setValue(ENCODING_PREF_KEY, encoding);
                fEncodingEditor.setPreferenceStore(store);

                fEncodingEditor.setPage(page);
                fEncodingEditor.load();

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

            return composite;
        }

        /*
         * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
         */
        protected void createButtonsForButtonBar(Composite parent) {
            createButton(parent, APPLY_ID, TextEditorMessages.ChangeEncodingAction_button_apply_label, false);
            super.createButtonsForButtonBar(parent);
        }

        /*
         * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
         */
        protected void buttonPressed(int buttonId) {
            if (buttonId == APPLY_ID)
                apply();
            else
                super.buttonPressed(buttonId);
        }

        /*
         * @see org.eclipse.jface.dialogs.Dialog#okPressed()
         */
        protected void okPressed() {
            apply();
            super.okPressed();
        }

        private void apply() {
            fEncodingEditor.store();

            if (resource == null) {
                String encoding = fEncodingEditor.getPreferenceStore()
                        .getString(fEncodingEditor.getPreferenceName());
                encodingSupport.setEncoding(encoding);
            }
        }
    };
    dialog.open();
}

From source file:org.eclipse.vjet.eclipse.internal.ui.preferences.formatting.JavaPreview.java

License:Open Source License

/**
 * Create a new Java preview/*from  w w  w. ja va 2s .  c  o  m*/
 * @param workingValues
 * @param parent
 */
public JavaPreview(Map workingValues, Composite parent) {
    VjoTextTools tools = VjetUIPlugin.getDefault().getTextTools();
    fPreviewDocument = new Document();
    fWorkingValues = workingValues;
    tools.setupDocumentPartitioner(fPreviewDocument, IJavaScriptPartitions.JAVA_PARTITIONING);

    PreferenceStore prioritizedSettings = new PreferenceStore();
    prioritizedSettings.setValue(VjetPlugin.COMPILER_SOURCE, VjetPlugin.VERSION_1_5);
    prioritizedSettings.setValue(VjetPlugin.COMPILER_COMPLIANCE, VjetPlugin.VERSION_1_5);
    prioritizedSettings.setValue(VjetPlugin.COMPILER_CODEGEN_TARGET_PLATFORM, VjetPlugin.VERSION_1_5);
    prioritizedSettings.setValue(VjetPlugin.COMPILER_PB_ASSERT_IDENTIFIER, VjetPlugin.ERROR);

    IPreferenceStore[] chain = { prioritizedSettings, VjetUIPlugin.getDefault().getPreferenceStore(),
            EditorsUI.getPreferenceStore() };
    fPreferenceStore = new ChainedPreferenceStore(chain);
    fSourceViewer = new JavaSourceViewer(parent, null, null, false,
            SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER, fPreferenceStore);
    fViewerConfiguration = new SimpleJavascriptSourceViewerConfiguration(tools.getColorManager(),
            fPreferenceStore, null, IJavaScriptPartitions.JAVA_PARTITIONING, true);
    fSourceViewer.configure(fViewerConfiguration);
    fSourceViewer.getTextWidget().setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT));

    fMarginPainter = new MarginPainter(fSourceViewer);
    final RGB rgb = PreferenceConverter.getColor(fPreferenceStore,
            AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLOR);
    fMarginPainter.setMarginRulerColor(tools.getColorManager().getColor(rgb));
    fSourceViewer.addPainter(fMarginPainter);

    new JavaSourcePreviewerUpdater();
    fSourceViewer.setDocument(fPreviewDocument);
}

From source file:org.eclipse.wb.internal.core.model.generation.GenerationSettings.java

License:Open Source License

/**
 * Deduces code generation settings for this toolkit.
 *//*  www . j av a2s  .c  o  m*/
private void deduce(Set<AbstractComponentInfo> components) throws Exception {
    if (!m_store.getBoolean(P_DEDUCE_SETTINGS)) {
        return;
    }
    // use this JavaInfo
    JavaInfo javaInfo = components.iterator().next();
    // prepare preference store for editor level settings
    IPreferenceStore editorPreferences;
    {
        editorPreferences = new PreferenceStore();
        setPreferences(javaInfo,
                new ChainedPreferenceStore(new IPreferenceStore[] { editorPreferences, m_store }));
    }
    // do deduce
    deduceVariable(components, editorPreferences);
    deduceStatement(components, editorPreferences);
    // check that statement generator (deduced or default) is compatible with variable
    {
        VariableSupportDescription variableDescription = getVariable(javaInfo);
        StatementGeneratorDescription statementDescription = getStatement(javaInfo);
        StatementGeneratorDescription[] compatibleStatements = getStatements(variableDescription);
        if (!ArrayUtils.contains(compatibleStatements, statementDescription)) {
            editorPreferences.setValue(P_STATEMENT_GENERATOR_ID, compatibleStatements[0].getId());
        }
    }
}

From source file:org.eclipse.wst.jsdt.debug.internal.ui.launching.JavaScriptConnectTab.java

License:Open Source License

/**
 * Handles creating the UI for the connector selected
 *///from  w  w w.  j  av  a 2  s  .c om
void handleConnectorSelected() {
    Connector connect = getSelectedConnector();
    if (connect == null || connect.equals(this.selectedconnector)) {
        //nothing changed
        return;
    }
    this.selectedconnector = connect;
    String desc = this.selectedconnector.description();
    if (desc != null) {
        this.description.setText(desc);
    } else {
        this.description.setText(Messages.no_description_provided);
    }
    this.editormap.clear();
    //get rid of the old controls
    Control[] children = this.argumentsgroup.getChildren();
    for (int i = 0; i < children.length; i++) {
        children[i].dispose();
    }
    PreferenceStore store = new PreferenceStore();
    Entry entry = null;
    Argument argument = null;
    FieldEditor editor = null;
    String key = null;
    for (Iterator iter = this.selectedconnector.defaultArguments().entrySet().iterator(); iter.hasNext();) {
        entry = (Entry) iter.next();
        key = (String) entry.getKey();
        argument = (Argument) entry.getValue();
        if (argument instanceof IntegerArgument) {
            //create an int editor
            store.setDefault(argument.name(), ((IntegerArgument) argument).intValue());
            editor = new IntegerFieldEditor(argument.name(), argument.label(), this.argumentsgroup);
        } else if (argument instanceof BooleanArgument) {
            //create boolean editor
            store.setDefault(argument.name(), ((BooleanArgument) argument).booleanValue());
            editor = new BooleanFieldEditor(argument.name(), argument.label(), this.argumentsgroup);
            editor.fillIntoGrid(argumentsgroup, 2);
        } else if (argument instanceof StringArgument) {
            //create String editor
            store.setDefault(argument.name(), argument.value());
            editor = new StringFieldEditor(argument.name(), argument.label(), this.argumentsgroup);
        } else if (argument instanceof SelectedArgument) {
            //create list selection editor
            List choices = ((SelectedArgument) argument).choices();
            String[][] namesAndValues = new String[choices.size()][2];
            int count = 0;
            for (Iterator iter2 = choices.iterator(); iter2.hasNext();) {
                String choice = (String) iter2.next();
                namesAndValues[count][0] = choice;
                namesAndValues[count][1] = choice;
                count++;
            }
            store.setDefault(argument.name(), argument.value());
            editor = new ComboFieldEditor(argument.name(), argument.label(), namesAndValues,
                    this.argumentsgroup);
        }
        if (editor != null) {
            editor.setPreferenceStore(store);
            editor.loadDefault();
            editor.setPropertyChangeListener(this);
            this.editormap.put(key, editor);
            editor = null;
        }
    }
    //reset margins to undo FieldEditor bogosity
    GridLayout gd = (GridLayout) this.argumentsgroup.getLayout();
    gd.marginHeight = 5;
    gd.marginWidth = 5;
    this.argumentsgroup.getParent().layout(true);
    this.argumentsgroup.setVisible(true);
    this.argumentsgroup.layout(true);
    updateLaunchConfigurationDialog();
}

From source file:org.eclipse.wst.jsdt.internal.ui.preferences.formatter.JavaPreview.java

License:Open Source License

/**
 * Create a new Java preview//  ww w. ja va 2  s. com
 * @param workingValues
 * @param parent
 */
public JavaPreview(Map workingValues, Composite parent) {
    JavaScriptTextTools tools = JavaScriptPlugin.getDefault().getJavaTextTools();
    fPreviewDocument = new Document();
    fWorkingValues = workingValues;
    tools.setupJavaDocumentPartitioner(fPreviewDocument, IJavaScriptPartitions.JAVA_PARTITIONING);

    PreferenceStore prioritizedSettings = new PreferenceStore();
    prioritizedSettings.setValue(JavaScriptCore.COMPILER_SOURCE, JavaScriptCore.VERSION_1_5);
    prioritizedSettings.setValue(JavaScriptCore.COMPILER_COMPLIANCE, JavaScriptCore.VERSION_1_5);
    prioritizedSettings.setValue(JavaScriptCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaScriptCore.VERSION_1_5);
    prioritizedSettings.setValue(JavaScriptCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaScriptCore.ERROR);

    IPreferenceStore[] chain = { prioritizedSettings,
            JavaScriptPlugin.getDefault().getCombinedPreferenceStore() };
    fPreferenceStore = new ChainedPreferenceStore(chain);
    fSourceViewer = new JavaSourceViewer(parent, null, null, false,
            SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER, fPreferenceStore);
    fViewerConfiguration = new SimpleJavaSourceViewerConfiguration(tools.getColorManager(), fPreferenceStore,
            null, IJavaScriptPartitions.JAVA_PARTITIONING, true);
    fSourceViewer.configure(fViewerConfiguration);
    fSourceViewer.getTextWidget().setFont(JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT));

    fMarginPainter = new MarginPainter(fSourceViewer);
    final RGB rgb = PreferenceConverter.getColor(fPreferenceStore,
            AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLOR);
    fMarginPainter.setMarginRulerColor(tools.getColorManager().getColor(rgb));
    fSourceViewer.addPainter(fMarginPainter);

    new JavaSourcePreviewerUpdater();
    fSourceViewer.setDocument(fPreviewDocument);
}

From source file:org.eclipsetrader.ui.internal.charts.DataImportJobTest.java

License:Open Source License

public void testGetDefaultYearsStartDate() throws Exception {
    PreferenceStore preferences = new PreferenceStore();
    preferences.setValue(UIActivator.PREFS_INITIAL_BACKFILL_METHOD, 1);
    preferences.setValue(UIActivator.PREFS_INITIAL_BACKFILL_YEARS, 5);

    Calendar c = Calendar.getInstance();
    c.set(Calendar.MILLISECOND, 0);
    c.add(Calendar.YEAR, -preferences.getInt(UIActivator.PREFS_INITIAL_BACKFILL_YEARS));

    DataImportJob job = new DataImportJob(new Security("Test", null), 0, null, null, null);
    job.preferences = preferences;/*from  w ww  . jav  a2  s.co  m*/

    assertEquals(c.getTime(), job.getDefaultStartDate());
}

From source file:org.eclipsetrader.ui.internal.charts.DataImportJobTest.java

License:Open Source License

public void testGetDefaultStartDate() throws Exception {
    PreferenceStore preferences = new PreferenceStore();
    preferences.setValue(UIActivator.PREFS_INITIAL_BACKFILL_METHOD, 0);
    preferences.setValue(UIActivator.PREFS_INITIAL_BACKFILL_START_DATE, "20010512");

    Date expectedDate = new SimpleDateFormat("yyyyMMdd")
            .parse(preferences.getString(UIActivator.PREFS_INITIAL_BACKFILL_START_DATE));

    DataImportJob job = new DataImportJob(new Security("Test", null), 0, null, null, null);
    job.preferences = preferences;//from  ww  w.  ja v  a2  s  . c om

    assertEquals(expectedDate, job.getDefaultStartDate());
}

From source file:org.eclipsetrader.ui.internal.charts.DefaultsPageTest.java

License:Open Source License

public void testDefaultBackfillMethodSelection() throws Exception {
    PreferenceStore preferences = new PreferenceStore();

    DefaultsPage page = new DefaultsPage();
    page.setPreferenceStore(preferences);
    page.createContents(shell);//from w ww  . jav a  2s .  c  om

    page.performDefaults();

    assertTrue(page.useStartDate.getSelection());
    assertFalse(page.useYears.getSelection());
}

From source file:org.eclipsetrader.ui.internal.charts.DefaultsPageTest.java

License:Open Source License

public void testDefaultStartDateSelection() throws Exception {
    PreferenceStore preferences = new PreferenceStore();

    DefaultsPage page = new DefaultsPage();
    page.setPreferenceStore(preferences);
    page.createContents(shell);// w w  w  .  j  av  a  2 s. c  o  m

    page.performDefaults();

    assertNull(page.startDate.getSelection());
}

From source file:org.eclipsetrader.ui.internal.charts.DefaultsPageTest.java

License:Open Source License

public void testDefaultYearsSelection() throws Exception {
    PreferenceStore preferences = new PreferenceStore();

    DefaultsPage page = new DefaultsPage();
    page.setPreferenceStore(preferences);
    page.createContents(shell);//from   ww w.  j  a va 2s.c om

    page.performDefaults();

    assertEquals(1, page.years.getSelection());
}