use of org.eclipse.jface.text.templates.TemplateContext in project linuxtools by eclipse.
the class SpecfileCompletionProcessor method computeTemplateProposals.
/**
* Compute the templates proposals, these proposals are contextual on
* sections. Return an array of template proposals for the given viewer,
* region, specfile, prefix.
*
* @param viewer
* the viewer for which the context is created
* @param region
* the region into <code>document</code> for which the context is
* created
* @param specfile
* the specfile element
* @param prefix
* the prefix string
* @return a ICompletionProposal[]
*/
private List<? extends ICompletionProposal> computeTemplateProposals(ITextViewer viewer, IRegion region, Specfile specfile, String prefix) {
TemplateContext context = createContext(viewer, region, specfile);
List<TemplateProposal> matches = new ArrayList<>();
if (context == null) {
return matches;
}
ITextSelection selection = (ITextSelection) viewer.getSelectionProvider().getSelection();
// $NON-NLS-1$
context.setVariable("selection", selection.getText());
String id = context.getContextType().getId();
Template[] templates = Activator.getDefault().getTemplateStore().getTemplates(id);
for (Template template : templates) {
try {
context.getContextType().validate(template.getPattern());
} catch (TemplateException e) {
continue;
}
int relevance = getRelevance(template, prefix);
if (relevance > 0) {
matches.add(new TemplateProposal(template, context, region, Activator.getDefault().getImage(TEMPLATE_ICON), relevance));
}
}
Collections.sort(matches, (t1, t2) -> (t2.getRelevance() - t1.getRelevance()));
return matches;
}
use of org.eclipse.jface.text.templates.TemplateContext in project liferay-ide by liferay.
the class AddJSFPortletOperation method createModeJSPFiles.
@Override
protected IStatus createModeJSPFiles() {
IDataModel dm = getDataModel();
StringBuffer jsfNamespaces = new StringBuffer();
if (getDataModel().getBooleanProperty(ICE_FACES)) {
jsfNamespaces.append("\txmlns:ace=\"http://www.icefaces.org/icefaces/components\"\n");
jsfNamespaces.append("\txmlns:icecore=\"http://www.icefaces.org/icefaces/core\"\n");
}
if (getDataModel().getBooleanProperty(LIFERAY_FACES_ALLOY)) {
jsfNamespaces.append("\txmlns:aui=\"http://liferay.com/faces/aui\"\n");
}
if (getDataModel().getBooleanProperty(PRIME_FACES)) {
jsfNamespaces.append("\txmlns:p=\"http://primefaces.org/ui\"\n");
}
if (getDataModel().getBooleanProperty(RICH_FACES)) {
jsfNamespaces.append("\txmlns:rich=\"http://richfaces.org/rich\"\n");
}
if (getDataModel().getBooleanProperty(STANDARD_JSF)) {
jsfNamespaces.append("");
}
TemplateContext context = new DocumentTemplateContext(portletContextType, new Document(), 0, 0);
context.setVariable("portlet_name", getDataModel().getStringProperty(PORTLET_NAME));
context.setVariable("jsf_namespaces", jsfNamespaces.toString());
if (dm.getBooleanProperty(VIEW_MODE)) {
createResourceForMode("javax.portlet.faces.defaultViewId.view", JSF_VIEW_MODE_TEMPLATE, context);
}
if (dm.getBooleanProperty(EDIT_MODE)) {
createResourceForMode("javax.portlet.faces.defaultViewId.edit", JSF_EDIT_MODE_TEMPLATE, context);
}
if (dm.getBooleanProperty(HELP_MODE)) {
createResourceForMode("javax.portlet.faces.defaultViewId.help", JSF_HELP_MODE_TEMPLATE, context);
}
return Status.OK_STATUS;
}
use of org.eclipse.jface.text.templates.TemplateContext in project liferay-ide by liferay.
the class StructuresContentAssistProcessor method getTemplateProposals.
private ICompletionProposal[] getTemplateProposals(IProject eclipseprj, ITextViewer viewer, int offset, String contextTypeId, Node currentNode, String prefix) {
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());
TemplateContext context = createContext(viewer, region, contextTypeId);
if (context == null) {
return new ICompletionProposal[0];
}
// name of the selection variables {line, word}_selection
// $NON-NLS-1$
context.setVariable("selection", selection.getText());
StructuresTemplateContext templateContext = StructuresTemplateContext.fromId(contextTypeId);
// add the user defined templates - separate them from the rest of the templates
// so that we know what they are and can assign proper icon to them.
Image image = PortalImages.IMG_USER_TEMPLATE;
List<TemplateProposal> matches = new ArrayList<TemplateProposal>();
TemplateStore store = PortalUI.getDefault().getTemplateStore();
if (store != null) {
Template[] templates = store.getTemplates(contextTypeId);
for (Template template : templates) {
TemplateProposal proposal = createProposalForTemplate(prefix, region, context, image, template, true);
if (proposal != null) {
matches.add(proposal);
}
}
}
image = null;
Template[] templates = templateContext.getTemplates(eclipseprj, currentNode, prefix);
for (Template template : templates) {
TemplateProposal proposal = createProposalForTemplate(prefix, region, context, image, template, false);
if (proposal != null) {
matches.add(proposal);
}
}
return (ICompletionProposal[]) matches.toArray(new ICompletionProposal[matches.size()]);
}
use of org.eclipse.jface.text.templates.TemplateContext in project syncope by apache.
the class HTMLTemplateAssistProcessor method computeCompletionProposals.
public ICompletionProposal[] computeCompletionProposals(final ITextViewer viewer, final int offsetinp) {
int offset = offsetinp;
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());
TemplateContext context = createContext(viewer, region);
if (context == null) {
return new ICompletionProposal[0];
}
context.setVariable("selection", selection.getText());
Template[] templates = getTemplates(context.getContextType().getId());
List<ICompletionProposal> matches = new ArrayList<ICompletionProposal>();
for (int i = 0; i < templates.length; i++) {
Template template = templates[i];
try {
context.getContextType().validate(template.getPattern());
} catch (final TemplateException e) {
continue;
}
if (template.getName().startsWith(prefix) && template.matches(prefix, context.getContextType().getId())) {
matches.add(createProposal(template, context, (IRegion) region, getRelevance(template, prefix)));
}
}
return matches.toArray(new ICompletionProposal[matches.size()]);
}
use of org.eclipse.jface.text.templates.TemplateContext in project webtools.sourceediting by eclipse.
the class HTMLTemplateCompletionProcessor 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());
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()]);
}
Aggregations