Search in sources :

Example 1 with SystemJob

use of org.jkiss.dbeaver.model.runtime.SystemJob in project dbeaver by serge-rider.

the class ResultSetFilterPanel method getProposals.

@Override
public IContentProposal[] getProposals(String contents, int position) {
    if (!viewer.getPreferenceStore().getBoolean(ResultSetPreferences.RESULT_SET_FILTER_AUTO_COMPLETE_PROPOSIAL)) {
        return null;
    }
    SQLSyntaxManager syntaxManager = new SQLSyntaxManager();
    DBPDataSource dataSource = viewer.getDataSource();
    if (dataSource != null) {
        syntaxManager.init(dataSource);
    }
    SQLWordPartDetector wordDetector = new SQLWordPartDetector(new Document(contents), syntaxManager, position);
    String word = wordDetector.getFullWord();
    final List<IContentProposal> proposals = new ArrayList<>();
    if (CommonUtils.isEmptyTrimmed(word))
        word = contents;
    word = word.toLowerCase(Locale.ENGLISH);
    String attrName = word;
    final DBRRunnableWithProgress reader = monitor -> {
        DBDAttributeBinding[] attributes = viewer.getModel().getAttributes();
        for (DBDAttributeBinding attribute : attributes) {
            if (attribute.isCustom()) {
                continue;
            }
            final String name = DBUtils.getUnQuotedIdentifier(attribute.getDataSource(), attribute.getName());
            if (CommonUtils.isEmpty(attrName) || name.toLowerCase(Locale.ENGLISH).startsWith(attrName)) {
                final String content = DBUtils.getQuotedIdentifier(attribute) + " ";
                proposals.add(new ContentProposalExt(content, attribute.getName(), DBInfoUtils.makeObjectDescription(monitor, attribute.getAttribute(), false), content.length(), DBValueFormatting.getObjectImage(attribute)));
            }
        }
    };
    SystemJob searchJob = new SystemJob("Extract attribute proposals", reader);
    searchJob.schedule();
    UIUtils.waitJobCompletion(searchJob);
    String[] filterKeywords = { SQLConstants.KEYWORD_AND, SQLConstants.KEYWORD_OR, SQLConstants.KEYWORD_IS, SQLConstants.KEYWORD_NOT, SQLConstants.KEYWORD_NULL };
    for (String kw : filterKeywords) {
        if (attrName.isEmpty() || kw.startsWith(attrName.toUpperCase())) {
            if (dataSource != null) {
                kw = dataSource.getSQLDialect().storesUnquotedCase().transform(kw);
            }
            proposals.add(new ContentProposal(kw + " ", kw + ": SQL expression keyword"));
        }
    }
    return proposals.toArray(new IContentProposal[0]);
}
Also used : ResultSetHandlerMain(org.jkiss.dbeaver.ui.controls.resultset.handler.ResultSetHandlerMain) org.jkiss.dbeaver.ui(org.jkiss.dbeaver.ui) StyledText(org.eclipse.swt.custom.StyledText) IWorkbenchCommandConstants(org.eclipse.ui.IWorkbenchCommandConstants) DBDDataFilter(org.jkiss.dbeaver.model.data.DBDDataFilter) ContentProposal(org.eclipse.jface.fieldassist.ContentProposal) Matcher(java.util.regex.Matcher) PartInitException(org.eclipse.ui.PartInitException) Locale(java.util.Locale) ContentProposalAdapter(org.eclipse.jface.fieldassist.ContentProposalAdapter) IContentProposal(org.eclipse.jface.fieldassist.IContentProposal) SystemJob(org.jkiss.dbeaver.model.runtime.SystemJob) IAdaptable(org.eclipse.core.runtime.IAdaptable) CommonUtils(org.jkiss.utils.CommonUtils) org.eclipse.swt.graphics(org.eclipse.swt.graphics) DBDAttributeConstraint(org.jkiss.dbeaver.model.data.DBDAttributeConstraint) StyledTextUtils(org.jkiss.dbeaver.ui.controls.StyledTextUtils) Collection(java.util.Collection) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) DBStyles(org.jkiss.dbeaver.ui.css.DBStyles) ContentAssistUtils(org.jkiss.dbeaver.ui.contentassist.ContentAssistUtils) List(java.util.List) DBException(org.jkiss.dbeaver.DBException) SWT(org.eclipse.swt.SWT) SQLSyntaxManager(org.jkiss.dbeaver.model.sql.SQLSyntaxManager) SQLUtils(org.jkiss.dbeaver.model.sql.SQLUtils) Pattern(java.util.regex.Pattern) SQLWordPartDetector(org.jkiss.dbeaver.model.sql.parser.SQLWordPartDetector) ContentProposalExt(org.jkiss.dbeaver.ui.contentassist.ContentProposalExt) DBWorkbench(org.jkiss.dbeaver.runtime.DBWorkbench) SQLConstants(org.jkiss.dbeaver.model.sql.SQLConstants) Nullable(org.jkiss.code.Nullable) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) NotNull(org.jkiss.code.NotNull) UIServiceSQL(org.jkiss.dbeaver.runtime.ui.UIServiceSQL) ArrayList(java.util.ArrayList) Document(org.eclipse.jface.text.Document) Log(org.jkiss.dbeaver.Log) ResultSetMessages(org.jkiss.dbeaver.ui.controls.resultset.internal.ResultSetMessages) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) org.jkiss.dbeaver.model(org.jkiss.dbeaver.model) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) org.eclipse.swt.events(org.eclipse.swt.events) IContentProposalProvider(org.eclipse.jface.fieldassist.IContentProposalProvider) IUndoManager(org.eclipse.jface.text.IUndoManager) TextEditorUtils(org.jkiss.dbeaver.ui.editors.TextEditorUtils) org.eclipse.swt.widgets(org.eclipse.swt.widgets) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) TextViewerUndoManager(org.eclipse.jface.text.TextViewerUndoManager) CSSUtils(org.jkiss.dbeaver.ui.css.CSSUtils) TextViewer(org.eclipse.jface.text.TextViewer) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) GridLayout(org.eclipse.swt.layout.GridLayout) SQLWordPartDetector(org.jkiss.dbeaver.model.sql.parser.SQLWordPartDetector) ContentProposalExt(org.jkiss.dbeaver.ui.contentassist.ContentProposalExt) ArrayList(java.util.ArrayList) Document(org.eclipse.jface.text.Document) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) SystemJob(org.jkiss.dbeaver.model.runtime.SystemJob) ContentProposal(org.eclipse.jface.fieldassist.ContentProposal) IContentProposal(org.eclipse.jface.fieldassist.IContentProposal) IContentProposal(org.eclipse.jface.fieldassist.IContentProposal) SQLSyntaxManager(org.jkiss.dbeaver.model.sql.SQLSyntaxManager) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)

Example 2 with SystemJob

use of org.jkiss.dbeaver.model.runtime.SystemJob in project dbeaver by serge-rider.

the class SQLContextInformer method makeObjectDescription.

public static String makeObjectDescription(@Nullable DBRProgressMonitor monitor, DBPNamedObject object, boolean html) {
    final PropertiesReader reader = new PropertiesReader(object, html);
    if (monitor == null) {
        SystemJob searchJob = new SystemJob("Extract object properties info", reader);
        searchJob.schedule();
        UIUtils.waitJobCompletion(searchJob);
    } else {
        reader.run(monitor);
    }
    return reader.getPropertiesInfo();
}
Also used : SystemJob(org.jkiss.dbeaver.model.runtime.SystemJob)

Example 3 with SystemJob

use of org.jkiss.dbeaver.model.runtime.SystemJob in project dbeaver by dbeaver.

the class SQLContextInformer method makeObjectDescription.

public static String makeObjectDescription(@Nullable DBRProgressMonitor monitor, DBPNamedObject object, boolean html) {
    final PropertiesReader reader = new PropertiesReader(object, html);
    if (monitor == null) {
        SystemJob searchJob = new SystemJob("Extract object properties info", reader);
        searchJob.schedule();
        UIUtils.waitJobCompletion(searchJob);
    } else {
        reader.run(monitor);
    }
    return reader.getPropertiesInfo();
}
Also used : SystemJob(org.jkiss.dbeaver.model.runtime.SystemJob)

Example 4 with SystemJob

use of org.jkiss.dbeaver.model.runtime.SystemJob in project dbeaver by dbeaver.

the class ResultSetFilterPanel method getProposals.

@Override
public IContentProposal[] getProposals(String contents, int position) {
    if (!viewer.getPreferenceStore().getBoolean(ResultSetPreferences.RESULT_SET_FILTER_AUTO_COMPLETE_PROPOSIAL)) {
        return null;
    }
    SQLSyntaxManager syntaxManager = new SQLSyntaxManager();
    DBPDataSource dataSource = viewer.getDataSource();
    if (dataSource != null) {
        syntaxManager.init(dataSource);
    }
    SQLWordPartDetector wordDetector = new SQLWordPartDetector(new Document(contents), syntaxManager, position);
    String word = wordDetector.getFullWord();
    final List<IContentProposal> proposals = new ArrayList<>();
    if (CommonUtils.isEmptyTrimmed(word))
        word = contents;
    word = word.toLowerCase(Locale.ENGLISH);
    String attrName = word;
    final DBRRunnableWithProgress reader = monitor -> {
        DBDAttributeBinding[] attributes = viewer.getModel().getAttributes();
        for (DBDAttributeBinding attribute : attributes) {
            if (attribute.isCustom()) {
                continue;
            }
            final String name = DBUtils.getUnQuotedIdentifier(attribute.getDataSource(), attribute.getName());
            if (CommonUtils.isEmpty(attrName) || name.toLowerCase(Locale.ENGLISH).startsWith(attrName)) {
                final String content = DBUtils.getQuotedIdentifier(attribute) + " ";
                proposals.add(new ContentProposalExt(content, attribute.getName(), DBInfoUtils.makeObjectDescription(monitor, attribute.getAttribute(), false), content.length(), DBValueFormatting.getObjectImage(attribute)));
            }
        }
    };
    SystemJob searchJob = new SystemJob("Extract attribute proposals", reader);
    searchJob.schedule();
    UIUtils.waitJobCompletion(searchJob);
    String[] filterKeywords = { SQLConstants.KEYWORD_AND, SQLConstants.KEYWORD_OR, SQLConstants.KEYWORD_IS, SQLConstants.KEYWORD_NOT, SQLConstants.KEYWORD_NULL };
    for (String kw : filterKeywords) {
        if (attrName.isEmpty() || kw.startsWith(attrName.toUpperCase())) {
            if (dataSource != null) {
                kw = dataSource.getSQLDialect().storesUnquotedCase().transform(kw);
            }
            proposals.add(new ContentProposal(kw + " ", kw + ": SQL expression keyword"));
        }
    }
    return proposals.toArray(new IContentProposal[0]);
}
Also used : ResultSetHandlerMain(org.jkiss.dbeaver.ui.controls.resultset.handler.ResultSetHandlerMain) org.jkiss.dbeaver.ui(org.jkiss.dbeaver.ui) StyledText(org.eclipse.swt.custom.StyledText) IWorkbenchCommandConstants(org.eclipse.ui.IWorkbenchCommandConstants) DBDDataFilter(org.jkiss.dbeaver.model.data.DBDDataFilter) ContentProposal(org.eclipse.jface.fieldassist.ContentProposal) Matcher(java.util.regex.Matcher) PartInitException(org.eclipse.ui.PartInitException) Locale(java.util.Locale) ContentProposalAdapter(org.eclipse.jface.fieldassist.ContentProposalAdapter) IContentProposal(org.eclipse.jface.fieldassist.IContentProposal) SystemJob(org.jkiss.dbeaver.model.runtime.SystemJob) IAdaptable(org.eclipse.core.runtime.IAdaptable) CommonUtils(org.jkiss.utils.CommonUtils) org.eclipse.swt.graphics(org.eclipse.swt.graphics) DBDAttributeConstraint(org.jkiss.dbeaver.model.data.DBDAttributeConstraint) StyledTextUtils(org.jkiss.dbeaver.ui.controls.StyledTextUtils) Collection(java.util.Collection) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) DBStyles(org.jkiss.dbeaver.ui.css.DBStyles) ContentAssistUtils(org.jkiss.dbeaver.ui.contentassist.ContentAssistUtils) List(java.util.List) DBException(org.jkiss.dbeaver.DBException) SWT(org.eclipse.swt.SWT) SQLSyntaxManager(org.jkiss.dbeaver.model.sql.SQLSyntaxManager) SQLUtils(org.jkiss.dbeaver.model.sql.SQLUtils) Pattern(java.util.regex.Pattern) SQLWordPartDetector(org.jkiss.dbeaver.model.sql.parser.SQLWordPartDetector) ContentProposalExt(org.jkiss.dbeaver.ui.contentassist.ContentProposalExt) DBWorkbench(org.jkiss.dbeaver.runtime.DBWorkbench) SQLConstants(org.jkiss.dbeaver.model.sql.SQLConstants) Nullable(org.jkiss.code.Nullable) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) NotNull(org.jkiss.code.NotNull) UIServiceSQL(org.jkiss.dbeaver.runtime.ui.UIServiceSQL) ArrayList(java.util.ArrayList) Document(org.eclipse.jface.text.Document) Log(org.jkiss.dbeaver.Log) ResultSetMessages(org.jkiss.dbeaver.ui.controls.resultset.internal.ResultSetMessages) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) org.jkiss.dbeaver.model(org.jkiss.dbeaver.model) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) org.eclipse.swt.events(org.eclipse.swt.events) IContentProposalProvider(org.eclipse.jface.fieldassist.IContentProposalProvider) IUndoManager(org.eclipse.jface.text.IUndoManager) TextEditorUtils(org.jkiss.dbeaver.ui.editors.TextEditorUtils) org.eclipse.swt.widgets(org.eclipse.swt.widgets) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) TextViewerUndoManager(org.eclipse.jface.text.TextViewerUndoManager) CSSUtils(org.jkiss.dbeaver.ui.css.CSSUtils) TextViewer(org.eclipse.jface.text.TextViewer) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) GridLayout(org.eclipse.swt.layout.GridLayout) SQLWordPartDetector(org.jkiss.dbeaver.model.sql.parser.SQLWordPartDetector) ContentProposalExt(org.jkiss.dbeaver.ui.contentassist.ContentProposalExt) ArrayList(java.util.ArrayList) Document(org.eclipse.jface.text.Document) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) SystemJob(org.jkiss.dbeaver.model.runtime.SystemJob) ContentProposal(org.eclipse.jface.fieldassist.ContentProposal) IContentProposal(org.eclipse.jface.fieldassist.IContentProposal) IContentProposal(org.eclipse.jface.fieldassist.IContentProposal) SQLSyntaxManager(org.jkiss.dbeaver.model.sql.SQLSyntaxManager) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)

Aggregations

SystemJob (org.jkiss.dbeaver.model.runtime.SystemJob)4 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 Locale (java.util.Locale)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 IAdaptable (org.eclipse.core.runtime.IAdaptable)2 ContentProposal (org.eclipse.jface.fieldassist.ContentProposal)2 ContentProposalAdapter (org.eclipse.jface.fieldassist.ContentProposalAdapter)2 IContentProposal (org.eclipse.jface.fieldassist.IContentProposal)2 IContentProposalProvider (org.eclipse.jface.fieldassist.IContentProposalProvider)2 Document (org.eclipse.jface.text.Document)2 IUndoManager (org.eclipse.jface.text.IUndoManager)2 TextViewer (org.eclipse.jface.text.TextViewer)2 TextViewerUndoManager (org.eclipse.jface.text.TextViewerUndoManager)2 SWT (org.eclipse.swt.SWT)2 StyledText (org.eclipse.swt.custom.StyledText)2 org.eclipse.swt.events (org.eclipse.swt.events)2 org.eclipse.swt.graphics (org.eclipse.swt.graphics)2