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();
}
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();
}
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);
}
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();
}
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);
}
Aggregations