Search in sources :

Example 21 with TemplatePersistenceData

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

the class AbstractTemplatesPage method getContextTypeId.

/**
 * Returns the context type id of the selected template.
 *
 * @return the context type id of the selected template or the first from the
 *         registry if no templates are selected
 */
private String getContextTypeId() {
    IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
    Object item;
    if (selection.size() == 0)
        return getContextTypeRegistry().contextTypes().next().getId();
    if (selection.size() == 1) {
        item = selection.getFirstElement();
        if (item instanceof TemplatePersistenceData)
            return ((TemplatePersistenceData) item).getTemplate().getContextTypeId();
        return ((TemplateContextType) item).getId();
    }
    Iterator<?> it = selection.iterator();
    String contextId = null;
    while (it.hasNext()) {
        item = it.next();
        if (contextId == null)
            contextId = getContextId(item);
        else if (!contextId.equals(getContextId(item)))
            return getContextTypeRegistry().contextTypes().next().getId();
    }
    return contextId;
}
Also used : TemplatePersistenceData(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType)

Example 22 with TemplatePersistenceData

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

the class AbstractTemplatesPage method setSelectedTemplates.

/**
 * Set the selected templates
 */
private void setSelectedTemplates() {
    IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
    Iterator<?> it = selection.iterator();
    TemplatePersistenceData[] data = new TemplatePersistenceData[selection.size()];
    int i = 0;
    while (it.hasNext()) {
        Object o = it.next();
        if (o instanceof TemplatePersistenceData)
            data[i++] = (TemplatePersistenceData) o;
        else {
            fSelectedTemplates = new TemplatePersistenceData[0];
            return;
        }
    }
    fSelectedTemplates = data;
}
Also used : TemplatePersistenceData(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Point(org.eclipse.swt.graphics.Point)

Example 23 with TemplatePersistenceData

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

the class AbstractTemplatesPage method copyTemplates.

/**
 * Copy the selected templates to another context
 *
 * @param templates an array of template data
 * @param contextId the context id
 */
private void copyTemplates(TemplatePersistenceData[] templates, String contextId) {
    TemplatePersistenceData[] newTemplates = new TemplatePersistenceData[templates.length];
    for (int i = 0; i < templates.length; i++) {
        Template t = templates[i].getTemplate();
        newTemplates[i] = new TemplatePersistenceData(new Template(t.getName(), t.getDescription(), contextId, t.getPattern(), t.isAutoInsertable()), true);
        getTemplateStore().add(newTemplates[i]);
    }
    saveTemplateStore();
    refresh();
    fTreeViewer.setSelection(new StructuredSelection(newTemplates), true);
}
Also used : TemplatePersistenceData(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) Point(org.eclipse.swt.graphics.Point) Template(org.eclipse.jface.text.templates.Template)

Example 24 with TemplatePersistenceData

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

the class TemplatePreferencePage method updateViewerInput.

/**
 * Updates the pattern viewer.
 */
protected void updateViewerInput() {
    IStructuredSelection selection = (IStructuredSelection) fTableViewer.getSelection();
    if (selection.size() == 1) {
        TemplatePersistenceData data = (TemplatePersistenceData) selection.getFirstElement();
        Template template = data.getTemplate();
        fPatternViewer.getDocument().set(template.getPattern());
    } else {
        // $NON-NLS-1$
        fPatternViewer.getDocument().set("");
    }
}
Also used : TemplatePersistenceData(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Template(org.eclipse.jface.text.templates.Template)

Example 25 with TemplatePersistenceData

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

the class TemplatePreferencePage method edit.

private void edit(TemplatePersistenceData data) {
    Template oldTemplate = data.getTemplate();
    Template newTemplate = editTemplate(new Template(oldTemplate), true, true);
    if (newTemplate != null) {
        if (!newTemplate.getName().equals(oldTemplate.getName()) && MessageDialog.openQuestion(getShell(), TemplatesMessages.TemplatePreferencePage_question_create_new_title, TemplatesMessages.TemplatePreferencePage_question_create_new_message)) {
            data = new TemplatePersistenceData(newTemplate, true);
            fTemplateStore.add(data);
            fTableViewer.refresh();
        } else {
            data.setTemplate(newTemplate);
            fTableViewer.refresh(data);
        }
        selectionChanged1();
        fTableViewer.setChecked(data, data.isEnabled());
        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) Template(org.eclipse.jface.text.templates.Template)

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