Search in sources :

Example 1 with ProgressAdapter

use of org.eclipse.swt.browser.ProgressAdapter in project xtext-eclipse by eclipse.

the class XbaseInformationControl method createContent.

/**
 * Xbase - modification+ added detailPane
 */
@Override
protected void createContent(Composite parent) {
    fSashForm = new SashForm(parent, parent.getStyle());
    fSashForm.setOrientation(SWT.VERTICAL);
    fBrowser = new Browser(fSashForm, SWT.NONE);
    fBrowser.setJavascriptEnabled(false);
    Display display = getShell().getDisplay();
    ColorRegistry registry = JFaceResources.getColorRegistry();
    // $NON-NLS-1$
    Color foreground = registry.get("org.eclipse.ui.workbench.HOVER_FOREGROUND");
    // $NON-NLS-1$
    Color background = registry.get("org.eclipse.ui.workbench.HOVER_BACKGROUND");
    if (background != null && foreground != null) {
        fBrowser.setForeground(foreground);
        fBrowser.setBackground(background);
    } else {
        fBrowser.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
        fBrowser.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
    }
    fBrowser.addProgressListener(new ProgressAdapter() {

        @Override
        public void completed(ProgressEvent event) {
            fCompleted = true;
        }
    });
    fBrowser.addOpenWindowListener(new OpenWindowListener() {

        @Override
        public void open(WindowEvent event) {
            // Cancel opening of new windows
            event.required = true;
        }
    });
    // Replace browser's built-in context menu with none
    fSashForm.setMenu(new Menu(getShell(), SWT.NONE));
    detailPaneComposite = createComposite(fSashForm, 1, 1, GridData.FILL_BOTH);
    Layout layout = detailPaneComposite.getLayout();
    if (layout instanceof GridLayout) {
        GridLayout gl = (GridLayout) layout;
        gl.marginHeight = 0;
        gl.marginWidth = 0;
        gl.numColumns = 1;
    }
    if (background != null && foreground != null) {
        detailPaneComposite.setForeground(foreground);
        detailPaneComposite.setBackground(background);
    } else {
        detailPaneComposite.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
        detailPaneComposite.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
    }
    resourceProvider = new HoverEditedResourceProvider();
    embeddedEditor = xbaseHoverConfiguration.getEditorFactory().newEditor(resourceProvider).readOnly().processIssuesBy(new IValidationIssueProcessor() {

        @Override
        public void processIssues(List<Issue> issues, IProgressMonitor monitor) {
        }
    }).withParent(detailPaneComposite);
    Control viewerControl = embeddedEditor.getViewer().getControl();
    if (background != null && foreground != null) {
        viewerControl.setForeground(foreground);
        viewerControl.setBackground(background);
    } else {
        viewerControl.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
        viewerControl.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
    }
    embeddedEditor.getDocument().setValidationJob(null);
    createTextLayout();
}
Also used : Issue(org.eclipse.xtext.validation.Issue) Color(org.eclipse.swt.graphics.Color) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) IValidationIssueProcessor(org.eclipse.xtext.ui.editor.validation.IValidationIssueProcessor) SashForm(org.eclipse.swt.custom.SashForm) GridLayout(org.eclipse.swt.layout.GridLayout) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IXtextBrowserInformationControl(org.eclipse.xtext.ui.editor.hover.html.IXtextBrowserInformationControl) AbstractInformationControl(org.eclipse.jface.text.AbstractInformationControl) Control(org.eclipse.swt.widgets.Control) ColorRegistry(org.eclipse.jface.resource.ColorRegistry) TextLayout(org.eclipse.swt.graphics.TextLayout) Layout(org.eclipse.swt.widgets.Layout) GridLayout(org.eclipse.swt.layout.GridLayout) WindowEvent(org.eclipse.swt.browser.WindowEvent) ProgressAdapter(org.eclipse.swt.browser.ProgressAdapter) Menu(org.eclipse.swt.widgets.Menu) OpenWindowListener(org.eclipse.swt.browser.OpenWindowListener) Browser(org.eclipse.swt.browser.Browser) Display(org.eclipse.swt.widgets.Display)

Example 2 with ProgressAdapter

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

the class BrowserInformationControl method createContent.

@Override
protected void createContent(Composite parent) {
    fBrowser = new Browser(parent, SWT.NONE);
    fBrowser.setJavascriptEnabled(false);
    Display display = getShell().getDisplay();
    fBrowser.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
    fBrowser.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
    fBrowser.addProgressListener(new ProgressAdapter() {

        @Override
        public void completed(ProgressEvent event) {
            fCompleted = true;
        }
    });
    fBrowser.addOpenWindowListener(new OpenWindowListener() {

        @Override
        public void open(WindowEvent event) {
            // Cancel opening of new windows
            event.required = true;
        }
    });
    // Replace browser's built-in context menu with none
    fBrowser.setMenu(new Menu(getShell(), SWT.NONE));
    createTextLayout();
}
Also used : WindowEvent(org.eclipse.swt.browser.WindowEvent) ProgressAdapter(org.eclipse.swt.browser.ProgressAdapter) Menu(org.eclipse.swt.widgets.Menu) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) OpenWindowListener(org.eclipse.swt.browser.OpenWindowListener) Browser(org.eclipse.swt.browser.Browser) Display(org.eclipse.swt.widgets.Display)

Example 3 with ProgressAdapter

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

the class Test_org_eclipse_swt_browser_Browser method test_VisibilityWindowListener_multiple_shells.

/**
 * Verify that if multiple child shells are open, no duplicate visibility events are sent.
 */
@Test
public void test_VisibilityWindowListener_multiple_shells() {
    AtomicBoolean secondChildCompleted = new AtomicBoolean(false);
    AtomicInteger childCount = new AtomicInteger(0);
    browser.addOpenWindowListener(event -> {
        Shell childShell = new Shell(shell);
        childShell.setText("Child shell " + childCount.get());
        childShell.setLayout(new FillLayout());
        Browser browserChild = new Browser(childShell, SWT.NONE);
        event.browser = browserChild;
        browserChild.setText("Child window");
        browserChild.addVisibilityWindowListener(new VisibilityWindowAdapter() {

            AtomicInteger invocationCount = new AtomicInteger(1);

            AtomicInteger childID = new AtomicInteger(childCount.get());

            @Override
            public void show(WindowEvent event) {
                if (childID.get() == 0 && invocationCount.get() >= 2) {
                    // are considered 'legal' as long as they don't contain size and location information.
                    if (event.location != null || event.size != null) {
                        fail("Child browser's visibility show listener should only be fired once");
                    }
                }
                invocationCount.incrementAndGet();
            }
        });
        if (childCount.get() == 1) {
            browserChild.addProgressListener(new ProgressAdapter() {

                @Override
                public void completed(ProgressEvent event) {
                    secondChildCompleted.set(true);
                }
            });
        }
        childShell.open();
        childCount.incrementAndGet();
    });
    shell.open();
    browser.setText("<html>" + "<script type='text/javascript'>" + // opens child window.
    "window.open();" + "window.open();" + "</script>\n" + "<body>This test uses javascript to open a new window.</body></html>");
    boolean passed = waitForPassCondition(() -> secondChildCompleted.get());
    String errMsg = "\nTest timed out.";
    assertTrue(errMsg, passed);
}
Also used : VisibilityWindowAdapter(org.eclipse.swt.browser.VisibilityWindowAdapter) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Shell(org.eclipse.swt.widgets.Shell) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) WindowEvent(org.eclipse.swt.browser.WindowEvent) FillLayout(org.eclipse.swt.layout.FillLayout) ProgressAdapter(org.eclipse.swt.browser.ProgressAdapter) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) Browser(org.eclipse.swt.browser.Browser) Test(org.junit.Test)

Example 4 with ProgressAdapter

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

the class Test_org_eclipse_swt_browser_Browser method test_ProgressListener_newProgressAdapter_closeShell.

@Test
public void test_ProgressListener_newProgressAdapter_closeShell() {
    Display display = Display.getCurrent();
    Shell shell = new Shell(display);
    Browser browser = new Browser(shell, SWT.NONE);
    browser.addProgressListener(new ProgressAdapter() {
    });
    shell.close();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ProgressAdapter(org.eclipse.swt.browser.ProgressAdapter) Display(org.eclipse.swt.widgets.Display) Browser(org.eclipse.swt.browser.Browser) Test(org.junit.Test)

Example 5 with ProgressAdapter

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

the class Test_org_eclipse_swt_browser_Browser method test_setJavascriptEnabled_multipleInstances.

/**
 * Check that if there are two browser instances, turning off JS in one instance doesn't turn off JS in the other instance.
 */
@Test
public void test_setJavascriptEnabled_multipleInstances() {
    AtomicInteger pageLoadCount = new AtomicInteger(1);
    AtomicInteger pageLoadCountSecondInstance = new AtomicInteger(1);
    AtomicBoolean instanceOneFinishedCorrectly = new AtomicBoolean(false);
    AtomicBoolean instanceTwoFinishedCorrectly = new AtomicBoolean(false);
    Browser browserSecondInsance = new Browser(shell, SWT.None);
    browser.addProgressListener(completedAdapter(event -> {
        if (pageLoadCount.get() == 1) {
            browser.setJavascriptEnabled(false);
            pageLoadCount.set(2);
            browser.setText("First instance, second page (with javascript turned off)");
            pageLoadCountSecondInstance.set(2);
            browserSecondInsance.setText("Second instance, second page (javascript execution not changed)");
        } else if (pageLoadCount.get() == 2) {
            pageLoadCount.set(3);
            Boolean shouldBeNull = (Boolean) browser.evaluate("return true");
            assertNull("1) Evaluate execution should be null, but 'true was returned'", shouldBeNull);
            instanceOneFinishedCorrectly.set(true);
        }
    }));
    browserSecondInsance.addProgressListener(new ProgressAdapter() {

        @Override
        public void completed(ProgressEvent event) {
            if (pageLoadCountSecondInstance.get() == 2) {
                pageLoadCountSecondInstance.set(3);
                Boolean shouldBeTrue = (Boolean) browserSecondInsance.evaluate("return true");
                assertTrue("2) Javascript should be executable in second instance (as javascript was not turned off), but it was not. " + "Expected:'someStr', Actual:" + shouldBeTrue, shouldBeTrue);
                instanceTwoFinishedCorrectly.set(true);
            }
        }
    });
    browser.setText("First Instance, first page");
    browserSecondInsance.setText("Second instance, first page");
    shell.open();
    boolean passed = waitForPassCondition(() -> {
        return instanceOneFinishedCorrectly.get() && instanceTwoFinishedCorrectly.get();
    });
    String message = "3) Test timed out. Debug Info:\n" + "InstanceOneFinishedCorrectly: " + instanceOneFinishedCorrectly.get() + "\n" + "InstanceTwoFinishedCorrectly: " + instanceTwoFinishedCorrectly.get() + "\n" + "Instance 1 & 2 page counts: " + pageLoadCount.get() + " & " + pageLoadCountSecondInstance.get();
    assertTrue(message, passed);
}
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) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ProgressAdapter(org.eclipse.swt.browser.ProgressAdapter) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) Browser(org.eclipse.swt.browser.Browser) Test(org.junit.Test)

Aggregations

ProgressAdapter (org.eclipse.swt.browser.ProgressAdapter)8 Browser (org.eclipse.swt.browser.Browser)7 ProgressEvent (org.eclipse.swt.browser.ProgressEvent)7 WindowEvent (org.eclipse.swt.browser.WindowEvent)4 FillLayout (org.eclipse.swt.layout.FillLayout)4 Display (org.eclipse.swt.widgets.Display)4 OpenWindowListener (org.eclipse.swt.browser.OpenWindowListener)3 Shell (org.eclipse.swt.widgets.Shell)3 Test (org.junit.Test)3 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 SWTException (org.eclipse.swt.SWTException)2 TitleListener (org.eclipse.swt.browser.TitleListener)2 VisibilityWindowAdapter (org.eclipse.swt.browser.VisibilityWindowAdapter)2 Menu (org.eclipse.swt.widgets.Menu)2 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringReader (java.io.StringReader)1