Search in sources :

Example 1 with URLHyperlink

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 };
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) URLHyperlink(org.eclipse.jface.text.hyperlink.URLHyperlink) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) IResource(org.eclipse.core.resources.IResource)

Example 2 with URLHyperlink

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;
}
Also used : URLHyperlink(org.eclipse.jface.text.hyperlink.URLHyperlink) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) SpecfileEditor(org.eclipse.linuxtools.internal.rpm.ui.editor.SpecfileEditor)

Example 3 with URLHyperlink

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;
}
Also used : CTabFolder(org.eclipse.swt.custom.CTabFolder) KeyAdapter(org.eclipse.swt.events.KeyAdapter) ProjectionViewer(org.eclipse.jface.text.source.projection.ProjectionViewer) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) Viewer(org.eclipse.jface.viewers.Viewer) IFocusService(org.eclipse.ui.swt.IFocusService) CTabItem(org.eclipse.swt.custom.CTabItem) URL(java.net.URL) KeyEvent(org.eclipse.swt.events.KeyEvent) URLHyperlink(org.eclipse.jface.text.hyperlink.URLHyperlink) LocationListener(org.eclipse.swt.browser.LocationListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) LocationEvent(org.eclipse.swt.browser.LocationEvent) SWTError(org.eclipse.swt.SWTError) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) MouseAdapter(org.eclipse.swt.events.MouseAdapter) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) SWTException(org.eclipse.swt.SWTException) Point(org.eclipse.swt.graphics.Point) Region(org.eclipse.jface.text.Region) AbstractMarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.AbstractMarkupLanguage) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) Browser(org.eclipse.swt.browser.Browser) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 4 with URLHyperlink

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());
}
Also used : URLHyperlink(org.eclipse.jface.text.hyperlink.URLHyperlink) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) IEditorPart(org.eclipse.ui.IEditorPart) URLHyperlinkWithMacroDetector(org.eclipse.linuxtools.internal.rpm.ui.editor.hyperlink.URLHyperlinkWithMacroDetector) IRegion(org.eclipse.jface.text.IRegion) Test(org.junit.Test)

Example 5 with URLHyperlink

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();
        }
    }
}
Also used : IStorageEditorInput(org.eclipse.ui.IStorageEditorInput) URLHyperlink(org.eclipse.jface.text.hyperlink.URLHyperlink) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) IEditorInput(org.eclipse.ui.IEditorInput)

Aggregations

URLHyperlink (org.eclipse.jface.text.hyperlink.URLHyperlink)7 IHyperlink (org.eclipse.jface.text.hyperlink.IHyperlink)5 File (java.io.File)2 URL (java.net.URL)2 IFile (org.eclipse.core.resources.IFile)2 Region (org.eclipse.jface.text.Region)2 PartInitException (org.eclipse.ui.PartInitException)2 MalformedURLException (java.net.MalformedURLException)1 IResource (org.eclipse.core.resources.IResource)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 IRegion (org.eclipse.jface.text.IRegion)1 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)1 ProjectionViewer (org.eclipse.jface.text.source.projection.ProjectionViewer)1 IPropertyChangeListener (org.eclipse.jface.util.IPropertyChangeListener)1 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)1 Viewer (org.eclipse.jface.viewers.Viewer)1 SpecfileEditor (org.eclipse.linuxtools.internal.rpm.ui.editor.SpecfileEditor)1 URLHyperlinkWithMacroDetector (org.eclipse.linuxtools.internal.rpm.ui.editor.hyperlink.URLHyperlinkWithMacroDetector)1