Search in sources :

Example 1 with SQLTemplateCompletionProposal

use of org.jkiss.dbeaver.ui.editors.sql.templates.SQLTemplateCompletionProposal in project dbeaver by serge-rider.

the class SQLCompletionProcessor method makeTemplateProposals.

@NotNull
private ICompletionProposal[] makeTemplateProposals(ITextViewer viewer, SQLCompletionAnalyzer.CompletionRequest request) {
    String wordPart = request.wordPart.toLowerCase();
    final List<SQLTemplateCompletionProposal> templateProposals = new ArrayList<>();
    // Templates
    for (Template template : editor.getTemplatesPage().getTemplateStore().getTemplates()) {
        if (template.getName().toLowerCase().startsWith(wordPart)) {
            templateProposals.add(new SQLTemplateCompletionProposal(template, new SQLContext(SQLTemplatesRegistry.getInstance().getTemplateContextRegistry().getContextType(template.getContextTypeId()), viewer.getDocument(), new Position(request.wordDetector.getStartOffset(), request.wordDetector.getLength()), editor), new Region(request.documentOffset, 0), null));
        }
    }
    Collections.sort(templateProposals, new Comparator<SQLTemplateCompletionProposal>() {

        @Override
        public int compare(SQLTemplateCompletionProposal o1, SQLTemplateCompletionProposal o2) {
            return o1.getDisplayString().compareTo(o2.getDisplayString());
        }
    });
    return templateProposals.toArray(new ICompletionProposal[templateProposals.size()]);
}
Also used : Position(org.eclipse.jface.text.Position) SQLTemplateCompletionProposal(org.jkiss.dbeaver.ui.editors.sql.templates.SQLTemplateCompletionProposal) Region(org.eclipse.jface.text.Region) SQLContext(org.jkiss.dbeaver.ui.editors.sql.templates.SQLContext) Template(org.eclipse.jface.text.templates.Template) NotNull(org.jkiss.code.NotNull)

Aggregations

Position (org.eclipse.jface.text.Position)1 Region (org.eclipse.jface.text.Region)1 Template (org.eclipse.jface.text.templates.Template)1 NotNull (org.jkiss.code.NotNull)1 SQLContext (org.jkiss.dbeaver.ui.editors.sql.templates.SQLContext)1 SQLTemplateCompletionProposal (org.jkiss.dbeaver.ui.editors.sql.templates.SQLTemplateCompletionProposal)1