Search in sources :

Example 66 with Browser

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

the class TutorialsDialog method createDialogArea.

@Override
protected Control createDialogArea(final Composite parent) {
    browser = new Browser(parent, SWT.NONE);
    try {
        browser.setText(TutorialsHelper.getHelper().getHtmlContent());
    } catch (IOException e) {
        CommonExceptionHandler.process(e);
    }
    browser.addLocationListener(new BrowserDynamicPartLocationListener());
    return parent;
}
Also used : BrowserDynamicPartLocationListener(org.talend.commons.ui.html.BrowserDynamicPartLocationListener) IOException(java.io.IOException) Browser(org.eclipse.swt.browser.Browser)

Example 67 with Browser

use of org.eclipse.swt.browser.Browser in project eclipse.platform.text by eclipse.

the class BrowserInformationControl method isAvailable.

/**
 * Tells whether the SWT Browser widget and hence this information
 * control is available.
 *
 * @param parent the parent component used for checking or <code>null</code> if none
 * @return <code>true</code> if this control is available
 */
public static boolean isAvailable(Composite parent) {
    if (!fgAvailabilityChecked) {
        try {
            Browser browser = new Browser(parent, SWT.NONE);
            browser.dispose();
            fgIsAvailable = true;
            Slider sliderV = new Slider(parent, SWT.VERTICAL);
            Slider sliderH = new Slider(parent, SWT.HORIZONTAL);
            int width = sliderV.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
            int height = sliderH.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
            fgScrollBarSize = new Point(width, height);
            sliderV.dispose();
            sliderH.dispose();
        } catch (SWTError er) {
            fgIsAvailable = false;
        } finally {
            fgAvailabilityChecked = true;
        }
    }
    return fgIsAvailable;
}
Also used : SWTError(org.eclipse.swt.SWTError) Slider(org.eclipse.swt.widgets.Slider) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) Browser(org.eclipse.swt.browser.Browser)

Example 68 with Browser

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

the class AbstractInjector method findIntroPageBrowser.

/**
 * Looks for the open intro page editor (and HTML editor) and returns the Browser instance. This (unfortunately)
 * involves some heavy reflection stuff as there is no other way to attach a listener otherwise. If the intro page
 * editor cannot be found then <code>null</code> is returned.
 *
 * @param introPageFile the temporary intro page file
 * @return the browser instance showing the intro page or <code>null</code>
 */
@SuppressWarnings("restriction")
static Browser findIntroPageBrowser(final File introPageFile) {
    for (IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) {
        for (IWorkbenchPage page : window.getPages()) {
            for (IEditorReference ref : page.getEditorReferences()) {
                try {
                    if (isIntroPageEditor(ref, introPageFile)) {
                        IEditorPart part = ref.getEditor(false);
                        if (part instanceof WebBrowserEditor) {
                            WebBrowserEditor editor = (WebBrowserEditor) part;
                            Field webBrowser = editor.getClass().getDeclaredField("webBrowser");
                            webBrowser.setAccessible(true);
                            BrowserViewer viewer = (BrowserViewer) webBrowser.get(editor);
                            Field browserField = viewer.getClass().getDeclaredField("browser");
                            browserField.setAccessible(true);
                            return (Browser) browserField.get(viewer);
                        }
                    }
                } catch (PartInitException ex) {
                    NodeLogger.getLogger(AbstractInjector.class).error("Could not open web browser with intro page: " + ex.getMessage(), ex);
                } catch (SecurityException | NoSuchFieldException | IllegalArgumentException | IllegalAccessException ex) {
                    NodeLogger.getLogger(AbstractInjector.class).error("Could not attach location listener to web browser: " + ex.getMessage(), ex);
                }
            }
        }
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) WebBrowserEditor(org.eclipse.ui.internal.browser.WebBrowserEditor) IEditorPart(org.eclipse.ui.IEditorPart) Field(java.lang.reflect.Field) IEditorReference(org.eclipse.ui.IEditorReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) BrowserViewer(org.eclipse.ui.internal.browser.BrowserViewer) PartInitException(org.eclipse.ui.PartInitException) Browser(org.eclipse.swt.browser.Browser)

Example 69 with Browser

use of org.eclipse.swt.browser.Browser 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 70 with Browser

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

the class HelpView method createPartControl.

/**
 * {@inheritDoc}
 */
@Override
public void createPartControl(final Composite parent) {
    getViewSite().getPage().addSelectionListener(this);
    try {
        m_text = null;
        m_browser = new Browser(parent, SWT.NONE);
        m_browser.addLocationListener(this);
        // add us as listeners of the page selection
        m_browser.setText("");
        m_isFallback = false;
    } catch (SWTError e) {
        NodeLogger.getLogger(getClass()).warn("No html browser for node description available.", e);
        m_browser = null;
        m_text = new FallbackBrowser(parent, SWT.READ_ONLY | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
        m_isFallback = true;
    }
}
Also used : SWTError(org.eclipse.swt.SWTError) IWebBrowser(org.eclipse.ui.browser.IWebBrowser) Browser(org.eclipse.swt.browser.Browser)

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