1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package org.argeo.cms.ui.jcr.model;
17  
18  import javax.jcr.Node;
19  import javax.jcr.NodeIterator;
20  import javax.jcr.RepositoryException;
21  import javax.jcr.Workspace;
22  
23  import org.argeo.eclipse.ui.EclipseUiException;
24  import org.argeo.eclipse.ui.TreeParent;
25  
26  
27  
28  
29  
30  
31  
32  public class SingleJcrNodeElem extends TreeParent {
33  
34  	private final Node node;
35  	private String alias = null;
36  
37  	
38  	public SingleJcrNodeElem(TreeParent parent, Node node, String name) {
39  		super(name);
40  		setParent(parent);
41  		this.node = node;
42  	}
43  
44  	
45  
46  
47  
48  
49  	public SingleJcrNodeElem(TreeParent parent, Node node, String name, String alias) {
50  		super(name);
51  		setParent(parent);
52  		this.node = node;
53  		this.alias = alias;
54  	}
55  
56  	
57  	public Node getNode() {
58  		return node;
59  	}
60  
61  	protected String getRepositoryAlias() {
62  		return alias;
63  	}
64  
65  	
66  
67  
68  
69  	@Override
70  	public synchronized Object[] getChildren() {
71  		if (isLoaded()) {
72  			return super.getChildren();
73  		} else {
74  			
75  			try {
76  				NodeIterator ni = node.getNodes();
77  				while (ni.hasNext()) {
78  					Node curNode = ni.nextNode();
79  					addChild(new SingleJcrNodeElem(this, curNode, curNode.getName()));
80  				}
81  				return super.getChildren();
82  			} catch (RepositoryException re) {
83  				throw new EclipseUiException("Cannot initialize SingleJcrNode children", re);
84  			}
85  		}
86  	}
87  
88  	@Override
89  	public boolean hasChildren() {
90  		try {
91  			if (node.getSession().isLive())
92  				return node.hasNodes();
93  			else
94  				return false;
95  		} catch (RepositoryException re) {
96  			throw new EclipseUiException("Cannot check children node existence", re);
97  		}
98  	}
99  }