1 package org
.argeo
.slc
.client
.ui
.views
;
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);
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();
30 emd
= executionModuleNode
.getAgentNode().getAgent()
31 .getExecutionModuleDescriptor(emd
.getName(),
33 executionModuleNode
.cacheDescriptor(emd
);
34 // for (String flowName : executionModuleNode.getFlowDescriptors()
36 // executionModuleNode.addChild(new FlowNode(flowName,
37 // executionModuleNode));
39 return executionModuleNode
.getChildren();
40 } else if (parent
instanceof AgentNode
) {
41 AgentNode agentNode
= (AgentNode
) parent
;
43 if (log
.isTraceEnabled())
44 log
.trace("Scan agent " + agentNode
);
46 agentNode
.clearChildren();
47 for (ExecutionModuleDescriptor desc
: agentNode
.getAgent()
48 .listExecutionModuleDescriptors()) {
49 agentNode
.addChild(new ExecutionModuleNode(agentNode
, desc
));
52 return agentNode
.getChildren();
53 } else if (parent
instanceof TreeParent
) {
54 return ((TreeParent
) parent
).getChildren();
55 } else if (parent
instanceof FlowNode
) {
58 List
<AgentNode
> agentNodes
= new ArrayList
<AgentNode
>();
59 for (SlcAgent slcAgent
: slcAgents
) {
60 agentNodes
.add(new AgentNode(slcAgent
));
62 return agentNodes
.toArray();
66 public Object
getParent(Object node
) {
67 // if (node instanceof TreeObject) {
68 // return ((TreeObject) node).getParent();
73 public boolean hasChildren(Object parent
) {
74 if (parent
instanceof TreeParent
&& ((TreeParent
) parent
).isLoaded()) {
75 return ((TreeParent
) parent
).hasChildren();
76 } else if (parent
instanceof AgentNode
) {
78 } else if (parent
instanceof ExecutionModuleNode
) {
84 public void inputChanged(Viewer v
, Object oldInput
, Object newInput
) {
87 public void dispose() {
90 public Object
[] getElements(Object parent
) {
91 return getChildren(parent
);
94 public void setSlcAgents(List
<SlcAgent
> slcAgents
) {
95 this.slcAgents
= slcAgents
;
98 public class AgentNode
extends TreeParent
{
99 private final SlcAgent agent
;
101 public AgentNode(SlcAgent agent
) {
102 super(agent
.toString());
106 public SlcAgent
getAgent() {
111 public class ExecutionModuleNode
extends TreeParent
{
112 private final AgentNode agentNode
;
113 private ExecutionModuleDescriptor descriptor
;
114 private Map
<String
, ExecutionFlowDescriptor
> flowDescriptors
;
116 public ExecutionModuleNode(AgentNode agentNode
,
117 ExecutionModuleDescriptor descriptor
) {
118 super(descriptor
.toString());
119 this.agentNode
= agentNode
;
120 this.descriptor
= descriptor
;
124 public AgentNode
getAgentNode() {
128 public ExecutionModuleDescriptor
getDescriptor() {
132 public void cacheDescriptor(ExecutionModuleDescriptor descriptor
) {
133 this.descriptor
= descriptor
;
135 SortedMap
<String
, FolderNode
> folderNodes
= new TreeMap
<String
, FolderNode
>();
137 flowDescriptors
= new HashMap
<String
, ExecutionFlowDescriptor
>();
138 for (ExecutionFlowDescriptor fd
: descriptor
.getExecutionFlows()) {
139 // if (log.isTraceEnabled())
140 // log.trace("fd.path=" + fd.getPath() + ", fd.name="
143 // find path and label
146 int lastSlash
= fd
.getName().lastIndexOf('/');
147 if ((fd
.getPath() == null || fd
.getPath().trim().equals(""))
149 path
= fd
.getName().substring(0, lastSlash
);
150 label
= fd
.getName().substring(lastSlash
+ 1);
153 label
= fd
.getName();
155 // if (log.isTraceEnabled())
156 // log.trace("path=" + path + ", label=" + label);
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(), this));
163 FolderNode folderNode
= mkdirs(this, path
, folderNodes
);
165 .addChild(new FlowNode(label
, fd
.getName(), this));
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
;
212 public class FlowNode
extends TreeObject
{
213 private final String flowName
;
214 private final ExecutionModuleNode executionModuleNode
;
216 public FlowNode(String label
, String flowName
,
217 ExecutionModuleNode executionModuleNode
) {
219 this.flowName
= flowName
;
220 this.executionModuleNode
= executionModuleNode
;
223 public String
getFlowName() {
227 public ExecutionModuleNode
getExecutionModuleNode() {
228 return executionModuleNode
;
233 public class FolderNode
extends TreeParent
{
234 public FolderNode(String name
) {