Java Code Examples for org.eclipse.jface.text.templates.persistence.TemplatePersistenceData#getTemplate()
The following examples show how to use
org.eclipse.jface.text.templates.persistence.TemplatePersistenceData#getTemplate() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AdvancedTemplatesPreferencePage.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@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("", "", ""); } }
Example 2
Source File: GamlTemplateStore.java From gama with GNU General Public License v3.0 | 6 votes |
public void directAdd(final TemplatePersistenceData data, final boolean isEdited) { if (isEdited) { add(data); } else { // Trick the template store so that (1) the template is considered // as "user added" while (2) maintaining a proper id final String id = data.getId(); final TemplatePersistenceData d2 = new TemplatePersistenceData(data.getTemplate(), true) { @Override public String getId() { return id; } }; add(d2); } }
Example 3
Source File: ProjectTemplateStore.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public void load() throws IOException { if (fProjectStore != null) { fProjectStore.load(); Set<String> datas= new HashSet<String>(); TemplatePersistenceData[] data= fProjectStore.getTemplateData(false); for (int i= 0; i < data.length; i++) { datas.add(data[i].getId()); } data= fInstanceStore.getTemplateData(false); for (int i= 0; i < data.length; i++) { TemplatePersistenceData orig= data[i]; if (!datas.contains(orig.getId())) { TemplatePersistenceData copy= new TemplatePersistenceData(new Template(orig.getTemplate()), orig.isEnabled(), orig.getId()); fProjectStore.add(copy); copy.setDeleted(true); } } } }
Example 4
Source File: ConfigurableTemplateStore.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** * 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(), templates.getPath() + "." //$NON-NLS-1$ + 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); } } }
Example 5
Source File: TypeScriptTemplatePreferencePage.java From typescript.java with MIT License | 5 votes |
protected void updateViewerInput() { IStructuredSelection selection= (IStructuredSelection) getTableViewer().getSelection(); SourceViewer viewer= getViewer(); if (selection.size() == 1 && selection.getFirstElement() instanceof TemplatePersistenceData) { TemplatePersistenceData data= (TemplatePersistenceData) selection.getFirstElement(); Template template= data.getTemplate(); String contextId= template.getContextTypeId(); TemplateContextType type= JSDTTypeScriptUIPlugin.getDefault().getTemplateContextRegistry().getContextType(contextId); fTemplateProcessor.setContextType(type); IDocument doc= viewer.getDocument(); String start= null; if ("javadoc".equals(contextId)) { //$NON-NLS-1$ start= "/**" + doc.getLegalLineDelimiters()[0]; //$NON-NLS-1$ } else start= ""; //$NON-NLS-1$ doc.set(start + template.getPattern()); int startLen= start.length(); viewer.setDocument(doc, startLen, doc.getLength() - startLen); } else { viewer.getDocument().set(""); //$NON-NLS-1$ } }
Example 6
Source File: CodeTemplateBlock.java From typescript.java with MIT License | 5 votes |
protected void updateSourceViewerInput(List selection) { if (fPatternViewer == null || fPatternViewer.getTextWidget().isDisposed()) { return; } if (selection.size() == 1 && selection.get(0) instanceof TemplatePersistenceData) { TemplatePersistenceData data = (TemplatePersistenceData) selection.get(0); Template template = data.getTemplate(); TemplateContextType type = JavaScriptPlugin.getDefault().getCodeTemplateContextRegistry() .getContextType(template.getContextTypeId()); fTemplateProcessor.setContextType(type); fPatternViewer.getDocument().set(template.getPattern()); } else { fPatternViewer.getDocument().set(""); //$NON-NLS-1$ } }
Example 7
Source File: CodeTemplateBlock.java From typescript.java with MIT License | 5 votes |
private void edit(TemplatePersistenceData data) { Template newTemplate = new Template(data.getTemplate()); EditTemplateDialog dialog = new EditTemplateDialog(getShell(), newTemplate, true, false, JavaScriptPlugin.getDefault().getCodeTemplateContextRegistry()); if (dialog.open() == Window.OK) { // changed data.setTemplate(dialog.getTemplate()); fCodeTemplateTree.refresh(data); fCodeTemplateTree.selectElements(new StructuredSelection(data)); } }
Example 8
Source File: GamlTemplateStore.java From gama with GNU General Public License v3.0 | 5 votes |
/** * Adds a template to the internal store. The added templates must have a unique id. * * @param data * the template data to add */ @Override protected void internalAdd(final TemplatePersistenceData data) { if (!data.isCustom()) { // give the data a new unique id final String id = getNewIdFromId(data.getId()); final TemplatePersistenceData d2 = new TemplatePersistenceData(data.getTemplate(), true, id); super.internalAdd(d2); } }
Example 9
Source File: StubUtility.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Only to be used by tests * * @param templateId the template id * @param pattern the new pattern * @param project not used */ public static void setCodeTemplate(String templateId, String pattern, IJavaProject project) { TemplateStore codeTemplateStore= JavaPlugin.getDefault().getCodeTemplateStore(); TemplatePersistenceData data= codeTemplateStore.getTemplateData(templateId); Template orig= data.getTemplate(); Template copy= new Template(orig.getName(), orig.getDescription(), orig.getContextTypeId(), pattern, true); data.setTemplate(copy); }
Example 10
Source File: CompatibilityTemplateStore.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static TemplatePersistenceData findSimilarTemplate(TemplatePersistenceData[] datas, Template template, boolean isCodeTemplates) { for (int i= 0; i < datas.length; i++) { TemplatePersistenceData data= datas[i]; Template orig= data.getTemplate(); if (isSimilar(template, orig, isCodeTemplates)) return data; } return null; }
Example 11
Source File: JavaTemplatePreferencePage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override protected void updateViewerInput() { IStructuredSelection selection= (IStructuredSelection) getTableViewer().getSelection(); SourceViewer viewer= getViewer(); if (selection.size() == 1 && selection.getFirstElement() instanceof TemplatePersistenceData) { TemplatePersistenceData data= (TemplatePersistenceData) selection.getFirstElement(); Template template= data.getTemplate(); String contextId= template.getContextTypeId(); TemplateContextType type= JavaPlugin.getDefault().getTemplateContextRegistry().getContextType(contextId); fTemplateProcessor.setContextType(type); IDocument doc= viewer.getDocument(); String start= null; if ("javadoc".equals(contextId)) { //$NON-NLS-1$ start= "/**" + doc.getLegalLineDelimiters()[0]; //$NON-NLS-1$ } else start= ""; //$NON-NLS-1$ doc.set(start + template.getPattern()); int startLen= start.length(); viewer.setDocument(doc, startLen, doc.getLength() - startLen); } else { viewer.getDocument().set(""); //$NON-NLS-1$ } }
Example 12
Source File: CodeTemplateBlock.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
protected void updateSourceViewerInput(List<Object> selection) { if (fPatternViewer == null || fPatternViewer.getTextWidget().isDisposed()) { return; } if (selection.size() == 1 && selection.get(0) instanceof TemplatePersistenceData) { TemplatePersistenceData data= (TemplatePersistenceData) selection.get(0); Template template= data.getTemplate(); TemplateContextType type= JavaPlugin.getDefault().getCodeTemplateContextRegistry().getContextType(template.getContextTypeId()); fTemplateProcessor.setContextType(type); fPatternViewer.getDocument().set(template.getPattern()); } else { fPatternViewer.getDocument().set(""); //$NON-NLS-1$ } }
Example 13
Source File: CodeTemplateBlock.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void edit(TemplatePersistenceData data) { Template newTemplate= new Template(data.getTemplate()); EditTemplateDialog dialog= new EditTemplateDialog(getShell(), newTemplate, true, false, JavaPlugin.getDefault().getCodeTemplateContextRegistry()); if (dialog.open() == Window.OK) { // changed data.setTemplate(dialog.getTemplate()); fCodeTemplateTree.refresh(data); fCodeTemplateTree.selectElements(new StructuredSelection(data)); } }
Example 14
Source File: LangTemplatePreferencePage.java From goclipse with Eclipse Public License 1.0 | 5 votes |
@Override protected void updateViewerInput() { IStructuredSelection selection= (IStructuredSelection) getTableViewer().getSelection(); if(selection.size() == 1 && selection.getFirstElement() instanceof TemplatePersistenceData) { TemplatePersistenceData data= (TemplatePersistenceData) selection.getFirstElement(); Template template= data.getTemplate(); getViewer().getDocument().set(template.getPattern()); } else { getViewer().getDocument().set(""); } }