下面列出了怎么用org.eclipse.jface.text.hyperlink.IHyperlinkDetector的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
List<IHyperlinkDetector> detectors = new LinkedList<IHyperlinkDetector>();
IHyperlinkDetector[] inheritedDetectors = super.getHyperlinkDetectors(sourceViewer);
if (inheritedDetectors != null) {
for (final IHyperlinkDetector detector : inheritedDetectors) {
detectors.add(new IHyperlinkDetector() {
@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region,
boolean canShowMultipleHyperlinks) {
try {
IHyperlink[] result = detector.detectHyperlinks(textViewer, region, canShowMultipleHyperlinks);
// fail safe detector: don't return an empty array
// but null (see org.eclipse.jface.text.hyperlink.HyperlinkManager.findHyperlinks(IRegion))
if (result != null && result.length == 0) {
return null;
}
return result;
}
catch (Throwable e) {
// fail safe hyperlink detector - prevent others
// from failing
}
return null;
}
});
}
}
detectors.add(detector);
return detectors.toArray(new IHyperlinkDetector[detectors.size()]);
}
public Object execute(ExecutionEvent event) throws ExecutionException
{
final IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
final TLAEditor tlaEditor = activeEditor.getAdapter(TLAEditor.class);
final ITextSelection selection = (ITextSelection) tlaEditor.getSelectionProvider().getSelection();
final IRegion region = new Region(selection.getOffset(), selection.getLength());
// get the detectors
final ISourceViewer internalSourceViewer = tlaEditor.getSourceViewer();
final IHyperlinkDetector[] hyperlinkDetectors = tlaEditor.getSourceViewerConfiguration()
.getHyperlinkDetectors(internalSourceViewer);
if (hyperlinkDetectors != null)
{
for (int i = 0; i < hyperlinkDetectors.length; i++)
{
// detect
final IHyperlink[] hyperlinks = hyperlinkDetectors[i].detectHyperlinks(internalSourceViewer, region,
false);
if (hyperlinks != null && hyperlinks.length > 0)
{
// open
final IHyperlink hyperlink = hyperlinks[0];
hyperlink.open();
break;
}
}
}
return null;
}
@Override
public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
return new IHyperlinkDetector[] { new URLHyperlinkDetector(), //
new SwaggerReferenceHyperlinkDetector(), //
new PathParamHyperlinkDetector(), //
new DefinitionHyperlinkDetector() };
}
@Override
public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
return new IHyperlinkDetector[] { new URLHyperlinkDetector(), //
new PathParamHyperlinkDetector(), //
new DefinitionHyperlinkDetector(), //
new OpenApi3ReferenceHyperlinkDetector(), //
new SecuritySchemeHyperlinkDetector(), //
new LinkOperationHyperlinkDetector(), //
new LinkOperationRefHyperlinkDetector() };
}
/** Custom IHyperlinkDetector. */
@Override
public Class<? extends IHyperlinkDetector> bindIHyperlinkDetector() {
return N4JSHyperlinkDetector.class;
}
@Override
public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
return null;
}
public Class<? extends IHyperlinkDetector> bindIHyperlinkDetector() {
return DefaultHyperlinkDetector.class;
}
public void setDetector(IHyperlinkDetector detector) {
this.detector = detector;
}
public IHyperlinkDetector getDetector() {
return detector;
}
@Override
public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
return new IHyperlinkDetector[]{new ImpexTypeHyperlinkDetector()};
}
@Override
public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
return new IHyperlinkDetector[] { new URLHyperlinkDetector() };
}
@Override
public Class<? extends IHyperlinkDetector> bindIHyperlinkDetector() {
return GamlHyperlinkDetector.class;
}
@Override
public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
return null;
}
public void setHyperlinkDetectors(IHyperlinkDetector[] hyperlinkDetectors, int eventStateMask) {
viewer.setHyperlinkDetectors(hyperlinkDetectors, eventStateMask);
}
@Override
public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
return null;
}