Search in sources :

Example 6 with ProgressListener

use of org.eclipse.swt.browser.ProgressListener in project jbosstools-openshift by jbosstools.

the class BrowserBasedLoginDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite container = (Composite) super.createDialogArea(parent);
    container.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(container);
    browser = new Browser(container, SWT.BORDER);
    browser.setText("Loading");
    Browser.clearSessions();
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(browser);
    final ProgressBar progressBar = new ProgressBar(container, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(progressBar);
    ProgressListener progressListener = new ProgressListener() {

        @Override
        public void changed(ProgressEvent event) {
            if (event.total <= 0)
                return;
            int ratio = event.current * 100 / event.total;
            progressBar.setSelection(ratio);
        }

        @Override
        public void completed(ProgressEvent event) {
            progressBar.setSelection(0);
            info = processor.getRequestInfo(browser, browser.getUrl(), browser.getText());
            if (null != info) {
                close();
            }
        }
    };
    browser.addProgressListener(progressListener);
    setURL(startURL);
    return container;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) ProgressListener(org.eclipse.swt.browser.ProgressListener) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) ProgressBar(org.eclipse.swt.widgets.ProgressBar) Point(org.eclipse.swt.graphics.Point) Browser(org.eclipse.swt.browser.Browser)

Example 7 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)

Example 8 with ProgressListener

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

the class BrowserWindow method init.

public void init(Shell parent, String url, int w, int h, boolean allowResize, boolean isModal) {
    int style = SWT.DIALOG_TRIM;
    if (allowResize) {
        style |= SWT.RESIZE;
    }
    if (isModal) {
        style |= SWT.APPLICATION_MODAL;
    }
    shell = ShellFactory.createShell(parent, style);
    shell.setLayout(new FillLayout());
    Utils.setShellIcon(shell);
    shell.setText(url);
    shell.addTraverseListener(new TraverseListener() {

        @Override
        public void keyTraversed(TraverseEvent e) {
            if (e.detail == SWT.TRAVERSE_ESCAPE) {
                shell.dispose();
                e.doit = false;
            }
        }
    });
    final Listener escListener = new Listener() {

        @Override
        public void handleEvent(Event event) {
            if (event.keyCode == 27) {
                shell.dispose();
            }
        }
    };
    shell.getDisplay().addFilter(SWT.KeyDown, escListener);
    shell.addListener(SWT.Dispose, new Listener() {

        @Override
        public void handleEvent(Event event) {
            event.display.removeFilter(SWT.KeyDown, escListener);
        }
    });
    browser = Utils.createSafeBrowser(shell, SWT.NONE);
    if (browser == null) {
        shell.dispose();
        return;
    }
    context = new BrowserContext("browser-window" + Math.random(), browser, null, true);
    context.addMessageListener(new TorrentListener());
    context.addMessageListener(new VuzeListener());
    context.addMessageListener(new DisplayListener());
    context.addMessageListener(new ConfigListener(browser));
    context.addMessageListener(new MetaSearchListener(new OpenCloseSearchDetailsListener() {

        @Override
        public void resizeSecondaryBrowser() {
        }

        @Override
        public void resizeMainBrowser() {
        }

        @Override
        public void openSearchResults(Map params) {
        }

        @Override
        public void closeSearchResults(Map params) {
            if (browser.isDisposed() || browser.getShell().isDisposed()) {
                return;
            }
            shell.dispose();
        }
    }));
    browser.addProgressListener(new ProgressListener() {

        @Override
        public void completed(ProgressEvent event) {
            if (browser.isDisposed() || browser.getShell().isDisposed()) {
                return;
            }
            shell.open();
        }

        @Override
        public void changed(ProgressEvent event) {
        }
    });
    browser.addCloseWindowListener(new CloseWindowListener() {

        @Override
        public void close(WindowEvent event) {
            if (browser.isDisposed() || browser.getShell().isDisposed()) {
                return;
            }
            context.debug("window.close called");
            shell.dispose();
        }
    });
    browser.addTitleListener(new TitleListener() {

        @Override
        public void changed(TitleEvent event) {
            if (browser.isDisposed() || browser.getShell().isDisposed()) {
                return;
            }
            shell.setText(event.title);
        }
    });
    browser.addStatusTextListener(new StatusTextListener() {

        @Override
        public void changed(StatusTextEvent event) {
            if (browser.isDisposed() || browser.getShell().isDisposed()) {
                return;
            }
            if (MessageBoxShell.STATUS_TEXT_CLOSE.equals(event.text)) {
                // For some reason disposing the shell / browser in the same Thread makes
                // ieframe.dll crash on windows.
                Utils.execSWTThreadLater(0, new Runnable() {

                    @Override
                    public void run() {
                        if (!browser.isDisposed() && !shell.isDisposed()) {
                            shell.close();
                        }
                    }
                });
            }
        }
    });
    SimpleTimer.addEvent("showWin", SystemTime.getOffsetTime(3000), new TimerEventPerformer() {

        @Override
        public void perform(TimerEvent event) {
            Utils.execSWTThread(new AERunnable() {

                @Override
                public void runSupport() {
                    if (shell != null && !shell.isDisposed()) {
                        shell.open();
                    }
                }
            });
        }
    });
    if (w > 0 && h > 0) {
        Rectangle computeTrim = shell.computeTrim(0, 0, w, h);
        shell.setSize(computeTrim.width, computeTrim.height);
    // shell.setSize(w, h);
    }
    Utils.centerWindowRelativeTo(shell, parent);
    browser.setUrl(url);
    browser.setData("StartURL", url);
}
Also used : OpenCloseSearchDetailsListener(com.biglybt.ui.swt.browser.OpenCloseSearchDetailsListener) TitleListener(org.eclipse.swt.browser.TitleListener) StatusTextListener(org.eclipse.swt.browser.StatusTextListener) OpenCloseSearchDetailsListener(com.biglybt.ui.swt.browser.OpenCloseSearchDetailsListener) TitleListener(org.eclipse.swt.browser.TitleListener) ProgressListener(org.eclipse.swt.browser.ProgressListener) CloseWindowListener(org.eclipse.swt.browser.CloseWindowListener) Rectangle(org.eclipse.swt.graphics.Rectangle) StatusTextListener(org.eclipse.swt.browser.StatusTextListener) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) StatusTextEvent(org.eclipse.swt.browser.StatusTextEvent) CloseWindowListener(org.eclipse.swt.browser.CloseWindowListener) BrowserContext(com.biglybt.ui.swt.browser.BrowserContext) FillLayout(org.eclipse.swt.layout.FillLayout) TitleEvent(org.eclipse.swt.browser.TitleEvent) ProgressListener(org.eclipse.swt.browser.ProgressListener) WindowEvent(org.eclipse.swt.browser.WindowEvent) StatusTextEvent(org.eclipse.swt.browser.StatusTextEvent) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) WindowEvent(org.eclipse.swt.browser.WindowEvent) TitleEvent(org.eclipse.swt.browser.TitleEvent) Map(java.util.Map)

Example 9 with ProgressListener

use of org.eclipse.swt.browser.ProgressListener in project OpenTCS-4 by touchmii.

the class BrowserTab method createExampleControls.

@Override
protected void createExampleControls(Composite parent) {
    parent.setLayout(new FillLayout());
    browser = new Browser(parent, getStyle());
    if (hasCreateProperty(PROP_PROGRESS_LISTENER)) {
        browser.addProgressListener(new ProgressListener() {

            @Override
            public void changed(final ProgressEvent event) {
                log("changed: " + event);
            }

            @Override
            public void completed(final ProgressEvent event) {
                log("completed: " + event);
            }
        });
    }
    registerControl(browser);
}
Also used : ProgressListener(org.eclipse.swt.browser.ProgressListener) FillLayout(org.eclipse.swt.layout.FillLayout) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) Browser(org.eclipse.swt.browser.Browser)

Example 10 with ProgressListener

use of org.eclipse.swt.browser.ProgressListener in project knime-workbench by knime.

the class SubnodeLayoutJSONEditorPage method createConfigurationLayoutComposite.

private Composite createConfigurationLayoutComposite(final Composite parent) {
    final Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, false));
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    // Web resources
    final WebTemplate template = WebTemplateUtil.getWebTemplateFromBundleID("knimeConfigurationLayoutEditor_1.0.0");
    final WebTemplate dT = WebTemplateUtil.getWebTemplateFromBundleID("knimeConfigurationLayoutEditor_1.0.0_Debug");
    VisualLayoutViewCreator creator = new VisualLayoutViewCreator(template, dT);
    String html = "";
    try {
        html = creator.createWebResources("configuration layout editor", null, null, "");
    } catch (final IOException e) {
        LOGGER.error("Cannot create configuration layout editor", e);
    }
    // Create browser
    m_configurationBrowser = new Browser(composite, SWT.NONE);
    try {
        m_configurationBrowser.setUrl(new File(html).toURI().toURL().toString());
    } catch (MalformedURLException e) {
        LOGGER.error(e.getMessage(), e);
    }
    m_configurationBrowser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    // Create JSON Objects
    final List<ConfigurationLayoutEditorJSONNode> nodes = createJSONConfigurationNodeList();
    // ensure node layout is written the same as the metanode layout
    final ObjectMapper mapper = JSONLayoutPage.getConfiguredObjectMapper();
    String jsonNodes = "";
    try {
        jsonNodes = mapper.writeValueAsString(nodes);
    } catch (JsonProcessingException e) {
        LOGGER.error("Cannot write JSON: " + e.getMessage(), e);
    }
    // variables in progress listener must be final
    final String jsonLayoutConst = getJsonConfigurationDocument();
    final String jsonNodesConst = jsonNodes;
    m_configurationBrowser.addProgressListener(new ProgressListener() {

        @Override
        public void changed(final ProgressEvent event) {
        // do nothing
        }

        @Override
        public void completed(final ProgressEvent event) {
            m_configurationBrowser.evaluate("setNodes(\'" + jsonNodesConst + "\');");
            m_configurationBrowser.evaluate("setLayout(\'" + jsonLayoutConst + "\');");
        }
    });
    m_configurationLayoutUpdate = new UpdateConfigurationFunction(m_configurationBrowser, "pushLayout");
    return composite;
}
Also used : MalformedURLException(java.net.MalformedURLException) Composite(org.eclipse.swt.widgets.Composite) IOException(java.io.IOException) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) GridLayout(org.eclipse.swt.layout.GridLayout) WebTemplate(org.knime.core.node.web.WebTemplate) ProgressListener(org.eclipse.swt.browser.ProgressListener) GridData(org.eclipse.swt.layout.GridData) File(java.io.File) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Browser(org.eclipse.swt.browser.Browser)

Aggregations

ProgressEvent (org.eclipse.swt.browser.ProgressEvent)32 ProgressListener (org.eclipse.swt.browser.ProgressListener)32 Browser (org.eclipse.swt.browser.Browser)22 FillLayout (org.eclipse.swt.layout.FillLayout)14 Display (org.eclipse.swt.widgets.Display)13 Shell (org.eclipse.swt.widgets.Shell)13 LocationListener (org.eclipse.swt.browser.LocationListener)11 LocationEvent (org.eclipse.swt.browser.LocationEvent)10 GridLayout (org.eclipse.swt.layout.GridLayout)8 Composite (org.eclipse.swt.widgets.Composite)8 IOException (java.io.IOException)6 Test (org.junit.Test)6 SWT (org.eclipse.swt.SWT)5 TitleListener (org.eclipse.swt.browser.TitleListener)5 WindowEvent (org.eclipse.swt.browser.WindowEvent)5 Point (org.eclipse.swt.graphics.Point)5 MalformedURLException (java.net.MalformedURLException)4 SWTError (org.eclipse.swt.SWTError)4 BrowserFunction (org.eclipse.swt.browser.BrowserFunction)4 CloseWindowListener (org.eclipse.swt.browser.CloseWindowListener)4