]> git.argeo.org Git - gpl/argeo-slc.git/blob - plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/commands/RunSlcFlow.java
Fix renamed third-party bundles
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui / src / main / java / org / argeo / slc / client / ui / commands / RunSlcFlow.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16 package org.argeo.slc.client.ui.commands;
17
18 import java.util.HashMap;
19 import java.util.Map;
20
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;
30
31 public class RunSlcFlow extends AbstractHandler {
32 private ExecutionModulesManager modulesManager;
33
34 public Object execute(ExecutionEvent event) throws ExecutionException {
35 try {
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);
40
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);
48
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);
57 }
58 efd.setValues(values);
59 }
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);
66 // }
67 // }.start();
68 return null;
69 } catch (Exception e) {
70 throw new SlcException("Could not execute command "
71 + event.getCommand() + " as SLC flow", e);
72 }
73 }
74
75 public void setModulesManager(
76 ExecutionModulesManager executionModulesManager) {
77 this.modulesManager = executionModulesManager;
78 }
79
80 }