private Preferences getBundlesNode() { try { if (prefBundles == null || !prefBundles.nodeExists("")) { //$NON-NLS-1$ prefBundles = new ConfigurationScope().getNode(ORG_ECLIPSE_CORE_INTERNAL_PREFERENCES_OSGI); } return prefBundles; } catch (BackingStoreException e) { // ignore } return null; } }
@SuppressWarnings("deprecation") private void handleUseProjectSettings() { boolean isUseProjectSettings = useProjectSettingsButton.getSelection(); link.setEnabled(!isUseProjectSettings); if (!isUseProjectSettings) { ((FixedScopedPreferenceStore) getPreferenceStore()).setSearchContexts(new IScopeContext[] { new InstanceScope(), new ConfigurationScope() }); } else { ((FixedScopedPreferenceStore) getPreferenceStore()).setSearchContexts(new IScopeContext[] { new ProjectScope(currentProject()), new InstanceScope(), new ConfigurationScope() }); } updateFieldEditors(isUseProjectSettings); }
@SuppressWarnings("deprecation") public IPreferenceStore getWritablePreferenceStore() { lazyInitialize(); FixedScopedPreferenceStore result = new FixedScopedPreferenceStore(new InstanceScope(), getQualifier()); result.setSearchContexts(new IScopeContext[] { new InstanceScope(), new ConfigurationScope() }); return result; }
protected HashSet getDisabledModules() { IEclipsePreferences node = new ConfigurationScope().getNode(PREFERENCES_PLUGIN); String tmp = node.get(IStorageConstants.DISABLED_PROVIDERS_KEY, null); if (tmp == null || tmp.length() == 0) return null; HashSet modules = new HashSet(); String[] disabledProviders = tmp.split(","); //$NON-NLS-1$ for (int i = 0; i < disabledProviders.length; i++) { modules.add(disabledProviders[i]); } return modules; }
@SuppressWarnings("deprecation") public IPreferenceStore getWritablePreferenceStore(Object context) { lazyInitialize(); if (context instanceof IFileEditorInput) { context = ((IFileEditorInput) context).getFile().getProject(); } if (context instanceof IProject) { ProjectScope projectScope = new ProjectScope((IProject) context); FixedScopedPreferenceStore result = new FixedScopedPreferenceStore(projectScope, getQualifier()); result.setSearchContexts(new IScopeContext[] { projectScope, new InstanceScope(), new ConfigurationScope() }); return result; } return getWritablePreferenceStore(); }
protected HashSet getDisabledModules() { IEclipsePreferences node = new ConfigurationScope().getNode(AuthPlugin.PI_AUTH); String tmp = node.get(IStorageConstants.DISABLED_PROVIDERS_KEY, null); if (tmp == null || tmp.length() == 0) return null; HashSet disabledModules = new HashSet(); String[] disabledProviders = tmp.split(","); //$NON-NLS-1$ for (int i = 0; i < disabledProviders.length; i++) { disabledModules.add(disabledProviders[i]); } return disabledModules; } }
/** * Flush the bundle's preferences. */ public void ungetService(Bundle bundle, ServiceRegistration registration, Object service) { try { //new InstanceScope().getNode(getQualifier(bundle)).flush(); new ConfigurationScope().getNode(getQualifier(bundle)).flush(); } catch (BackingStoreException e) { //best effort } }
protected boolean getBooleanPreference(String key, boolean defaultValue) { IPreferencesService prefService = GCActivator.getService(IPreferencesService.class); if (prefService == null) return defaultValue; List<IEclipsePreferences> nodes = new ArrayList<IEclipsePreferences>(); // todo we should look in the instance scope as well but have to be careful that the instance location has been set nodes.add(new ConfigurationScope().getNode(GCActivator.ID)); nodes.add(new DefaultScope().getNode(GCActivator.ID)); return Boolean.valueOf(prefService.get(key, Boolean.toString(defaultValue), nodes.toArray(new Preferences[nodes.size()]))).booleanValue(); }
protected boolean getBooleanPreference(String key, boolean defaultValue) { IPreferencesService prefService = GCActivator.getService(IPreferencesService.class); if (prefService == null) return defaultValue; List<IEclipsePreferences> nodes = new ArrayList<IEclipsePreferences>(); // todo we should look in the instance scope as well but have to be careful that the instance location has been set nodes.add(new ConfigurationScope().getNode(GCActivator.ID)); nodes.add(new DefaultScope().getNode(GCActivator.ID)); return Boolean.valueOf(prefService.get(key, Boolean.toString(defaultValue), nodes.toArray(new Preferences[nodes.size()]))).booleanValue(); }
public OSGiPreferencesServiceManager(BundleContext context) { context.addBundleListener(this); //prefBundles = new InstanceScope().getNode(ORG_ECLIPSE_CORE_INTERNAL_PREFERENCES_OSGI); prefBundles = new ConfigurationScope().getNode(ORG_ECLIPSE_CORE_INTERNAL_PREFERENCES_OSGI); //clean up prefs for bundles that have been uninstalled try { //get list of currently installed bundles Bundle[] allBundles = context.getBundles(); Set bundleQualifiers = new TreeSet(); for (int i = 0; i < allBundles.length; i++) { bundleQualifiers.add(getQualifier(allBundles[i])); } //get list of bundles we created prefs for String[] prefsBundles = prefBundles.keys(); //remove prefs nodes for bundles that are no longer installed for (int i = 0; i < prefsBundles.length; i++) { if (!bundleQualifiers.contains(prefsBundles[i])) { removePrefs(prefsBundles[i]); } } } catch (BackingStoreException e) { //best effort } }
protected void removePrefs(String qualifier) throws BackingStoreException { //remove bundle's prefs //new InstanceScope().getNode(qualifier).removeNode(); new ConfigurationScope().getNode(qualifier).removeNode(); //remove from our list of bundles with prefs Preferences bundlesNode = getBundlesNode(); bundlesNode.remove(qualifier); bundlesNode.flush(); }
/** * Creates a new OSGiPreferencesServiceImpl for each bundle. */ public Object getService(Bundle bundle, ServiceRegistration registration) { String qualifier = getQualifier(bundle); //remember we created prefs for this bundle Preferences bundlesNode = getBundlesNode(); bundlesNode.put(qualifier, ""); //$NON-NLS-1$ try { bundlesNode.flush(); } catch (BackingStoreException e) { //best effort } //return new OSGiPreferencesServiceImpl(new InstanceScope().getNode(getQualifier(bundle))); return new OSGiPreferencesServiceImpl(new ConfigurationScope().getNode(getQualifier(bundle))); }
public void performOk() { if (!providerModified) return; // save current selection StringBuffer tmp = new StringBuffer(); boolean first = true; TableItem[] items = providerTable.getItems(); for (int i = 0; i < items.length; i++) { if (items[i].getChecked()) continue; if (!first) tmp.append(','); else first = false; tmp.append(((PasswordProviderDescription) items[i].getData()).getId()); } IEclipsePreferences node = new ConfigurationScope().getNode(PREFERENCES_PLUGIN); if (first) node.remove(IStorageConstants.DISABLED_PROVIDERS_KEY); else node.put(IStorageConstants.DISABLED_PROVIDERS_KEY, tmp.toString()); try { node.flush(); } catch (BackingStoreException e) { // nothing can be done } // logout so that previously selected default provider is not reused InternalExchangeUtils.passwordProvidersReset(); }
protected void internalInitialize() throws StorageException { if (cipherAlgorithm != null && keyFactoryAlgorithm != null) { if (roundtrip(cipherAlgorithm, keyFactoryAlgorithm)) return; // this is a bad situation - JVM cipher no longer available. Both log and throw an exception String msg = NLS.bind(SecAuthMessages.noAlgorithm, cipherAlgorithm); StorageException e = new StorageException(StorageException.INTERNAL_ERROR, msg); AuthPlugin.getDefault().logError(msg, e); throw e; } if (cipherAlgorithm == null || keyFactoryAlgorithm == null) { IEclipsePreferences eclipseNode = new ConfigurationScope().getNode(AuthPlugin.PI_AUTH); cipherAlgorithm = eclipseNode.get(IStorageConstants.CIPHER_KEY, IStorageConstants.DEFAULT_CIPHER); keyFactoryAlgorithm = eclipseNode.get(IStorageConstants.KEY_FACTORY_KEY, IStorageConstants.DEFAULT_KEY_FACTORY); } if (roundtrip(cipherAlgorithm, keyFactoryAlgorithm)) return; String unavailableCipher = cipherAlgorithm; detect(); if (availableCiphers.size() == 0) throw new StorageException(StorageException.INTERNAL_ERROR, SecAuthMessages.noAlgorithms); // use first available cipherAlgorithm = (String) availableCiphers.keySet().iterator().next(); keyFactoryAlgorithm = (String) availableCiphers.get(cipherAlgorithm); String msg = NLS.bind(SecAuthMessages.usingAlgorithm, unavailableCipher, cipherAlgorithm); AuthPlugin.getDefault().logMessage(msg); }
public TabAdvanced(TabFolder folder, int index, final Shell shell) { TabItem tab = new TabItem(folder, SWT.NONE, index); tab.setText(SecUIMessages.tabAdvanced); Composite page = new Composite(folder, SWT.NONE); tab.setControl(page); Label cipherLabel = new Label(page, SWT.NONE); cipherLabel.setText(SecUIMessages.selectCipher); cipherSelector = new Combo(page, SWT.READ_ONLY | SWT.DROP_DOWN); GridData gridDataSelector = new GridData(GridData.FILL, GridData.BEGINNING, true, false); cipherSelector.setLayoutData(gridDataSelector); // initialize values eclipseNode = new ConfigurationScope().getNode(PREFERENCES_PLUGIN); defaultCipherAlgorithm = eclipseNode.get(IStorageConstants.CIPHER_KEY, IStorageConstants.DEFAULT_CIPHER); availableCiphers = InternalExchangeUtils.ciphersDetectAvailable(); // fill cipher selector int position = 0; for (Iterator i = availableCiphers.keySet().iterator(); i.hasNext();) { String cipherAlgorithm = (String) i.next(); cipherSelector.add(cipherAlgorithm, position); if (defaultCipherAlgorithm.equals(cipherAlgorithm)) cipherSelector.select(position); position++; } GridLayoutFactory.fillDefaults().margins(LayoutConstants.getMargins()).numColumns(1).generateLayout(page); }