/* ******************************************************************************
* Copyright (c) 2006-2012 XMind Ltd. and others.
*
* This file is a part of XMind 3. XMind releases 3 and
* above are dual-licensed under the Eclipse Public License (EPL),
* which is available at http://www.eclipse.org/legal/epl-v10.html
* and the GNU Lesser General Public License (LGPL),
* which is available at http://www.gnu.org/licenses/lgpl.html
* See http://www.xmind.net/license.html for details.
*
* Contributors:
* XMind Ltd. - initial API and implementation
*******************************************************************************/
package net.xmind.workbench.internal.actions;
import java.io.IOException;
import java.net.URL;
import net.xmind.signin.XMindNet;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.osgi.framework.Bundle;
/**
* @author Frank Shaka
*
*/
public class HelpActionDelegate implements IWorkbenchWindowActionDelegate {
private static final String ONLINE_HELP_URL = "http://www.xmind.net/xmind/help/"; //$NON-NLS-1$
private IWorkbenchWindow window;
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
*/
public void dispose() {
this.window = null;
}
/*
* (non-Javadoc)
*
* @seeorg.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.
* IWorkbenchWindow)
*/
public void init(IWorkbenchWindow window) {
this.window = window;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
*/
public void run(IAction action) {
if (window == null)
return;
XMindNet.gotoURL(false, findHelpURL());
}
private String findHelpURL() {
Bundle helpBundle = Platform.getBundle("org.xmind.ui.help"); //$NON-NLS-1$
if (helpBundle != null) {
URL url = FileLocator.find(helpBundle, new Path(
"$nl$/contents/index.html"), null); //$NON-NLS-1$
if (url != null) {
try {
url = FileLocator.toFileURL(url);
return url.toExternalForm();
} catch (IOException e) {
}
}
}
return ONLINE_HELP_URL;
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action
* .IAction, org.eclipse.jface.viewers.ISelection)
*/
public void selectionChanged(IAction action, ISelection selection) {
// do nothing
}
}