@Override public boolean isDeleted() { return ref.isDeleted(); }
/** * Returns all template data. * * @param includeDeleted whether to include deleted data * @return all template data, whether enabled or not */ public TemplatePersistenceData[] getTemplateData(boolean includeDeleted) { List<TemplatePersistenceData> datas= new ArrayList<>(); for (TemplatePersistenceData data : fTemplates) { if (includeDeleted || !data.isDeleted()) datas.add(data); } return datas.toArray(new TemplatePersistenceData[datas.size()]); }
/** * Restores all contributed templates that have been deleted. */ public void restoreDeleted() { for (TemplatePersistenceData data : fTemplates) { if (data.isDeleted()) data.setDeleted(false); } }
/** * Returns all enabled templates for the given context type. * * @param contextTypeId the id of the context type of the requested templates, or <code>null</code> if all templates should be returned * @return all enabled templates for the given context type */ public Template[] getTemplates(String contextTypeId) { List<Template> templates= new ArrayList<>(); for (TemplatePersistenceData data : fTemplates) { if (data.isEnabled() && !data.isDeleted() && (contextTypeId == null || contextTypeId.equals(data.getTemplate().getContextTypeId()))) templates.add(data.getTemplate()); } return templates.toArray(new Template[templates.size()]); }
/** * Returns the first enabled template that matches the given template id. * * @param id the id of the template searched for * @return the first enabled template that matches id, or <code>null</code> if none is found * @since 3.1 */ public Template findTemplateById(String id) { TemplatePersistenceData data= getTemplateData(id); if (data != null && !data.isDeleted()) return data.getTemplate(); return null; }
/** * Returns the first enabled template that matches both name and context type id. * * @param name the name of the template searched for * @param contextTypeId the context type id to clip unwanted templates, or <code>null</code> if any context type is OK * @return the first enabled template that matches both name and context type id, or <code>null</code> if none is found */ public Template findTemplate(String name, String contextTypeId) { Assert.isNotNull(name); for (TemplatePersistenceData data : fTemplates) { Template template= data.getTemplate(); if (data.isEnabled() && !data.isDeleted() && (contextTypeId == null || contextTypeId.equals(template.getContextTypeId())) && name.equals(template.getName())) return template; } return null; }
/** * 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; } }
deleted.setValue(data.isDeleted() ? Boolean.toString(true) : Boolean.toString(false)); attributes.setNamedItem(deleted);
/** * 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); } } }