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
.TreeParent
;
13 import org
.argeo
.slc
.execution
.ExecutionFlowDescriptor
;
14 import org
.argeo
.slc
.execution
.ExecutionModuleDescriptor
;
15 import org
.argeo
.slc
.runtime
.SlcAgent
;
16 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
17 import org
.eclipse
.jface
.viewers
.Viewer
;
19 public class ExecutionModulesContentProvider
implements ITreeContentProvider
{
20 private final static Log log
= LogFactory
21 .getLog(ExecutionModulesContentProvider
.class);
24 private List
<SlcAgent
> slcAgents
;
26 public Object
[] getChildren(Object parent
) {
27 if (parent
instanceof ExecutionModuleNode
) {
28 ExecutionModuleNode executionModuleNode
= (ExecutionModuleNode
) parent
;
29 ExecutionModuleDescriptor emd
= executionModuleNode
.getDescriptor();
31 // Terminate the building of UI specific object emd
32 emd
= executionModuleNode
35 .getExecutionModuleDescriptor(emd
.getName(),
37 executionModuleNode
.cacheDescriptor(emd
);
39 // This is not recursive, e.g. ExecutionModuleNode build a Tree of
41 // treeObject and cache it in the cacheDescriptor.
42 // Then we only have TreeObjects
43 return executionModuleNode
.getChildren();
44 } else if (parent
instanceof AgentNode
) {
45 AgentNode agentNode
= (AgentNode
) parent
;
47 if (log
.isTraceEnabled())
48 log
.trace("Scan agent " + agentNode
);
50 agentNode
.clearChildren();
51 for (ExecutionModuleDescriptor desc
: agentNode
.getAgent()
52 .listExecutionModuleDescriptors()) {
53 agentNode
.addChild(new ExecutionModuleNode(agentNode
, desc
));
56 return agentNode
.getChildren();
57 } else if (parent
instanceof TreeParent
) {
58 return ((TreeParent
) parent
).getChildren();
59 } else if (parent
instanceof FlowNode
) {
62 List
<AgentNode
> agentNodes
= new ArrayList
<AgentNode
>();
63 for (SlcAgent slcAgent
: slcAgents
) {
64 agentNodes
.add(new AgentNode(slcAgent
));
66 return agentNodes
.toArray();
70 public Object
getParent(Object node
) {
71 // if (node instanceof TreeObject) {
72 // return ((TreeObject) node).getParent();
77 public boolean hasChildren(Object parent
) {
78 if (parent
instanceof TreeParent
&& ((TreeParent
) parent
).isLoaded()) {
79 return ((TreeParent
) parent
).hasChildren();
80 } else if (parent
instanceof AgentNode
) {
82 } else if (parent
instanceof ExecutionModuleNode
) {
88 public void inputChanged(Viewer v
, Object oldInput
, Object newInput
) {
91 public void dispose() {
94 public Object
[] getElements(Object parent
) {
95 return getChildren(parent
);
100 public class AgentNode
extends TreeParent
{
101 private final SlcAgent agent
;
103 public AgentNode(SlcAgent agent
) {
104 super(agent
.toString());
108 public SlcAgent
getAgent() {
113 public class ExecutionModuleNode
extends TreeParent
{
114 private final AgentNode agentNode
;
115 private ExecutionModuleDescriptor descriptor
;
116 private Map
<String
, ExecutionFlowDescriptor
> flowDescriptors
;
118 public ExecutionModuleNode(AgentNode agentNode
,
119 ExecutionModuleDescriptor descriptor
) {
120 super(descriptor
.toString());
121 this.agentNode
= agentNode
;
122 this.descriptor
= descriptor
;
126 public AgentNode
getAgentNode() {
130 public ExecutionModuleDescriptor
getDescriptor() {
134 public void cacheDescriptor(ExecutionModuleDescriptor descriptor
) {
135 this.descriptor
= descriptor
;
137 SortedMap
<String
, FolderNode
> folderNodes
= new TreeMap
<String
, FolderNode
>();
138 flowDescriptors
= new HashMap
<String
, ExecutionFlowDescriptor
>();
140 for (ExecutionFlowDescriptor fd
: descriptor
.getExecutionFlows()) {
141 // Find, format and store path and label values for each flow
144 // we format name of type path="" & name="path/toTest/Test" to :
145 // path="path/toTest/" name="Test"
148 int lastSlash
= fd
.getName().lastIndexOf('/');
149 if ((fd
.getPath() == null || fd
.getPath().trim().equals(""))
151 path
= fd
.getName().substring(0, lastSlash
);
152 label
= fd
.getName().substring(lastSlash
+ 1);
155 label
= fd
.getName();
158 if (path
== null || path
.trim().equals("")
159 || path
.trim().equals("/")) {
160 // directChildren.put(name, new FlowNode(name, this));
161 addChild(new FlowNode(label
, fd
.getName(), fd
, this));
163 FolderNode folderNode
= mkdirs(this, path
, folderNodes
);
164 folderNode
.addChild(new FlowNode(label
, fd
.getName(), fd
,
168 flowDescriptors
.put(fd
.getName(), fd
);
170 // TODO: make it readonly
173 protected FolderNode
mkdirs(TreeParent root
, String path
,
174 SortedMap
<String
, FolderNode
> folderNodes
) {
176 if (path
.charAt(0) != '/')
178 if (path
.charAt(path
.length() - 1) == '/')
179 path
= path
.substring(0, path
.length() - 1);
181 if (folderNodes
.containsKey(path
))
182 return folderNodes
.get(path
);
184 int lastIndx
= path
.lastIndexOf('/');
188 folderName
= path
.substring(lastIndx
+ 1);
189 parentPath
= path
.substring(0, lastIndx
);
196 if (parentPath
.equals(""))
199 parent
= mkdirs(root
, parentPath
, folderNodes
);
200 FolderNode newFolder
= new FolderNode(folderName
);
201 parent
.addChild(newFolder
);
202 folderNodes
.put(path
, newFolder
);
206 public Map
<String
, ExecutionFlowDescriptor
> getFlowDescriptors() {
207 return flowDescriptors
;
216 * The implementation of a vernice of a given slc process. Note that
217 * we store the parent node (execution module node) & the
218 * ExecutionFlowDescriptor.
220 public class FlowNode
extends TreeParent
{
222 private final String flowName
;
223 private final ExecutionModuleNode executionModuleNode
;
224 private final ExecutionFlowDescriptor executionFlowDescriptor
;
226 public FlowNode(String label
, String flowName
,
227 ExecutionFlowDescriptor executionFlowDescriptor
,
228 ExecutionModuleNode parent
) {
230 this.flowName
= flowName
;
231 this.executionFlowDescriptor
= executionFlowDescriptor
;
232 this.executionModuleNode
= parent
;
235 public String
getFlowName() {
239 public ExecutionModuleNode
getExecutionModuleNode() {
240 return executionModuleNode
;
243 public ExecutionFlowDescriptor
getExecutionFlowDescriptor() {
244 return executionFlowDescriptor
;
249 public class FolderNode
extends TreeParent
{
250 public FolderNode(String name
) {
257 public void setSlcAgents(List
<SlcAgent
> slcAgents
) {
258 this.slcAgents
= slcAgents
;