+ class ViewContentProvider extends SimpleNodeContentProvider {
+
+ public ViewContentProvider(Session session) {
+ super(session,
+ new String[] { SlcJcrConstants.VM_AGENT_FACTORY_PATH });
+ }
+
+ // @Override
+ // protected Object[] getChildren(Node node) throws RepositoryException
+ // {
+ // if (node.isNodeType(SlcTypes.SLC_AGENT_FACTORY)) {
+ // List<AgentNodesWrapper> wrappers = new
+ // ArrayList<AgentNodesWrapper>();
+ // for (NodeIterator nit = node.getNodes(); nit.hasNext();) {
+ // wrappers.add(new AgentNodesWrapper(nit.nextNode()));
+ // }
+ // return wrappers.toArray();
+ // }
+ // return super.getChildren(node);
+ // }
+
+ @Override
+ protected Object[] sort(Object parent, Object[] children) {
+ Object[] sorted = new Object[children.length];
+ System.arraycopy(children, 0, sorted, 0, children.length);
+ Arrays.sort(sorted, new ViewComparator());
+ return sorted;
+ }
+
+ @Override
+ protected List<Node> filterChildren(List<Node> children)
+ throws RepositoryException {
+ for (Iterator<Node> it = children.iterator(); it.hasNext();) {
+ Node node = it.next();
+ // execution spec definitions
+ if (node.getName().equals(SLC_EXECUTION_SPECS))
+ it.remove();
+ // flow values
+ else if (node.getParent().isNodeType(
+ SlcTypes.SLC_EXECUTION_FLOW))
+ it.remove();
+ }
+ return super.filterChildren(children);
+ }
+
+ @Override
+ public boolean hasChildren(Object element) {
+ if (element instanceof Node) {
+ Node node = (Node) element;
+ try {
+ if (node.isNodeType(SlcTypes.SLC_EXECUTION_FLOW))
+ return false;
+ } catch (RepositoryException e) {
+ throw new SlcException("Cannot check has children", e);
+ }
+ }
+ return super.hasChildren(element);
+ }
+ }
+
+ static class ViewComparator implements Comparator<Object> {
+
+ public int compare(Object o1, Object o2) {
+ try {
+ if (o1 instanceof Node && o2 instanceof Node) {
+ Node node1 = (Node) o1;
+ Node node2 = (Node) o2;
+
+ if (node1.getName().equals(SLC_EXECUTION_SPECS))
+ return -100;
+ if (node2.getName().equals(SLC_EXECUTION_SPECS))
+ return 100;
+
+ if (node1.isNodeType(SLC_EXECUTION_FLOW)
+ && node2.isNodeType(SLC_EXECUTION_FLOW)) {
+ return node1.getName().compareTo(node2.getName());
+ } else if (node1.isNodeType(SLC_EXECUTION_FLOW)
+ && !node2.isNodeType(SLC_EXECUTION_FLOW)) {
+ return 1;
+ } else if (!node1.isNodeType(SLC_EXECUTION_FLOW)
+ && node2.isNodeType(SLC_EXECUTION_FLOW)) {
+ return -1;
+ } else {
+ // TODO: check title
+ return node1.getName().compareTo(node2.getName());
+ }
+ }
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Cannot compare " + o1 + " and " + o2,
+ e);
+ }
+ return 0;
+ }
+
+ }
+
+ // /** Wraps the execution modules of an agent. */
+ // static class AgentNodesWrapper extends NodesWrapper {
+ //
+ // public AgentNodesWrapper(Node node) {
+ // super(node);
+ // }
+ //
+ // protected List<WrappedNode> getWrappedNodes()
+ // throws RepositoryException {
+ // List<WrappedNode> children = new ArrayList<WrappedNode>();
+ // Node executionModules = getNode();
+ // for (NodeIterator nit = executionModules.getNodes(); nit.hasNext();) {
+ // for (NodeIterator nitVersions = nit.nextNode().getNodes(); nitVersions
+ // .hasNext();) {
+ // children.add(new WrappedNode(this, nitVersions.nextNode()));
+ // }
+ // }
+ // return children;
+ // }
+ //
+ // }
+
+ class VmAgentObserver extends AsyncUiEventListener {
+ protected void onEventInUiThread(EventIterator events) {
+ // List<Node> baseNodes = ((SimpleNodeContentProvider) viewer
+ // .getContentProvider()).getBaseNodes();
+ // Node baseNode = baseNodes.get(0);
+ //
+ // while (events.hasNext()) {
+ // Event event = events.nextEvent();
+ // try {
+ // String path = event.getPath();
+ // String baseNodePath = baseNode.getPath();
+ // if (path.startsWith(baseNodePath)) {
+ // String relPath = path
+ // .substring(baseNodePath.length() + 1);
+ // log.debug("relPath: " + relPath);
+ // if (baseNode.hasNode(relPath)) {
+ // Node refreshNode = baseNode.getNode(relPath);
+ // log.debug("refreshNode: " + refreshNode);
+ // viewer.refresh(refreshNode);
+ // }
+ //
+ // }
+ // // if (log.isDebugEnabled())
+ // // log.debug("Process " + path + ": " + event);
+ //
+ // // if (session.itemExists(path)) {
+ // // Node parentNode = session.getNode(path).getParent();
+ // // log.debug("Parent: " + parentNode);
+ // // viewer.refresh(parentNode);
+ // // }
+ // } catch (RepositoryException e) {
+ // log.warn("Cannot process event " + event + ": " + e);
+ // }
+ // }
+
+ // try {
+ // Node vmAgentNode = session
+ // .getNode(SlcJcrConstants.VM_AGENT_FACTORY_PATH);
+ // viewer.refresh(vmAgentNode);
+ // } catch (RepositoryException e) {
+ // log.warn("Cannot process event : " + e);
+ // }
+ // TODO: optimize based on event
+ viewer.refresh();
+ }
+ }
+
+ class ViewLabelProvider extends DefaultNodeLabelProvider implements