use of org.eclipse.swt.browser.LocationListener in project mylyn.docs by eclipse.
the class MarkupEditor method createSourceViewer.
@Override
protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
sourceViewerConfiguration.initializeDefaultFonts();
tabFolder = new CTabFolder(parent, SWT.BOTTOM);
{
sourceTab = new CTabItem(tabFolder, SWT.NONE);
updateSourceTabLabel();
viewer = new MarkupProjectionViewer(tabFolder, ruler, getOverviewRuler(), isOverviewRulerVisible(), styles | SWT.WRAP);
sourceTab.setControl(((Viewer) viewer).getControl());
tabFolder.setSelection(sourceTab);
}
try {
previewTab = new CTabItem(tabFolder, SWT.NONE);
previewTab.setText(Messages.MarkupEditor_preview);
previewTab.setToolTipText(Messages.MarkupEditor_preview_tooltip);
browser = new Browser(tabFolder, SWT.NONE);
// bug 260479: open hyperlinks in a browser
browser.addLocationListener(new LocationListener() {
public void changed(LocationEvent event) {
event.doit = false;
}
public void changing(LocationEvent event) {
// if it looks like an absolute URL
if (event.location.matches("([a-zA-Z]{3,8})://?.*")) {
// $NON-NLS-1$
// workaround for browser problem (bug 262043)
// $NON-NLS-1$
int idxOfSlashHash = event.location.indexOf("/#");
if (idxOfSlashHash != -1) {
// allow javascript-based scrolling to work
if (!event.location.startsWith("file:///#")) {
// $NON-NLS-1$
event.doit = false;
}
return;
}
// workaround end
event.doit = false;
try {
PlatformUI.getWorkbench().getBrowserSupport().createBrowser(// $NON-NLS-1$
"org.eclipse.ui.browser").openURL(new URL(event.location));
} catch (Exception e) {
new URLHyperlink(new Region(0, 1), event.location).open();
}
}
}
});
previewTab.setControl(browser);
} catch (SWTError e) {
// disable preview, the exception is probably due to the internal browser not being available
if (previewTab != null) {
previewTab.dispose();
previewTab = null;
}
logPreviewTabUnavailable(e);
}
tabFolder.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent selectionevent) {
widgetSelected(selectionevent);
}
public void widgetSelected(SelectionEvent selectionevent) {
if (isShowingPreview()) {
updatePreview();
}
}
});
viewer.getTextWidget().addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
public void widgetSelected(SelectionEvent e) {
updateOutlineSelection();
}
});
viewer.getTextWidget().addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (isRelevantKeyCode(e.keyCode)) {
updateOutlineSelection();
}
}
private boolean isRelevantKeyCode(int keyCode) {
// for some reason not all key presses result in a selection change
switch(keyCode) {
case SWT.ARROW_DOWN:
case SWT.ARROW_LEFT:
case SWT.ARROW_RIGHT:
case SWT.ARROW_UP:
case SWT.PAGE_DOWN:
case SWT.PAGE_UP:
return true;
}
return false;
}
});
viewer.getTextWidget().addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
updateOutlineSelection();
}
});
IFocusService focusService = PlatformUI.getWorkbench().getService(IFocusService.class);
if (focusService != null) {
focusService.addFocusTracker(viewer.getTextWidget(), MarkupEditor.EDITOR_SOURCE_VIEWER);
}
viewer.getTextWidget().setData(MarkupLanguage.class.getName(), getMarkupLanguage());
viewer.getTextWidget().setData(ISourceViewer.class.getName(), viewer);
getSourceViewerDecorationSupport(viewer);
updateDocument();
if (preferencesListener == null) {
preferencesListener = new IPropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
if (viewer.getTextWidget() == null || viewer.getTextWidget().isDisposed()) {
return;
}
if (isFontPreferenceChange(event)) {
viewer.getTextWidget().getDisplay().asyncExec(new Runnable() {
public void run() {
reloadPreferences();
}
});
}
}
};
WikiTextUiPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(preferencesListener);
}
return viewer;
}
use of org.eclipse.swt.browser.LocationListener in project epp.mpc by eclipse.
the class OverviewToolTip method createToolTipContentArea.
@Override
protected Composite createToolTipContentArea(Event event, final Composite parent) {
Shell shell = parent.getShell();
setData(Shell.class.getName(), shell);
AbstractMarketplaceDiscoveryItem.setWidgetId(shell, DiscoveryItem.WIDGET_ID_OVERVIEW);
GridLayoutFactory.fillDefaults().applyTo(parent);
Color backgroundColor = parent.getDisplay().getSystemColor(SWT.COLOR_WHITE);
final Composite container = new Composite(parent, SWT.NULL);
container.setBackground(backgroundColor);
boolean hasImage = false;
if (overview.getScreenshot() != null) {
hasImage = true;
}
final boolean addLearnMoreLink = browser != null && overview.getUrl() != null && overview.getUrl().length() > 0;
final int borderWidth = 1;
final int heightHint = SCREENSHOT_HEIGHT + (borderWidth * 2);
final int widthHint = SCREENSHOT_WIDTH;
final int containerWidthHintWithImage = 650;
final int containerWidthHintWithoutImage = 500;
GridDataFactory.fillDefaults().grab(true, true).hint(hasImage ? containerWidthHintWithImage : containerWidthHintWithoutImage, SWT.DEFAULT).applyTo(container);
GridLayoutFactory.fillDefaults().numColumns((leftImage != null) ? 3 : 2).margins(5, 5).spacing(3, 0).applyTo(container);
if (leftImage != null) {
Label imageLabel = new Label(container, SWT.NONE);
imageLabel.setImage(leftImage);
imageLabel.setBackground(backgroundColor);
int imageWidthHint = leftImage.getBounds().width + 5;
GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.BEGINNING).hint(imageWidthHint, SWT.DEFAULT).applyTo(imageLabel);
}
String summary = overview.getSummary();
Composite summaryContainer = new Composite(container, SWT.NULL);
summaryContainer.setBackground(backgroundColor);
GridLayoutFactory.fillDefaults().applyTo(summaryContainer);
GridDataFactory gridDataFactory = GridDataFactory.fillDefaults().grab(true, true).span(hasImage ? 1 : 2, 1);
if (hasImage) {
gridDataFactory.hint(widthHint, heightHint);
}
gridDataFactory.applyTo(summaryContainer);
Browser summaryLabel = new Browser(summaryContainer, SWT.NULL);
Font dialogFont = JFaceResources.getDialogFont();
FontData[] fontData = dialogFont.getFontData();
// $NON-NLS-1$
String attr = "";
// $NON-NLS-1$
String fontSizeUnitOfMeasure = "pt";
if (Platform.OS_MACOSX.equals(Platform.getOS())) {
// $NON-NLS-1$
fontSizeUnitOfMeasure = "px";
} else if (Platform.OS_WIN32.equals(Platform.getOS())) {
// $NON-NLS-1$
attr = "overflow: auto; ";
}
String cssStyle = // $NON-NLS-1$ //$NON-NLS-2$
"body, p, div, * {" + attr + "font-family:\"" + fontData[0].getName() + "\",Arial,sans-serif !important;font-size:" + fontData[0].getHeight() + fontSizeUnitOfMeasure + // $NON-NLS-1$ //$NON-NLS-2$
" !important;" + // $NON-NLS-1$
"} body { margin: 0px; background-color: white;}";
summaryLabel.setFont(dialogFont);
String html = // $NON-NLS-1$//$NON-NLS-2$
"<html><style>" + cssStyle + "</style><body>" + TextUtil.cleanInformalHtmlMarkup(summary) + // $NON-NLS-1$
"</body></html>";
summaryLabel.setText(html);
summaryLabel.setBackground(backgroundColor);
// instead of opening links in the tooltip, open a new browser window
summaryLabel.addLocationListener(new LocationListener() {
public void changing(LocationEvent event) {
if (event.location.equals("about:blank")) {
// $NON-NLS-1$
return;
}
event.doit = false;
OverviewToolTip.this.hide();
WorkbenchUtil.openUrl(event.location, IWorkbenchBrowserSupport.AS_EXTERNAL);
}
public void changed(LocationEvent event) {
}
});
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).hint(SWT.DEFAULT, hasImage ? SWT.DEFAULT : SCREENSHOT_HEIGHT).applyTo(summaryLabel);
if (hasImage) {
final Composite imageContainer = new Composite(container, SWT.BORDER);
GridLayoutFactory.fillDefaults().applyTo(imageContainer);
GridDataFactory.fillDefaults().grab(false, false).align(SWT.CENTER, SWT.BEGINNING).hint(widthHint + (borderWidth * 2), heightHint).applyTo(imageContainer);
Label imageLabel = new Label(imageContainer, SWT.NULL);
GridDataFactory.fillDefaults().hint(widthHint, SCREENSHOT_HEIGHT).indent(borderWidth, borderWidth).applyTo(imageLabel);
imageLabel.setBackground(backgroundColor);
imageLabel.setSize(widthHint, SCREENSHOT_HEIGHT);
provideImage(imageLabel, source, overview.getScreenshot());
final Cursor handCursor = new Cursor(imageLabel.getDisplay(), SWT.CURSOR_HAND);
imageLabel.setCursor(handCursor);
imageLabel.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
handCursor.dispose();
}
});
imageLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
OverviewToolTip.this.hide();
WorkbenchUtil.openUrl(overview.getScreenshot(), IWorkbenchBrowserSupport.AS_EXTERNAL);
}
});
// creates a border
imageContainer.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY));
}
if (addLearnMoreLink) {
Link link = new Link(summaryContainer, SWT.NULL);
AbstractMarketplaceDiscoveryItem.setWidgetId(link, DiscoveryItem.WIDGET_ID_LEARNMORE);
GridDataFactory.fillDefaults().grab(false, false).align(SWT.BEGINNING, SWT.CENTER).applyTo(link);
link.setText(Messages.OverviewToolTip_learnMoreLink);
link.setBackground(backgroundColor);
link.setToolTipText(NLS.bind(Messages.OverviewToolTip_openUrlInBrowser, overview.getUrl()));
link.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
OverviewToolTip.this.hide();
browser.openUrl(overview.getUrl());
}
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
});
}
if (!hasImage) {
// prevent overviews with no image from providing unlimited text.
Point optimalSize = summaryContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
if (optimalSize.y > (heightHint + 10)) {
((GridData) summaryContainer.getLayoutData()).heightHint = heightHint;
container.layout(true);
}
}
// hack: cause the tooltip to gain focus so that we can capture the escape key
// this must be done async since the tooltip is not yet visible.
Display.getCurrent().asyncExec(new Runnable() {
public void run() {
if (!parent.isDisposed()) {
parent.setFocus();
}
}
});
return container;
}
use of org.eclipse.swt.browser.LocationListener in project BiglyBT by BiglySoftware.
the class BrowserWrapperFake method setUrl.
@Override
public void setUrl(final String _url) {
url = _url;
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
String url_str = _url;
int pos = url_str.indexOf('?');
if (pos != -1) {
url_str = url_str.substring(0, pos);
}
link_label.setText(url_str);
browser.layout();
for (LocationListener l : location_listeners) {
try {
LocationEvent event = new LocationEvent(browser);
event.top = true;
event.location = _url;
l.changed(event);
} catch (Throwable e) {
Debug.out(e);
}
}
for (ProgressListener l : progress_listeners) {
try {
ProgressEvent event = new ProgressEvent(browser);
l.completed(event);
} catch (Throwable e) {
Debug.out(e);
}
}
for (TitleListener l : title_listeners) {
try {
TitleEvent event = new TitleEvent(browser);
event.title = "Browser Disabled";
l.changed(event);
} catch (Throwable e) {
Debug.out(e);
}
}
}
});
}
use of org.eclipse.swt.browser.LocationListener in project BiglyBT by BiglySoftware.
the class FullUpdateWindow method open.
public static void open(final String url, final UIFunctions.actionListener listener) {
boolean ok = false;
final boolean[] listener_informed = { false };
try {
if (current_shell != null && !current_shell.isDisposed()) {
return;
}
final Shell parentShell = Utils.findAnyShell();
final Shell shell = current_shell = ShellFactory.createShell(parentShell, SWT.BORDER | SWT.APPLICATION_MODAL | SWT.TITLE | SWT.RESIZE | SWT.DIALOG_TRIM);
if (shell == null) {
return;
}
shell.setLayout(new FillLayout());
if (parentShell != null) {
parentShell.setCursor(shell.getDisplay().getSystemCursor(SWT.CURSOR_WAIT));
}
shell.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
try {
if (parentShell != null) {
parentShell.setCursor(e.display.getSystemCursor(SWT.CURSOR_ARROW));
}
if (browserFunction != null && !browserFunction.isDisposed()) {
browserFunction.dispose();
}
current_shell = null;
} finally {
if (!listener_informed[0]) {
try {
listener.actionComplete(false);
} catch (Throwable f) {
Debug.out(f);
}
}
}
}
});
BrowserWrapper browser = Utils.createSafeBrowser(shell, SWT.NONE);
if (browser == null) {
shell.dispose();
return;
}
browser.addTitleListener(new TitleListener() {
@Override
public void changed(TitleEvent event) {
if (shell.isDisposed()) {
return;
}
shell.setText(event.title);
}
});
browser.addOpenWindowListener(new BrowserWrapper.OpenWindowListener() {
@Override
public void open(BrowserWrapper.WindowEvent event) {
final BrowserWrapper subBrowser = Utils.createSafeBrowser(shell, SWT.NONE);
if (subBrowser == null) {
return;
}
subBrowser.addLocationListener(new LocationListener() {
@Override
public void changed(LocationEvent arg0) {
}
@Override
public void changing(LocationEvent event) {
if (event.location == null || !event.location.startsWith("http")) {
return;
}
event.doit = false;
Utils.launch(event.location);
Utils.execSWTThreadLater(1000, new AERunnable() {
@Override
public void runSupport() {
subBrowser.dispose();
}
});
}
});
subBrowser.setBrowser(event);
}
});
browserFunction = browser.addBrowserFunction("sendVuzeUpdateEvent", new BrowserWrapper.BrowserFunction() {
private String last = null;
@Override
public Object function(Object[] arguments) {
if (shell.isDisposed()) {
return null;
}
if (arguments == null) {
Debug.out("Invalid sendVuzeUpdateEvent null ");
return null;
}
if (arguments.length < 1) {
Debug.out("Invalid sendVuzeUpdateEvent length " + arguments.length + " not 1");
return null;
}
if (!(arguments[0] instanceof String)) {
Debug.out("Invalid sendVuzeUpdateEvent " + (arguments[0] == null ? "NULL" : arguments.getClass().getSimpleName()) + " not String");
return null;
}
String text = ((String) arguments[0]).toLowerCase();
if (last != null && last.equals(text)) {
return null;
}
last = text;
if (text.contains("page-loaded")) {
Utils.centreWindow(shell);
if (parentShell != null) {
parentShell.setCursor(shell.getDisplay().getSystemCursor(SWT.CURSOR_ARROW));
}
shell.open();
} else if (text.startsWith("set-size")) {
String[] strings = text.split(" ");
if (strings.length > 2) {
try {
int w = Integer.parseInt(strings[1]);
int h = Integer.parseInt(strings[2]);
Rectangle computeTrim = shell.computeTrim(0, 0, w, h);
shell.setSize(computeTrim.width, computeTrim.height);
} catch (Exception ignored) {
}
}
} else if (text.contains("decline") || text.contains("close")) {
Utils.execSWTThreadLater(0, new AERunnable() {
@Override
public void runSupport() {
shell.dispose();
}
});
} else if (text.contains("accept")) {
Utils.execSWTThreadLater(0, new AERunnable() {
@Override
public void runSupport() {
listener_informed[0] = true;
try {
listener.actionComplete(true);
} catch (Throwable e) {
Debug.out(e);
}
shell.dispose();
}
});
}
return null;
}
});
browser.addStatusTextListener(new StatusTextListener() {
@Override
public void changed(StatusTextEvent event) {
if (browserFunction != null) {
browserFunction.function(new Object[] { event.text });
}
}
});
browser.addLocationListener(new LocationListener() {
@Override
public void changing(LocationEvent event) {
}
@Override
public void changed(LocationEvent event) {
}
});
String final_url = url + (url.indexOf('?') == -1 ? "?" : "&") + "locale=" + MessageText.getCurrentLocale().toString() + "&azv=" + Constants.BIGLYBT_VERSION;
SimpleTimer.addEvent("fullupdate.pageload", SystemTime.getOffsetTime(5000), new TimerEventPerformer() {
@Override
public void perform(TimerEvent event) {
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
if (!shell.isDisposed()) {
shell.open();
}
}
});
}
});
browser.setUrl(final_url);
if (browser.isFake()) {
shell.setSize(400, 500);
Utils.centreWindow(shell);
browser.setUrl(Constants.URL_CLIENT_HOME);
browser.setText("Update available, please go to www.biglybt.com to update.");
shell.open();
}
ok = true;
} finally {
if (!ok) {
try {
listener.actionComplete(false);
} catch (Throwable f) {
Debug.out(f);
}
}
}
}
use of org.eclipse.swt.browser.LocationListener in project netxms-ocilib by stevemqeen.
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();
}
Aggregations