1 package org
.argeo
.slc
.client
.ui
.views
;
3 import java
.util
.HashMap
;
5 import java
.util
.SortedMap
;
6 import java
.util
.TreeMap
;
8 import org
.apache
.commons
.logging
.Log
;
9 import org
.apache
.commons
.logging
.LogFactory
;
10 import org
.argeo
.eclipse
.ui
.TreeObject
;
11 import org
.argeo
.eclipse
.ui
.TreeParent
;
12 import org
.argeo
.slc
.execution
.ExecutionFlowDescriptor
;
13 import org
.argeo
.slc
.execution
.ExecutionModuleDescriptor
;
14 import org
.argeo
.slc
.runtime
.SlcAgent
;
15 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
16 import org
.eclipse
.jface
.viewers
.Viewer
;
18 public class ExecutionModulesContentProvider
implements ITreeContentProvider
{
19 private final static Log log
= LogFactory
20 .getLog(ExecutionModulesContentProvider
.class);
22 private SlcAgent slcAgent
;
25 public Object
[] getChildren(Object parent
) {
26 if (parent
instanceof ExecutionModuleNode
) {
27 ExecutionModuleNode executionModuleNode
= (ExecutionModuleNode
) parent
;
28 ExecutionModuleDescriptor emd
= executionModuleNode
.getDescriptor();
29 emd
= executionModuleNode
.getAgentNode().getAgent()
30 .getExecutionModuleDescriptor(emd
.getName(),
32 executionModuleNode
.cacheDescriptor(emd
);
33 // for (String flowName : executionModuleNode.getFlowDescriptors()
35 // executionModuleNode.addChild(new FlowNode(flowName,
36 // executionModuleNode));
38 return executionModuleNode
.getChildren();
39 } else if (parent
instanceof AgentNode
) {
40 AgentNode agentNode
= (AgentNode
) parent
;
42 if (log
.isTraceEnabled())
43 log
.trace("Scan agent " + agentNode
);
45 agentNode
.clearChildren();
46 for (ExecutionModuleDescriptor desc
: agentNode
.getAgent()
47 .listExecutionModuleDescriptors()) {
48 agentNode
.addChild(new ExecutionModuleNode(agentNode
, desc
));
51 return agentNode
.getChildren();
52 } else if (parent
instanceof TreeParent
) {
53 return ((TreeParent
) parent
).getChildren();
54 } else if (parent
instanceof FlowNode
) {
58 Object
[] arr
= { new AgentNode(slcAgent
) };
64 public Object
getParent(Object node
) {
65 // if (node instanceof TreeObject) {
66 // return ((TreeObject) node).getParent();
72 public boolean hasChildren(Object parent
) {
73 if (parent
instanceof TreeParent
&& ((TreeParent
) parent
).isLoaded()) {
74 return ((TreeParent
) parent
).hasChildren();
75 } else if (parent
instanceof AgentNode
) {
77 } else if (parent
instanceof ExecutionModuleNode
) {
84 public void inputChanged(Viewer v
, Object oldInput
, Object newInput
) {
88 public void dispose() {
92 public Object
[] getElements(Object parent
) {
93 return getChildren(parent
);
96 public void setSlcAgent(SlcAgent slcAgent
) {
97 this.slcAgent
= slcAgent
;
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
>();
139 // SortedMap<String, FlowNode> directChildren = new TreeMap<String,
142 flowDescriptors
= new HashMap
<String
, ExecutionFlowDescriptor
>();
143 for (ExecutionFlowDescriptor fd
: descriptor
.getExecutionFlows()) {
144 if (log
.isTraceEnabled())
146 .trace("path=" + fd
.getPath() + ", name="
149 String path
= fd
.getPath();
150 String name
= fd
.getName();
152 if (path
== null || path
.trim().equals("")) {
153 // directChildren.put(name, new FlowNode(name, this));
154 addChild(new FlowNode(name
, this));
156 FolderNode folderNode
= mkdirs(this, path
, folderNodes
);
157 folderNode
.addChild(new FlowNode(name
, this));
160 flowDescriptors
.put(fd
.getName(), fd
);
162 // TODO: make it readonly
165 protected FolderNode
mkdirs(TreeParent root
, String path
,
166 SortedMap
<String
, FolderNode
> folderNodes
) {
167 if (path
.charAt(path
.length() - 1) == '/')
168 path
= path
.substring(0, path
.length() - 1);
170 if (folderNodes
.containsKey(path
))
171 return folderNodes
.get(path
);
173 int lastIndx
= path
.lastIndexOf('/');
174 String folderName
= path
.substring(lastIndx
+ 1);
175 String parentPath
= path
.substring(0, lastIndx
);
178 if (parentPath
.equals(""))
181 parent
= mkdirs(root
, parentPath
, folderNodes
);
182 FolderNode newFolder
= new FolderNode(folderName
);
183 parent
.addChild(newFolder
);
184 folderNodes
.put(path
, newFolder
);
188 public Map
<String
, ExecutionFlowDescriptor
> getFlowDescriptors() {
189 return flowDescriptors
;
194 public class FlowNode
extends TreeObject
{
195 private final String flowName
;
196 private final ExecutionModuleNode executionModuleNode
;
198 public FlowNode(String flowName
, ExecutionModuleNode executionModuleNode
) {
200 this.flowName
= flowName
;
201 this.executionModuleNode
= executionModuleNode
;
204 public String
getFlowName() {
208 public ExecutionModuleNode
getExecutionModuleNode() {
209 return executionModuleNode
;
214 public class FolderNode
extends TreeParent
{
215 public FolderNode(String name
) {