Search in sources :

Example 21 with ProgressListener

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

the class WizardNodeView method callOpenView.

/**
 * {@inheritDoc}
 */
@Override
public final void callOpenView(final String title, final Rectangle knimeWindowBounds) {
    m_title = (title == null ? "View" : title);
    Display display = getDisplay();
    m_shell = new Shell(display, SWT.SHELL_TRIM);
    m_shell.setText(m_title);
    m_shell.setImage(ImageRepository.getIconImage(SharedImages.KNIME));
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    m_shell.setLayout(layout);
    m_browser = new Browser(m_shell, SWT.NONE);
    m_browser.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
    m_browser.setText(getViewCreator().createMessageHTML("Loading view..."), true);
    Composite buttonComposite = new Composite(m_shell, SWT.NONE);
    buttonComposite.setLayoutData(new GridData(GridData.END, GridData.END, false, false));
    buttonComposite.setLayout(new RowLayout());
    ToolBar toolBar = new ToolBar(buttonComposite, SWT.BORDER | SWT.HORIZONTAL);
    ToolItem resetButton = new ToolItem(toolBar, SWT.PUSH);
    resetButton.setText("Reset");
    resetButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            // Could only call if actual settings have been changed,
            // however there might be things in views that one can change
            // which do not get saved, then it's nice to trigger the event anyways.
            /*if (checkSettingsChanged()) {*/
            modelChanged();
        /*}*/
        }
    });
    new ToolItem(toolBar, SWT.SEPARATOR);
    ToolItem applyButton = new ToolItem(toolBar, SWT.DROP_DOWN);
    applyButton.setText("Apply");
    applyButton.setToolTipText("Applies the current settings and triggers a re-execute of the node.");
    DropdownSelectionListener applyListener = new DropdownSelectionListener(applyButton);
    String aTTooltip = "Applies the current settings and triggers a re-execute of the node.";
    applyListener.add("Apply temporarily", aTTooltip, new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            applyTriggered(false);
        }
    });
    String nDTooltip = "Applies the current settings as the node default settings and triggers a re-execute of the node.";
    applyListener.add("Apply as new default", nDTooltip, new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            applyTriggered(true);
        }
    });
    applyButton.addSelectionListener(applyListener);
    applyButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (e.detail != SWT.ARROW) {
                if (checkSettingsChanged()) {
                    showApplyDialog();
                }
            }
        }
    });
    new ToolItem(toolBar, SWT.SEPARATOR);
    ToolItem closeButton = new ToolItem(toolBar, SWT.DROP_DOWN);
    closeButton.setText("Close");
    closeButton.setToolTipText("Closes the view.");
    DropdownSelectionListener closeListener = new DropdownSelectionListener(closeButton);
    String cDTooltip = "Closes the view and discards any changes made.";
    closeListener.add("Close && Discard", cDTooltip, new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            m_shell.dispose();
        }
    });
    String cATooltip = "Closes the view, applies the current settings and triggers a re-execute of the node.";
    closeListener.add("Close && Apply temporarily", cATooltip, new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (applyTriggered(false)) {
                m_shell.dispose();
            }
        }
    });
    String cTTooltip = "Closes the view, applies the current settings as node defaults and triggers a re-execute of the node.";
    closeListener.add("Close && Apply as new default", cTTooltip, new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (applyTriggered(true)) {
                m_shell.dispose();
            }
        }
    });
    closeButton.addSelectionListener(closeListener);
    closeButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (e.detail != SWT.ARROW) {
                if (checkSettingsChanged()) {
                    /*MessageDialogWithToggle dialog =
                            MessageDialogWithToggle.openOkCancelConfirm(m_browser.getShell(), "Discard Settings",
                                "View settings have changed and will be lost. Do you want to continue?",
                                "Do not ask again", false, null, null);*/
                    if (!showCloseDialog()) {
                        return;
                    }
                }
                m_shell.dispose();
            }
        }
    });
    m_shell.addListener(SWT.Close, new Listener() {

        @Override
        public void handleEvent(final Event event) {
            if (checkSettingsChanged()) {
                event.doit = showCloseDialog();
            }
        }
    });
    // TODO: make initial size dynamic
    m_shell.setSize(1024, 768);
    Point middle = new Point(knimeWindowBounds.width / 2, knimeWindowBounds.height / 2);
    // Left upper point for window
    Point newLocation = new Point(middle.x - (m_shell.getSize().x / 2) + knimeWindowBounds.x, middle.y - (m_shell.getSize().y / 2) + knimeWindowBounds.y);
    m_shell.setLocation(newLocation.x, newLocation.y);
    m_shell.addDisposeListener(new org.eclipse.swt.events.DisposeListener() {

        @Override
        public void widgetDisposed(final DisposeEvent e) {
            callCloseView();
        }
    });
    m_shell.open();
    display.asyncExec(new Runnable() {

        @Override
        public void run() {
            m_browser.addProgressListener(new ProgressListener() {

                @Override
                public void completed(final ProgressEvent event) {
                    if (m_viewSet && !m_initialized) {
                        WizardNode<REP, VAL> model = getModel();
                        WizardViewCreator<REP, VAL> creator = getViewCreator();
                        String initCall = creator.createInitJSViewMethodCall(model.getViewRepresentation(), model.getViewValue());
                        initCall = creator.wrapInTryCatch(initCall);
                        // The execute call might fire the completed event again in some browsers!
                        m_initialized = true;
                        m_browser.execute(initCall);
                    }
                }

                @Override
                public void changed(final ProgressEvent event) {
                // do nothing
                }
            });
            setBrowserURL();
        }
    });
}
Also used : ProgressListener(org.eclipse.swt.browser.ProgressListener) Listener(org.eclipse.swt.widgets.Listener) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) Shell(org.eclipse.swt.widgets.Shell) GridLayout(org.eclipse.swt.layout.GridLayout) RowLayout(org.eclipse.swt.layout.RowLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ToolItem(org.eclipse.swt.widgets.ToolItem) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Point(java.awt.Point) ProgressListener(org.eclipse.swt.browser.ProgressListener) GridData(org.eclipse.swt.layout.GridData) ToolBar(org.eclipse.swt.widgets.ToolBar) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Event(org.eclipse.swt.widgets.Event) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Display(org.eclipse.swt.widgets.Display) Browser(org.eclipse.swt.browser.Browser)

Example 22 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_ProgressListener_newListener_closeShell.

@Test
public void test_ProgressListener_newListener_closeShell() {
    Display display = Display.getCurrent();
    Shell shell = new Shell(display);
    Browser browser = new Browser(shell, SWT.NONE);
    browser.addProgressListener(new ProgressListener() {

        @Override
        public void changed(ProgressEvent event) {
        }

        @Override
        public void completed(ProgressEvent event) {
        }
    });
    shell.close();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ProgressListener(org.eclipse.swt.browser.ProgressListener) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) Display(org.eclipse.swt.widgets.Display) Browser(org.eclipse.swt.browser.Browser) Test(org.junit.Test)

Example 23 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 24 with ProgressListener

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

the class OAuthDialog 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 OAuthBrowser(container, SWT.BORDER);
    browser.setText(loadingHtml);
    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);
        }
    };
    TokenListener tokenListener = new TokenListener() {

        @Override
        public void tokenReceived(TokenEvent event) {
            token = event.getToken();
            if (autoClose) {
                OAuthDialog.this.close();
            }
        }
    };
    browser.addProgressListener(progressListener);
    browser.addTokenListener(tokenListener);
    setURL(url);
    return container;
}
Also used : TokenEvent(org.jboss.tools.openshift.internal.ui.wizard.connection.OAuthBrowser.TokenEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) ProgressListener(org.eclipse.swt.browser.ProgressListener) TokenListener(org.jboss.tools.openshift.internal.ui.wizard.connection.OAuthBrowser.TokenListener) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) ProgressBar(org.eclipse.swt.widgets.ProgressBar) Point(org.eclipse.swt.graphics.Point)

Example 25 with ProgressListener

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

the class SimpleBrowserWindow method init.

private void init(Shell parent, String url, int w, int h, boolean allowResize, boolean isModal) {
    if (parent == null) {
        parent = Utils.findAnyShell();
    }
    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);
    browser = Utils.createSafeBrowser(shell, SWT.NONE);
    if (browser == null) {
        shell.dispose();
        return;
    }
    browser.addProgressListener(new ProgressListener() {

        @Override
        public void completed(ProgressEvent event) {
            shell.open();
        }

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

        @Override
        public void close(WindowEvent event) {
            if (shell == null || shell.isDisposed()) {
                return;
            }
            shell.dispose();
        }
    });
    browser.addTitleListener(new TitleListener() {

        @Override
        public void changed(TitleEvent event) {
            if (shell == null || shell.isDisposed()) {
                return;
            }
            shell.setText(event.title);
        }
    });
    if (w > 0 && h > 0) {
        shell.setSize(w, h);
    }
    Utils.centerWindowRelativeTo(shell, parent);
    browser.setUrl(url);
    browser.setData("StartURL", url);
}
Also used : TitleListener(org.eclipse.swt.browser.TitleListener) TitleEvent(org.eclipse.swt.browser.TitleEvent) ProgressListener(org.eclipse.swt.browser.ProgressListener) CloseWindowListener(org.eclipse.swt.browser.CloseWindowListener) WindowEvent(org.eclipse.swt.browser.WindowEvent) FillLayout(org.eclipse.swt.layout.FillLayout) ProgressEvent(org.eclipse.swt.browser.ProgressEvent)

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