use of org.eclipse.swt.browser.LocationAdapter in project azure-tools-for-java by Microsoft.
the class LoginDialog method createDlgBody.
private void createDlgBody(Composite container) {
final Browser browser = new Browser(container, SWT.NONE);
browser.addLocationListener(new LocationAdapter() {
@Override
public void changing(LocationEvent locationEvent) {
System.out.println("\t--> locationEvent.location: " + locationEvent.location);
if (locationEvent.location.startsWith(redirectUriStr)) {
setResult(locationEvent.location);
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
//Browser.clearSessions();
close();
}
});
}
}
});
// String[] headers = new String[] {
// "User-Agent: SwtBrowser"
// };
// browser.setUrl(requestUriStr, null, headers);
browser.setUrl(requestUriStr);
}
use of org.eclipse.swt.browser.LocationAdapter in project bndtools by bndtools.
the class JPMBrowserView method createPartControl.
@Override
public void createPartControl(Composite parent) {
StackLayout stack = new StackLayout();
parent.setLayout(stack);
JpmPreferences prefs = new JpmPreferences();
if (prefs.getBrowserSelection() == JpmPreferences.PREF_BROWSER_EXTERNAL) {
external = true;
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(2, false));
new Label(composite, SWT.NONE).setText("JPM is configured to open in an external browser.");
Hyperlink linkToPrefs = new Hyperlink(composite, SWT.NONE);
linkToPrefs.setText("Open Preference Page");
linkToPrefs.setUnderlined(true);
linkToPrefs.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(HyperlinkEvent e) {
PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(getViewSite().getShell(), "bndtools.prefPages.jpm", new String[] { "bndtools.prefPages.jpm" }, null);
dialog.open();
}
});
// linkToPrefs.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false));
stack.topControl = composite;
} else {
if (prefs.getBrowserSelection() == JpmPreferences.PREF_BROWSER_PLATFORM_DEFAULT) {
browser = new Browser(parent, SWT.NONE);
stack.topControl = browser;
} else if (prefs.getBrowserSelection() == JpmPreferences.PREF_BROWSER_WEBKIT) {
browser = new Browser(parent, SWT.WEBKIT);
stack.topControl = browser;
} else if (prefs.getBrowserSelection() == JpmPreferences.PREF_BROWSER_MOZILLA) {
browser = new Browser(parent, SWT.MOZILLA);
stack.topControl = browser;
}
createActions();
// Prevent navigation away from JPM4J.org, and redirect from HTTP back to HTTPS
browser.addLocationListener(new LocationAdapter() {
@Override
public void changing(LocationEvent event) {
setContentDescription(event.location);
/*
*
if (event.location.startsWith(HTTPS_URL))
return;
if (event.location.startsWith(HTTP_URL))
event.location = event.location.replaceFirst(HTTP_URL, HTTP_URL);
else
event.doit = false;
*/
}
});
}
selectionService = getViewSite().getWorkbenchWindow().getSelectionService();
selectionService.addSelectionListener(this);
handleWorkbenchSelection(selectionService.getSelection());
}
Aggregations