]>
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",
43 * Insure that a model element is inline with the underlying data by
44 * cleaning the corresponding subtree and building it again.
46 public static void forceRebuild(TreeParent element
) {
47 // TODO implement this method if needed.
50 * Workaround to get the alias of the repository that contains the given
51 * element. As we cannot browse the UI tree upward we recursively browse it
52 * downward until we find the given element
54 // public static String getRepositoryAliasFromITreeElement(
55 // NodeContentProvider ncp, Object element) {
56 // RepositoryNode repositoryNode = null;
57 // if (element instanceof RepositoryNode)
58 // return ((RepositoryNode) element).getName();
59 // else if (element instanceof RepositoryRegister)
60 // throw new ArgeoException(
61 // "Cannot get alias for a repository register");
63 // // Get root elements
64 // Object[] elements = ncp.getElements(null);
67 // for (int i = 0; i < elements.length; i++) {
68 // if (elements[i] instanceof Node) {
69 // Node curNode = (Node) elements[i];
70 // if (curNode.isNodeType(ArgeoTypes.ARGEO_USER_HOME)) {
71 // // Do nothing, we'll find the node in the "normal" tree
73 // // get corresponding alias this way round
75 // throw new ArgeoException(
76 // "Normal nodes should not be at the root of NodeTreeViewer");
77 // } else if (elements[i] instanceof RepositoryRegister) {
78 // RepositoryRegister repositoryRegister = (RepositoryRegister) elements[i];
79 // Map<String, Repository> repositories = repositoryRegister
80 // .getRepositories();
82 // for (String name : repositories.keySet()) {
83 // boolean found = isElementInCurrentTreePart(
85 // new RepositoryNode(name, repositories.get(name)),
91 // throw new ArgeoException(
92 // "Unexpected object class at the root of NodeTreeViewer");
94 // } catch (RepositoryException re) {
95 // throw new ArgeoException(
96 // "Unexpected error while retrieving Alias name", re);
101 // /** implements the recursivity */
102 // private static boolean isElementInCurrentTreePart(NodeContentProvider
104 // Object parentElement, NodParente searchedElement) {
105 // boolean found = false;
106 // if (parentElement instanceof WorkspaceNode) {
107 // WorkspaceNode wn = (WorkspaceNode) parentElement;
108 // Object[] children = wn.getChildren();
109 // int i = children.length - 1;
110 // while (!found && i >= 0) {
111 // found = isElementInCurrentTreePart(ncp, children[i],
115 // } else if (parentElement instanceof RepositoryNode) {
116 // RepositoryNode rn = (RepositoryNode) parentElement;
117 // Object[] children = rn.getChildren();
118 // int i = children.length - 1;
119 // while (!found && i >= 0) {
120 // found = isElementInCurrentTreePart(ncp, children[i],
125 // Node node = (Node) parentElement;
126 // if (node.equals(searchedElement))
130 // ni = node.getNodes();
131 // while (!found && ni.hasNext()) {
132 // found = isElementInCurrentTreePart(ncp, ni.nextNode(),
135 // } catch (RepositoryException e) {
136 // throw new ArgeoException("unexpected erreur while recursively"
137 // + " recovering RepositoryNode for selected object", e);