Search in sources :

Example 16 with BaseTextEditor

use of org.jkiss.dbeaver.ui.editors.text.BaseTextEditor in project dbeaver by dbeaver.

the class AbstractCommentHandler method execute.

public final Object execute(ExecutionEvent event) throws ExecutionException {
    BaseTextEditor textEditor = BaseTextEditor.getTextEditor(HandlerUtil.getActiveEditor(event));
    if (textEditor != null) {
        ICommentsSupport commentsSupport = textEditor.getCommentsSupport();
        IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
        if (document != null && commentsSupport != null) {
            // get current text selection
            ISelectionProvider provider = textEditor.getSelectionProvider();
            if (provider != null) {
                ISelection selection = provider.getSelection();
                if (selection instanceof ITextSelection) {
                    ITextSelection textSelection = (ITextSelection) selection;
                    if (!textSelection.isEmpty()) {
                        try {
                            processAction(textEditor.getSelectionProvider(), commentsSupport, document, textSelection);
                        } catch (BadLocationException e) {
                            log.warn(e);
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ICommentsSupport(org.jkiss.dbeaver.ui.ICommentsSupport) ISelection(org.eclipse.jface.viewers.ISelection) BaseTextEditor(org.jkiss.dbeaver.ui.editors.text.BaseTextEditor) IDocument(org.eclipse.jface.text.IDocument) ITextSelection(org.eclipse.jface.text.ITextSelection) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 17 with BaseTextEditor

use of org.jkiss.dbeaver.ui.editors.text.BaseTextEditor in project dbeaver by dbeaver.

the class LoadTextFileHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    BaseTextEditor editor = BaseTextEditor.getTextEditor(HandlerUtil.getActiveEditor(event));
    if (editor == null) {
        return null;
    }
    editor.loadFromExternalFile();
    return null;
}
Also used : BaseTextEditor(org.jkiss.dbeaver.ui.editors.text.BaseTextEditor)

Aggregations

BaseTextEditor (org.jkiss.dbeaver.ui.editors.text.BaseTextEditor)17 BadLocationException (org.eclipse.jface.text.BadLocationException)4 IDocument (org.eclipse.jface.text.IDocument)4 ITextSelection (org.eclipse.jface.text.ITextSelection)4 ISelection (org.eclipse.jface.viewers.ISelection)4 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)4 StyledText (org.eclipse.swt.custom.StyledText)4 Action (org.eclipse.jface.action.Action)3 Separator (org.eclipse.jface.action.Separator)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 IAction (org.eclipse.jface.action.IAction)2 TextViewer (org.eclipse.jface.text.TextViewer)2 PartInitException (org.eclipse.ui.PartInitException)2 AbstractTextEditor (org.eclipse.ui.texteditor.AbstractTextEditor)2 DBException (org.jkiss.dbeaver.DBException)2 ICommentsSupport (org.jkiss.dbeaver.ui.ICommentsSupport)2