2 * Copyright (C) 2007-2012 Argeo GmbH
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.
16 package org
.argeo
.slc
.client
.ui
.commands
;
18 import java
.util
.HashMap
;
21 import org
.argeo
.slc
.SlcException
;
22 import org
.argeo
.slc
.execution
.ExecutionFlowDescriptor
;
23 import org
.argeo
.slc
.execution
.ExecutionModulesManager
;
24 import org
.argeo
.slc
.execution
.RealizedFlow
;
25 import org
.eclipse
.core
.commands
.AbstractHandler
;
26 import org
.eclipse
.core
.commands
.Command
;
27 import org
.eclipse
.core
.commands
.ExecutionEvent
;
28 import org
.eclipse
.core
.commands
.ExecutionException
;
29 import org
.eclipse
.core
.commands
.IParameter
;
31 public class RunSlcFlow
extends AbstractHandler
{
32 private ExecutionModulesManager modulesManager
;
34 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
36 Command command
= event
.getCommand();
37 String name
= command
.getName();
38 String module
= name
.substring(0, name
.indexOf(':'));
39 String flowName
= name
.substring(name
.indexOf(':') + 1);
41 final RealizedFlow realizedFlow
= new RealizedFlow();
42 realizedFlow
.setModuleName(module
);
43 // FIXME deal with version
44 String version
= "0.0.0";
45 realizedFlow
.setModuleVersion(version
);
46 ExecutionFlowDescriptor efd
= new ExecutionFlowDescriptor();
47 efd
.setName(flowName
);
49 Map
<String
, Object
> values
= new HashMap
<String
, Object
>();
50 if (command
.getParameters() != null) {
51 for (IParameter param
: command
.getParameters()) {
52 String argName
= param
.getId();
53 // FIXME make it safer
54 Object value
= param
.getValues().getParameterValues()
55 .values().iterator().next();
56 values
.put(argName
, value
);
58 efd
.setValues(values
);
60 realizedFlow
.setFlowDescriptor(efd
);
61 // new Thread("SLC Flow " + name + " from Eclipse command "
62 // + command.getId()) {
63 // public void run() {
64 modulesManager
.start(realizedFlow
.getModuleNameVersion());
65 modulesManager
.execute(realizedFlow
);
69 } catch (Exception e
) {
70 throw new SlcException("Could not execute command "
71 + event
.getCommand() + " as SLC flow", e
);
75 public void setModulesManager(
76 ExecutionModulesManager executionModulesManager
) {
77 this.modulesManager
= executionModulesManager
;