Search in sources :

Example 1 with DBSObjectReference

use of org.jkiss.dbeaver.model.struct.DBSObjectReference in project dbeaver by serge-rider.

the class SearchMetadataQuery method run.

@Override
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
    try {
        List<DBSObjectType> objectTypes = params.getObjectTypes();
        String objectNameMask = params.getObjectNameMask();
        if (params.getMatchType() == SearchMetadataConstants.MATCH_INDEX_STARTS_WITH) {
            if (!objectNameMask.endsWith("%")) {
                //$NON-NLS-1$
                //$NON-NLS-1$
                objectNameMask = objectNameMask + "%";
            }
        } else if (params.getMatchType() == SearchMetadataConstants.MATCH_INDEX_CONTAINS) {
            if (!objectNameMask.startsWith("%")) {
                //$NON-NLS-1$
                //$NON-NLS-1$
                objectNameMask = "%" + objectNameMask;
            }
            if (!objectNameMask.endsWith("%")) {
                //$NON-NLS-1$
                //$NON-NLS-1$
                objectNameMask = objectNameMask + "%";
            }
        }
        DBNModel navigatorModel = DBeaverCore.getInstance().getNavigatorModel();
        DBRProgressMonitor localMonitor = RuntimeUtils.makeMonitor(monitor);
        Collection<DBSObjectReference> objects = structureAssistant.findObjectsByMask(localMonitor, params.getParentObject(), objectTypes.toArray(new DBSObjectType[objectTypes.size()]), objectNameMask, params.isCaseSensitive(), true, params.getMaxResults());
        for (DBSObjectReference reference : objects) {
            if (monitor.isCanceled()) {
                break;
            }
            try {
                DBSObject object = reference.resolveObject(localMonitor);
                if (object != null) {
                    DBNNode node = navigatorModel.getNodeByObject(localMonitor, object, false);
                    if (node != null) {
                        searchResult.addObjects(Collections.singletonList(node));
                    }
                }
            } catch (DBException e) {
                log.error(e);
            }
        }
        return Status.OK_STATUS;
    } catch (DBException e) {
        return GeneralUtils.makeExceptionStatus(e);
    }
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBException(org.jkiss.dbeaver.DBException) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBSObjectType(org.jkiss.dbeaver.model.struct.DBSObjectType) DBSObjectReference(org.jkiss.dbeaver.model.struct.DBSObjectReference) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel)

Example 2 with DBSObjectReference

use of org.jkiss.dbeaver.model.struct.DBSObjectReference in project dbeaver by serge-rider.

the class SQLHyperlinkDetector method detectHyperlinks.

@Nullable
@Override
public synchronized IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
    this.contextInformer.searchInformation(region);
    if (!this.contextInformer.hasObjects()) {
        // Long task - just return no links for now
        return null;
    } else {
        // Create hyperlinks based on references
        final SQLIdentifierDetector.WordRegion wordRegion = this.contextInformer.getWordRegion();
        final IRegion hlRegion = new Region(wordRegion.identStart, wordRegion.identEnd - wordRegion.identStart);
        final List<DBSObjectReference> references = this.contextInformer.getObjectReferences();
        IHyperlink[] links = new IHyperlink[references.size()];
        for (int i = 0, objectsSize = references.size(); i < objectsSize; i++) {
            links[i] = new EntityHyperlink(contextInformer.getEditor().getSite(), references.get(i), hlRegion);
        }
        return links;
    }
}
Also used : IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) DBSObjectReference(org.jkiss.dbeaver.model.struct.DBSObjectReference) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) IRegion(org.eclipse.jface.text.IRegion) EntityHyperlink(org.jkiss.dbeaver.ui.editors.entity.EntityHyperlink) Nullable(org.jkiss.code.Nullable)

Example 3 with DBSObjectReference

use of org.jkiss.dbeaver.model.struct.DBSObjectReference in project dbeaver by serge-rider.

the class SQLInformationProvider method getInformation2.

@Override
public Object getInformation2(ITextViewer textViewer, IRegion subject) {
    if (implementation != null) {
        Object s = implementation.getHoverInfo2(textViewer, subject);
        if (s != null) {
            return s;
        }
    }
    //SQLCompletionProposal proposal = new SQLCompletionProposal();
    SQLContextInformer informer = new SQLContextInformer(editor, editor.getSyntaxManager());
    informer.searchInformation(subject);
    DBSObject object = null;
    if (informer.hasObjects()) {
        // Make object description
        DBRProgressMonitor monitor = VoidProgressMonitor.INSTANCE;
        final DBSObjectReference objectRef = informer.getObjectReferences().get(0);
        try {
            object = objectRef.resolveObject(monitor);
        } catch (DBException e) {
            // Can't resolve
            return e.getMessage();
        }
    } else if (ArrayUtils.isEmpty(informer.getKeywords())) {
        return null;
    }
    return SQLContextInformer.readAdditionalProposalInfo(null, editor.getDataSource(), object, informer.getKeywords(), informer.getKeywordType());
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBException(org.jkiss.dbeaver.DBException) DBSObjectReference(org.jkiss.dbeaver.model.struct.DBSObjectReference) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)

Aggregations

DBSObjectReference (org.jkiss.dbeaver.model.struct.DBSObjectReference)3 DBException (org.jkiss.dbeaver.DBException)2 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)2 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)2 IRegion (org.eclipse.jface.text.IRegion)1 Region (org.eclipse.jface.text.Region)1 IHyperlink (org.eclipse.jface.text.hyperlink.IHyperlink)1 Nullable (org.jkiss.code.Nullable)1 DBNModel (org.jkiss.dbeaver.model.navigator.DBNModel)1 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)1 DBSObjectType (org.jkiss.dbeaver.model.struct.DBSObjectType)1 EntityHyperlink (org.jkiss.dbeaver.ui.editors.entity.EntityHyperlink)1