/*******************************************************************************
 * Copyright (c) 2010 Oak Ridge National Laboratory.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 ******************************************************************************/
package org.csstudio.opibuilder.widgets.figures;


import org.csstudio.opibuilder.editparts.AbstractBaseEditPart;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.internal.browser.BrowserViewer;

/**Figure for a web browser widget.
 * @author Xihui Chen
 *
 */
@SuppressWarnings("restriction")
public class WebBrowserFigure extends AbstractWebBrowserFigure<BrowserViewer> {


	private BrowserViewer browserViewer;
	private Browser browser;
		
	public WebBrowserFigure(AbstractBaseEditPart editPart, boolean showToolbar) {
		super(editPart, showToolbar ? BrowserViewer.BUTTON_BAR
				| BrowserViewer.LOCATION_BAR : SWT.None);
	}
	
	public void setUrl(String url){
		if(runmode && url.trim().length() > 0)
			browserViewer.setURL(url);
	}

	public Browser getBrowser() {
		return browser;
	}

	@Override
	protected  BrowserViewer createSWTWidget(Composite parent, int style) {
		browserViewer = new BrowserViewer(parent, style);
		browserViewer.setLayoutData(null);
		browser = browserViewer.getBrowser();
		return browserViewer;
		
	}
	
}

@@ -568,16 +568,194 @@
 itPart;%0A
+import org.csstudio.opibuilder.util.ErrorHandlerUtil;%0Aimport org.eclipse.draw2d.ColorConstants;%0Aimport org.eclipse.draw2d.Graphics;%0Aimport org.eclipse.draw2d.geometry.Rectangle;%0A
 import o
@@ -1151,24 +1151,56 @@
 er browser;%0A
+%09%0A%09private String errorMassage;%0A
 %09%09%0A%09public W
@@ -1451,16 +1451,26 @@
 () %3E 0)%0A
+%09%09%09try %7B%0A%09
 %09%09%09brows
@@ -1491,16 +1491,797 @@
 L(url);%0A
+%09%09%09%7D catch (Exception e) %7B%0A%09%09%09%09errorMassage = %22Failed to set URL to the web browser widget.%5Cn%22 +%0A%09%09%09%09%09%09%22It may not available on your platform.%5Cn%22 + e;%0A%09%09%09%09ErrorHandlerUtil.handleError(errorMassage, e);%0A%09%09%09%7D%0A%09%7D%0A%09%0A%09@Override%0A%09protected void paintOutlineFigure(Graphics graphics) %7B%0A%09%09super.paintOutlineFigure(graphics);%0A%09%09if(errorMassage != null)%7B%0A%09%09%09graphics.pushState();%0A%09%09%09graphics.setBackgroundColor(ColorConstants.white);%0A%09%09%09Rectangle clientArea = getClientArea();%0A%09%09%09graphics.fillRectangle(clientArea);%0A%09%09%09if(getBorder() == null)%7B%0A%09%09%09%09graphics.setForegroundColor(ColorConstants.gray);%0A%09%09%09%09graphics.drawRectangle(getBounds());%0A%09%09%09%7D%0A%09%09%09graphics.setForegroundColor(ColorConstants.red);%0A%09%09%09graphics.drawText(errorMassage, clientArea.x, clientArea.y);%0A%09%09%09graphics.popState();%0A%09%09%7D%0A%09%09%0A
 %09%7D%0A%0A%09pub
@@ -2413,16 +2413,25 @@
 tyle) %7B%0A
+%09%09try %7B%0A%09
 %09%09browse
@@ -2472,24 +2472,25 @@
 , style);%0A%09%09
+%09
 browserViewe
@@ -2512,16 +2512,17 @@
 (null);%0A
+%09
 %09%09browse
@@ -2553,16 +2553,211 @@
 wser();%0A
+%09%09%7D catch (Exception e) %7B%0A%09%09%09errorMassage = %22Failed to create web browser widget.%5Cn%22 +%0A%09%09%09%09%09%22It may not available on your platform.%5Cn%22 + e;;%0A%09%09%09ErrorHandlerUtil.handleError(errorMassage, e);%0A%09%09%7D%0A
 %09%09return

add error handling in case of web browser widget doesn't work