use of org.eclipse.jface.text.templates.Template in project webtools.sourceediting by eclipse.
the class NewDTDTemplatesWizardPage method getSelectedTemplate.
/**
* Get the currently selected template.
*
* @return
*/
private Template getSelectedTemplate() {
Template template = null;
IStructuredSelection selection = (IStructuredSelection) fTableViewer.getSelection();
if (selection.size() == 1) {
template = (Template) selection.getFirstElement();
}
return template;
}
use of org.eclipse.jface.text.templates.Template in project webtools.sourceediting by eclipse.
the class NewDTDTemplatesWizardPage method getTemplateString.
/**
* Returns template string to insert.
*
* @return String to insert or null if none is to be inserted
*/
String getTemplateString() {
String templateString = null;
Template template = getSelectedTemplate();
if (template != null) {
TemplateContextType contextType = DTDUIPlugin.getDefault().getTemplateContextRegistry().getContextType(TemplateContextTypeIdsDTD.NEW);
IDocument document = new Document();
TemplateContext context = new DocumentTemplateContext(contextType, document, 0, 0);
try {
TemplateBuffer buffer = context.evaluate(template);
templateString = buffer.getString();
} catch (Exception e) {
// $NON-NLS-1$
Logger.log(Logger.WARNING_DEBUG, "Could not create template for new dtd", e);
}
}
return templateString;
}
use of org.eclipse.jface.text.templates.Template in project webtools.sourceediting by eclipse.
the class XSLTemplateCompletionProcessor method getTemplates.
@Override
protected Template[] getTemplates(String contextTypeId) {
Template[] templates = null;
TemplateStore store = getTemplateStore();
if (store != null) {
templates = store.getTemplates(contextTypeId);
}
return templates;
}
use of org.eclipse.jface.text.templates.Template in project webtools.sourceediting by eclipse.
the class NewXSLFileTemplatesWizardPage method saveLastSavedPreferences.
void saveLastSavedPreferences() {
// $NON-NLS-1$
String templateName = "";
Template template = getSelectedTemplate();
if (template != null) {
templateName = template.getName();
}
XSLUIPlugin.getDefault().getPreferenceStore().setValue(XSLUIConstants.NEW_FILE_TEMPLATE_NAME, templateName);
XSLUIPlugin.getDefault().savePluginPreferences();
}
use of org.eclipse.jface.text.templates.Template in project webtools.sourceediting by eclipse.
the class NewXSLFileTemplatesWizardPage method enableTemplates.
void enableTemplates() {
boolean enabled = fUseTemplateButton.getSelection();
if (enabled) {
setSelectedTemplate(fLastSelectedTemplateName);
} else {
// save last selected template
Template template = getSelectedTemplate();
if (template != null)
fLastSelectedTemplateName = template.getName();
else
// $NON-NLS-1$
fLastSelectedTemplateName = "";
fTableViewer.setSelection(null);
}
fTableViewer.getControl().setEnabled(enabled);
fPatternViewer.getControl().setEnabled(enabled);
}
Aggregations