use of org.eclipse.jface.text.templates.Template in project webtools.sourceediting by eclipse.
the class NewTagTemplatesWizardPage method saveLastSavedPreferences.
/**
* Save template name used for next call to New JSP File wizard.
*/
void saveLastSavedPreferences() {
// $NON-NLS-1$
String templateName = "";
Template template = getSelectedTemplate();
if (template != null) {
templateName = template.getName();
}
JSPUIPlugin.getDefault().getPreferenceStore().setValue(JSPUIPreferenceNames.NEW_TAG_FILE_TEMPLATE_NAME, templateName);
JSPUIPlugin.getDefault().savePluginPreferences();
}
use of org.eclipse.jface.text.templates.Template in project webtools.sourceediting by eclipse.
the class JSPTemplateCompletionProcessor method getTemplates.
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 JSPTemplateCompletionProcessor method computeCompletionProposals.
/*
* Copied from super class except instead of calling createContext(viewer,
* region) call createContext(viewer, region, offset) instead
*/
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
ITextSelection selection = (ITextSelection) viewer.getSelectionProvider().getSelection();
// adjust offset to end of normalized selection
if (selection.getOffset() == offset)
offset = selection.getOffset() + selection.getLength();
String prefix = extractPrefix(viewer, offset);
Region region = new Region(offset - prefix.length(), prefix.length());
// If there's no prefix, check if we're in a tag open region
if (prefix.trim().length() == 0) {
IndexedRegion treeNode = ContentAssistUtils.getNodeAt(viewer, offset);
if (treeNode instanceof IDOMText) {
IDOMNode node = (IDOMNode) treeNode;
// Check each region in the node, if the offset is after a tag region, replace it with the template
IStructuredDocumentRegion cursor = node.getFirstStructuredDocumentRegion();
IStructuredDocumentRegion end = node.getLastStructuredDocumentRegion();
do {
if (cursor != null && DOMRegionContext.XML_TAG_OPEN.equals(cursor.getType()) && cursor.getStartOffset() == offset - 1) {
// We have a tag to replace
offset = cursor.getStartOffset();
region = new Region(cursor.getStartOffset(), cursor.getLength());
break;
}
} while (cursor != end && (cursor = cursor.getNext()) != null);
}
}
TemplateContext context = createContext(viewer, region, offset);
if (context == null)
return new ICompletionProposal[0];
// name of the selection variables {line, word}_selection
// //$NON-NLS-1$
context.setVariable("selection", selection.getText());
Template[] templates = getTemplates(context.getContextType().getId());
List matches = new ArrayList();
for (int i = 0; i < templates.length; i++) {
Template template = templates[i];
try {
context.getContextType().validate(template.getPattern());
} catch (TemplateException e) {
continue;
}
if (template.matches(prefix, context.getContextType().getId()))
matches.add(createProposal(template, context, (IRegion) region, getRelevance(template, prefix)));
}
Collections.sort(matches, fgProposalComparator);
return (ICompletionProposal[]) matches.toArray(new ICompletionProposal[matches.size()]);
}
use of org.eclipse.jface.text.templates.Template in project webtools.sourceediting by eclipse.
the class DTDUIPreferenceInitializer method initializeDefaultPreferences.
/*
* (non-Javadoc)
*
* @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences()
*/
public void initializeDefaultPreferences() {
IPreferenceStore store = DTDUIPlugin.getDefault().getPreferenceStore();
ColorRegistry registry = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry();
// DTD Style Preferences
// $NON-NLS-1$
String NOBACKGROUNDBOLD = " | null | false";
// $NON-NLS-1$
String JUSTITALIC = " | null | false | true";
String styleValue = ColorHelper.findRGBString(registry, IStyleConstantsDTD.DTD_DEFAULT, 0, 0, 0) + NOBACKGROUNDBOLD;
// black
store.setDefault(IStyleConstantsDTD.DTD_DEFAULT, styleValue);
styleValue = ColorHelper.findRGBString(registry, IStyleConstantsDTD.DTD_TAG, 63, 63, 191) + NOBACKGROUNDBOLD;
// blue
store.setDefault(IStyleConstantsDTD.DTD_TAG, styleValue);
styleValue = ColorHelper.findRGBString(registry, IStyleConstantsDTD.DTD_TAGNAME, 63, 63, 191) + NOBACKGROUNDBOLD;
// blue
store.setDefault(IStyleConstantsDTD.DTD_TAGNAME, styleValue);
styleValue = ColorHelper.findRGBString(registry, IStyleConstantsDTD.DTD_COMMENT, 127, 127, 127) + NOBACKGROUNDBOLD;
// grey
store.setDefault(IStyleConstantsDTD.DTD_COMMENT, styleValue);
styleValue = ColorHelper.findRGBString(registry, IStyleConstantsDTD.DTD_KEYWORD, 128, 0, 0) + NOBACKGROUNDBOLD;
// dark
store.setDefault(IStyleConstantsDTD.DTD_KEYWORD, styleValue);
// red
styleValue = ColorHelper.findRGBString(registry, IStyleConstantsDTD.DTD_STRING, 63, 159, 95) + JUSTITALIC;
// green
store.setDefault(IStyleConstantsDTD.DTD_STRING, styleValue);
styleValue = ColorHelper.findRGBString(registry, IStyleConstantsDTD.DTD_DATA, 191, 95, 95) + NOBACKGROUNDBOLD;
// light
store.setDefault(IStyleConstantsDTD.DTD_DATA, styleValue);
// red
styleValue = ColorHelper.findRGBString(registry, IStyleConstantsDTD.DTD_SYMBOL, 128, 0, 0) + NOBACKGROUNDBOLD;
// dark
store.setDefault(IStyleConstantsDTD.DTD_SYMBOL, styleValue);
// red
// set default new xml file template to use in new file wizard
/*
* Need to find template name that goes with default template id (name
* may change for differnt language)
*/
// $NON-NLS-1$
String templateName = "";
// $NON-NLS-1$
Template template = DTDUIPlugin.getDefault().getTemplateStore().findTemplateById("org.eclipse.wst.dtd.ui.internal.templates.xmldeclaration");
if (template != null)
templateName = template.getName();
store.setDefault(DTDUIPreferenceNames.NEW_FILE_TEMPLATE_NAME, templateName);
store.setDefault(DTDUIPreferenceNames.ACTIVATE_PROPERTIES, true);
}
use of org.eclipse.jface.text.templates.Template in project webtools.sourceediting by eclipse.
the class NewDTDTemplatesWizardPage method saveLastSavedPreferences.
/**
* Save template name used for next call to New DTD File wizard.
*/
void saveLastSavedPreferences() {
// $NON-NLS-1$
String templateName = "";
Template template = getSelectedTemplate();
if (template != null) {
templateName = template.getName();
}
DTDUIPlugin.getDefault().getPreferenceStore().setValue(DTDUIPreferenceNames.NEW_FILE_TEMPLATE_NAME, templateName);
DTDUIPlugin.getDefault().savePluginPreferences();
}
Aggregations