Search in sources :

Example 11 with TemplatePersistenceData

use of org.eclipse.jface.text.templates.persistence.TemplatePersistenceData in project eclipse.platform.text by eclipse.

the class TemplatePreferencePage method add.

private void add() {
    Iterator<TemplateContextType> it = fContextTypeRegistry.contextTypes();
    if (it.hasNext()) {
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        Template template = new Template("", "", it.next().getId(), "", true);
        Template newTemplate = editTemplate(template, false, true);
        if (newTemplate != null) {
            TemplatePersistenceData data = new TemplatePersistenceData(newTemplate, true);
            fTemplateStore.add(data);
            fTableViewer.refresh();
            fTableViewer.setChecked(data, true);
            fTableViewer.setSelection(new StructuredSelection(data));
        }
    }
}
Also used : TemplatePersistenceData(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType) Template(org.eclipse.jface.text.templates.Template)

Example 12 with TemplatePersistenceData

use of org.eclipse.jface.text.templates.persistence.TemplatePersistenceData in project eclipse.platform.text by eclipse.

the class TemplatePreferencePage method export.

private void export() {
    IStructuredSelection selection = (IStructuredSelection) fTableViewer.getSelection();
    Object[] templates = selection.toArray();
    TemplatePersistenceData[] datas = new TemplatePersistenceData[templates.length];
    for (int i = 0; i != templates.length; i++) datas[i] = (TemplatePersistenceData) templates[i];
    export(datas);
}
Also used : TemplatePersistenceData(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 13 with TemplatePersistenceData

use of org.eclipse.jface.text.templates.persistence.TemplatePersistenceData in project eclipse.platform.text by eclipse.

the class TemplatePreferencePage method revert.

private void revert() {
    IStructuredSelection selection = (IStructuredSelection) fTableViewer.getSelection();
    Iterator<?> elements = selection.iterator();
    while (elements.hasNext()) {
        TemplatePersistenceData data = (TemplatePersistenceData) elements.next();
        data.revert();
        fTableViewer.setChecked(data, data.isEnabled());
    }
    selectionChanged1();
    fTableViewer.refresh();
}
Also used : TemplatePersistenceData(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 14 with TemplatePersistenceData

use of org.eclipse.jface.text.templates.persistence.TemplatePersistenceData in project eclipse.platform.text by eclipse.

the class TemplatePreferencePage method remove.

private void remove() {
    IStructuredSelection selection = (IStructuredSelection) fTableViewer.getSelection();
    Iterator<?> elements = selection.iterator();
    while (elements.hasNext()) {
        TemplatePersistenceData data = (TemplatePersistenceData) elements.next();
        fTemplateStore.delete(data);
    }
    fTableViewer.refresh();
}
Also used : TemplatePersistenceData(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 15 with TemplatePersistenceData

use of org.eclipse.jface.text.templates.persistence.TemplatePersistenceData in project erlide_eclipse by erlang.

the class ErlideContributionTemplateStore method readIncludedTemplates.

private void readIncludedTemplates(final Collection<TemplatePersistenceData> templates, final String[] files) {
    for (final String file : files) {
        if (file != null) {
            try (final InputStream input = new FileInputStream(new File(file));
                InputStream stream = new BufferedInputStream(input)) {
                final TemplateReaderWriter reader = new TemplateReaderWriter();
                final TemplatePersistenceData[] datas = reader.read(stream, null);
                for (final TemplatePersistenceData data : datas) {
                    if (validateTemplate(data.getTemplate())) {
                        templates.add(data);
                    }
                }
            } catch (final IOException x) {
            }
        }
    }
}
Also used : TemplatePersistenceData(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) TemplateReaderWriter(org.eclipse.jface.text.templates.persistence.TemplateReaderWriter) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

TemplatePersistenceData (org.eclipse.jface.text.templates.persistence.TemplatePersistenceData)36 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)17 Template (org.eclipse.jface.text.templates.Template)13 TemplateReaderWriter (org.eclipse.jface.text.templates.persistence.TemplateReaderWriter)8 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)8 InputStream (java.io.InputStream)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 URL (java.net.URL)4 TemplateContextType (org.eclipse.jface.text.templates.TemplateContextType)4 BufferedInputStream (java.io.BufferedInputStream)3 PropertyResourceBundle (java.util.PropertyResourceBundle)3 ResourceBundle (java.util.ResourceBundle)3 Point (org.eclipse.swt.graphics.Point)3 Bundle (org.osgi.framework.Bundle)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 Action (org.eclipse.jface.action.Action)2 IAction (org.eclipse.jface.action.IAction)2 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)2