Search in sources :

Example 1 with ProgressListener

use of org.eclipse.swt.browser.ProgressListener in project cubrid-manager by CUBRID.

the class BrowserEditorPart method initBrowser.

private void initBrowser(Composite parent) {
    browser = new Browser(parent, SWT.None);
    browser.setLayoutData(createGridData(FILL_BOTH, 3, 1, -1, -1));
    // Add location change listener
    browser.addLocationListener(new LocationListener() {

        public void changing(LocationEvent e) {
            location.setText(e.location);
        }

        public void changed(LocationEvent e) {
            noOp();
        }
    });
    // Add loading listener
    browser.addProgressListener(new ProgressListener() {

        // Set stopItem and progress bar status
        public void changed(ProgressEvent e) {
            if (!stopItem.isEnabled() && e.total != e.current) {
                stopItem.setEnabled(true);
            }
        }

        // Set stopItem,backItem,forwardItem and progress bar status
        public void completed(ProgressEvent e) {
            stopItem.setEnabled(false);
            backItem.setEnabled(browser.isBackEnabled());
            forwardItem.setEnabled(browser.isForwardEnabled());
        }
    });
}
Also used : ProgressListener(org.eclipse.swt.browser.ProgressListener) LocationListener(org.eclipse.swt.browser.LocationListener) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) LocationEvent(org.eclipse.swt.browser.LocationEvent) Browser(org.eclipse.swt.browser.Browser)

Example 2 with ProgressListener

use of org.eclipse.swt.browser.ProgressListener in project eclipse.platform.swt by eclipse.

the class BrowserExample method show.

void show(boolean owned, Point location, Point size, boolean addressBar, boolean menuBar, boolean statusBar, boolean toolBar) {
    final Shell shell = browser.getShell();
    if (owned) {
        if (location != null)
            shell.setLocation(location);
        if (size != null)
            shell.setSize(shell.computeSize(size.x, size.y));
    }
    FormData data = null;
    if (toolBar) {
        toolbar = new ToolBar(parent, SWT.NONE);
        data = new FormData();
        data.top = new FormAttachment(0, 5);
        toolbar.setLayoutData(data);
        itemBack = new ToolItem(toolbar, SWT.PUSH);
        itemBack.setText(getResourceString("Back"));
        itemForward = new ToolItem(toolbar, SWT.PUSH);
        itemForward.setText(getResourceString("Forward"));
        final ToolItem itemStop = new ToolItem(toolbar, SWT.PUSH);
        itemStop.setText(getResourceString("Stop"));
        final ToolItem itemRefresh = new ToolItem(toolbar, SWT.PUSH);
        itemRefresh.setText(getResourceString("Refresh"));
        final ToolItem itemGo = new ToolItem(toolbar, SWT.PUSH);
        itemGo.setText(getResourceString("Go"));
        itemBack.setEnabled(browser.isBackEnabled());
        itemForward.setEnabled(browser.isForwardEnabled());
        Listener listener = event -> {
            ToolItem item = (ToolItem) event.widget;
            if (item == itemBack)
                browser.back();
            else if (item == itemForward)
                browser.forward();
            else if (item == itemStop)
                browser.stop();
            else if (item == itemRefresh)
                browser.refresh();
            else if (item == itemGo)
                browser.setUrl(locationBar.getText());
        };
        itemBack.addListener(SWT.Selection, listener);
        itemForward.addListener(SWT.Selection, listener);
        itemStop.addListener(SWT.Selection, listener);
        itemRefresh.addListener(SWT.Selection, listener);
        itemGo.addListener(SWT.Selection, listener);
        canvas = new Canvas(parent, SWT.NO_BACKGROUND);
        data = new FormData();
        data.width = 24;
        data.height = 24;
        data.top = new FormAttachment(0, 5);
        data.right = new FormAttachment(100, -5);
        canvas.setLayoutData(data);
        final Rectangle rect = images[0].getBounds();
        canvas.addListener(SWT.Paint, e -> {
            Point pt = ((Canvas) e.widget).getSize();
            e.gc.drawImage(images[index], 0, 0, rect.width, rect.height, 0, 0, pt.x, pt.y);
        });
        canvas.addListener(SWT.MouseDown, e -> browser.setUrl(getResourceString("Startup")));
        final Display display = parent.getDisplay();
        display.asyncExec(new Runnable() {

            @Override
            public void run() {
                if (canvas.isDisposed())
                    return;
                if (busy) {
                    index++;
                    if (index == images.length)
                        index = 0;
                    canvas.redraw();
                }
                display.timerExec(150, this);
            }
        });
    }
    if (addressBar) {
        locationBar = new Text(parent, SWT.BORDER);
        data = new FormData();
        if (toolbar != null) {
            data.top = new FormAttachment(toolbar, 0, SWT.TOP);
            data.left = new FormAttachment(toolbar, 5, SWT.RIGHT);
            data.right = new FormAttachment(canvas, -5, SWT.DEFAULT);
        } else {
            data.top = new FormAttachment(0, 0);
            data.left = new FormAttachment(0, 0);
            data.right = new FormAttachment(100, 0);
        }
        locationBar.setLayoutData(data);
        locationBar.addListener(SWT.DefaultSelection, e -> browser.setUrl(locationBar.getText()));
    }
    if (statusBar) {
        status = new Label(parent, SWT.NONE);
        progressBar = new ProgressBar(parent, SWT.NONE);
        data = new FormData();
        data.left = new FormAttachment(0, 5);
        data.right = new FormAttachment(progressBar, 0, SWT.DEFAULT);
        data.bottom = new FormAttachment(100, -5);
        status.setLayoutData(data);
        data = new FormData();
        data.right = new FormAttachment(100, -5);
        data.bottom = new FormAttachment(100, -5);
        progressBar.setLayoutData(data);
        browser.addStatusTextListener(event -> status.setText(event.text));
    }
    parent.setLayout(new FormLayout());
    Control aboveBrowser = toolBar ? (Control) canvas : (addressBar ? (Control) locationBar : null);
    data = new FormData();
    data.left = new FormAttachment(0, 0);
    data.top = aboveBrowser != null ? new FormAttachment(aboveBrowser, 5, SWT.DEFAULT) : new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    data.bottom = status != null ? new FormAttachment(status, -5, SWT.DEFAULT) : new FormAttachment(100, 0);
    browser.setLayoutData(data);
    if (statusBar || toolBar) {
        browser.addProgressListener(new ProgressListener() {

            @Override
            public void changed(ProgressEvent event) {
                if (event.total == 0)
                    return;
                int ratio = event.current * 100 / event.total;
                if (progressBar != null)
                    progressBar.setSelection(ratio);
                busy = event.current != event.total;
                if (!busy) {
                    index = 0;
                    if (canvas != null)
                        canvas.redraw();
                }
            }

            @Override
            public void completed(ProgressEvent event) {
                if (progressBar != null)
                    progressBar.setSelection(0);
                busy = false;
                index = 0;
                if (canvas != null) {
                    itemBack.setEnabled(browser.isBackEnabled());
                    itemForward.setEnabled(browser.isForwardEnabled());
                    canvas.redraw();
                }
            }
        });
    }
    if (addressBar || statusBar || toolBar) {
        browser.addLocationListener(LocationListener.changedAdapter(event -> {
            busy = true;
            if (event.top && locationBar != null)
                locationBar.setText(event.location);
        }));
    }
    if (title) {
        browser.addTitleListener(event -> shell.setText(event.title + " - " + getResourceString("window.title")));
    }
    parent.layout(true);
    if (owned)
        shell.open();
}
Also used : FormData(org.eclipse.swt.layout.FormData) ProgressBar(org.eclipse.swt.widgets.ProgressBar) ToolBar(org.eclipse.swt.widgets.ToolBar) Image(org.eclipse.swt.graphics.Image) Rectangle(org.eclipse.swt.graphics.Rectangle) ProgressListener(org.eclipse.swt.browser.ProgressListener) ImageData(org.eclipse.swt.graphics.ImageData) Point(org.eclipse.swt.graphics.Point) SWTError(org.eclipse.swt.SWTError) ResourceBundle(java.util.ResourceBundle) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) Composite(org.eclipse.swt.widgets.Composite) Listener(org.eclipse.swt.widgets.Listener) LocationListener(org.eclipse.swt.browser.LocationListener) Canvas(org.eclipse.swt.widgets.Canvas) VisibilityWindowListener(org.eclipse.swt.browser.VisibilityWindowListener) FillLayout(org.eclipse.swt.layout.FillLayout) Browser(org.eclipse.swt.browser.Browser) Text(org.eclipse.swt.widgets.Text) Shell(org.eclipse.swt.widgets.Shell) FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) MissingResourceException(java.util.MissingResourceException) IOException(java.io.IOException) FormAttachment(org.eclipse.swt.layout.FormAttachment) Display(org.eclipse.swt.widgets.Display) ToolItem(org.eclipse.swt.widgets.ToolItem) SWT(org.eclipse.swt.SWT) Label(org.eclipse.swt.widgets.Label) Control(org.eclipse.swt.widgets.Control) InputStream(java.io.InputStream) FormLayout(org.eclipse.swt.layout.FormLayout) ProgressListener(org.eclipse.swt.browser.ProgressListener) Listener(org.eclipse.swt.widgets.Listener) LocationListener(org.eclipse.swt.browser.LocationListener) VisibilityWindowListener(org.eclipse.swt.browser.VisibilityWindowListener) Canvas(org.eclipse.swt.widgets.Canvas) Rectangle(org.eclipse.swt.graphics.Rectangle) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) Shell(org.eclipse.swt.widgets.Shell) Control(org.eclipse.swt.widgets.Control) ProgressListener(org.eclipse.swt.browser.ProgressListener) ToolBar(org.eclipse.swt.widgets.ToolBar) ProgressBar(org.eclipse.swt.widgets.ProgressBar) FormAttachment(org.eclipse.swt.layout.FormAttachment) ToolItem(org.eclipse.swt.widgets.ToolItem) Display(org.eclipse.swt.widgets.Display)

Example 3 with ProgressListener

use of org.eclipse.swt.browser.ProgressListener in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_browser_Browser method test_setUrl_remote_with_post.

/**
 * This test requires working Internet connection
 */
@Test
public void test_setUrl_remote_with_post() {
    // Fails on webkit1 but likely not going to try to support it.
    assumeFalse(webkit1SkipMsg(), isWebkit1);
    // This test sometimes times out if build server has a bad connection. Thus for this test we have a longer timeout.
    secondsToWaitTillFail = 35;
    String url = "https://bugs.eclipse.org/bugs/buglist.cgi";
    // Skip this test if we don't have a working Internet connection.
    assumeTrue("Skipping test due to bad internet connection", checkInternet(url));
    testLog.append("checkInternet() passed");
    Runnable browserSetFunc = () -> {
        testLog.append("Setting Browser url to:" + url);
        boolean opSuccess = browser.setUrl(url, "bug_severity=enhancement&bug_status=NEW&email1=rgrunber&emailassigned_to1=1&emailtype1=substring", null);
        assertTrue("Expecting setUrl() to return true", opSuccess);
    };
    final AtomicReference<Boolean> completed = new AtomicReference<>(new Boolean(false));
    browser.addProgressListener(completedAdapter(event -> {
        testLog.append("ProgressListener fired");
        completed.set(true);
    }));
    browserSetFunc.run();
    shell.open();
    boolean hasFinished = waitForPassCondition(() -> completed.get().booleanValue());
    assertTrue("Test timed out. ProgressListener not fired " + testLog.toString(), hasFinished);
    // Even a successful empty query returns about 10000 chars of HTML
    int numChars = browser.getText().length();
    assertTrue("Response data contained " + numChars + " chars.", numChars > 10000);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) StatusTextListener(org.eclipse.swt.browser.StatusTextListener) URL(java.net.URL) Assume.assumeFalse(org.junit.Assume.assumeFalse) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LocationAdapter(org.eclipse.swt.browser.LocationAdapter) CloseWindowListener(org.eclipse.swt.browser.CloseWindowListener) ProgressListener(org.eclipse.swt.browser.ProgressListener) TitleListener(org.eclipse.swt.browser.TitleListener) VisibilityWindowAdapter(org.eclipse.swt.browser.VisibilityWindowAdapter) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) Point(org.eclipse.swt.graphics.Point) AtomicReferenceArray(java.util.concurrent.atomic.AtomicReferenceArray) BrowserFunction(org.eclipse.swt.browser.BrowserFunction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) TestName(org.junit.rules.TestName) LocationListener.changedAdapter(org.eclipse.swt.browser.LocationListener.changedAdapter) VisibilityWindowListener.showAdapter(org.eclipse.swt.browser.VisibilityWindowListener.showAdapter) WindowEvent(org.eclipse.swt.browser.WindowEvent) LocationListener(org.eclipse.swt.browser.LocationListener) ProgressListener.completedAdapter(org.eclipse.swt.browser.ProgressListener.completedAdapter) Assert.fail(org.junit.Assert.fail) SWTException(org.eclipse.swt.SWTException) VisibilityWindowListener(org.eclipse.swt.browser.VisibilityWindowListener) FillLayout(org.eclipse.swt.layout.FillLayout) AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray) Before(org.junit.Before) OpenWindowListener(org.eclipse.swt.browser.OpenWindowListener) ProgressAdapter(org.eclipse.swt.browser.ProgressAdapter) Browser(org.eclipse.swt.browser.Browser) Shell(org.eclipse.swt.widgets.Shell) MalformedURLException(java.net.MalformedURLException) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Display(org.eclipse.swt.widgets.Display) Instant(java.time.Instant) LocationListener.changingAdapter(org.eclipse.swt.browser.LocationListener.changingAdapter) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.junit.Rule) Assert.assertFalse(org.junit.Assert.assertFalse) SWT(org.eclipse.swt.SWT) LocationEvent(org.eclipse.swt.browser.LocationEvent) Assume.assumeTrue(org.junit.Assume.assumeTrue) Assert.assertEquals(org.junit.Assert.assertEquals) AtomicReference(java.util.concurrent.atomic.AtomicReference) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Point(org.eclipse.swt.graphics.Point) Test(org.junit.Test)

Example 4 with ProgressListener

use of org.eclipse.swt.browser.ProgressListener in project arduino-eclipse-plugin by Sloeber.

the class PleaseHelp method createContents.

@Override
protected Control createContents(Composite parent) {
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 3;
    parent.setLayout(gridLayout);
    try {
        this.browser = new Browser(parent, SWT.NONE);
    } catch (SWTError e) {
        // $NON-NLS-1$
        System.out.println("Could not instantiate Browser: " + e.getMessage());
    }
    GridData data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.verticalAlignment = GridData.FILL;
    data.horizontalSpan = 3;
    data.grabExcessHorizontalSpace = true;
    data.grabExcessVerticalSpace = true;
    this.browser.setLayoutData(data);
    this.browser.addProgressListener(new ProgressListener() {

        @Override
        public void changed(ProgressEvent event) {
        // I'm not interested in change
        }

        @Override
        public void completed(ProgressEvent event) {
            PleaseHelp.this.ph.setBlockOnOpen(false);
            PleaseHelp.this.ph.open();
        }
    });
    this.buttonBar = createButtonBar(parent);
    org.osgi.framework.Version version = FrameworkUtil.getBundle(getClass()).getVersion();
    // $NON-NLS-1$
    String url = myhelpLocation + "?os=" + Platform.getOS();
    // $NON-NLS-1$
    url += "&arch=" + Platform.getOSArch();
    // $NON-NLS-1$
    url += "&majorVersion=" + version.getMajor();
    // $NON-NLS-1$
    url += "&minorVersion=" + version.getMinor();
    // $NON-NLS-1$
    url += "&microVersion=" + version.getMicro();
    // $NON-NLS-1$
    url += "&qualifierVersion=" + version.getQualifier();
    this.browser.setUrl(url);
    return parent;
}
Also used : SWTError(org.eclipse.swt.SWTError) GridLayout(org.eclipse.swt.layout.GridLayout) ProgressListener(org.eclipse.swt.browser.ProgressListener) GridData(org.eclipse.swt.layout.GridData) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) Browser(org.eclipse.swt.browser.Browser)

Example 5 with ProgressListener

use of org.eclipse.swt.browser.ProgressListener in project BiglyBT by BiglySoftware.

the class BrowserWrapperFake method setUrl.

@Override
public void setUrl(final String _url) {
    url = _url;
    Utils.execSWTThread(new Runnable() {

        @Override
        public void run() {
            String url_str = _url;
            int pos = url_str.indexOf('?');
            if (pos != -1) {
                url_str = url_str.substring(0, pos);
            }
            link_label.setText(url_str);
            browser.layout();
            for (LocationListener l : location_listeners) {
                try {
                    LocationEvent event = new LocationEvent(browser);
                    event.top = true;
                    event.location = _url;
                    l.changed(event);
                } catch (Throwable e) {
                    Debug.out(e);
                }
            }
            for (ProgressListener l : progress_listeners) {
                try {
                    ProgressEvent event = new ProgressEvent(browser);
                    l.completed(event);
                } catch (Throwable e) {
                    Debug.out(e);
                }
            }
            for (TitleListener l : title_listeners) {
                try {
                    TitleEvent event = new TitleEvent(browser);
                    event.title = "Browser Disabled";
                    l.changed(event);
                } catch (Throwable e) {
                    Debug.out(e);
                }
            }
        }
    });
}
Also used : TitleListener(org.eclipse.swt.browser.TitleListener) TitleEvent(org.eclipse.swt.browser.TitleEvent) ProgressListener(org.eclipse.swt.browser.ProgressListener) LocationListener(org.eclipse.swt.browser.LocationListener) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) LocationEvent(org.eclipse.swt.browser.LocationEvent)

Aggregations

ProgressEvent (org.eclipse.swt.browser.ProgressEvent)11 ProgressListener (org.eclipse.swt.browser.ProgressListener)11 Browser (org.eclipse.swt.browser.Browser)7 LocationListener (org.eclipse.swt.browser.LocationListener)4 GridLayout (org.eclipse.swt.layout.GridLayout)4 Display (org.eclipse.swt.widgets.Display)4 Shell (org.eclipse.swt.widgets.Shell)4 LocationEvent (org.eclipse.swt.browser.LocationEvent)3 TitleListener (org.eclipse.swt.browser.TitleListener)3 Point (org.eclipse.swt.graphics.Point)3 FillLayout (org.eclipse.swt.layout.FillLayout)3 Composite (org.eclipse.swt.widgets.Composite)3 IOException (java.io.IOException)2 URL (java.net.URL)2 SWT (org.eclipse.swt.SWT)2 SWTError (org.eclipse.swt.SWTError)2 CloseWindowListener (org.eclipse.swt.browser.CloseWindowListener)2 StatusTextListener (org.eclipse.swt.browser.StatusTextListener)2 TitleEvent (org.eclipse.swt.browser.TitleEvent)2 VisibilityWindowListener (org.eclipse.swt.browser.VisibilityWindowListener)2