@Override public boolean isUserAdded() { return ref.isUserAdded(); }
/** * Removes a template from the store. * * @param data the template to remove */ public void delete(TemplatePersistenceData data) { if (data.isUserAdded()) fTemplates.remove(data); else data.setDeleted(true); }
/** * 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(); }
/** * 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; } }
for (int i= datas.length - 1; i >= 0; i--) { TemplatePersistenceData data= datas[i]; if (data.isUserAdded()) { if (similar != data && !similar.isUserAdded()) { similar.setTemplate(data.getTemplate()); store.delete(data); datas= store.getTemplateData(true); for (int i= datas.length - 1; i >= 0; i--) { if (datas[i].isUserAdded()) store.delete(datas[i]);
/** * Adds a template encapsulated in its persistent form. * * @param data the template to add */ public void add(TemplatePersistenceData data) { if (!validateTemplate(data.getTemplate())) return; if (data.isUserAdded()) { fTemplates.add(data); } else { for (TemplatePersistenceData persistenceData : fTemplates) { if (persistenceData.getId() != null && persistenceData.getId().equals(data.getId())) { persistenceData.setTemplate(data.getTemplate()); persistenceData.setDeleted(data.isDeleted()); persistenceData.setEnabled(data.isEnabled()); return; } } // add an id which is not contributed as add-on if (data.getTemplate() != null) { TemplatePersistenceData newData= new TemplatePersistenceData(data.getTemplate(), data.isEnabled(), data.getId()); fTemplates.add(newData); } } }