use of org.eclipse.swt.browser.LocationListener 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();
}
use of org.eclipse.swt.browser.LocationListener in project eclipse.platform.swt by eclipse-platform.
the class Bug511797_locChanged 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);
browser.addLocationListener(new LocationListener() {
@Override
public void changing(LocationEvent event) {
System.out.println("Changing ....");
}
@Override
public void changed(LocationEvent event) {
System.out.println("Changed !!!!");
}
});
browser.setText("Hello world");
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
use of org.eclipse.swt.browser.LocationListener in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_browser_Browser method test_LocationListener_evaluateInCallback.
/**
* This test replicates what happens internally
* if you click on a link in a javadoc popup hoverbox.
* I.e, in a location listener, evaluation() is performed.
*
* The goal of this test is to ensure there are no 'Freezes'/deadlocks if
* javascript evaluation is invoked inside an SWT listener.
*
* At time of writing, it also highlights that evaluation inside SWT listeners
* is not consistent across browsers.
*/
@Test
public void test_LocationListener_evaluateInCallback() {
assumeTrue(isWebkit2 || SwtTestUtil.isCocoa || SwtTestUtil.isWindows);
// On Webki1 this test works, but is prone to crashes. See Bug 509411
AtomicBoolean changingFinished = new AtomicBoolean(false);
AtomicBoolean changedFinished = new AtomicBoolean(false);
browser.addLocationListener(new LocationListener() {
@Override
public void changing(LocationEvent event) {
// Broken on Webkit1. I.e evaluate() in a 'changing()' signal doesn't do anything.
browser.evaluate("SWTchanging = true");
changingFinished.set(true);
}
@Override
public void changed(LocationEvent event) {
browser.evaluate("SWTchanged = true");
changedFinished.set(true);
}
});
browser.setText("<body>Hello <b>World</b></body>");
// Wait till both listeners were fired.
if (SwtTestUtil.isWindows) {
// Windows doesn't reach changedFinished.get();
waitForPassCondition(changingFinished::get);
} else
waitForPassCondition(() -> (changingFinished.get() && changedFinished.get()));
// Inspect if evaluate() was executed correctly.
Boolean changed = false;
try {
changed = (Boolean) browser.evaluate("return SWTchanged");
} catch (SWTException e) {
}
Boolean changing = false;
try {
changing = (Boolean) browser.evaluate("return SWTchanging");
} catch (SWTException e) {
}
String errMsg = "\n changing: fired:" + changingFinished.get() + " evaluated:" + changing + "\n changed: fired:" + changedFinished.get() + " evaluated:" + changed;
boolean passed = false;
if (isWebkit2) {
// Evaluation works in all cases.
passed = changingFinished.get() && changedFinished.get() && changed && changing;
} else if (isWebkit1) {
// On Webkit1, evaluation in 'changing' fails.
// && changing (broken)
passed = changingFinished.get() && changedFinished.get() && changed;
} else if (SwtTestUtil.isCocoa) {
// On Cocoa, evaluation in 'changing' fails.
// && changing (broken)
passed = changingFinished.get() && changedFinished.get() && changed;
} else if (SwtTestUtil.isWindows) {
// On Windows, evaluation inside SWT listeners fails altogether.
// Further, only 'changing' is fired if evaluation is invoked inside listeners.
passed = changingFinished.get();
}
assertTrue(errMsg, passed);
}
use of org.eclipse.swt.browser.LocationListener in project netxms by netxms.
the class BrowserView method createPartControl.
/* (non-Javadoc)
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createPartControl(Composite parent) {
browser = new Browser(parent, SWT.NONE);
browser.addLocationListener(new LocationListener() {
@Override
public void changing(LocationEvent event) {
setPartName(String.format(Messages.get().BrowserView_PartName_Changing, event.location));
actionStop.setEnabled(true);
}
@Override
public void changed(LocationEvent event) {
setPartName(String.format(Messages.get().BrowserView_PartName_Changed, getTitle(browser.getText(), event.location)));
actionStop.setEnabled(false);
}
});
createActions();
contributeToActionBars();
}
use of org.eclipse.swt.browser.LocationListener in project core by jcryptool.
the class BrowserView method createPartControl.
@Override
public void createPartControl(Composite parent) {
GridLayout gridLayout = new GridLayout();
gridLayout.verticalSpacing = 2;
parent.setLayout(gridLayout);
controls = new Controls(parent, SWT.NONE, this);
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
gridData.heightHint = 28;
controls.setLayoutData(gridData);
browser = new Browser(parent, SWT.NONE);
browser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
browser.setUrl(BROWSER_HOME);
browser.addLocationListener(new LocationListener() {
public void changed(LocationEvent event) {
history.put(browser.getUrl(), browser.getUrl());
controls.getUrlField().setItems(history.values().toArray(new String[0]));
controls.getUrlField().setText(browser.getUrl());
controls.getBackButton().setEnabled(browser.isBackEnabled());
controls.getForwardButton().setEnabled(browser.isForwardEnabled());
controls.animateReloadButton(false);
}
public void changing(LocationEvent event) {
controls.animateReloadButton(true);
}
});
browser.addStatusTextListener(new StatusTextListener() {
public void changed(StatusTextEvent event) {
status.setText(event.text);
}
});
status = new Text(parent, SWT.BORDER | SWT.READ_ONLY | SWT.SINGLE);
status.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, // $NON-NLS-1$
"org.jcryptool.webbrowser.webBrowserView");
}
Aggregations