/** * 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; }
/** * Reads templates from a reader and returns them. The reader must present * a serialized form as produced by the <code>save</code> method. * * @param reader the reader to read templates from * @return the read templates, encapsulated in instances of <code>TemplatePersistenceData</code> * @throws IOException if reading from the stream fails */ public TemplatePersistenceData[] read(Reader reader) throws IOException { return read(reader, null); }
/** * 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(); }
/** * In some cases, we must continue to respect the deprecated TemplatePresistenceData * even though we are given {@link org.eclipse.text.templates.TemplatePersistenceData}. * * @param data The {@link org.eclipse.text.templates.TemplatePersistenceData} that will * underlie this object. * @since 3.14 */ public TemplatePersistenceData(org.eclipse.text.templates.TemplatePersistenceData data) { super(data.getTemplate(), data.isEnabled(), data.getId()); // these are ignored this.ref= data instanceof TemplatePersistenceData ? ((TemplatePersistenceData) data).ref : data; // no double wrapping }
public void setProjectSpecific(String id, boolean projectSpecific) { Assert.isNotNull(fProjectStore); TemplatePersistenceData data= fProjectStore.getTemplateData(id); if (data == null) { return; // does not exist } else { data.setDeleted(!projectSpecific); } }
/** * Restores all contributed templates that have been deleted. */ public void restoreDeleted() { for (TemplatePersistenceData data : fTemplates) { if (data.isDeleted()) data.setDeleted(false); } }
@Override public void setDeleted(boolean isDeleted) { ref.setDeleted(isDeleted); }
@Override public boolean isUserAdded() { return ref.isUserAdded(); }
/** * Returns <code>true</code> if a context type id specifies a valid context type * or if no context type registry is present. * * @param contextTypeId the context type id to look for * @return <code>true</code> if the context type specified by the id * is present in the context type registry, or if no registry is * specified */ private boolean contextExists(String contextTypeId) { return contextTypeId != null && (fRegistry == null || fRegistry.getContextType(contextTypeId) != null); }
public void revertChanges() throws IOException { if (fProjectStore != null) { // nothing to do } else { fInstanceStore.load(); } } }
public TemplatePersistenceData[] getTemplateData() { if (fProjectStore != null) { return fProjectStore.getTemplateData(true); } else { return fInstanceStore.getTemplateData(true); } }
@Override public void setEnabled(boolean isEnabled) { ref.setEnabled(isEnabled); }
@Override public void addContextType(TemplateContextType contextType) { super.addContextType(contextType); }
/** * Deletes all user-added templates and reverts all contributed templates. * <p> * <strong>Note:</strong> the store will be saved after restoring. * </p> */ public void restoreDefaults() { restoreDefaults(true); }
@Override public boolean isCustom() { return ref.isCustom(); }
@Override public boolean isModified() { return ref.isModified(); }
@Override public void revert() { ref.revert(); }
private String getStringValue(NamedNodeMap attributes, String name) throws SAXException { String val= getStringValue(attributes, name, null); if (val == null) throw new SAXException(TextTemplateMessages.getString("TemplateReaderWriter.error.missing_attribute")); //$NON-NLS-1$ return val; }
/** * Required to support equals() with deprecated type org.eclipse.jface.text.templates.persistence.TemplatePersistenceData. * @param data non null * @return unique id to support {@link #equals(Object)} * @since 3.8 */ protected static final UUID getUniqueIdForEquals(TemplatePersistenceData data) { return data.getUniqueIdForEquals(); }
@Override public Iterator<TemplateContextType> contextTypes() { return super.contextTypes(); } }