package de.prob2.ui.eclipse;

import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;

import de.prob.webconsole.WebConsole;
import de.prob.webconsole.servlets.visualizations.IRefreshListener;

public class BrowserView extends ViewPart implements IRefreshListener {

	private final int port;
	private Composite canvas;
	private Browser browser;
	protected String url;

	public BrowserView(String url) {
		this.url = url;
		port = WebConsole.getPort();
	}

	/**
	 * This is a callback that will allow us to create the viewer and initialize
	 * it.
	 */
	@Override
	public void createPartControl(final Composite parent) {
		createSWTBrowser(parent);
	}

	private void createSWTBrowser(Composite parent) {
		Browser b = new Browser(parent, SWT.NONE);
		this.browser = b;
		load(getUrl());
		canvas = b;
	}

	public void refresh() {
		browser.refresh();
	}

	public void load(String url) {
		if (url != null) {
			browser.setUrl("http://localhost:" + port + "/" + url);

		}
	}

	protected String getUrl() {
		return url;
	}

	/**
	 * Passing the focus request to the viewer's control.
	 */
	@Override
	public void setFocus() {
		canvas.setFocus();
	}

}
@@ -984,9 +984,9 @@
 url 
-!
+=
 = nu
@@ -991,16 +991,124 @@
 null) %7B%0A
+%09%09%09// FIXME log error?%0A%09%09%09return;%0A%09%09%7D%0A%09%09if (url.startsWith(%22http://%22)) %7B%0A%09%09%09browser.setUrl(url);%0A%09%09%7D else %7B%0A
 %09%09%09brows
@@ -1158,17 +1158,16 @@
 + url);%0A
-%0A
 %09%09%7D%0A%09%7D%0A%0A

allow full urls in BrowserView