Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2009 IBM Corporation and others. 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 Contributors: IBM Corporation - initial API and implementation /
package org.eclipse.help.ui.internal.handlers;
public class OpenBundleResourceHandler extends AbstractHandler {
	private static final String PARAM_ID_PLUGIN = "plugin"//$NON-NLS-1$
	private static final String PARAM_ID_PATH = "path"//$NON-NLS-1$
	public Object execute(ExecutionEvent eventthrows ExecutionException {
		String pluginId = event.getParameter();
		String pluginPath = event.getParameter();
		URL url;
		File workspaceFile;
		String errorMessage=""//$NON-NLS-1$
		if (pluginId == null || pluginPath==null) {
			url = null;
else {
			try {
				if(pluginPath.startsWith("/")) //$NON-NLS-1$
					pluginPath = pluginPath.substring(1);
				url = new URL(Platform.getInstanceLocation().getURL().toString()+pluginId+"/"+pluginPath); //$NON-NLS-1$
				workspaceFile = new File(url.getFile());	
				if(!workspaceFile.exists())
				{	
					url = BaseHelpSystem.resolve("/" + pluginId + '/' + pluginPath , true); //$NON-NLS-1$
					if (url == null)
					{
						errorMessage="file not found:" + pluginId+"/"+pluginPath//$NON-NLS-1$ //$NON-NLS-2$
						throw new ExecutionException(errorMessage);
					}		
				}
			}
			catch (Exception ex) {
				throw new ExecutionException(errorMessageex);
			}
		}
		String browserId = pluginId+"."+pluginPath//$NON-NLS-1$
		try {
			IWorkbenchBrowserSupport browserSupport = PlatformUI.getWorkbench()
			IWebBrowser browser = browserSupport.createBrowser(browserId); 
			browser.openURL(url);
catch (PartInitException ex) {
			throw new ExecutionException("error opening browser"ex); //$NON-NLS-1$
		}
		return null;
	}
New to GrepCode? Check out our FAQ X