1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.argeo.eclipse.ui.jcr;
17
18 import java.util.ArrayList;
19 import java.util.Arrays;
20 import java.util.List;
21
22 import javax.jcr.Node;
23 import javax.jcr.RepositoryException;
24 import javax.jcr.Session;
25
26 import org.argeo.eclipse.ui.EclipseUiException;
27 import org.argeo.jcr.JcrUtils;
28
29
30 public class SimpleNodeContentProvider extends AbstractNodeContentProvider {
31 private static final long serialVersionUID = -8245193308831384269L;
32 private final List<String> basePaths;
33 private Boolean mkdirs = false;
34
35 public SimpleNodeContentProvider(Session session, String... basePaths) {
36 this(session, Arrays.asList(basePaths));
37 }
38
39 public SimpleNodeContentProvider(Session session, List<String> basePaths) {
40 super(session);
41 this.basePaths = basePaths;
42 }
43
44 @Override
45 protected Boolean isBasePath(String path) {
46 if (basePaths.contains(path))
47 return true;
48 return super.isBasePath(path);
49 }
50
51 public Object[] getElements(Object inputElement) {
52 try {
53 List<Node> baseNodes = new ArrayList<Node>();
54 for (String basePath : basePaths)
55 if (mkdirs && !getSession().itemExists(basePath))
56 baseNodes.add(JcrUtils.mkdirs(getSession(), basePath));
57 else
58 baseNodes.add(getSession().getNode(basePath));
59 return baseNodes.toArray();
60 } catch (RepositoryException e) {
61 throw new EclipseUiException("Cannot get base nodes for " + basePaths,
62 e);
63 }
64 }
65
66 public List<String> getBasePaths() {
67 return basePaths;
68 }
69
70 public void setMkdirs(Boolean mkdirs) {
71 this.mkdirs = mkdirs;
72 }
73
74 }