Commit 65a055a6 authored by Romain Bioteau's avatar Romain Bioteau

BS-12182

Add menu entry opening browser
refactor open browser operation
parent d745f565
......@@ -490,4 +490,11 @@
version="0.0.0"
unpack="false"/>
<plugin
id="org.bonitasoft.studio.browser"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>
</feature>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="src-test/java"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.bonitasoft.studio.browser</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Browser Support Plugin
Bundle-SymbolicName: org.bonitasoft.studio.browser
Bundle-Version: 6.5.0.qualifier
Bundle-Activator: org.bonitasoft.studio.browser.BrowserSupportPlugin
Bundle-Vendor: Bonitasoft S.A.
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.junit;bundle-version="4.11.0";resolution:=optional,
org.mockito;bundle-version="1.9.5";resolution:=optional,
assertj-core;bundle-version="1.5.0";resolution:=optional,
org.eclipse.ui.browser,
org.bonitasoft.studio.preferences,
org.bonitasoft.studio.common
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Export-Package: org.bonitasoft.studio.browser.operation
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
src.excludes = src-test/java/
noBrowserFoundTitle=No web browser defined
noBrowserFoundMsg=The Portal cannot be launched because no web browser has been defined. Please set a web browser in order to continue.
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.bonitasoft.studio.bundles</groupId>
<artifactId>plugins</artifactId>
<version>6.5.0-SNAPSHOT</version>
</parent>
<groupId>org.bonitasoft.studio.bundles.plugins</groupId>
<artifactId>org.bonitasoft.studio.browser</artifactId>
<packaging>eclipse-plugin</packaging>
</project>
/**
* Copyright (C) 2014 BonitaSoft S.A.
* BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.browser.operation;
import org.junit.After;
import org.junit.Before;
/**
* @author Romain Bioteau
*
*/
public class OpenBrowserOperationTest {
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
}
}
package org.bonitasoft.studio.browser;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
public class BrowserSupportPlugin extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "org.bonitasoft.studio.browser"; //$NON-NLS-1$
// The shared instance
private static BrowserSupportPlugin plugin;
/**
* The constructor
*/
public BrowserSupportPlugin() {
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static BrowserSupportPlugin getDefault() {
return plugin;
}
}
/**
* Copyright (C) 2014 BonitaSoft S.A.
* BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.browser.i18n;
import org.eclipse.osgi.util.NLS;
/**
* @author Romain Bioteau
*
*/
public class Messages extends NLS {
static {
NLS.initializeMessages("messages", Messages.class);
}
public static String noBrowserFoundTitle;
public static String noBrowserFoundMsg;
}
/**
* Copyright (C) 2014 BonitaSoft S.A.
* BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.browser.operation;
import java.net.URL;
import org.bonitasoft.studio.browser.i18n.Messages;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.preferences.dialog.BonitaPreferenceDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.browser.IWebBrowser;
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
import org.eclipse.ui.internal.browser.ExternalBrowserInstance;
import org.eclipse.ui.internal.browser.WebBrowserUtil;
/**
* @author Romain Bioteau
*
*/
public class OpenBrowserOperation implements Runnable {
protected static final String TYPE_ID = "org.bonitasoft.studio.browser"; //$NON-NLS-1$
private final URL url;
private ExternalBrowserInstance externalBrowser;
public OpenBrowserOperation(final URL url) {
this.url = url;
}
public void setExternalBrowser(final ExternalBrowserInstance externalBrowser) {
this.externalBrowser = externalBrowser;
}
public void execute() {
Display.getDefault().syncExec(this);
}
protected void openBrowser() throws PartInitException {
if (browserIsSet()) {
IWebBrowser browser = externalBrowser;
if (browser == null) {
browser = PlatformUI.getWorkbench().getBrowserSupport().createBrowser(IWorkbenchBrowserSupport.AS_EDITOR, TYPE_ID, "", ""); //$NON-NLS-1$
}
browser.openURL(url);
}
}
protected boolean browserIsSet() {
if (noExternalBrowserSet()) {
if (MessageDialog.openConfirm(Display.getDefault().getActiveShell(), Messages.noBrowserFoundTitle, Messages.noBrowserFoundMsg)) {
final BonitaPreferenceDialog dialog = new BonitaPreferenceDialog(Display.getDefault().getActiveShell());
dialog.create();
dialog.setSelectedPreferencePage(BonitaPreferenceDialog.WEB_BROWSER_PAGE_ID);
dialog.open();
}
return false;
}
return true;
}
protected boolean noExternalBrowserSet() {
return !WebBrowserUtil.canUseSystemBrowser() && WebBrowserUtil.getExternalBrowserPaths().isEmpty();
}
@Override
public void run() {
try {
openBrowser();
} catch (final PartInitException e) {
BonitaStudioLog.error(e);
}
}
}
......@@ -38,7 +38,8 @@ Require-Bundle: org.bonitasoft.studio.engine;bundle-version="1.0.0",
org.bonitasoft.studio.refactoring;bundle-version="6.3.0",
org.eclipse.emf;bundle-version="2.6.0",
org.eclipse.emf.transaction,
org.eclipse.emf.databinding
org.eclipse.emf.databinding,
org.bonitasoft.studio.browser;bundle-version="6.5.0"
Export-Package: org.bonitasoft.studio.businessobject.core.operation,or
g.bonitasoft.studio.businessobject.core.repository,org.bonitasoft.stu
dio.businessobject.ui,org.bonitasoft.studio.businessobject.ui.wizard
......
......@@ -39,7 +39,8 @@ Require-Bundle: org.bonitasoft.studio.model;bundle-version="1.0.0",
org.eclipse.jdt.core,
org.eclipse.xtext.ui,
org.bonitasoft.studio.document;bundle-version="6.5.0",
org.bonitasoft.studio.pagedesigner;bundle-version="6.5.0"
org.bonitasoft.studio.pagedesigner;bundle-version="6.5.0",
org.bonitasoft.studio.browser;bundle-version="6.5.0"
Export-Package: org.bonitasoft.studio.engine,org.bonitasoft.studio.eng
ine.command,org.bonitasoft.studio.engine.config,org.bonitasoft.studio
.engine.contribution,org.bonitasoft.studio.engine.export,org.bonitaso
......
......@@ -50,8 +50,6 @@ running = Running...
restartingWebServer = Restarting web server...
resetingEngine = Cleaning engine database...
undeploymentFailedMessage = Run has failed while undeploying the process
noBrowserFoundTitle = No web browser defined
noBrowserFoundMsg = The Portal cannot be launched because no web browser has been defined. Please set a web browser in order to continue.
cannotStartTomcatTitle=Tomcat cannot be launched
cannotStartTomcatMessage=Tomcat cannot be launched:\nthe port might be already used by another application.\nPossible causes are that another Studio or another Tomcat is already running.
noInitiatorDefinedTitle=No initiator defined
......
......@@ -21,6 +21,7 @@ import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import java.net.URL;
import org.bonitasoft.studio.browser.operation.OpenBrowserOperation;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.engine.BOSEngineManager;
import org.bonitasoft.studio.engine.i18n.Messages;
......@@ -57,16 +58,16 @@ public abstract class AbstractOpenConsoleCommand extends AbstractHandler {
public AbstractOpenConsoleCommand() {
super();
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
public Object execute(final ExecutionEvent event) throws ExecutionException {
try{
refreshTheme = (Boolean) (event != null && event.getParameters() != null && event.getParameters().get(REFRESH_THEME_PARAMETER) != null ? event.getParameters().get(REFRESH_THEME_PARAMETER) : true) ;
//close intro
executeJob();
}catch (Exception e) {
}catch (final Exception e) {
BonitaStudioLog.error(e);
ErrorDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
"error",
......@@ -83,24 +84,24 @@ public abstract class AbstractOpenConsoleCommand extends AbstractHandler {
final IRunnableWithProgress runnable = new IRunnableWithProgress(){
@Override
public void run(IProgressMonitor monitor)
public void run(final IProgressMonitor monitor)
throws InvocationTargetException, InterruptedException {
try{
monitor.beginTask(Messages.initializingUserXP, IProgressMonitor.UNKNOWN);
BOSEngineManager.getInstance().start();
setURL(getURLBuilder().toURL(monitor));
if(refreshTheme){
String currentTheme = BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore().getString(BonitaPreferenceConstants.DEFAULT_USERXP_THEME) ;
String installedTheme = BonitaUserXpPreferencePage.getInstalledThemeId() ;
final String currentTheme = BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore().getString(BonitaPreferenceConstants.DEFAULT_USERXP_THEME) ;
final String installedTheme = BonitaUserXpPreferencePage.getInstalledThemeId() ;
if(installedTheme != null && !installedTheme.equals(currentTheme)){
BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore().setValue(BonitaPreferenceConstants.DEFAULT_USERXP_THEME, currentTheme) ;
BonitaUserXpPreferencePage.updateBonitaHome() ;
}
}
if (!runSynchronously) {
new OpenBrowserCommand(url,BonitaPreferenceConstants.CONSOLE_BROWSER_ID,"Bonita User Experience").execute(null); //$NON-NLS-1$
new OpenBrowserOperation(url).execute(); //$NON-NLS-1$
}
}catch(Exception e){
}catch(final Exception e){
BonitaStudioLog.error(e);
}finally{
monitor.done();
......@@ -118,7 +119,7 @@ public abstract class AbstractOpenConsoleCommand extends AbstractHandler {
public void run() {
try{
progressManager.run(true, false, runnable) ;
} catch (Exception e) {
} catch (final Exception e) {
BonitaStudioLog.error(e);
}
......@@ -127,7 +128,7 @@ public abstract class AbstractOpenConsoleCommand extends AbstractHandler {
}
} catch (Exception e) {
} catch (final Exception e) {
BonitaStudioLog.error(e);
}
......@@ -142,7 +143,7 @@ public abstract class AbstractOpenConsoleCommand extends AbstractHandler {
}
public void setURL(URL url) throws MalformedURLException {
public void setURL(final URL url) throws MalformedURLException {
this.url = url;
}
......
/**
* Copyright (C) 2009 BonitaSoft S.A.
* BonitaSoft, 31 rue Gustave Eiffel - 38000 Grenoble
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.engine.command;
import java.net.URL;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.engine.i18n.Messages;
import org.bonitasoft.studio.preferences.dialog.BonitaPreferenceDialog;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.Status;
import org.eclipse.gmf.runtime.common.ui.util.WindowUtil;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.browser.IWebBrowser;
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
import org.eclipse.ui.internal.browser.ExternalBrowserInstance;
import org.eclipse.ui.internal.browser.WebBrowserUtil;
/**
* @author Romain Bioteau
*
*/
public class OpenBrowserCommand extends AbstractHandler {
public static final String APPLI_PATH = "/application/BonitaApplication.html?"; //$NON-NLS-1$
private URL url ;
private String typeId ;
private String title;
private ExternalBrowserInstance externalBrowser;
public OpenBrowserCommand(){
super();
}
public OpenBrowserCommand(URL url,String typeId,String title){
this.url = url ;
this.typeId = typeId ;
this.title = title ;
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
try{
if(browserIsSet()){
IWebBrowser browser = null;
if (externalBrowser!=null){
browser = externalBrowser;
} else {
browser = PlatformUI.getWorkbench().getBrowserSupport().createBrowser(IWorkbenchBrowserSupport.AS_EDITOR,typeId,title,""); //$NON-NLS-1$
}
browser.openURL(url);
}
}catch (Exception e) {
BonitaStudioLog.error(e);
ErrorDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
"error", //$NON-NLS-1$
"error starting server", //$NON-NLS-1$
Status.OK_STATUS);
}
}
});
return null;
}
protected boolean browserIsSet() {
if(!WebBrowserUtil.canUseSystemBrowser() && WebBrowserUtil.getExternalBrowserPaths().isEmpty()){
if(MessageDialog.openConfirm(Display.getDefault().getActiveShell(), Messages.noBrowserFoundTitle,Messages.noBrowserFoundMsg)){
final BonitaPreferenceDialog dialog = new BonitaPreferenceDialog(Display.getDefault().getActiveShell());
dialog.create();
dialog.setSelectedPreferencePage(BonitaPreferenceDialog.WEB_BROWSER_PAGE_ID);
WindowUtil.centerDialog(dialog.getShell(),Display.getDefault().getActiveShell()) ;
dialog.open();
}
return false;
}
return true;
}
public void setExternalBrowser(ExternalBrowserInstance externalBrowser){
this.externalBrowser = externalBrowser;
}
/**
* @param url2
*/
public void setURL(URL url) {
this.url = url;
}
}
......@@ -129,10 +129,6 @@ public class Messages extends NLS {
public static String undeploymentFailedMessage;
public static String noBrowserFoundMsg;
public static String noBrowserFoundTitle;
public static String cannotStartTomcatTitle;
public static String cannotStartTomcatMessage;
......
......@@ -19,17 +19,16 @@ package org.bonitasoft.studio.engine.operation;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import org.bonitasoft.studio.browser.operation.OpenBrowserOperation;
import org.bonitasoft.studio.common.jface.BonitaErrorDialog;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.engine.BOSWebServerManager;
import org.bonitasoft.studio.engine.EnginePlugin;
import org.bonitasoft.studio.engine.command.OpenBrowserCommand;
import org.bonitasoft.studio.engine.i18n.Messages;
import org.bonitasoft.studio.engine.preferences.EnginePreferenceConstants;
import org.bonitasoft.studio.model.process.AbstractProcess;
import org.bonitasoft.studio.model.process.Actor;
import org.bonitasoft.studio.preferences.BonitaPreferenceConstants;
import org.eclipse.core.commands.Command;