/** * Save the given Configuration to the persistent storage. * * <p>Only {@link ProgrammerConfig} objects obtained with the {@link #getConfigEditable(String)} * method should be passed to this method, however this is currently not enforced. * * @param config <code>ProgrammerConfig</code> to be saved. * @throws BackingStoreException If this configuration cannot be written to the preference storage * area. */ public void saveConfig(ProgrammerConfig config) throws BackingStoreException { // save the config config.save(getConfigPreferences(config)); // If the config is already in the cache update the cached config to the // new values if (fConfigsCache.containsKey(config.getId())) { ProgrammerConfig oldconfig = fConfigsCache.get(config.getId()); oldconfig.loadFromConfig(config); } else { // Add the new config to the cache fConfigsCache.put(config.getId(), config); } // Remove from the pending id list (if it is a newly created config) fPendingIds.remove(config.getId()); }
/** * Deletes the given configuration from the preference storage area. * * <p>Note: This Object is still valid and further calls to {@link #saveConfig(ProgrammerConfig)} * will add this configuration back to the preference storage. * * @throws BackingStoreException */ public void deleteConfig(ProgrammerConfig config) throws BackingStoreException { String id = config.getId(); // If the config is in the cache, remove it from the cache if (fConfigsCache.containsKey(id)) { fConfigsCache.remove(id); } // Remove the Preference node for the config and flush the preferences // If the node does not exist do nothing - no need to create the node // just to remove it again if (fPreferences.nodeExists(id)) { Preferences cfgnode = fPreferences.node(id); cfgnode.removeNode(); fPreferences.flush(); } }
/** * Get the preference node for the given configuration * * @param config * @return */ private Preferences getConfigPreferences(ProgrammerConfig config) { String id = config.getId(); return fPreferences.node(id); }