1 package org
.argeo
.slc
.client
.ui
.providers
;
3 import java
.util
.ArrayList
;
4 import java
.util
.HashMap
;
7 import java
.util
.SortedMap
;
8 import java
.util
.TreeMap
;
10 import org
.apache
.commons
.logging
.Log
;
11 import org
.apache
.commons
.logging
.LogFactory
;
12 import org
.argeo
.eclipse
.ui
.TreeObject
;
13 import org
.argeo
.eclipse
.ui
.TreeParent
;
14 import org
.argeo
.slc
.execution
.ExecutionFlowDescriptor
;
15 import org
.argeo
.slc
.execution
.ExecutionModuleDescriptor
;
16 import org
.argeo
.slc
.runtime
.SlcAgent
;
17 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
18 import org
.eclipse
.jface
.viewers
.Viewer
;
20 public class ExecutionModulesContentProvider
implements ITreeContentProvider
{
21 private final static Log log
= LogFactory
22 .getLog(ExecutionModulesContentProvider
.class);
25 private List
<SlcAgent
> slcAgents
;
27 public Object
[] getChildren(Object parent
) {
28 if (parent
instanceof ExecutionModuleNode
) {
29 ExecutionModuleNode executionModuleNode
= (ExecutionModuleNode
) parent
;
30 ExecutionModuleDescriptor emd
= executionModuleNode
.getDescriptor();
32 // Terminate the building of UI specific object emd
33 emd
= executionModuleNode
36 .getExecutionModuleDescriptor(emd
.getName(),
38 executionModuleNode
.cacheDescriptor(emd
);
40 // This is not recursive, e.g. ExecutionModuleNode build a Tree of
42 // treeObject and cache it in the cacheDescriptor.
43 // Then we only have TreeObjects
44 return executionModuleNode
.getChildren();
45 } else if (parent
instanceof AgentNode
) {
46 AgentNode agentNode
= (AgentNode
) parent
;
48 if (log
.isTraceEnabled())
49 log
.trace("Scan agent " + agentNode
);
51 agentNode
.clearChildren();
52 for (ExecutionModuleDescriptor desc
: agentNode
.getAgent()
53 .listExecutionModuleDescriptors()) {
54 agentNode
.addChild(new ExecutionModuleNode(agentNode
, desc
));
57 return agentNode
.getChildren();
58 } else if (parent
instanceof TreeParent
) {
59 return ((TreeParent
) parent
).getChildren();
60 } else if (parent
instanceof FlowNode
) {
63 List
<AgentNode
> agentNodes
= new ArrayList
<AgentNode
>();
64 for (SlcAgent slcAgent
: slcAgents
) {
65 agentNodes
.add(new AgentNode(slcAgent
));
67 return agentNodes
.toArray();
71 public Object
getParent(Object node
) {
72 // if (node instanceof TreeObject) {
73 // return ((TreeObject) node).getParent();
78 public boolean hasChildren(Object parent
) {
79 if (parent
instanceof TreeParent
&& ((TreeParent
) parent
).isLoaded()) {
80 return ((TreeParent
) parent
).hasChildren();
81 } else if (parent
instanceof AgentNode
) {
83 } else if (parent
instanceof ExecutionModuleNode
) {
89 public void inputChanged(Viewer v
, Object oldInput
, Object newInput
) {
92 public void dispose() {
95 public Object
[] getElements(Object parent
) {
96 return getChildren(parent
);
101 public class AgentNode
extends TreeParent
{
102 private final SlcAgent agent
;
104 public AgentNode(SlcAgent agent
) {
105 super(agent
.toString());
109 public SlcAgent
getAgent() {
114 public class ExecutionModuleNode
extends TreeParent
{
115 private final AgentNode agentNode
;
116 private ExecutionModuleDescriptor descriptor
;
117 private Map
<String
, ExecutionFlowDescriptor
> flowDescriptors
;
119 public ExecutionModuleNode(AgentNode agentNode
,
120 ExecutionModuleDescriptor descriptor
) {
121 super(descriptor
.toString());
122 this.agentNode
= agentNode
;
123 this.descriptor
= descriptor
;
127 public AgentNode
getAgentNode() {
131 public ExecutionModuleDescriptor
getDescriptor() {
135 public void cacheDescriptor(ExecutionModuleDescriptor descriptor
) {
136 this.descriptor
= descriptor
;
138 SortedMap
<String
, FolderNode
> folderNodes
= new TreeMap
<String
, FolderNode
>();
139 flowDescriptors
= new HashMap
<String
, ExecutionFlowDescriptor
>();
141 for (ExecutionFlowDescriptor fd
: descriptor
.getExecutionFlows()) {
142 // Find, format and store path and label values for each flow
145 // we format name of type path="" & name="path/toTest/Test" to :
146 // path="path/toTest/" name="Test"
149 int lastSlash
= fd
.getName().lastIndexOf('/');
150 if ((fd
.getPath() == null || fd
.getPath().trim().equals(""))
152 path
= fd
.getName().substring(0, lastSlash
);
153 label
= fd
.getName().substring(lastSlash
+ 1);
156 label
= fd
.getName();
159 if (path
== null || path
.trim().equals("")
160 || path
.trim().equals("/")) {
161 // directChildren.put(name, new FlowNode(name, this));
162 addChild(new FlowNode(label
, fd
.getName(), fd
, this));
164 FolderNode folderNode
= mkdirs(this, path
, folderNodes
);
165 folderNode
.addChild(new FlowNode(label
, fd
.getName(), fd
,
169 flowDescriptors
.put(fd
.getName(), fd
);
171 // TODO: make it readonly
174 protected FolderNode
mkdirs(TreeParent root
, String path
,
175 SortedMap
<String
, FolderNode
> folderNodes
) {
177 if (path
.charAt(0) != '/')
179 if (path
.charAt(path
.length() - 1) == '/')
180 path
= path
.substring(0, path
.length() - 1);
182 if (folderNodes
.containsKey(path
))
183 return folderNodes
.get(path
);
185 int lastIndx
= path
.lastIndexOf('/');
189 folderName
= path
.substring(lastIndx
+ 1);
190 parentPath
= path
.substring(0, lastIndx
);
197 if (parentPath
.equals(""))
200 parent
= mkdirs(root
, parentPath
, folderNodes
);
201 FolderNode newFolder
= new FolderNode(folderName
);
202 parent
.addChild(newFolder
);
203 folderNodes
.put(path
, newFolder
);
207 public Map
<String
, ExecutionFlowDescriptor
> getFlowDescriptors() {
208 return flowDescriptors
;
217 * The implementation of a vernice of a given slc process. Note that
218 * we store the parent node (execution module node) & the
219 * ExecutionFlowDescriptor.
221 public class FlowNode
extends TreeObject
{
223 private final String flowName
;
224 private final ExecutionModuleNode executionModuleNode
;
225 private final ExecutionFlowDescriptor executionFlowDescriptor
;
227 public FlowNode(String label
, String flowName
,
228 ExecutionFlowDescriptor executionFlowDescriptor
,
229 ExecutionModuleNode parent
) {
231 this.flowName
= flowName
;
232 this.executionFlowDescriptor
= executionFlowDescriptor
;
233 this.executionModuleNode
= parent
;
236 public String
getFlowName() {
240 public ExecutionModuleNode
getExecutionModuleNode() {
241 return executionModuleNode
;
244 public ExecutionFlowDescriptor
getExecutionFlowDescriptor() {
245 return executionFlowDescriptor
;
250 public class FolderNode
extends TreeParent
{
251 public FolderNode(String name
) {
258 public void setSlcAgents(List
<SlcAgent
> slcAgents
) {
259 this.slcAgents
= slcAgents
;