List of usage examples for org.eclipse.jface.preference PreferenceStore setValue
@Override public void setValue(String name, boolean value)
From source file:com.android.sdkstats.SdkStatsService.java
License:Apache License
/** * Send a "ping" to the Google toolbar server, if enough time has * elapsed since the last ping, and if the user has not opted out. * If this is the first time, notify the user and offer an opt-out. * Note: UI operations (if any) are synchronous, but the actual ping * (if any) is sent in a <i>non-daemon</i> background thread. * * @param app name to report in the ping * @param version to report in the ping//from w w w . jav a 2s . c o m * @param display an optional {@link Display} object to use, or null, if a new one should be * created. */ public static void ping(final String app, final String version, final Display display) { // Unique, randomly assigned ID for this installation. PreferenceStore prefs = getPreferenceStore(); if (prefs != null) { if (prefs.contains(PING_ID) == false) { // First time: make up a new ID. TODO: Use something more random? prefs.setValue(PING_ID, new Random().nextLong()); // ask the user whether he/she wants to opt-out. // This will call doPing in the Display thread after the dialog closes. getUserPermissionAndPing(app, version, prefs, display); } else { doPing(app, version, prefs); } } }
From source file:com.android.sdkstats.SdkStatsService.java
License:Apache License
/** * Pings the usage stats server, as long as the prefs contain the opt-in boolean * @param app name to report in the ping * @param version to report in the ping/*from w ww .j a v a 2 s . c o m*/ * @param prefs the preference store where the opt-in value and ping times are store */ private static void doPing(final String app, String version, PreferenceStore prefs) { // Validate the application and version input. final String normalVersion = normalizeVersion(app, version); // If the user has not opted in, do nothing and quietly return. if (!prefs.getBoolean(PING_OPT_IN)) { // user opted out. return; } // If the last ping *for this app* was too recent, do nothing. String timePref = PING_TIME + "." + app; //$NON-NLS-1$ long now = System.currentTimeMillis(); long then = prefs.getLong(timePref); if (now - then < PING_INTERVAL_MSEC) { // too soon after a ping. return; } // Record the time of the attempt, whether or not it succeeds. prefs.setValue(timePref, now); try { prefs.save(); } catch (IOException ioe) { } // Send the ping itself in the background (don't block if the // network is down or slow or confused). final long id = prefs.getLong(PING_ID); new Thread() { @Override public void run() { try { actuallySendPing(app, normalVersion, id); } catch (IOException e) { e.printStackTrace(); } } }.start(); }
From source file:com.android.sdkstats.SdkStatsService.java
License:Apache License
/** * Prompt the user for whether they want to opt out of reporting, and then calls * {@link #doPing(String, String, PreferenceStore)} *///from w ww .j a va2 s . com private static void getUserPermissionAndPing(final String app, final String version, final PreferenceStore prefs, Display display) { boolean dispose = false; if (display == null) { display = new Display(); dispose = true; } final Display currentDisplay = display; final boolean disposeDisplay = dispose; display.asyncExec(new Runnable() { public void run() { // Whether the user gave permission (size-1 array for writing to). // Initialize to false, set when the user clicks the button. final boolean[] permission = new boolean[] { false }; final Shell shell = new Shell(currentDisplay, SWT.TITLE | SWT.BORDER); shell.setText(WINDOW_TITLE_TEXT); shell.setLayout(new GridLayout(1, false)); // 1 column // Take the default font and scale it up for the title. final Label title = new Label(shell, SWT.CENTER | SWT.WRAP); final FontData[] fontdata = title.getFont().getFontData(); for (int i = 0; i < fontdata.length; i++) { fontdata[i].setHeight(fontdata[i].getHeight() * 4 / 3); } title.setFont(new Font(currentDisplay, fontdata)); title.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); title.setText(HEADER_TEXT); final Label notice = new Label(shell, SWT.WRAP); notice.setFont(title.getFont()); notice.setForeground(new Color(currentDisplay, 255, 0, 0)); notice.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); notice.setText(NOTICE_TEXT); final Link text = new Link(shell, SWT.WRAP); text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); text.setText(BODY_TEXT); text.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { openUrl(event.text); } }); final Button checkbox = new Button(shell, SWT.CHECK); checkbox.setSelection(true); // Opt-in by default. checkbox.setText(CHECKBOX_TEXT); final Link footer = new Link(shell, SWT.WRAP); footer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); footer.setText(FOOTER_TEXT); final Button button = new Button(shell, SWT.PUSH); button.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER)); button.setText(BUTTON_TEXT); button.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { permission[0] = checkbox.getSelection(); shell.close(); } }); // Size the window to a fixed width, as high as necessary, // centered. final Point size = shell.computeSize(450, SWT.DEFAULT, true); final Rectangle screen = currentDisplay.getClientArea(); shell.setBounds(screen.x + screen.width / 2 - size.x / 2, screen.y + screen.height / 2 - size.y / 2, size.x, size.y); shell.open(); while (!shell.isDisposed()) { if (!currentDisplay.readAndDispatch()) currentDisplay.sleep(); } // the dialog has closed, take care of storing the user preference // and do the ping (in a different thread) prefs.setValue(PING_OPT_IN, permission[0]); try { prefs.save(); doPing(app, version, prefs); } catch (IOException ioe) { } if (disposeDisplay) { currentDisplay.dispose(); } } }); }
From source file:com.aptana.internal.ui.text.spelling.SpellingConfigurationBlock.java
License:Open Source License
/** * Creates the encoding field editor.//from ww w .ja v a 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:com.mindquarry.desktop.preferences.pages.ProxySettingsPage.java
License:Open Source License
@Override public boolean performOk() { PreferenceStore store = (PreferenceStore) getPreferenceStore(); if (enableProxy != null) { store.setValue(PREF_PROXY_ENABLED, enableProxy.getSelection()); store.setValue(PREF_PROXY_LOGIN, login.getText()); store.setValue(PREF_PROXY_PASSWORD, pwd.getText()); store.setValue(PREF_PROXY_URL, url.getText()); EventBus.send(new ProxySettingsChangedEvent(this, enableProxy.getSelection(), url.getText(), pwd.getText(), login.getText())); }//from w w w . j av a 2s.co m return true; }
From source file:com.rockwellcollins.atc.sysml2aadl.Importer.java
License:Open Source License
private IProject getOrCreateProject(AadlPackage ap, String name) throws Exception { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject p = root.getProject(name);/*from ww w . ja v a 2 s . com*/ if (p.exists()) { return p; } p.create(null); p.open(null); IFolder defModDir = p.getFolder(WorkspacePlugin.DEFAULT_MODEL_DIR); IFolder xmlPack = defModDir.getFolder(WorkspacePlugin.AADL_PACKAGES_DIR); IFolder xmlPSet = defModDir.getFolder(WorkspacePlugin.PROPERTY_SETS_DIR); IFolder defSrcDir = p.getFolder(WorkspacePlugin.DEFAULT_SOURCE_DIR); IFolder srcPack = defSrcDir.getFolder(WorkspacePlugin.AADL_PACKAGES_DIR); IFolder srcPSet = defSrcDir.getFolder(WorkspacePlugin.PROPERTY_SETS_DIR); try { CoreUtility.createFolder(xmlPack, true, true, null); CoreUtility.createFolder(xmlPSet, true, true, null); CoreUtility.createFolder(srcPack, true, true, null); CoreUtility.createFolder(srcPSet, true, true, null); } catch (CoreException e) { e.printStackTrace(); } String filepath = p.getFile(WorkspacePlugin.AADLPATH_FILENAME).getRawLocation().toString(); PreferenceStore ps = new PreferenceStore(filepath); ps.setValue(WorkspacePlugin.PROJECT_SOURCE_DIR, WorkspacePlugin.DEFAULT_SOURCE_DIR); ps.setValue(WorkspacePlugin.PROJECT_MODEL_DIR, WorkspacePlugin.DEFAULT_MODEL_DIR); ps.save(); p.refreshLocal(1, null); AadlNature.addNature(p, null); addXtextNature(p); addPluginResourcesDependency(p); return p; }
From source file:descent.internal.ui.preferences.formatter.JavaPreview.java
License:Open Source License
/** * Create a new Java preview/* w w w . ja va 2 s .c o m*/ * @param workingValues * @param parent */ public JavaPreview(Map workingValues, Composite parent) { JavaTextTools tools = JavaPlugin.getDefault().getJavaTextTools(); fPreviewDocument = new Document(); fWorkingValues = workingValues; tools.setupJavaDocumentPartitioner(fPreviewDocument, IJavaPartitions.JAVA_PARTITIONING); PreferenceStore prioritizedSettings = new PreferenceStore(); prioritizedSettings.setValue(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_x); prioritizedSettings.setValue(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_x); prioritizedSettings.setValue(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_x); prioritizedSettings.setValue(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR); IPreferenceStore[] chain = { prioritizedSettings, JavaPlugin.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, IJavaPartitions.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:eclipse.spellchecker.preferences.SpellingConfigurationBlock.java
License:Open Source License
/** * Creates the encoding field editor.// ww w .j a v a 2s .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:ext.org.eclipse.jdt.internal.ui.preferences.formatter.JavaPreview.java
License:Open Source License
public JavaPreview(Map<String, String> workingValues, Composite parent) { JavaTextTools tools = JavaPlugin.getDefault().getJavaTextTools(); fPreviewDocument = new Document(); fWorkingValues = workingValues;/*w ww . j av a 2 s . c om*/ tools.setupJavaDocumentPartitioner(fPreviewDocument, IJavaPartitions.JAVA_PARTITIONING); PreferenceStore prioritizedSettings = new PreferenceStore(); prioritizedSettings.setValue(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); prioritizedSettings.setValue(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); prioritizedSettings.setValue(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5); prioritizedSettings.setValue(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR); IPreferenceStore[] chain = { prioritizedSettings, JavaPlugin.getDefault().getCombinedPreferenceStore() }; fPreferenceStore = new ChainedPreferenceStore(chain); fSourceViewer = new JavaSourceViewer(parent, null, null, false, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER, fPreferenceStore); fSourceViewer.setEditable(false); Cursor arrowCursor = fSourceViewer.getTextWidget().getDisplay().getSystemCursor(SWT.CURSOR_ARROW); fSourceViewer.getTextWidget().setCursor(arrowCursor); // Don't set caret to 'null' as this causes https://bugs.eclipse.org/293263 // fSourceViewer.getTextWidget().setCaret(null); fViewerConfiguration = new SimpleJavaSourceViewerConfiguration(tools.getColorManager(), fPreferenceStore, null, IJavaPartitions.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:net.certiv.fluentmark.spell.SpellingConfigurationBlock.java
License:Open Source License
/** * Creates the encoding field editor./*from ww w . j a v a 2 s . 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(); } }