]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - utils/JcrUiUtils.java
1 package org
.argeo
.jcr
.ui
.explorer
.utils
;
4 import javax
.jcr
.RepositoryException
;
6 import org
.argeo
.ArgeoException
;
7 import org
.argeo
.eclipse
.ui
.TreeParent
;
8 import org
.argeo
.jcr
.ui
.explorer
.model
.SingleJcrNode
;
9 import org
.argeo
.jcr
.ui
.explorer
.model
.WorkspaceNode
;
11 /** Centralizes some useful methods to build Uis with JCR */
12 public class JcrUiUtils
{
14 /** Insure that the UI componant is not stale, refresh if needed */
15 public static void forceRefreshIfNeeded(TreeParent element
) {
18 if (element
instanceof SingleJcrNode
)
19 curNode
= ((SingleJcrNode
) element
).getNode();
20 else if (element
instanceof WorkspaceNode
)
21 curNode
= ((WorkspaceNode
) element
).getRootNode();
24 // TODO implement specific methods for other cases
27 // we mainly rely on nb of children
28 if (element
.getChildren().length
== curNode
.getNodes().getSize())
31 // get rid of children of UI object
32 element
.clearChildren();
33 element
.getChildren();
35 } catch (RepositoryException re
) {
36 throw new ArgeoException(
37 "Unexpected error while synchronising the UI with the JCR repository",
42 * Workaround to get the alias of the repository that contains the given
43 * element. As we cannot browse the UI tree upward we recursively browse it
44 * downward until we find the given element
46 // public static String getRepositoryAliasFromITreeElement(
47 // NodeContentProvider ncp, Object element) {
48 // RepositoryNode repositoryNode = null;
49 // if (element instanceof RepositoryNode)
50 // return ((RepositoryNode) element).getName();
51 // else if (element instanceof RepositoryRegister)
52 // throw new ArgeoException(
53 // "Cannot get alias for a repository register");
55 // // Get root elements
56 // Object[] elements = ncp.getElements(null);
59 // for (int i = 0; i < elements.length; i++) {
60 // if (elements[i] instanceof Node) {
61 // Node curNode = (Node) elements[i];
62 // if (curNode.isNodeType(ArgeoTypes.ARGEO_USER_HOME)) {
63 // // Do nothing, we'll find the node in the "normal" tree
65 // // get corresponding alias this way round
67 // throw new ArgeoException(
68 // "Normal nodes should not be at the root of NodeTreeViewer");
69 // } else if (elements[i] instanceof RepositoryRegister) {
70 // RepositoryRegister repositoryRegister = (RepositoryRegister) elements[i];
71 // Map<String, Repository> repositories = repositoryRegister
72 // .getRepositories();
74 // for (String name : repositories.keySet()) {
75 // boolean found = isElementInCurrentTreePart(
77 // new RepositoryNode(name, repositories.get(name)),
83 // throw new ArgeoException(
84 // "Unexpected object class at the root of NodeTreeViewer");
86 // } catch (RepositoryException re) {
87 // throw new ArgeoException(
88 // "Unexpected error while retrieving Alias name", re);
93 // /** implements the recursivity */
94 // private static boolean isElementInCurrentTreePart(NodeContentProvider
96 // Object parentElement, NodParente searchedElement) {
97 // boolean found = false;
98 // if (parentElement instanceof WorkspaceNode) {
99 // WorkspaceNode wn = (WorkspaceNode) parentElement;
100 // Object[] children = wn.getChildren();
101 // int i = children.length - 1;
102 // while (!found && i >= 0) {
103 // found = isElementInCurrentTreePart(ncp, children[i],
107 // } else if (parentElement instanceof RepositoryNode) {
108 // RepositoryNode rn = (RepositoryNode) parentElement;
109 // Object[] children = rn.getChildren();
110 // int i = children.length - 1;
111 // while (!found && i >= 0) {
112 // found = isElementInCurrentTreePart(ncp, children[i],
117 // Node node = (Node) parentElement;
118 // if (node.equals(searchedElement))
122 // ni = node.getNodes();
123 // while (!found && ni.hasNext()) {
124 // found = isElementInCurrentTreePart(ncp, ni.nextNode(),
127 // } catch (RepositoryException e) {
128 // throw new ArgeoException("unexpected erreur while recursively"
129 // + " recovering RepositoryNode for selected object", e);