]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/SimpleNodeContentProvider.java
Make CMS wizard more robust
[lgpl/argeo-commons.git] / org.argeo.eclipse.ui / src / org / argeo / eclipse / ui / jcr / SimpleNodeContentProvider.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
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 /** Simple JCR node content provider taking a list of String as base path. */
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 }