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;
}
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;
}
Aggregations