Search in sources :

Example 16 with ProgressListener

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

the class Bug505418_Listeners_evals method locationChange.

@SuppressWarnings("unused")
private static void locationChange() {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    Button button = new Button(shell, SWT.PUSH);
    final Browser browser = new Browser(shell, SWT.NONE);
    button.setText("Click to increase count.");
    button.addMouseListener(new MouseListener() {

        @Override
        public void mouseUp(MouseEvent e) {
        }

        @Override
        public void mouseDown(MouseEvent e) {
            shell.setText("Count: " + count++);
        }

        @Override
        public void mouseDoubleClick(MouseEvent e) {
        }
    });
    browser.setText("<html><title>Snippet</title><body><a href=\"https://eclipse.org/\">Eclipse.org  Disposing on link change causes hang</a></body></html>");
    browser.addProgressListener(new ProgressListener() {

        @Override
        public void completed(ProgressEvent event) {
            browser.addLocationListener(new LocationListener() {

                @Override
                public void changing(LocationEvent event) {
                    System.out.println("changing...");
                    String value = (String) browser.evaluate("return 'Changing eval...'");
                    System.out.println("changing returned: " + value);
                // widget.browser.evaluate("return 'Changing eval...'");
                // event.doit = false; // Stop page load.
                }

                @Override
                public void changed(LocationEvent event) {
                    System.out.print("Changed!");
                    String value = (String) browser.evaluate("return 'finished callback'");
                    System.out.println("Changed returned: " + value);
                }
            });
        }

        @Override
        public void changed(ProgressEvent event) {
        }
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) FillLayout(org.eclipse.swt.layout.FillLayout) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) Shell(org.eclipse.swt.widgets.Shell) MouseListener(org.eclipse.swt.events.MouseListener) ProgressListener(org.eclipse.swt.browser.ProgressListener) Button(org.eclipse.swt.widgets.Button) LocationListener(org.eclipse.swt.browser.LocationListener) LocationEvent(org.eclipse.swt.browser.LocationEvent) Display(org.eclipse.swt.widgets.Display) Browser(org.eclipse.swt.browser.Browser)

Example 17 with ProgressListener

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

the class Bug505418_Listeners_evals method progressListener.

private static void progressListener() {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    Button button = new Button(shell, SWT.PUSH);
    final Browser browser = new Browser(shell, SWT.NONE);
    button.setText("Click to increase count.");
    button.addMouseListener(new MouseListener() {

        @Override
        public void mouseUp(MouseEvent e) {
        }

        @Override
        public void mouseDown(MouseEvent e) {
            shell.setText("Count: " + count++);
        }

        @Override
        public void mouseDoubleClick(MouseEvent e) {
        }
    });
    browser.setText("<html><title>Snippet</title><body><a href=\"https://eclipse.org/\">Eclipse.org  Disposing on link change causes hang</a></body></html>");
    browser.addProgressListener(new ProgressListener() {

        @Override
        public void completed(ProgressEvent event) {
            System.out.println("compleated!! " + event.current);
            evalTest(browser, "");
        }

        @Override
        public void changed(ProgressEvent event) {
            System.out.println("changing..." + event.current);
            evalTest(browser, "");
        }
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) MouseListener(org.eclipse.swt.events.MouseListener) MouseEvent(org.eclipse.swt.events.MouseEvent) ProgressListener(org.eclipse.swt.browser.ProgressListener) Button(org.eclipse.swt.widgets.Button) FillLayout(org.eclipse.swt.layout.FillLayout) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) Display(org.eclipse.swt.widgets.Display) Browser(org.eclipse.swt.browser.Browser)

Example 18 with ProgressListener

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

the class Bug510972_WinClearedSignal_auto method main.

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    final Browser browser = new Browser(shell, SWT.NONE);
    class CustomFunction extends // Note: Local class defined inside method.
    BrowserFunction {

        CustomFunction(Browser browser, String name) {
            super(browser, name);
        }

        @Override
        public Object function(Object[] arguments) {
            System.out.println(this.getName() + " called from javascript");
            if (count == 0) {
                browser.setText("2nd page load");
                count++;
            } else {
                System.out.println("Test passed.");
            }
            return null;
        }
    }
    browser.setText("1st (initial) page load");
    new CustomFunction(browser, "callCustomFunction");
    browser.execute("callCustomFunction()");
    browser.addProgressListener(new ProgressListener() {

        @Override
        public void completed(ProgressEvent event) {
            System.out.println("load finished.");
            browser.execute("document.body.style.backgroundColor = 'red'");
            browser.execute("callCustomFunction()");
        }

        @Override
        public void changed(ProgressEvent event) {
        }
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) BrowserFunction(org.eclipse.swt.browser.BrowserFunction) ProgressListener(org.eclipse.swt.browser.ProgressListener) FillLayout(org.eclipse.swt.layout.FillLayout) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) Display(org.eclipse.swt.widgets.Display) Browser(org.eclipse.swt.browser.Browser)

Example 19 with ProgressListener

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

the class BrowserViewer method addBrowserListeners.

/**
 */
private void addBrowserListeners() {
    if (browser == null)
        return;
    // respond to ExternalBrowserInstance StatusTextEvents events by
    // updating the status line
    browser.addStatusTextListener(event -> {
        // System.out.println("status: " + event.text); //$NON-NLS-1$
        if (container != null) {
            IStatusLineManager status = container.getActionBars().getStatusLineManager();
            status.setMessage(event.text);
        }
    });
    // Add listener for new window creation so that we can instead of
    // opening a separate
    // new window in which the session is lost, we can instead open a new
    // window in a new
    // shell within the browser area thereby maintaining the session.
    browser.addOpenWindowListener(event -> {
        Shell shell2 = new Shell(getShell(), SWT.SHELL_TRIM);
        shell2.setLayout(new FillLayout());
        shell2.setText(Messages.viewWebBrowserTitle);
        shell2.setImage(getShell().getImage());
        if (event.location != null)
            shell2.setLocation(event.location);
        if (event.size != null)
            shell2.setSize(event.size);
        int style = 0;
        if (showURLbar)
            style += LOCATION_BAR;
        if (showToolbar)
            style += BUTTON_BAR;
        BrowserViewer browser2 = new BrowserViewer(shell2, style);
        browser2.newWindow = true;
        event.browser = browser2.browser;
    });
    browser.addVisibilityWindowListener(new VisibilityWindowAdapter() {

        @Override
        public void show(WindowEvent e) {
            Browser browser2 = (Browser) e.widget;
            if (browser2.getParent().getParent() instanceof Shell) {
                Shell shell = (Shell) browser2.getParent().getParent();
                if (e.location != null)
                    shell.setLocation(e.location);
                if (e.size != null)
                    shell.setSize(shell.computeSize(e.size.x, e.size.y));
                shell.open();
            }
        }
    });
    browser.addCloseWindowListener(event -> {
        // else its an editor window
        if (newWindow)
            getShell().dispose();
        else
            container.close();
    });
    browser.addProgressListener(new ProgressListener() {

        @Override
        public void changed(ProgressEvent event) {
            // System.out.println("progress: " + event.current + ", " + event.total); //$NON-NLS-1$ //$NON-NLS-2$
            if (event.total == 0)
                return;
            boolean done = (event.current == event.total);
            int percentProgress = event.current * 100 / event.total;
            if (container != null) {
                IProgressMonitor monitor = container.getActionBars().getStatusLineManager().getProgressMonitor();
                if (done) {
                    monitor.done();
                    progressWorked = 0;
                } else if (progressWorked == 0) {
                    // $NON-NLS-1$
                    monitor.beginTask("", event.total);
                    progressWorked = percentProgress;
                } else {
                    monitor.worked(event.current - progressWorked);
                    progressWorked = event.current;
                }
            }
            if (showToolbar) {
                if (!busy.isBusy() && !done)
                    loading = true;
                else if (// once the progress hits
                busy.isBusy() && done)
                    // 100 percent, done, set
                    // busy to false
                    loading = false;
                // System.out.println("loading: " + loading); //$NON-NLS-1$
                updateBackNextBusy();
                updateHistory();
            }
        }

        @Override
        public void completed(ProgressEvent event) {
            if (container != null) {
                IProgressMonitor monitor = container.getActionBars().getStatusLineManager().getProgressMonitor();
                monitor.done();
            }
            if (showToolbar) {
                loading = false;
                updateBackNextBusy();
                updateHistory();
            }
        }
    });
    if (showURLbar) {
        browser.addLocationListener(new LocationAdapter() {

            @Override
            public void changed(LocationEvent event) {
                if (!event.top)
                    return;
                if (combo != null) {
                    if (!"about:blank".equals(event.location)) {
                        // $NON-NLS-1$
                        combo.setText(event.location);
                        addToHistory(event.location);
                        updateHistory();
                    }
                // else
                // combo.setText(""); //$NON-NLS-1$
                }
                if (showToolbar) {
                    // enable auto-refresh button if URL is a file
                    File temp = getFile(browser.getUrl());
                    if (temp != null && temp.exists()) {
                        autoRefresh.setEnabled(true);
                        if (autoRefresh.getSelection()) {
                            fileChangedWatchService(temp);
                        }
                    } else {
                        autoRefresh.setSelection(false);
                        toggleAutoRefresh();
                        autoRefresh.setEnabled(false);
                    }
                }
            }
        });
    }
    browser.addTitleListener(event -> {
        String oldTitle = title;
        title = event.title;
        firePropertyChangeEvent(PROPERTY_TITLE, oldTitle, title);
    });
}
Also used : IStatusLineManager(org.eclipse.jface.action.IStatusLineManager) LocationAdapter(org.eclipse.swt.browser.LocationAdapter) FillLayout(org.eclipse.swt.layout.FillLayout) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) VisibilityWindowAdapter(org.eclipse.swt.browser.VisibilityWindowAdapter) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProgressListener(org.eclipse.swt.browser.ProgressListener) WindowEvent(org.eclipse.swt.browser.WindowEvent) File(java.io.File) LocationEvent(org.eclipse.swt.browser.LocationEvent) Browser(org.eclipse.swt.browser.Browser)

Example 20 with ProgressListener

use of org.eclipse.swt.browser.ProgressListener in project archi by archimatetool.

the class HintsView method createPartControl.

@Override
public void createPartControl(Composite parent) {
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.verticalSpacing = 0;
    parent.setLayout(layout);
    if (!JFaceResources.getFontRegistry().hasValueFor("HintsTitleFont")) {
        // $NON-NLS-1$
        FontData[] fontData = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT).getFontData();
        fontData[0].setHeight(fontData[0].getHeight() + 4);
        // $NON-NLS-1$
        JFaceResources.getFontRegistry().put("HintsTitleFont", fontData);
    }
    fTitleLabel = new CLabel(parent, SWT.NULL);
    // $NON-NLS-1$
    fTitleLabel.setFont(JFaceResources.getFont("HintsTitleFont"));
    // Use CSS styling for label color in case of Dark Theme
    // $NON-NLS-1$ //$NON-NLS-2$
    fTitleLabel.setData("style", "background-color: RGB(220, 235, 235); color: #000;");
    // fTitleLabel.setBackground(ColorFactory.get(220, 235, 235));
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    fTitleLabel.setLayoutData(gd);
    /*
         * It's possible that the system might not be able to create the Browser
         */
    fBrowser = createBrowser(parent);
    if (fBrowser == null) {
        // Create a message and show that instead
        fTitleLabel.setText(Messages.HintsView_2);
        Text text = new Text(parent, SWT.MULTI | SWT.WRAP);
        text.setLayoutData(new GridData(GridData.FILL_BOTH));
        text.setText(Messages.HintsView_3);
        text.setForeground(new Color(255, 45, 45));
        return;
    }
    gd = new GridData(GridData.FILL_BOTH);
    fBrowser.setLayoutData(gd);
    // Listen to Loading progress
    fBrowser.addProgressListener(new ProgressListener() {

        @Override
        public void completed(ProgressEvent event) {
            fPageLoaded = true;
        }

        @Override
        public void changed(ProgressEvent event) {
        }
    });
    // Listen to Diagram Editor Selections
    ComponentSelectionManager.INSTANCE.addSelectionListener(this);
    fActionPinContent = new PinAction();
    // IMenuManager menuManager = getViewSite().getActionBars().getMenuManager();
    // menuManager.add(fActionPinContent);
    IToolBarManager toolBarManager = getViewSite().getActionBars().getToolBarManager();
    toolBarManager.add(fActionPinContent);
    createFileMap();
    // Listen to workbench selections
    getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(this);
    // Help
    PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);
    // Initialise with whatever is selected in the workbench
    ISelection selection = getSite().getWorkbenchWindow().getSelectionService().getSelection();
    IWorkbenchPart part = getSite().getWorkbenchWindow().getPartService().getActivePart();
    selectionChanged(part, selection);
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) FontData(org.eclipse.swt.graphics.FontData) Color(org.eclipse.swt.graphics.Color) Text(org.eclipse.swt.widgets.Text) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ProgressListener(org.eclipse.swt.browser.ProgressListener) IToolBarManager(org.eclipse.jface.action.IToolBarManager) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) GridData(org.eclipse.swt.layout.GridData) ISelection(org.eclipse.jface.viewers.ISelection)

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