]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/utils/JcrUiUtils.java
2 * Copyright (C) 2007-2012 Mathieu Baudier
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.jcr
.ui
.explorer
.utils
;
18 import javax
.jcr
.Node
;
19 import javax
.jcr
.RepositoryException
;
21 import org
.argeo
.ArgeoException
;
22 import org
.argeo
.eclipse
.ui
.TreeParent
;
23 import org
.argeo
.jcr
.ui
.explorer
.model
.SingleJcrNode
;
24 import org
.argeo
.jcr
.ui
.explorer
.model
.WorkspaceNode
;
26 /** Centralizes some useful methods to build Uis with JCR */
27 public class JcrUiUtils
{
29 /** Insure that the UI componant is not stale, refresh if needed */
30 public static void forceRefreshIfNeeded(TreeParent element
) {
33 if (element
instanceof SingleJcrNode
)
34 curNode
= ((SingleJcrNode
) element
).getNode();
35 else if (element
instanceof WorkspaceNode
)
36 curNode
= ((WorkspaceNode
) element
).getRootNode();
39 // TODO implement specific methods for other cases
42 // we mainly rely on nb of children
43 if (element
.getChildren().length
== curNode
.getNodes().getSize())
46 // get rid of children of UI object
47 element
.clearChildren();
48 element
.getChildren();
50 } catch (RepositoryException re
) {
51 throw new ArgeoException(
52 "Unexpected error while synchronising the UI with the JCR repository",
58 * Insure that a model element is inline with the underlying data by
59 * cleaning the corresponding subtree and building it again.
61 public static void forceRebuild(TreeParent element
) {
62 // TODO implement this method if needed.
65 * Workaround to get the alias of the repository that contains the given
66 * element. As we cannot browse the UI tree upward we recursively browse it
67 * downward until we find the given element
69 // public static String getRepositoryAliasFromITreeElement(
70 // NodeContentProvider ncp, Object element) {
71 // RepositoryNode repositoryNode = null;
72 // if (element instanceof RepositoryNode)
73 // return ((RepositoryNode) element).getName();
74 // else if (element instanceof RepositoryRegister)
75 // throw new ArgeoException(
76 // "Cannot get alias for a repository register");
78 // // Get root elements
79 // Object[] elements = ncp.getElements(null);
82 // for (int i = 0; i < elements.length; i++) {
83 // if (elements[i] instanceof Node) {
84 // Node curNode = (Node) elements[i];
85 // if (curNode.isNodeType(ArgeoTypes.ARGEO_USER_HOME)) {
86 // // Do nothing, we'll find the node in the "normal" tree
88 // // get corresponding alias this way round
90 // throw new ArgeoException(
91 // "Normal nodes should not be at the root of NodeTreeViewer");
92 // } else if (elements[i] instanceof RepositoryRegister) {
93 // RepositoryRegister repositoryRegister = (RepositoryRegister) elements[i];
94 // Map<String, Repository> repositories = repositoryRegister
95 // .getRepositories();
97 // for (String name : repositories.keySet()) {
98 // boolean found = isElementInCurrentTreePart(
100 // new RepositoryNode(name, repositories.get(name)),
106 // throw new ArgeoException(
107 // "Unexpected object class at the root of NodeTreeViewer");
109 // } catch (RepositoryException re) {
110 // throw new ArgeoException(
111 // "Unexpected error while retrieving Alias name", re);
116 // /** implements the recursivity */
117 // private static boolean isElementInCurrentTreePart(NodeContentProvider
119 // Object parentElement, NodParente searchedElement) {
120 // boolean found = false;
121 // if (parentElement instanceof WorkspaceNode) {
122 // WorkspaceNode wn = (WorkspaceNode) parentElement;
123 // Object[] children = wn.getChildren();
124 // int i = children.length - 1;
125 // while (!found && i >= 0) {
126 // found = isElementInCurrentTreePart(ncp, children[i],
130 // } else if (parentElement instanceof RepositoryNode) {
131 // RepositoryNode rn = (RepositoryNode) parentElement;
132 // Object[] children = rn.getChildren();
133 // int i = children.length - 1;
134 // while (!found && i >= 0) {
135 // found = isElementInCurrentTreePart(ncp, children[i],
140 // Node node = (Node) parentElement;
141 // if (node.equals(searchedElement))
145 // ni = node.getNodes();
146 // while (!found && ni.hasNext()) {
147 // found = isElementInCurrentTreePart(ncp, ni.nextNode(),
150 // } catch (RepositoryException e) {
151 // throw new ArgeoException("unexpected erreur while recursively"
152 // + " recovering RepositoryNode for selected object", e);