Search in sources :

Example 56 with Browser

use of org.eclipse.swt.browser.Browser in project eclipse-integration-commons by spring-projects.

the class HtmlTooltip method createToolTipContentArea.

@Override
protected Composite createToolTipContentArea(Event event, Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(GridLayoutFactory.fillDefaults().create());
    Browser browser = new Browser(composite, SWT.NONE);
    browser.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
    browser.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
    browser.setJavascriptEnabled(false);
    browser.addOpenWindowListener(new OpenWindowListener() {

        @Override
        public void open(WindowEvent event) {
            // Cancel opening of new windows
            event.required = true;
        }
    });
    // Replace browser's built-in context menu with none
    browser.setMenu(new Menu(browser.getShell(), SWT.NONE));
    String htmlContent = html.get();
    browser.setText(htmlContent);
    Point size = computeSizeHint(browser, htmlContent);
    browser.setLayoutData(GridDataFactory.swtDefaults().hint(size.x, size.y).create());
    // Add after HTML content is set to avoid event fired after the content is set
    browser.addLocationListener(new LocationAdapter() {

        @Override
        public void changing(LocationEvent event) {
            super.changing(event);
            event.doit = false;
            try {
                PlatformUI.getWorkbench().getBrowserSupport().createBrowser(null).openURL(new URL(event.location));
                hide();
            } catch (PartInitException | MalformedURLException e) {
                UiPlugin.log(e);
            }
        }
    });
    return composite;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) LocationAdapter(org.eclipse.swt.browser.LocationAdapter) WindowEvent(org.eclipse.swt.browser.WindowEvent) Menu(org.eclipse.swt.widgets.Menu) Point(org.eclipse.swt.graphics.Point) OpenWindowListener(org.eclipse.swt.browser.OpenWindowListener) LocationEvent(org.eclipse.swt.browser.LocationEvent) URL(java.net.URL) Browser(org.eclipse.swt.browser.Browser)

Example 57 with Browser

use of org.eclipse.swt.browser.Browser in project eclipse-integration-commons by spring-projects.

the class StsBrowserView method createPartControl.

@Override
public void createPartControl(Composite parent) {
    parent.setLayout(new FillLayout());
    browserViewer = new StsBrowserViewer(parent, hasToolbar() ? StsBrowserViewer.BUTTON_BAR | StsBrowserViewer.LOCATION_BAR : SWT.NONE);
    if (initialUrl != null) {
        setUrl(initialUrl);
    }
    Browser browser = getBrowserViewer().getBrowser();
    if (browser != null) {
        browser.addProgressListener(new ProgressAdapter() {

            @Override
            public void completed(ProgressEvent event) {
                if (browserManager == null) {
                    browserManager = new StsBrowserManager();
                }
                browserManager.setClient(getBrowserViewer().getBrowser());
            }
        });
    }
}
Also used : FillLayout(org.eclipse.swt.layout.FillLayout) ProgressAdapter(org.eclipse.swt.browser.ProgressAdapter) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) Browser(org.eclipse.swt.browser.Browser)

Example 58 with Browser

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

the class EclipseMessageDialog method createMessageArea.

protected Control createMessageArea(Composite composite) {
    final Image image = this.getImage();
    if (image != null) {
        this.imageLabel = new Label(composite, 0);
        image.setBackground(this.imageLabel.getBackground());
        this.imageLabel.setImage(image);
        GridDataFactory.fillDefaults().align(16777216, 1).applyTo(this.imageLabel);
    }
    final Browser browser = new Browser(composite, SWT.NONE);
    browser.setText(this.getMessage().getContent());
    browser.setSize(360, 160);
    browser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    GridDataFactory.fillDefaults().align(4, 1).grab(true, false).hint(this.convertHorizontalDLUsToPixels(300), -1).applyTo(browser);
    return composite;
}
Also used : Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) Image(org.eclipse.swt.graphics.Image) Browser(org.eclipse.swt.browser.Browser)

Example 59 with Browser

use of org.eclipse.swt.browser.Browser 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("Searchable Repository 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)

Example 60 with Browser

use of org.eclipse.swt.browser.Browser in project tesb-studio-se by Talend.

the class EsbStartingBrowser method createPartControl.

@Override
public void createPartControl(Composite parent) {
    try {
        browser = new Browser(parent, SWT.NONE);
        browser.setText(EsbStartingHelper.getHelper().getHtmlContent());
        browser.addLocationListener(new BrowserDynamicPartLocationListener());
    } catch (IOException e) {
        ExceptionHandler.process(e);
    } catch (Throwable t) {
        Exception ex = new Exception("The internal web browser can not be access,the starting page won't be displayed");
        ExceptionHandler.process(ex);
    }
}
Also used : BrowserDynamicPartLocationListener(org.talend.commons.ui.html.BrowserDynamicPartLocationListener) IOException(java.io.IOException) IOException(java.io.IOException) Browser(org.eclipse.swt.browser.Browser) StartingBrowser(org.talend.rcp.intro.starting.StartingBrowser)

Aggregations

Browser (org.eclipse.swt.browser.Browser)117 Shell (org.eclipse.swt.widgets.Shell)40 FillLayout (org.eclipse.swt.layout.FillLayout)29 Composite (org.eclipse.swt.widgets.Composite)29 Display (org.eclipse.swt.widgets.Display)29 GridData (org.eclipse.swt.layout.GridData)28 Test (org.junit.Test)26 GridLayout (org.eclipse.swt.layout.GridLayout)20 LocationEvent (org.eclipse.swt.browser.LocationEvent)18 ProgressEvent (org.eclipse.swt.browser.ProgressEvent)18 Point (org.eclipse.swt.graphics.Point)18 IOException (java.io.IOException)16 SWTError (org.eclipse.swt.SWTError)16 BrowserFunction (org.eclipse.swt.browser.BrowserFunction)14 WindowEvent (org.eclipse.swt.browser.WindowEvent)14 Label (org.eclipse.swt.widgets.Label)14 URL (java.net.URL)13 LocationAdapter (org.eclipse.swt.browser.LocationAdapter)13 LocationListener (org.eclipse.swt.browser.LocationListener)13 ProgressAdapter (org.eclipse.swt.browser.ProgressAdapter)13