Search in sources :

Example 1 with IHyperlink

use of org.eclipse.jface.text.hyperlink.IHyperlink in project dbeaver by serge-rider.

the class NavigateObjectHandler method getCurrentHyperlink.

private IHyperlink getCurrentHyperlink(SQLEditorBase editor) {
    SQLHyperlinkDetector hyperlinkDetector = new SQLHyperlinkDetector(editor, editor.getSyntaxManager());
    ITextSelection selection = (ITextSelection) editor.getTextViewer().getSelection();
    IRegion curRegion = new Region(selection.getOffset(), 0);
    IHyperlink[] hyperLinks = hyperlinkDetector.detectHyperlinks(editor.getTextViewer(), curRegion, false);
    return ArrayUtils.isEmpty(hyperLinks) ? null : hyperLinks[0];
}
Also used : SQLHyperlinkDetector(org.jkiss.dbeaver.ui.editors.sql.syntax.SQLHyperlinkDetector) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) ITextSelection(org.eclipse.jface.text.ITextSelection) IRegion(org.eclipse.jface.text.IRegion)

Example 2 with IHyperlink

use of org.eclipse.jface.text.hyperlink.IHyperlink in project KaiZen-OpenAPI-Editor by RepreZen.

the class JsonReferenceHyperlinkDetector method doDetect.

@Override
protected IHyperlink[] doDetect(JsonDocument doc, ITextViewer viewer, HyperlinkInfo info, JsonPointer pointer) {
    URI baseURI = getBaseURI();
    AbstractNode node = doc.getModel().find(pointer);
    JsonReference reference = getFactory().createSimpleReference(getBaseURI(), node);
    if (reference == null) {
        reference = getFactory().create(node);
    }
    if (reference.isInvalid() || reference.isMissing(doc, getBaseURI())) {
        return null;
    }
    if (reference.isLocal()) {
        IRegion target = doc.getRegion(reference.getPointer());
        if (target == null) {
            return null;
        }
        return new IHyperlink[] { new SwaggerHyperlink(reference.getPointer().toString(), viewer, info.region, target) };
    } else {
        URI resolved;
        try {
            resolved = baseURI.resolve(reference.getUri());
        } catch (IllegalArgumentException e) {
            // the given string violates RFC 2396
            return null;
        }
        IFile file = DocumentUtils.getWorkspaceFile(resolved);
        if (file != null && file.exists()) {
            return new IHyperlink[] { createFileHyperlink(info.region, info.text, file, reference.getPointer()) };
        }
    }
    return null;
}
Also used : JsonReference(com.reprezen.swagedit.core.json.references.JsonReference) IFile(org.eclipse.core.resources.IFile) AbstractNode(com.reprezen.swagedit.core.model.AbstractNode) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) URI(java.net.URI) IRegion(org.eclipse.jface.text.IRegion)

Example 3 with IHyperlink

use of org.eclipse.jface.text.hyperlink.IHyperlink in project KaiZen-OpenAPI-Editor by RepreZen.

the class DefinitionHyperlinkDetector method doDetect.

@Override
protected IHyperlink[] doDetect(JsonDocument doc, ITextViewer viewer, HyperlinkInfo info, JsonPointer pointer) {
    JsonPointer targetPath;
    if (pointer.toString().matches(REQUIRED_PATTERN)) {
        targetPath = getRequiredPropertyPath(doc, info, pointer);
    } else {
        targetPath = getTagDefinitionPath(doc, info, pointer);
    }
    if (targetPath == null) {
        return null;
    }
    IRegion target = doc.getRegion(targetPath);
    if (target == null) {
        return null;
    }
    return new IHyperlink[] { new SwaggerHyperlink(info.text, viewer, info.region, target) };
}
Also used : SwaggerHyperlink(com.reprezen.swagedit.core.hyperlinks.SwaggerHyperlink) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) JsonPointer(com.fasterxml.jackson.core.JsonPointer) IRegion(org.eclipse.jface.text.IRegion)

Example 4 with IHyperlink

use of org.eclipse.jface.text.hyperlink.IHyperlink 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 5 with IHyperlink

use of org.eclipse.jface.text.hyperlink.IHyperlink in project dbeaver by serge-rider.

the class NavigateObjectHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    if (activeEditor instanceof SQLEditorBase) {
        SQLEditorBase editor = (SQLEditorBase) activeEditor;
        IHyperlink hyperlink = getCurrentHyperlink(editor);
        if (hyperlink != null) {
            IRegion selRegion2 = hyperlink.getHyperlinkRegion();
            editor.getTextViewer().setSelectedRange(selRegion2.getOffset(), selRegion2.getLength());
            hyperlink.open();
        }
    }
    return null;
}
Also used : SQLEditorBase(org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) IEditorPart(org.eclipse.ui.IEditorPart) IRegion(org.eclipse.jface.text.IRegion)

Aggregations

IRegion (org.eclipse.jface.text.IRegion)6 IHyperlink (org.eclipse.jface.text.hyperlink.IHyperlink)6 Region (org.eclipse.jface.text.Region)3 JsonPointer (com.fasterxml.jackson.core.JsonPointer)2 SwaggerHyperlink (com.reprezen.swagedit.core.hyperlinks.SwaggerHyperlink)2 JsonReference (com.reprezen.swagedit.core.json.references.JsonReference)1 AbstractNode (com.reprezen.swagedit.core.model.AbstractNode)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 IFile (org.eclipse.core.resources.IFile)1 ITextSelection (org.eclipse.jface.text.ITextSelection)1 IEditorPart (org.eclipse.ui.IEditorPart)1 Nullable (org.jkiss.code.Nullable)1 DBSObjectReference (org.jkiss.dbeaver.model.struct.DBSObjectReference)1 EntityHyperlink (org.jkiss.dbeaver.ui.editors.entity.EntityHyperlink)1 SQLEditorBase (org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase)1 SQLHyperlinkDetector (org.jkiss.dbeaver.ui.editors.sql.syntax.SQLHyperlinkDetector)1