Search in sources :

Example 21 with IWorkbenchBrowserSupport

use of org.eclipse.ui.browser.IWorkbenchBrowserSupport in project cubrid-manager by CUBRID.

the class CubridOnlineForumAction method run.

public void run() {
    String url = CommonUITool.urlEncodeForSpaces(Messages.msgCubridOnlineForumUrl);
    try {
        IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport();
        IWebBrowser browser = support.getExternalBrowser();
        browser.openURL(new URL(url));
    } catch (PartInitException e) {
        LOGGER.error("Can not initialize web browser on the application.", e);
    } catch (MalformedURLException e) {
        LOGGER.error("The url {} is invalid.", url, e);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) IWorkbenchBrowserSupport(org.eclipse.ui.browser.IWorkbenchBrowserSupport) IWebBrowser(org.eclipse.ui.browser.IWebBrowser) PartInitException(org.eclipse.ui.PartInitException) URL(java.net.URL)

Example 22 with IWorkbenchBrowserSupport

use of org.eclipse.ui.browser.IWorkbenchBrowserSupport in project cubrid-manager by CUBRID.

the class HelpDocumentAction method run.

public void run() {
    String url = CommonUITool.urlEncodeForSpaces(Messages.msgCubridHelpSiteUrl);
    try {
        IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport();
        IWebBrowser browser = support.getExternalBrowser();
        browser.openURL(new URL(url));
    } catch (PartInitException e) {
        LOGGER.error("Can not initialize web browser on the application.", e);
    } catch (MalformedURLException e) {
        LOGGER.error("The url {} is invalid.", url, e);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) IWorkbenchBrowserSupport(org.eclipse.ui.browser.IWorkbenchBrowserSupport) IWebBrowser(org.eclipse.ui.browser.IWebBrowser) PartInitException(org.eclipse.ui.PartInitException) URL(java.net.URL)

Example 23 with IWorkbenchBrowserSupport

use of org.eclipse.ui.browser.IWorkbenchBrowserSupport in project cubrid-manager by CUBRID.

the class CubridNewInfoEditorPart method createPartControl.

/**
	 * Create the editor content
	 *
	 * @param parent the parent composite
	 */
public void createPartControl(Composite parent) {
    String url = Platform.getNL().equals("ko_KR") ? CHECK_NEW_INFO_URL_KO : CHECK_NEW_INFO_URL_EN;
    try {
        Browser browser = new Browser(parent, SWT.NONE);
        browser.setUrl(url);
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
        Label label = new Label(parent, SWT.NONE);
        IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport();
        try {
            IWebBrowser browser = support.getExternalBrowser();
            browser.openURL(new URL(CommonUITool.urlEncodeForSpaces(url.toCharArray())));
        } catch (Exception browserEx) {
            LOGGER.warn(browserEx.getMessage(), browserEx);
            label.setText(Messages.errCannotOpenExternalBrowser);
            return;
        }
        label.setText(Messages.errCannotOpenInternalBrowser);
    }
}
Also used : Label(org.eclipse.swt.widgets.Label) IWorkbenchBrowserSupport(org.eclipse.ui.browser.IWorkbenchBrowserSupport) IWebBrowser(org.eclipse.ui.browser.IWebBrowser) PartInitException(org.eclipse.ui.PartInitException) URL(java.net.URL) Browser(org.eclipse.swt.browser.Browser) IWebBrowser(org.eclipse.ui.browser.IWebBrowser)

Example 24 with IWorkbenchBrowserSupport

use of org.eclipse.ui.browser.IWorkbenchBrowserSupport in project eclipse-integration-commons by spring-projects.

the class PluginManagerDialog method handleNavigation.

/**
 * Handles navigation from a hyperlink in the description area.
 *
 * @param urlExpression
 */
protected void handleNavigation(String urlExpression) {
    String errorMessage = null;
    try {
        URL url = new URL(urlExpression);
        boolean launched = Program.launch(url.toString());
        if (!launched) {
            IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport();
            try {
                if (support != null) {
                    IWebBrowser browser = support.getExternalBrowser();
                    if (browser != null) {
                        browser.openURL(url);
                        return;
                    } else {
                        errorMessage = "Unable to find browser support to navigate to URL. Check default browser support in Eclipse or OS";
                    }
                }
            } catch (PartInitException e) {
                errorMessage = "Unable to navigate to URL: " + e.getLocalizedMessage();
            }
        }
    } catch (MalformedURLException e) {
        errorMessage = "Unable to navigate to URL: " + e.getLocalizedMessage();
    }
    if (errorMessage != null) {
        InternalMessageDialogue dialog = new InternalMessageDialogue("Problems navigating to URL", errorMessage + ": " + urlExpression, MessageDialog.ERROR, false);
        dialog.open();
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) IWorkbenchBrowserSupport(org.eclipse.ui.browser.IWorkbenchBrowserSupport) IWebBrowser(org.eclipse.ui.browser.IWebBrowser) PartInitException(org.eclipse.ui.PartInitException) URL(java.net.URL)

Example 25 with IWorkbenchBrowserSupport

use of org.eclipse.ui.browser.IWorkbenchBrowserSupport in project eclipse-integration-commons by spring-projects.

the class UiUtil method uiThreadOpenUrl.

/**
 * Don't call this method unless you are in the UI thread!
 */
private static void uiThreadOpenUrl(String location, int browserChoice) {
    try {
        URL url = null;
        if (location != null) {
            url = new URL(location);
        }
        if (browserChoice == WebBrowserPreference.EXTERNAL) {
            try {
                IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport();
                support.getExternalBrowser().openURL(url);
            } catch (Exception e) {
            }
        } else {
            IWebBrowser browser;
            int flags;
            if (WorkbenchBrowserSupport.getInstance().isInternalWebBrowserAvailable()) {
                flags = IWorkbenchBrowserSupport.AS_EDITOR | IWorkbenchBrowserSupport.LOCATION_BAR | IWorkbenchBrowserSupport.NAVIGATION_BAR;
            } else {
                flags = IWorkbenchBrowserSupport.AS_EXTERNAL | IWorkbenchBrowserSupport.LOCATION_BAR | IWorkbenchBrowserSupport.NAVIGATION_BAR;
            }
            String generatedId = "org.eclipse.mylyn.web.browser-" + Calendar.getInstance().getTimeInMillis();
            browser = WorkbenchBrowserSupport.getInstance().createBrowser(flags, generatedId, null, null);
            browser.openURL(url);
        }
    } catch (PartInitException e) {
        MessageDialog.openError(Display.getDefault().getActiveShell(), "Failed to Open Browser", "Browser could not be initiated");
    } catch (MalformedURLException e) {
        if (location == null || location.trim().equals("")) {
            MessageDialog.openInformation(Display.getDefault().getActiveShell(), "Failed to Open Browser", "No URL to open." + location);
        } else {
            MessageDialog.openInformation(Display.getDefault().getActiveShell(), "Failed to Open Browser", "Could not open URL: " + location);
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) IWorkbenchBrowserSupport(org.eclipse.ui.browser.IWorkbenchBrowserSupport) IWebBrowser(org.eclipse.ui.browser.IWebBrowser) PartInitException(org.eclipse.ui.PartInitException) URL(java.net.URL) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) PartInitException(org.eclipse.ui.PartInitException) MalformedURLException(java.net.MalformedURLException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

IWorkbenchBrowserSupport (org.eclipse.ui.browser.IWorkbenchBrowserSupport)36 URL (java.net.URL)31 IWebBrowser (org.eclipse.ui.browser.IWebBrowser)29 PartInitException (org.eclipse.ui.PartInitException)21 MalformedURLException (java.net.MalformedURLException)18 GridData (org.eclipse.swt.layout.GridData)7 GridLayout (org.eclipse.swt.layout.GridLayout)6 IOException (java.io.IOException)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 Button (org.eclipse.swt.widgets.Button)5 Composite (org.eclipse.swt.widgets.Composite)5 Label (org.eclipse.swt.widgets.Label)5 Status (org.eclipse.core.runtime.Status)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 CoreException (org.eclipse.core.runtime.CoreException)3 HyperlinkEvent (org.eclipse.ui.forms.events.HyperlinkEvent)3 FormText (org.eclipse.ui.forms.widgets.FormText)3 Hyperlink (com.novocode.naf.swt.custom.Hyperlink)2 File (java.io.File)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2