Search in sources :

Example 1 with SQLIdentifierDetector

use of org.jkiss.dbeaver.ui.editors.sql.syntax.SQLIdentifierDetector in project dbeaver by serge-rider.

the class SQLEditorPropertyTester method test.

@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
    if (!(receiver instanceof SQLEditorBase)) {
        return false;
    }
    SQLEditor editor = (SQLEditor) receiver;
    final Control editorControl = editor.getEditorControl();
    if (editorControl == null) {
        return false;
    }
    boolean hasConnection = editor.getDataSourceContainer() != null;
    switch(property) {
        case PROP_CAN_EXECUTE:
            // Do not check hasActiveQuery - sometimes jface don't update action enablement after cursor change/typing
            return hasConnection;
        /* && (!"statement".equals(expectedValue) || editor.hasActiveQuery())*/
        case PROP_CAN_EXPLAIN:
            return hasConnection && DBUtils.getAdapter(DBCQueryPlanner.class, editor.getDataSource()) != null;
        case PROP_CAN_NAVIGATE:
            {
                // Check whether some word is under cursor
                ISelectionProvider selectionProvider = editor.getSelectionProvider();
                if (selectionProvider == null) {
                    return false;
                }
                ITextSelection selection = (ITextSelection) selectionProvider.getSelection();
                Document document = editor.getDocument();
                return selection != null && document != null && !new SQLIdentifierDetector(editor.getSyntaxManager().getStructSeparator(), editor.getSyntaxManager().getQuoteSymbol()).detectIdentifier(document, new Region(selection.getOffset(), selection.getLength())).isEmpty();
            }
        case PROP_CAN_EXPORT:
            return hasConnection && editor.hasActiveQuery();
        case PROP_HAS_SELECTION:
            {
                ISelection selection = editor.getSelectionProvider().getSelection();
                return selection instanceof ITextSelection && ((ITextSelection) selection).getLength() > 0;
            }
    }
    return false;
}
Also used : Control(org.eclipse.swt.widgets.Control) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ISelection(org.eclipse.jface.viewers.ISelection) SQLIdentifierDetector(org.jkiss.dbeaver.ui.editors.sql.syntax.SQLIdentifierDetector) Region(org.eclipse.jface.text.Region) Document(org.eclipse.jface.text.Document) ITextSelection(org.eclipse.jface.text.ITextSelection)

Example 2 with SQLIdentifierDetector

use of org.jkiss.dbeaver.ui.editors.sql.syntax.SQLIdentifierDetector in project dbeaver by dbeaver.

the class SQLEditorPropertyTester method test.

@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
    if (!(receiver instanceof SQLEditorBase)) {
        return false;
    }
    SQLEditor editor = (SQLEditor) receiver;
    final Control editorControl = editor.getEditorControl();
    if (editorControl == null) {
        return false;
    }
    boolean hasConnection = editor.getDataSourceContainer() != null;
    switch(property) {
        case PROP_CAN_EXECUTE:
            // Do not check hasActiveQuery - sometimes jface don't update action enablement after cursor change/typing
            return hasConnection;
        /* && (!"statement".equals(expectedValue) || editor.hasActiveQuery())*/
        case PROP_CAN_EXPLAIN:
            return hasConnection && DBUtils.getAdapter(DBCQueryPlanner.class, editor.getDataSource()) != null;
        case PROP_CAN_NAVIGATE:
            {
                // Check whether some word is under cursor
                ISelectionProvider selectionProvider = editor.getSelectionProvider();
                if (selectionProvider == null) {
                    return false;
                }
                ITextSelection selection = (ITextSelection) selectionProvider.getSelection();
                Document document = editor.getDocument();
                return selection != null && document != null && !new SQLIdentifierDetector(editor.getSyntaxManager().getStructSeparator(), editor.getSyntaxManager().getQuoteStrings()).detectIdentifier(document, new Region(selection.getOffset(), selection.getLength())).isEmpty();
            }
        case PROP_CAN_EXPORT:
            return hasConnection && editor.hasActiveQuery();
        case PROP_HAS_SELECTION:
            {
                ISelection selection = editor.getSelectionProvider().getSelection();
                return selection instanceof ITextSelection && ((ITextSelection) selection).getLength() > 0;
            }
    }
    return false;
}
Also used : Control(org.eclipse.swt.widgets.Control) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ISelection(org.eclipse.jface.viewers.ISelection) SQLIdentifierDetector(org.jkiss.dbeaver.ui.editors.sql.syntax.SQLIdentifierDetector) Region(org.eclipse.jface.text.Region) Document(org.eclipse.jface.text.Document) ITextSelection(org.eclipse.jface.text.ITextSelection)

Aggregations

Document (org.eclipse.jface.text.Document)2 ITextSelection (org.eclipse.jface.text.ITextSelection)2 Region (org.eclipse.jface.text.Region)2 ISelection (org.eclipse.jface.viewers.ISelection)2 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)2 Control (org.eclipse.swt.widgets.Control)2 SQLIdentifierDetector (org.jkiss.dbeaver.ui.editors.sql.syntax.SQLIdentifierDetector)2