2 * Copyright (C) 2007-2012 Mathieu Baudier
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org
.argeo
.slc
.client
.ui
.commands
;
19 import java
.util
.HashMap
;
22 import org
.argeo
.slc
.SlcException
;
23 import org
.argeo
.slc
.execution
.ExecutionFlowDescriptor
;
24 import org
.argeo
.slc
.execution
.ExecutionModulesManager
;
25 import org
.argeo
.slc
.execution
.RealizedFlow
;
26 import org
.eclipse
.core
.commands
.AbstractHandler
;
27 import org
.eclipse
.core
.commands
.Command
;
28 import org
.eclipse
.core
.commands
.ExecutionEvent
;
29 import org
.eclipse
.core
.commands
.ExecutionException
;
30 import org
.eclipse
.core
.commands
.IParameter
;
32 public class RunSlcFlow
extends AbstractHandler
{
33 private ExecutionModulesManager modulesManager
;
35 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
37 Command command
= event
.getCommand();
38 String name
= command
.getName();
39 String module
= name
.substring(0, name
.indexOf(':'));
40 String flowName
= name
.substring(name
.indexOf(':') + 1);
42 final RealizedFlow realizedFlow
= new RealizedFlow();
43 realizedFlow
.setModuleName(module
);
44 // FIXME deal with version
45 String version
= "0.0.0";
46 realizedFlow
.setModuleVersion(version
);
47 ExecutionFlowDescriptor efd
= new ExecutionFlowDescriptor();
48 efd
.setName(flowName
);
50 Map
<String
, Object
> values
= new HashMap
<String
, Object
>();
51 if (command
.getParameters() != null) {
52 for (IParameter param
: command
.getParameters()) {
53 String argName
= param
.getId();
54 // FIXME make it safer
55 Object value
= param
.getValues().getParameterValues()
56 .values().iterator().next();
57 values
.put(argName
, value
);
59 efd
.setValues(values
);
61 realizedFlow
.setFlowDescriptor(efd
);
62 // new Thread("SLC Flow " + name + " from Eclipse command "
63 // + command.getId()) {
64 // public void run() {
65 modulesManager
.start(realizedFlow
.getModuleNameVersion());
66 modulesManager
.execute(realizedFlow
);
70 } catch (Exception e
) {
71 throw new SlcException("Could not execute command "
72 + event
.getCommand() + " as SLC flow", e
);
76 public void setModulesManager(
77 ExecutionModulesManager executionModulesManager
) {
78 this.modulesManager
= executionModulesManager
;