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