use of org.eclipse.jface.text.templates.persistence.TemplatePersistenceData in project eclipse.platform.text by eclipse.
the class TemplatePreferencePage method updateButtons.
/**
* Updates the buttons.
*/
protected void updateButtons() {
IStructuredSelection selection = (IStructuredSelection) fTableViewer.getSelection();
int selectionCount = selection.size();
int itemCount = fTableViewer.getTable().getItemCount();
boolean canRestore = fTemplateStore.getTemplateData(true).length != fTemplateStore.getTemplateData(false).length;
boolean canRevert = false;
for (Iterator<?> it = selection.iterator(); it.hasNext(); ) {
TemplatePersistenceData data = (TemplatePersistenceData) it.next();
if (data.isModified()) {
canRevert = true;
break;
}
}
fEditButton.setEnabled(selectionCount == 1);
fExportButton.setEnabled(selectionCount > 0);
fRemoveButton.setEnabled(selectionCount > 0 && selectionCount <= itemCount);
fRestoreButton.setEnabled(canRestore);
fRevertButton.setEnabled(canRevert);
}
use of org.eclipse.jface.text.templates.persistence.TemplatePersistenceData in project eclipse.platform.text by eclipse.
the class TemplatePreferencePage method restoreDeleted.
private void restoreDeleted() {
TemplatePersistenceData[] oldTemplates = fTemplateStore.getTemplateData(false);
fTemplateStore.restoreDeleted();
TemplatePersistenceData[] newTemplates = fTemplateStore.getTemplateData(false);
fTableViewer.refresh();
fTableViewer.setCheckedElements(getEnabledTemplates());
ArrayList<TemplatePersistenceData> selection = new ArrayList<>();
selection.addAll(Arrays.asList(newTemplates));
selection.removeAll(Arrays.asList(oldTemplates));
fTableViewer.setSelection(new StructuredSelection(selection), true);
selectionChanged1();
}
use of org.eclipse.jface.text.templates.persistence.TemplatePersistenceData in project eclipse.platform.text by eclipse.
the class ContributionTemplateStore method readIncludedTemplates.
private void readIncludedTemplates(Collection<TemplatePersistenceData> templates, IConfigurationElement element) throws IOException {
String file = element.getAttribute(FILE);
if (file != null) {
Bundle plugin = Platform.getBundle(element.getContributor().getName());
URL url = FileLocator.find(plugin, Path.fromOSString(file), null);
if (url != null) {
ResourceBundle bundle = null;
String translations = element.getAttribute(TRANSLATIONS);
if (translations != null) {
URL bundleURL = FileLocator.find(plugin, Path.fromOSString(translations), null);
if (bundleURL != null) {
try (InputStream bundleStream = bundleURL.openStream()) {
bundle = new PropertyResourceBundle(bundleStream);
}
}
}
try (InputStream stream = new BufferedInputStream(url.openStream())) {
TemplateReaderWriter reader = new TemplateReaderWriter();
TemplatePersistenceData[] datas = reader.read(stream, bundle);
for (int i = 0; i < datas.length; i++) {
TemplatePersistenceData data = datas[i];
if (data.isCustom()) {
if (data.getId() == null)
EditorsPlugin.logErrorMessage(NLSUtility.format(ContributionTemplateMessages.ContributionTemplateStore_ignore_no_id, data.getTemplate().getName()));
else
EditorsPlugin.logErrorMessage(NLSUtility.format(ContributionTemplateMessages.ContributionTemplateStore_ignore_deleted, data.getTemplate().getName()));
} else if (validateTemplate(data.getTemplate())) {
templates.add(data);
}
}
}
}
}
}
use of org.eclipse.jface.text.templates.persistence.TemplatePersistenceData in project erlide_eclipse by erlang.
the class ErlideContributionTemplateStore method loadContributedTemplates.
/**
* Loads the templates contributed via the templates extension point.
*
* @throws IOException
* {@inheritDoc}
*/
@Override
protected void loadContributedTemplates() throws IOException {
super.loadContributedTemplates();
final String erlideTemplates = System.getProperty("erlide.templates");
if (erlideTemplates != null) {
final String[] l = erlideTemplates.split(";");
final Collection<TemplatePersistenceData> templates = new ArrayList<>();
readIncludedTemplates(templates, l);
for (final TemplatePersistenceData data : templates) {
add(data);
}
}
}
use of org.eclipse.jface.text.templates.persistence.TemplatePersistenceData in project dsl-devkit by dsldevkit.
the class ConfigurableTemplateStore method addTemplatesFromFile.
/**
* Contribute templates defined in file with the give URL.
*
* @param templates
* the URL of the file with templates
*/
private void addTemplatesFromFile(final URL templates) {
if (templates != null) {
TemplateReaderWriter reader = new TemplateReaderWriter();
try {
InputStream openStream = templates.openStream();
try {
TemplatePersistenceData[] datas = reader.read(openStream, null);
int templateCounter = 0;
for (TemplatePersistenceData data : datas) {
if (data.getId() == null) {
templateCounter++;
TemplatePersistenceData dataWithGenId = new TemplatePersistenceData(data.getTemplate(), data.isEnabled(), // $NON-NLS-1$
templates.getPath() + "." + templateCounter);
dataWithGenId.setDeleted(data.isDeleted());
internalAdd(dataWithGenId);
} else {
// if contributed template has an id
internalAdd(data);
}
}
} finally {
openStream.close();
}
} catch (IOException e) {
LOG.error(e);
}
}
}
Aggregations