Search in sources :

Example 1 with LocationAdapter

use of org.eclipse.swt.browser.LocationAdapter in project azure-tools-for-java by Microsoft.

the class LoginDialog method createDlgBody.

private void createDlgBody(Composite container) {
    final Browser browser = new Browser(container, SWT.NONE);
    browser.addLocationListener(new LocationAdapter() {

        @Override
        public void changing(LocationEvent locationEvent) {
            System.out.println("\t--> locationEvent.location: " + locationEvent.location);
            if (locationEvent.location.startsWith(redirectUriStr)) {
                setResult(locationEvent.location);
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        //Browser.clearSessions();
                        close();
                    }
                });
            }
        }
    });
    //        String[] headers = new String[] {
    //                "User-Agent: SwtBrowser"
    //        };
    //        browser.setUrl(requestUriStr, null, headers);
    browser.setUrl(requestUriStr);
}
Also used : LocationAdapter(org.eclipse.swt.browser.LocationAdapter) LocationEvent(org.eclipse.swt.browser.LocationEvent) Browser(org.eclipse.swt.browser.Browser)

Example 2 with LocationAdapter

use of org.eclipse.swt.browser.LocationAdapter in project bndtools by bndtools.

the class JPMBrowserView method createPartControl.

@Override
public void createPartControl(Composite parent) {
    StackLayout stack = new StackLayout();
    parent.setLayout(stack);
    JpmPreferences prefs = new JpmPreferences();
    if (prefs.getBrowserSelection() == JpmPreferences.PREF_BROWSER_EXTERNAL) {
        external = true;
        Composite composite = new Composite(parent, SWT.NONE);
        composite.setLayout(new GridLayout(2, false));
        new Label(composite, SWT.NONE).setText("JPM is configured to open in an external browser.");
        Hyperlink linkToPrefs = new Hyperlink(composite, SWT.NONE);
        linkToPrefs.setText("Open Preference Page");
        linkToPrefs.setUnderlined(true);
        linkToPrefs.addHyperlinkListener(new HyperlinkAdapter() {

            @Override
            public void linkActivated(HyperlinkEvent e) {
                PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(getViewSite().getShell(), "bndtools.prefPages.jpm", new String[] { "bndtools.prefPages.jpm" }, null);
                dialog.open();
            }
        });
        //            linkToPrefs.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false));
        stack.topControl = composite;
    } else {
        if (prefs.getBrowserSelection() == JpmPreferences.PREF_BROWSER_PLATFORM_DEFAULT) {
            browser = new Browser(parent, SWT.NONE);
            stack.topControl = browser;
        } else if (prefs.getBrowserSelection() == JpmPreferences.PREF_BROWSER_WEBKIT) {
            browser = new Browser(parent, SWT.WEBKIT);
            stack.topControl = browser;
        } else if (prefs.getBrowserSelection() == JpmPreferences.PREF_BROWSER_MOZILLA) {
            browser = new Browser(parent, SWT.MOZILLA);
            stack.topControl = browser;
        }
        createActions();
        // Prevent navigation away from JPM4J.org, and redirect from HTTP back to HTTPS
        browser.addLocationListener(new LocationAdapter() {

            @Override
            public void changing(LocationEvent event) {
                setContentDescription(event.location);
            /*
                     *
                    if (event.location.startsWith(HTTPS_URL))
                        return;
                    if (event.location.startsWith(HTTP_URL))
                        event.location = event.location.replaceFirst(HTTP_URL, HTTP_URL);
                    else
                        event.doit = false;
                     */
            }
        });
    }
    selectionService = getViewSite().getWorkbenchWindow().getSelectionService();
    selectionService.addSelectionListener(this);
    handleWorkbenchSelection(selectionService.getSelection());
}
Also used : HyperlinkEvent(org.eclipse.ui.forms.events.HyperlinkEvent) Composite(org.eclipse.swt.widgets.Composite) JpmPreferences(bndtools.preferences.JpmPreferences) LocationAdapter(org.eclipse.swt.browser.LocationAdapter) Label(org.eclipse.swt.widgets.Label) GridLayout(org.eclipse.swt.layout.GridLayout) PreferenceDialog(org.eclipse.jface.preference.PreferenceDialog) StackLayout(org.eclipse.swt.custom.StackLayout) LocationEvent(org.eclipse.swt.browser.LocationEvent) Hyperlink(org.eclipse.ui.forms.widgets.Hyperlink) HyperlinkAdapter(org.eclipse.ui.forms.events.HyperlinkAdapter) Browser(org.eclipse.swt.browser.Browser)

Aggregations

Browser (org.eclipse.swt.browser.Browser)2 LocationAdapter (org.eclipse.swt.browser.LocationAdapter)2 LocationEvent (org.eclipse.swt.browser.LocationEvent)2 JpmPreferences (bndtools.preferences.JpmPreferences)1 PreferenceDialog (org.eclipse.jface.preference.PreferenceDialog)1 StackLayout (org.eclipse.swt.custom.StackLayout)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 HyperlinkAdapter (org.eclipse.ui.forms.events.HyperlinkAdapter)1 HyperlinkEvent (org.eclipse.ui.forms.events.HyperlinkEvent)1 Hyperlink (org.eclipse.ui.forms.widgets.Hyperlink)1