public static IPreferenceFilter[] getPreferenceFilters() { final IPreferenceFilter[] transfers = new IPreferenceFilter[1]; // For export all create a preference filter that can export // all nodes of the Instance and Configuration scopes transfers[0] = new IPreferenceFilter() { @Override public String[] getScopes() { return new String[] { InstanceScope.SCOPE }; } @Override public Map getMapping(final String scope) { return null; } }; return transfers; }
private IPreferenceFilter[] getPreferenceImportFilters() { IPreferenceFilter filter = new IPreferenceFilter() { /** {@inheritDoc} */ @Override public String[] getScopes() { return new String[] {ConfigurationScope.SCOPE, InstanceScope.SCOPE}; } /** {@inheritDoc} */ @Override public Map<?, ?> getMapping(String scope) { return null; } }; return new IPreferenceFilter[] {filter}; }
/** * Applies preferences from a export file using IPreferenceFilter such that other prefs don't * get removed. This allows pref fragment files to do the right thing. */ private void transfer() { InputStream input = null; try { input = new BufferedInputStream(taskRef.newInputStream()); } catch (IOException e) { log.logError(e); } IPreferenceFilter[] filters = new IPreferenceFilter[1]; // Matches all prefs for both Instance and Config scope. filters[0] = new IPreferenceFilter() { public String[] getScopes() { return new String[] { InstanceScope.SCOPE, ConfigurationScope.SCOPE }; } @SuppressWarnings("rawtypes") // Eclipse doesn't do generics. public Map getMapping(String scope) { return null; } }; IPreferencesService service = Platform.getPreferencesService(); try { IExportedPreferences prefs = service.readPreferences(input); // Apply the prefs with the filters so they're only imported and others aren't removed. service.applyPreferences(prefs, filters); } catch (CoreException ex) { log.log(ex.getStatus()); } }