@Override
    public void insertTemplate(Template template, IDocument document)
    {
        if (!sqlEditor.validateEditorInputState())
            return;

        ISourceViewer contextViewer = sqlEditor.getViewer();
        ITextSelection textSelection = (ITextSelection) contextViewer.getSelectionProvider().getSelection();
        if (!isValidTemplate(document, template, textSelection.getOffset(), textSelection.getLength()))
            return;
        beginCompoundChange(contextViewer);
        /*
           * The Editor checks whether a completion for a word exists before it allows for the template to be
           * applied. We pickup the current text at the selection position and replace it with the first char
           * of the template name for this to succeed.
           * Another advantage by this method is that the template replaces the selected text provided the
           * selection by itself is not used in the template pattern.
           */
        String savedText;
        try {
            savedText = document.get(textSelection.getOffset(), textSelection.getLength());
            if (savedText.length() == 0) {
                String prefix = getIdentifierPart(document, template, textSelection.getOffset(), textSelection.getLength());
                if (prefix.length() > 0 && !template.getName().startsWith(prefix)) {
                    return;
                }
                if (prefix.length() > 0) {
                    contextViewer.setSelectedRange(textSelection.getOffset() - prefix.length(), prefix.length());
                    textSelection = (ITextSelection) contextViewer.getSelectionProvider().getSelection();
                }
            }
            document.replace(textSelection.getOffset(), textSelection.getLength(), template.getName().substring(0, 1));
        } catch (BadLocationException e) {
            endCompoundChange(contextViewer);
            return;
        }
        //Position position = new Position(textSelection.getOffset() + 1, 0);
        Region region = new Region(textSelection.getOffset(), 0);
        textSelection = new TextSelection(textSelection.getOffset(), 1);

        contextViewer.getSelectionProvider().setSelection(textSelection);
        SQLContext context = getContext(document, template, textSelection.getOffset(), textSelection.getLength());

        context.setVariable(GlobalTemplateVariables.SELECTION, savedText);
        if (context.getKey().length() == 0) {
            try {
                document.replace(textSelection.getOffset(), 1, savedText);
            } catch (BadLocationException e) {
                endCompoundChange(contextViewer);
                return;
            }
        }
        SQLTemplateCompletionProposal proposal = new SQLTemplateCompletionProposal(template, context, region, null);
        sqlEditor.getSite().getPage().activate(sqlEditor);
        proposal.apply(sqlEditor.getViewer(), ' ', 0, region.getOffset());
        final Point selection = proposal.getSelection(document);
        if (selection != null) {
            sqlEditor.getViewer().setSelectedRange(selection.x, selection.y);
            sqlEditor.getViewer().revealRange(selection.x, selection.y);
        }
        endCompoundChange(contextViewer);
    }
Create a new AbstractTemplatesPage for the JavaEditor

@param sqlEditor the java editor
plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/templates/SQLTemplatesPage.java