/** * Loads preferences from a properties file. * * @throws IOException if there are problems loading the preferences file */ private void loadPreferences() throws IOException { // props = new Properties(); String userFile = getPreferencesFilename(); if (log.isDebugEnabled()) log.debug("Loading from [" + userFile + "]"); File prefsFile = new File(userFile); if (!prefsFile.exists()) { File prefsDir = new File(System.getProperty("user.home") + File.separator + PROPS_DIR); if (!prefsDir.exists()) { prefsDir.mkdir(); } } prefStore = new PreferenceStore(getPreferencesFilename()); JFacePreferences.setPreferenceStore(prefStore); new JpwPreferenceInitializer().initializeDefaultPreferences(); if (prefsFile.exists()) { prefStore.load(); } // TODO: Check what happens if no file exists? if (log.isDebugEnabled()) log.debug("Loaded " + prefStore + " preference settings from file"); }
/** * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getReconciler(org.eclipse.jface.text.source.ISourceViewer) */ @Override public IReconciler getReconciler(ISourceViewer sourceViewer) { if (fPreferenceStore == null || !fPreferenceStore.getBoolean(SpellingService.PREFERENCE_SPELLING_ENABLED)) return null; if (!TexlipsePlugin.getDefault().getPreferenceStore().getBoolean(TexlipseProperties.ECLIPSE_BUILDIN_SPELLCHECKER)) return null; //Set TeXlipse spelling Engine as default PreferenceStore store = new PreferenceStore(); store.setValue(SpellingService.PREFERENCE_SPELLING_ENGINE, "org.eclipse.texlipse.LaTeXSpellEngine"); store.setValue(SpellingService.PREFERENCE_SPELLING_ENABLED, true); SpellingService spellingService = new SpellingService(store); if (spellingService.getActiveSpellingEngineDescriptor(store) == null) return null; IReconcilingStrategy strategy= new TeXSpellingReconcileStrategy(sourceViewer, spellingService); MonoReconciler reconciler= new MonoReconciler(strategy, true); reconciler.setDelay(500); reconciler.setProgressMonitor(new NullProgressMonitor()); return reconciler; }
@Override protected WipTabElements createDialogElements(Composite composite, final Runnable modifyListener, PreferenceStore store) { final TabElements basicElements = createBasicTabElements(composite, modifyListener, store, getParams()); final BackendSelectorControl backendSelector = new BackendSelectorControl(composite, backendMap, modifyListener); backendSelector.getMainControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); return new WipTabElements() { @Override public BackendSelectorControl getBackendSelector() { return backendSelector; } @Override public TabElements getBase() { return basicElements; } }; }
/** * Main launcher */ private Main() { this.startedPlugins = new ArrayList<DazzlPlugin>(); this.display = new Display(); Display.setAppName("Dazzl"); //$NON-NLS-1$ this.shell = new Shell(display); this.preferenceStores = new TreeMap<String, PreferenceStore>(); this.preferenceDirectory = new File( System.getProperty("user.home") //$NON-NLS-1$ + File.separator + Dazzl.DAZZL_PREFERENCE_DIR ); }
/** * Generates a new random ping ID and saves it in the preference store. * * @return The new ping ID. */ public long generateNewPingId() { PreferenceStore prefs = getPreferenceStore(); Random rnd = new Random(); long id = rnd.nextLong(); synchronized (DdmsPreferenceStore.class) { prefs.setValue(PING_ID, id); try { prefs.save(); } catch (IOException e) { /* ignore exceptions while saving preferences */ } } return id; }
/** * @return a styled text that can be used to show code with the colors based on the color cache received. */ public StyledText createStyledTextForCodePresentation(Composite parent) { styledText = new StyledText(parent, SWT.BORDER | SWT.READ_ONLY); this.backgroundColorCache = new ColorAndStyleCache(new PreferenceStore()); this.colorCache = new ColorAndStyleCache(null); try { styledText.setFont(new Font(parent.getDisplay(), FontUtils.getFontData(IFontUsage.STYLED, true))); } catch (Throwable e) { //ignore } updateBackgroundColor(); PydevPrefs.getChainedPrefStore().addPropertyChangeListener(this); return styledText; }
public void testInterpreterManager() throws Exception { Collection<String> pythonpath = new ArrayList<String>(); pythonpath.add(TestDependent.PYTHON_LIB); pythonpath.add(TestDependent.PYTHON_SITE_PACKAGES); PreferenceStore prefs = new PreferenceStore(); String interpreterStr = new InterpreterInfo("2.6", TestDependent.PYTHON_EXE, pythonpath).toString(); prefs.setValue(IInterpreterManager.PYTHON_INTERPRETER_PATH, interpreterStr); PythonInterpreterManager manager = new PythonInterpreterManager(prefs); checkSameInterpreterInfo(manager); manager.clearCaches(); InterpreterInfo info = checkSameInterpreterInfo(manager); pythonpath = new ArrayList<String>(); pythonpath.add(TestDependent.PYTHON_LIB); pythonpath.add(TestDependent.PYTHON_SITE_PACKAGES); pythonpath.add(additionalPythonpathEntry.toString()); interpreterStr = new InterpreterInfo("2.6", TestDependent.PYTHON_EXE, pythonpath).toString(); prefs.setValue(IInterpreterManager.PYTHON_INTERPRETER_PATH, interpreterStr); info = checkSameInterpreterInfo(manager); }
private PyCodeScanner createCodeScanner() { PreferenceStore store = new PreferenceStore(); store.putValue(PydevEditorPrefs.KEYWORD_COLOR, StringConverter.asString(new RGB(1, 0, 0))); store.putValue(PydevEditorPrefs.SELF_COLOR, StringConverter.asString(new RGB(2, 0, 0))); store.putValue(PydevEditorPrefs.CODE_COLOR, StringConverter.asString(new RGB(3, 0, 0))); store.putValue(PydevEditorPrefs.DECORATOR_COLOR, StringConverter.asString(new RGB(4, 0, 0))); store.putValue(PydevEditorPrefs.NUMBER_COLOR, StringConverter.asString(new RGB(5, 0, 0))); store.putValue(PydevEditorPrefs.FUNC_NAME_COLOR, StringConverter.asString(new RGB(6, 0, 0))); store.putValue(PydevEditorPrefs.CLASS_NAME_COLOR, StringConverter.asString(new RGB(7, 0, 0))); store.putValue(PydevEditorPrefs.OPERATORS_COLOR, StringConverter.asString(new RGB(8, 0, 0))); store.putValue(PydevEditorPrefs.PARENS_COLOR, StringConverter.asString(new RGB(9, 0, 0))); this.colorCache = new ColorAndStyleCache(store); PyCodeScanner scanner = new PyCodeScanner(colorCache); return scanner; }
/** * Should only be called for testing. Does not register as a thread. */ public PyParser(IGrammarVersionProvider grammarVersionProvider) { super(PyParserManager.getPyParserManager(new PreferenceStore())); if (grammarVersionProvider == null) { grammarVersionProvider = new IGrammarVersionProvider() { @Override public int getGrammarVersion() { return IPythonNature.LATEST_GRAMMAR_VERSION; } @Override public AdditionalGrammarVersionsToCheck getAdditionalGrammarVersions() throws MisconfigurationException { return null; } }; } this.grammarVersionProvider = grammarVersionProvider; }
public void testIntegration() throws Exception { PreferenceStore preferences = new PreferenceStore(); PyParserManager pyParserManager = PyParserManager.getPyParserManager(preferences); Document doc = new Document(); PyEditStub pyEdit = new PyEditStub(doc, new PydevFileEditorInputStub()); pyParserManager.attachParserTo(pyEdit); checkParserChanged(pyEdit, 1); doc.replace(0, 0, "\r\ntest"); checkParserChanged(pyEdit, 2); pyParserManager.attachParserTo(pyEdit); checkParserChanged(pyEdit, 3); doc.replace(0, 0, "\r\ntest"); //after this change, only 1 reparse should be asked, as the editor and doc is the same checkParserChanged(pyEdit, 4); pyParserManager.notifyEditorDisposed(pyEdit); doc.replace(0, 0, "\r\ntest"); //after this change, only 1 reparse should be asked, as the editor and doc is the same waitABit(); assertEquals(4, pyEdit.parserChanged); assertEquals(0, pyParserManager.getParsers().size()); }
@Before public void setUp() { evaluationService = mock( IEvaluationService.class ); workbench = mock( IWorkbench.class ); when( workbench.getService( IEvaluationService.class ) ).thenReturn( evaluationService ); preferences = new WorkspaceScopePreferences( new PreferenceStore() ); action = new CloseJUnitStatusAction( workbench, preferences ); }
private static PreferenceStore createPreferences(final Properties properties) throws IOException { final PreferenceStore preferences = new PreferenceStore(); ByteArrayOutputStream output = new ByteArrayOutputStream(); properties.store(output, null); ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray()); preferences.load(input); return preferences; }
private void load () { subComp = new Composite(parent, SWT.NULL); GridData gridData = new GridData(); gridData.horizontalSpan = colspan; subComp.setLayoutData(gridData); String s = UIUtil.getResourceLabel(labelRef); if (null == s) s = labelRef; this.editor = new BooleanFieldEditor(name, s, subComp); if (null != defaultValue) { PreferenceStore ps = new PreferenceStore(); ps.setValue(name, defaultValue.booleanValue()); editor.setPreferenceStore(ps); editor.load(); } }
@Override protected ELEMENTS createElements(Composite parent, Runnable modifyListener) { Composite composite = createDefaultComposite(parent); setControl(composite); PreferenceStore store = new PreferenceStore(); composite.setFont(parent.getFont()); return createDialogElements(composite, modifyListener, store); }
protected PreferenceStore createPreferenceStore() { final String fileName = preferencesCallback.getFileName(); final PreferenceStore store = new ConfigurationStore(fileName); // Set default values... for (final IPreference preference : preferences) { if (preference.getDefaultValue() != null) { store.setDefault(preference.getName(), preference.getDefaultValue()); } } return store; }
public JavaPreview(Map<String, String> workingValues, Composite parent) { JavaTextTools tools= JavaPlugin.getDefault().getJavaTextTools(); fPreviewDocument= new Document(); fWorkingValues= workingValues; tools.setupJavaDocumentPartitioner( fPreviewDocument, IJavaPartitions.JAVA_PARTITIONING); PreferenceStore prioritizedSettings= new PreferenceStore(); HashMap<String, String> complianceOptions= new HashMap<String, String>(); JavaModelUtil.setComplianceOptions(complianceOptions, JavaModelUtil.VERSION_LATEST); for (Entry<String, String> complianceOption : complianceOptions.entrySet()) { prioritizedSettings.setValue(complianceOption.getKey(), complianceOption.getValue()); } 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); }
public SystemTray( Map<String, PreferenceStore> stores, String currentPreferenceStore, List menuContributions ) { this.stores = stores; this.currentPreferenceStore = currentPreferenceStore; this.menuContributions = menuContributions; this.menuManager = new MenuManager(); createComponents(); }
/** * Save the prefs to the config file. */ public void save() { PreferenceStore prefs = getPreferenceStore(); synchronized (DdmsPreferenceStore.class) { try { prefs.save(); } catch (IOException ioe) { // FIXME com.android.dmmlib.Log.w("ddms", "Failed saving prefs file: " + ioe.getMessage()); } } }
/** * Retrieves the current ping ID, if set. * To know if the ping ID is set, use {@link #hasPingId()}. * <p/> * There is no magic value reserved for "missing ping id or invalid store". * The only proper way to know if the ping id is missing is to use {@link #hasPingId()}. */ public long getPingId() { PreferenceStore prefs = getPreferenceStore(); synchronized (DdmsPreferenceStore.class) { // Note: getLong() returns 0L if the ID is missing so we do that too when // there's no store. return prefs == null ? 0L : prefs.getLong(PING_ID); } }
/** * Returns the "ping opt in" value from the preference store. * This would be true if there's a valid preference store and * the user opted for sending ping statistics. */ public boolean isPingOptIn() { PreferenceStore prefs = getPreferenceStore(); synchronized (DdmsPreferenceStore.class) { return prefs != null && prefs.contains(PING_OPT_IN); } }
/** * Saves the "ping opt in" value in the preference store. * * @param optIn The new user opt-in value. */ public void setPingOptIn(boolean optIn) { PreferenceStore prefs = getPreferenceStore(); synchronized (DdmsPreferenceStore.class) { prefs.setValue(PING_OPT_IN, optIn); try { prefs.save(); } catch (IOException e) { /* ignore exceptions while saving preferences */ } } }
/** * Sets the ping time for the given app from the preference store. * Callers should use {@link System#currentTimeMillis()} for time stamps. * * @param app The app name identifier. * @param timeStamp The time stamp from the store. * 0L is a special value that should not be used. */ public void setPingTime(String app, long timeStamp) { PreferenceStore prefs = getPreferenceStore(); String timePref = PING_TIME + "." + app; //$NON-NLS-1$ synchronized (DdmsPreferenceStore.class) { prefs.setValue(timePref, timeStamp); try { prefs.save(); } catch (IOException ioe) { /* ignore exceptions while saving preferences */ } } }
/** * True if this is the first time the users runs ADT, which is detected by * the lack of the setting set using {@link #setAdtUsed(boolean)} * or this value being set to true. * * @return true if ADT has been used before * * @see #setAdtUsed(boolean) */ public boolean isAdtUsed() { PreferenceStore prefs = getPreferenceStore(); synchronized (DdmsPreferenceStore.class) { if (prefs == null || !prefs.contains(ADT_USED)) { return false; } return prefs.getBoolean(ADT_USED); } }
/** * Sets whether the ADT startup wizard has been shown. * ADT sets first to false once the welcome wizard has been shown once. * * @param used true if ADT has been used */ public void setAdtUsed(boolean used) { PreferenceStore prefs = getPreferenceStore(); synchronized (DdmsPreferenceStore.class) { prefs.setValue(ADT_USED, used); try { prefs.save(); } catch (IOException ioe) { /* ignore exceptions while saving preferences */ } } }
/** * Sets the last SDK OS path. * * @param osSdkPath The SDK OS Path. Can be null or empty. */ public void setLastSdkPath(String osSdkPath) { PreferenceStore prefs = getPreferenceStore(); synchronized (DdmsPreferenceStore.class) { prefs.setValue(LAST_SDK_PATH, osSdkPath); try { prefs.save(); } catch (IOException ioe) { /* ignore exceptions while saving preferences */ } } }
public static void setPreference(String name, Rectangle rect) { PreferenceStore prefs = getPreferences(); prefs.setValue(name + "_x", rect.x); prefs.setValue(name + "_y", rect.y); prefs.setValue(name + "_width", rect.width); prefs.setValue(name + "_height", rect.height); save(); }
public static Rectangle getPreferenceRectangle(String name) { PreferenceStore prefs = getPreferences(); int x = prefs.getInt(name + "_x"); int y = prefs.getInt(name + "_y"); int width = prefs.getInt(name + "_width"); int height = prefs.getInt(name + "_height"); return new Rectangle(x, y, width, height); }
private void loadAttributePreferences() { _preferences = new PreferenceStore(INI_FILENAME); List<String> attributesList = new ArrayList<String>(); //ensure the name is present, and first attributesList.add(ManagedQueue.ATTR_NAME); //add any others from the file try { _preferences.load(); String selectedAttributes = _preferences.getString(INI_QUEUE_ATTRIBUES); if (selectedAttributes.length() != 0) { String[] attributes = selectedAttributes.split(","); for (String attr : attributes) { if(attr.equals(ManagedQueue.ATTR_NAME)) { //the Name attribute is already present continue; } attributesList.add(attr); } } } catch (IOException e) { ViewUtility.popupErrorMessage("Error", "Unable to load previous attribute selections, defaulting to Name only"); System.err.println(e); } _selectedAttributes = attributesList; }
public OverlayPreferenceStore( IPreferences preference, OverlayKey[] overlayKeys ) { fParent = preference; fOverlayKeys = overlayKeys; fStore = new PreferenceStore( ); }
public PreferenceStore getStore() { store = new PreferenceStore(JISOCREATOR_CONFIG_DIR.concat(JISOCREATOR_CONFIG_FILENAME)); try { store.load(); } catch (IOException e) { logger.warn("Loading defaults", e); loadPreferencesFromBackup(); } return store; }
@Override protected void okPressed() { try { ((PreferenceStore) getPreferenceStore()).save(); } catch (IOException e) { Logger.getAnonymousLogger().log(Level.SEVERE, "I/O Error", e); } super.okPressed(); }
@Override public void setUp() throws Exception { super.setUp(); CompiledModule.COMPILED_MODULES_ENABLED = false; useOriginalRequestCompl = true; participant = new CtxParticipant(); ExtensionHelper.testingParticipants = new HashMap<String, List<Object>>(); ArrayList<Object> participants = new ArrayList<Object>(); /*IPyDevCompletionParticipant*/ participants.add(participant); ExtensionHelper.testingParticipants.put(ExtensionHelper.PYDEV_COMPLETION, participants); codeCompletion = new PyCodeCompletion(); this.restorePythonPath(false); final IPreferenceStore prefs = new PreferenceStore(); PyCodeCompletionPreferencesPage.getPreferencesForTests = new ICallback<IPreferenceStore, Object>() { @Override public IPreferenceStore call(Object arg) { return prefs; } }; prefs.setValue(PyCodeCompletionPreferencesPage.MATCH_BY_SUBSTRING_IN_CODE_COMPLETION, false); }
public PydevEditorPrefs() { setDescription("PyDev editor appearance settings"); setPreferenceStore(PydevPlugin.getDefault().getPreferenceStore()); fOverlayStore = createOverlayStore(); localStore = new PreferenceStore(); }
@Override public void setUp() throws Exception { super.setUp(); DEBUG = false; preferences = new PreferenceStore();//PydevPlugin.getDefault().getPluginPreferences(); CodeFoldingSetter.setPreferences(preferences); setAllOptions(false); }
public void testChangeInput() throws Exception { PreferenceStore preferences = new PreferenceStore(); PyParserManager pyParserManager = PyParserManager.getPyParserManager(preferences); Document doc = new Document(); PydevFileEditorInputStub input1 = new PydevFileEditorInputStub(); PydevFileEditorInputStub input2 = new PydevFileEditorInputStub(); //create them with the same input PyEditStub pyEdit1 = new PyEditStub(doc, input1); PyEditStub pyEdit2 = new PyEditStub(doc, input2); pyParserManager.attachParserTo(pyEdit1); pyParserManager.attachParserTo(pyEdit2); assertEquals(2, pyParserManager.getParsers().size()); pyEdit2.setInput(input1); pyParserManager.attachParserTo(pyEdit2); assertEquals(1, pyParserManager.getParsers().size()); pyEdit2.setInput(input2); //different input pyParserManager.attachParserTo(pyEdit2); assertEquals(2, pyParserManager.getParsers().size()); pyParserManager.notifyEditorDisposed(pyEdit1); pyParserManager.notifyEditorDisposed(pyEdit2); assertEquals(0, pyParserManager.getParsers().size()); }
public static void main(String[] args) { new DatabasePlugin(); // Dummy final IPreferenceStore store = new PreferenceStore() { }; new Scripts() { @Override public IPreferenceStore getPreferenceStore() { return store; } }; String statement = "sandra.kiss(susi)"; try { new DialogTester(statement); } catch (ParseException e) { e.printStackTrace(); } }
/** * Creates the encoding field editor. * * @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() { 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(); } }
public AbstractDetailsPart(IPreferenceStore masterPreferenceStore) { super(GRID); this.masterPreferenceStore = masterPreferenceStore; internalStore = new PreferenceStore(); }
/** * */ private void resetPreferenceStore() { internalStore = new PreferenceStore(); setPreferenceStore(null); }