Commit 212cd968 authored by Romain Bioteau's avatar Romain Bioteau
Browse files

Use parameterized command properly

parent c9a11cd3
......@@ -161,6 +161,11 @@
defaultHandler="org.bonitasoft.studio.actors.ui.handler.InstallOrganizationHandler"
id="org.bonitasoft.studio.engine.installOrganization"
name="%installOrganization">
<commandParameter
id="artifact"
name="artifact"
optional="false">
</commandParameter>
</command>
<command
defaultHandler="org.bonitasoft.studio.actors.ui.handler.EditFilterImplementationHandler"
......
......@@ -17,12 +17,9 @@
package org.bonitasoft.studio.actors.ui.wizard;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
import org.bonitasoft.studio.actors.i18n.Messages;
import org.bonitasoft.studio.actors.model.organization.Organization;
import org.bonitasoft.studio.actors.preference.ActorsPreferenceConstants;
import org.bonitasoft.studio.actors.ui.wizard.page.DefaultUserOrganizationWizardPage;
import org.bonitasoft.studio.actors.ui.wizard.page.SynchronizeOrganizationWizardPage;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
......@@ -31,7 +28,8 @@ import org.bonitasoft.studio.pics.Pics;
import org.bonitasoft.studio.preferences.BonitaPreferenceConstants;
import org.bonitasoft.studio.preferences.BonitaStudioPreferencesPlugin;
import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.Parameterization;
import org.eclipse.core.commands.ParameterizedCommand;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
......@@ -41,6 +39,7 @@ import org.eclipse.jface.wizard.Wizard;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.handlers.IHandlerService;
/**
* @author Romain Bioteau
......@@ -98,19 +97,14 @@ public class SynchronizeOrganizationWizard extends Wizard {
IRepositoryFileStore artifact = getFileStore() ;
ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class) ;
Command cmd = service.getCommand("org.bonitasoft.studio.engine.installOrganization") ;
Map<String, Object> parameters = new HashMap<String, Object>() ;
parameters.put("artifact", artifact.getName()) ;
ExecutionEvent ee = new ExecutionEvent(cmd, parameters, null, null) ;
try {
cmd.executeWithChecks(ee) ;
prefStore.setValue(ActorsPreferenceConstants.DEFAULT_ORGANIZATION, artifact.getDisplayName()) ;
} catch (Exception e) {
BonitaStudioLog.error(e) ;
return ;
}
IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class) ;
Command cmd = service.getCommand("org.bonitasoft.studio.engine.installOrganization") ;
try {
Parameterization p = new Parameterization(cmd.getParameter("artifact"), artifact.getName());
handlerService.executeCommand(new ParameterizedCommand(cmd, new Parameterization[]{p}), null);
} catch (Exception e) {
BonitaStudioLog.error(e);
}
final String organizationName = artifact.getDisplayName();
Display.getDefault().syncExec( new Runnable() {
public void run() {
......
......@@ -33,7 +33,8 @@ Require-Bundle: org.bonitasoft.studio.model;bundle-version="1.0.0",
org.bonitasoft.studio.condition.ui;bundle-version="1.0.0",
org.eclipse.xtext.ui;bundle-version="2.3.1",
org.bonitasoft.studio.xml;bundle-version="6.0.0",
org.eclipse.ui.browser;bundle-version="3.3.101"
org.eclipse.ui.browser;bundle-version="3.3.101",
org.eclipse.core.expressions
Export-Package: org.bonitasoft.studio.engine,
org.bonitasoft.studio.engine.command,
org.bonitasoft.studio.engine.config,
......
......@@ -48,6 +48,12 @@ import org.bonitasoft.studio.preferences.BonitaPreferenceConstants;
import org.bonitasoft.studio.preferences.BonitaStudioPreferencesPlugin;
import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.NotEnabledException;
import org.eclipse.core.commands.NotHandledException;
import org.eclipse.core.commands.Parameterization;
import org.eclipse.core.commands.ParameterizedCommand;
import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IConfigurationElement;
......@@ -55,6 +61,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.handlers.IHandlerService;
/**
* @author Romain Bioteau
......@@ -230,15 +237,14 @@ public class BOSEngineManager {
if(!isOrganizationLoaded()){
if(BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore().getBoolean(BonitaPreferenceConstants.LOAD_ORGANIZATION)) {
ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class) ;
IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class) ;
Command cmd = service.getCommand(INSTALL_ORGANIZATION_CMD_ID) ;
Map<String, String> parameters = new HashMap<String, String>() ;
String artifactId = BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore().getString(BonitaPreferenceConstants.DEFAULT_ORGANIZATION) ;
parameters.put("artifact", artifactId+".organization") ;
ExecutionEvent ee = new ExecutionEvent(cmd,parameters,null,null);
try {
cmd.executeWithChecks(ee) ;
Parameterization p = new Parameterization(cmd.getParameter("artifact"), artifactId+".organization");
handlerService.executeCommand(new ParameterizedCommand(cmd, new Parameterization[]{p}), null);
} catch (Exception e) {
BonitaStudioLog.error(e) ;
BonitaStudioLog.error(e);
}
}
organizationLoaded = true;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment