View Javadoc
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  @Deprecated
32  public class RunSlcFlow extends AbstractHandler {
33  	private ExecutionModulesManager modulesManager;
34  
35  	public Object execute(ExecutionEvent event) throws ExecutionException {
36  		try {
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);
41  
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);
49  
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);
58  				}
59  				efd.setValues(values);
60  			}
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);
67  			// }
68  			// }.start();
69  			return null;
70  		} catch (Exception e) {
71  			throw new SlcException("Could not execute command "
72  					+ event.getCommand() + " as SLC flow", e);
73  		}
74  	}
75  
76  	public void setModulesManager(
77  			ExecutionModulesManager executionModulesManager) {
78  		this.modulesManager = executionModulesManager;
79  	}
80  
81  }