use of org.eclipse.jface.text.hyperlink.URLHyperlink in project eclipse.platform.text by eclipse.
the class ProjectHyperlinkDetector method detectHyperlinks.
@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
ITextEditor textEditor = getAdapter(ITextEditor.class);
IResource resource = textEditor.getEditorInput().getAdapter(IResource.class);
String fileLocation = TextProcessor.process(IDEResourceInfoUtils.getLocationText(resource));
ShowInSystemExplorerHyperlink showInSystemExplorerHyperlink = new ShowInSystemExplorerHyperlink(fileLocation, region);
URLHyperlink fileUrlHyperlink = new URLHyperlink(region, fileLocation);
URLHyperlink projectFileHelpLink = new URLHyperlink(region, "https://help.eclipse.org/oxygen/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fmisc%2Fproject_description_file.html");
return new IHyperlink[] { showInSystemExplorerHyperlink, fileUrlHyperlink, projectFileHelpLink };
}
use of org.eclipse.jface.text.hyperlink.URLHyperlink in project linuxtools by eclipse.
the class URLHyperlinkWithMacroDetector method detectHyperlinks.
@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
if (specfile == null) {
SpecfileEditor a = this.getAdapter(SpecfileEditor.class);
if (a != null) {
specfile = a.getSpecfile();
} else {
return null;
}
}
IHyperlink[] returned = super.detectHyperlinks(textViewer, region, canShowMultipleHyperlinks);
if (returned != null && returned.length > 0) {
IHyperlink hyperlink = returned[0];
if (hyperlink instanceof URLHyperlink) {
URLHyperlink urlHyperlink = (URLHyperlink) hyperlink;
String newURLString = UiUtils.resolveDefines(specfile, urlHyperlink.getURLString());
return new IHyperlink[] { new URLHyperlink(urlHyperlink.getHyperlinkRegion(), newURLString) };
}
}
return returned;
}
use of org.eclipse.jface.text.hyperlink.URLHyperlink in project mylyn.docs by eclipse.
the class MarkupEditor method createSourceViewer.
@Override
protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
sourceViewerConfiguration.initializeDefaultFonts();
tabFolder = new CTabFolder(parent, SWT.BOTTOM);
{
sourceTab = new CTabItem(tabFolder, SWT.NONE);
updateSourceTabLabel();
viewer = new MarkupProjectionViewer(tabFolder, ruler, getOverviewRuler(), isOverviewRulerVisible(), styles | SWT.WRAP);
sourceTab.setControl(((Viewer) viewer).getControl());
tabFolder.setSelection(sourceTab);
}
try {
previewTab = new CTabItem(tabFolder, SWT.NONE);
previewTab.setText(Messages.MarkupEditor_preview);
previewTab.setToolTipText(Messages.MarkupEditor_preview_tooltip);
browser = new Browser(tabFolder, SWT.NONE);
// bug 260479: open hyperlinks in a browser
browser.addLocationListener(new LocationListener() {
public void changed(LocationEvent event) {
event.doit = false;
}
public void changing(LocationEvent event) {
// if it looks like an absolute URL
if (event.location.matches("([a-zA-Z]{3,8})://?.*")) {
// $NON-NLS-1$
// workaround for browser problem (bug 262043)
// $NON-NLS-1$
int idxOfSlashHash = event.location.indexOf("/#");
if (idxOfSlashHash != -1) {
// allow javascript-based scrolling to work
if (!event.location.startsWith("file:///#")) {
// $NON-NLS-1$
event.doit = false;
}
return;
}
// workaround end
event.doit = false;
try {
PlatformUI.getWorkbench().getBrowserSupport().createBrowser(// $NON-NLS-1$
"org.eclipse.ui.browser").openURL(new URL(event.location));
} catch (Exception e) {
new URLHyperlink(new Region(0, 1), event.location).open();
}
}
}
});
previewTab.setControl(browser);
} catch (SWTError e) {
// disable preview, the exception is probably due to the internal browser not being available
if (previewTab != null) {
previewTab.dispose();
previewTab = null;
}
logPreviewTabUnavailable(e);
}
tabFolder.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent selectionevent) {
widgetSelected(selectionevent);
}
public void widgetSelected(SelectionEvent selectionevent) {
if (isShowingPreview()) {
updatePreview();
}
}
});
viewer.getTextWidget().addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
public void widgetSelected(SelectionEvent e) {
updateOutlineSelection();
}
});
viewer.getTextWidget().addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (isRelevantKeyCode(e.keyCode)) {
updateOutlineSelection();
}
}
private boolean isRelevantKeyCode(int keyCode) {
// for some reason not all key presses result in a selection change
switch(keyCode) {
case SWT.ARROW_DOWN:
case SWT.ARROW_LEFT:
case SWT.ARROW_RIGHT:
case SWT.ARROW_UP:
case SWT.PAGE_DOWN:
case SWT.PAGE_UP:
return true;
}
return false;
}
});
viewer.getTextWidget().addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
updateOutlineSelection();
}
});
IFocusService focusService = PlatformUI.getWorkbench().getService(IFocusService.class);
if (focusService != null) {
focusService.addFocusTracker(viewer.getTextWidget(), MarkupEditor.EDITOR_SOURCE_VIEWER);
}
viewer.getTextWidget().setData(MarkupLanguage.class.getName(), getMarkupLanguage());
viewer.getTextWidget().setData(ISourceViewer.class.getName(), viewer);
getSourceViewerDecorationSupport(viewer);
updateDocument();
if (preferencesListener == null) {
preferencesListener = new IPropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
if (viewer.getTextWidget() == null || viewer.getTextWidget().isDisposed()) {
return;
}
if (isFontPreferenceChange(event)) {
viewer.getTextWidget().getDisplay().asyncExec(new Runnable() {
public void run() {
reloadPreferences();
}
});
}
}
};
WikiTextUiPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(preferencesListener);
}
return viewer;
}
use of org.eclipse.jface.text.hyperlink.URLHyperlink in project linuxtools by eclipse.
the class URLHyperlinkWithMacroDetectorTest method testDetectHyperlinks.
@Test
public void testDetectHyperlinks() throws PartInitException {
String testText = "Name: eclipse\nURL: http://www.%{name}.org/";
newFile(testText);
URLHyperlinkWithMacroDetector macroDetector = new URLHyperlinkWithMacroDetector();
macroDetector.setSpecfile(specfile);
IRegion region = new Region(20, 0);
IEditorPart openEditor = IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), testFile, "org.eclipse.linuxtools.rpm.ui.editor.SpecfileEditor");
editor = (SpecfileEditor) openEditor;
editor.doRevertToSaved();
IHyperlink[] returned = macroDetector.detectHyperlinks(editor.getSpecfileSourceViewer(), region, false);
URLHyperlink url = (URLHyperlink) returned[0];
assertEquals("http://www.eclipse.org/", url.getURLString());
}
use of org.eclipse.jface.text.hyperlink.URLHyperlink in project webtools.sourceediting by eclipse.
the class URLStorageHyperlink method open.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.text.hyperlink.IHyperlink#open()
*/
public void open() {
if (fURL != null) {
IEditorInput input = new StorageEditorInput(new URLStorage(fURL));
try {
final IEditorDescriptor descriptor = getEditorDescriptor();
if (descriptor != null) {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IDE.openEditor(page, input, descriptor.getId(), true);
}
} catch (PartInitException e) {
Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
new URLHyperlink(fRegion, fURL.toString()).open();
}
}
}
Aggregations