Search in sources :

Example 16 with TemplatePersistenceData

use of org.eclipse.jface.text.templates.persistence.TemplatePersistenceData in project mdw-designer by CenturyLinkCloud.

the class WorkspaceConfigurator method updateTemplate.

private void updateTemplate(TemplatePersistenceData data) {
    ProjectTemplateStore templateStore = new ProjectTemplateStore(null);
    TemplatePersistenceData[] dataElements = templateStore.getTemplateData();
    for (int i = 0; i < dataElements.length; i++) {
        String id = dataElements[i].getId();
        if (id != null && id.equals(data.getId())) {
            dataElements[i].setTemplate(data.getTemplate());
            break;
        }
    }
}
Also used : TemplatePersistenceData(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData) ProjectTemplateStore(org.eclipse.jdt.internal.ui.viewsupport.ProjectTemplateStore)

Example 17 with TemplatePersistenceData

use of org.eclipse.jface.text.templates.persistence.TemplatePersistenceData in project mdw-designer by CenturyLinkCloud.

the class WorkspaceConfigurator method importTemplates.

protected void importTemplates() {
    String baseUrl = getWorkspaceConfig().getMdwSettings().getWorkspaceSetupUrl();
    if (!baseUrl.endsWith("/"))
        baseUrl += "/";
    String templatesUrl = baseUrl;
    if (getWorkspaceConfig().getCodeTemplates().equals(WorkspaceConfig.CODE_TEMPLATES[0]))
        templatesUrl += "CenturyLinkITCodeTemplates.xml";
    else
        templatesUrl += "MDWCodeTemplates.xml";
    InputStream is = null;
    try {
        URL url = new URL(templatesUrl);
        URLConnection connection = url.openConnection();
        is = connection.getInputStream();
        TemplateReaderWriter reader = new TemplateReaderWriter();
        TemplatePersistenceData[] dataElements = reader.read(is, null);
        for (int i = 0; i < dataElements.length; i++) {
            updateTemplate(dataElements[i]);
        }
    } catch (Exception ex) {
        PluginMessages.uiError(getShell(), ex, "Import Templates");
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
            // do nothing
            }
        }
    }
}
Also used : TemplatePersistenceData(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData) InputStream(java.io.InputStream) TemplateReaderWriter(org.eclipse.jface.text.templates.persistence.TemplateReaderWriter) IOException(java.io.IOException) URL(java.net.URL) URLConnection(java.net.URLConnection) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IOException(java.io.IOException)

Example 18 with TemplatePersistenceData

use of org.eclipse.jface.text.templates.persistence.TemplatePersistenceData in project KaiZen-OpenAPI-Editor by RepreZen.

the class Activator method addNamedTemplates.

private void addNamedTemplates(String inlineContextId, String namedContextId, String key) {
    Template[] schemaTemplates = templateStore.getTemplates(inlineContextId);
    for (int i = 0; i < schemaTemplates.length; i++) {
        Template schemaTemplate = schemaTemplates[i];
        Template template = createNamedTemplate(schemaTemplate, namedContextId, key);
        templateStore.add(new TemplatePersistenceData(template, true));
    }
}
Also used : TemplatePersistenceData(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData) Template(org.eclipse.jface.text.templates.Template)

Example 19 with TemplatePersistenceData

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

the class AdvancedTemplatesPreferencePage method updateViewerInput.

@Override
protected void updateViewerInput() {
    IStructuredSelection selection = (IStructuredSelection) getTableViewer().getSelection();
    if (selection.size() == 1) {
        TemplatePersistenceData data = (TemplatePersistenceData) selection.getFirstElement();
        Template template = data.getTemplate();
        String name = template.getName();
        TemplateContextType contextType = getContextTypeRegistry().getContextType(template.getContextTypeId());
        if (contextType != null) {
            String prefix = "templates for " + grammarAccess.getGrammar().getName() + "'" + name + "'" + " for " + getContextTypeForGrammar(contextType) + ">>";
            String editablePart = template.getPattern();
            String suffix = "";
            partialEditor.updateModel(prefix, editablePart, suffix);
        } else {
            partialEditor.updateModel("", template.getPattern(), "");
        }
    } else {
        partialEditor.updateModel("", "", "");
    }
}
Also used : TemplatePersistenceData(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType) Template(org.eclipse.jface.text.templates.Template)

Example 20 with TemplatePersistenceData

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

the class AbstractTemplatesPage method initializeDND.

/**
 * Initializes drag and drop the template items
 */
private void initializeDND() {
    DragSourceAdapter dragListener = new DragSourceAdapter() {

        @Override
        public void dragStart(DragSourceEvent event) {
            if (getSelectedTemplates().length == 0) {
                event.doit = false;
            }
        }

        @Override
        public void dragSetData(DragSourceEvent event) {
            if (TemplatesTransfer.getInstance().isSupportedType(event.dataType)) {
                event.data = getSelectedTemplates();
            }
        }
    };
    fTreeViewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { TemplatesTransfer.getInstance() }, dragListener);
    DropTargetAdapter dropListener = new DropTargetAdapter() {

        Transfer textTransfer = TextTransfer.getInstance();

        Transfer templateTransfer = TemplatesTransfer.getInstance();

        @Override
        public void dragEnter(DropTargetEvent event) {
            if (event.detail == DND.DROP_DEFAULT)
                event.detail = DND.DROP_COPY;
        }

        @Override
        public void dragOperationChanged(DropTargetEvent event) {
            if (event.detail == DND.DROP_DEFAULT)
                event.detail = DND.DROP_COPY;
        }

        @Override
        public void dragOver(DropTargetEvent event) {
            event.feedback |= DND.FEEDBACK_SCROLL;
            if (event.item == null) {
                event.detail = DND.DROP_NONE;
                return;
            }
            int index = 0;
            boolean isTemplateTransfer = false;
            while (index < event.dataTypes.length) {
                if (textTransfer.isSupportedType(event.dataTypes[index])) {
                    break;
                }
                if (templateTransfer.isSupportedType(event.dataTypes[index])) {
                    isTemplateTransfer = true;
                    break;
                }
                index++;
            }
            if (index < event.dataTypes.length) {
                event.currentDataType = event.dataTypes[index];
                if (event.detail == DND.DROP_DEFAULT || !isTemplateTransfer)
                    event.detail = DND.DROP_COPY;
                return;
            }
        }

        @Override
        public void drop(DropTargetEvent event) {
            if (event.item == null)
                return;
            Object object = ((TreeItem) event.item).getData();
            final String contextId;
            if (object instanceof TemplateContextType)
                contextId = ((TemplateContextType) object).getId();
            else
                contextId = ((TemplatePersistenceData) object).getTemplate().getContextTypeId();
            if (textTransfer.isSupportedType(event.currentDataType)) {
                // $NON-NLS-1$ //$NON-NLS-2$
                String text = ((String) event.data).replaceAll("\\$", "\\$\\$");
                final Template template = new Template(createTemplateName(), TemplatesMessages.TemplatesPage_paste_description, contextId, text, true);
                getShell().getDisplay().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        addTemplate(template);
                    }
                });
                return;
            }
            if (templateTransfer.isSupportedType(event.currentDataType)) {
                final TemplatePersistenceData[] templates = (TemplatePersistenceData[]) event.data;
                final int dropType = event.detail;
                getShell().getDisplay().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        if (dropType == DND.DROP_COPY)
                            copyTemplates(templates, contextId);
                        else
                            moveTemplates(templates, contextId);
                    }
                });
            }
        }
    };
    Transfer[] transfers = new Transfer[] { TextTransfer.getInstance(), TemplatesTransfer.getInstance() };
    fTreeViewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, transfers, dropListener);
}
Also used : DragSourceAdapter(org.eclipse.swt.dnd.DragSourceAdapter) TemplatePersistenceData(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData) TreeItem(org.eclipse.swt.widgets.TreeItem) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) Point(org.eclipse.swt.graphics.Point) Template(org.eclipse.jface.text.templates.Template) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) DropTargetAdapter(org.eclipse.swt.dnd.DropTargetAdapter) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType)

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