@Override public boolean isCustom() { return ref.isCustom(); }
/** * Returns whether the receiver represents a modified template, i.e. a * contributed template that has been changed. * * @return <code>true</code> if the contained template is contributed but has been modified, <code>false</code> otherwise */ public boolean isModified() { return isCustom() && !isUserAdded(); }
/** * Adds a template to the internal store. The added templates must have * a unique id. * * @param data the template data to add */ protected void internalAdd(TemplatePersistenceData data) { if (!data.isCustom()) { // check if the added template is not a duplicate id String id= data.getId(); for (TemplatePersistenceData persistenceData : fTemplates) { if (persistenceData.getId() != null && persistenceData.getId().equals(id)) return; } fTemplates.add(data); } }
/** * Saves the templates to the preferences. * * @throws IOException if the templates cannot be written */ public void save() throws IOException { ArrayList<TemplatePersistenceData> custom= new ArrayList<>(); for (TemplatePersistenceData data : fTemplates) { if (data.isCustom() && !(data.isUserAdded() && data.isDeleted())) // don't save deleted user-added templates custom.add(data); } StringWriter output= new StringWriter(); TemplateReaderWriter writer= new TemplateReaderWriter(); writer.save(custom.toArray(new TemplatePersistenceData[custom.size()]), output); fIgnorePreferenceStoreChanges= true; try { fPreferenceStore.put(fKey, output.toString()); fPreferenceStore.flush(); } catch (BackingStoreException e) { } finally { fIgnorePreferenceStoreChanges= false; } }
/** * Saves the templates to the preferences. * * @throws IOException if the templates cannot be written */ @Override public void save() throws IOException { ArrayList<TemplatePersistenceData> custom= new ArrayList<>(); for (TemplatePersistenceData data : internalGetTemplates()) { if (data.isCustom() && !(data.isUserAdded() && data.isDeleted())) // don't save deleted user-added templates custom.add(data); } StringWriter output= new StringWriter(); TemplateReaderWriter writer= new TemplateReaderWriter(); writer.save(custom.toArray(new TemplatePersistenceData[custom.size()]), output); fIgnorePreferenceStoreChanges= true; try { fPreferenceStore.setValue(getKey(), output.toString()); if (fPreferenceStore instanceof IPersistentPreferenceStore) ((IPersistentPreferenceStore)fPreferenceStore).save(); } finally { fIgnorePreferenceStoreChanges= false; } }