]>
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
af06ba22074a1e863dea1dc60a354367614bf164
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
.RepositoriesNode
;
24 import org
.argeo
.jcr
.ui
.explorer
.model
.RepositoryNode
;
25 import org
.argeo
.jcr
.ui
.explorer
.model
.SingleJcrNode
;
26 import org
.argeo
.jcr
.ui
.explorer
.model
.WorkspaceNode
;
28 /** Centralizes some useful methods to build UIs with JCR */
29 public class JcrUiUtils
{
31 /** Insure that the UI component is not stale, refresh if needed */
32 public static void forceRefreshIfNeeded(TreeParent element
) {
35 boolean doRefresh
= false;
38 if (element
instanceof SingleJcrNode
) {
39 curNode
= ((SingleJcrNode
) element
).getNode();
40 } else if (element
instanceof WorkspaceNode
) {
41 curNode
= ((WorkspaceNode
) element
).getRootNode();
45 && element
.getChildren().length
!= curNode
.getNodes()
48 else if (element
instanceof RepositoryNode
) {
49 RepositoryNode rn
= (RepositoryNode
) element
;
50 String
[] wkpNames
= rn
.getAccessibleWorkspaceNames();
51 if (element
.getChildren().length
!= wkpNames
.length
)
53 } else if (element
instanceof RepositoriesNode
) {
54 RepositoriesNode rn
= (RepositoriesNode
) element
;
55 if (element
.getChildren().length
!= rn
.getRepositoryRegister()
56 .getRepositories().size())
60 element
.clearChildren();
61 element
.getChildren();
63 } catch (RepositoryException re
) {
64 throw new ArgeoException(
65 "Unexpected error while synchronising the UI with the JCR repository",
71 * Insure that a model element is inline with the underlying data by
72 * cleaning the corresponding subtree and building it again.
74 public static void forceRebuild(TreeParent element
) {
75 // TODO implement this method if needed.
78 * Workaround to get the alias of the repository that contains the given
79 * element. As we cannot browse the UI tree upward we recursively browse it
80 * downward until we find the given element
82 // public static String getRepositoryAliasFromITreeElement(
83 // NodeContentProvider ncp, Object element) {
84 // RepositoryNode repositoryNode = null;
85 // if (element instanceof RepositoryNode)
86 // return ((RepositoryNode) element).getName();
87 // else if (element instanceof RepositoryRegister)
88 // throw new ArgeoException(
89 // "Cannot get alias for a repository register");
91 // // Get root elements
92 // Object[] elements = ncp.getElements(null);
95 // for (int i = 0; i < elements.length; i++) {
96 // if (elements[i] instanceof Node) {
97 // Node curNode = (Node) elements[i];
98 // if (curNode.isNodeType(ArgeoTypes.ARGEO_USER_HOME)) {
99 // // Do nothing, we'll find the node in the "normal" tree
101 // // get corresponding alias this way round
103 // throw new ArgeoException(
104 // "Normal nodes should not be at the root of NodeTreeViewer");
105 // } else if (elements[i] instanceof RepositoryRegister) {
106 // RepositoryRegister repositoryRegister = (RepositoryRegister) elements[i];
107 // Map<String, Repository> repositories = repositoryRegister
108 // .getRepositories();
110 // for (String name : repositories.keySet()) {
111 // boolean found = isElementInCurrentTreePart(
113 // new RepositoryNode(name, repositories.get(name)),
119 // throw new ArgeoException(
120 // "Unexpected object class at the root of NodeTreeViewer");
122 // } catch (RepositoryException re) {
123 // throw new ArgeoException(
124 // "Unexpected error while retrieving Alias name", re);
129 // /** implements the recursivity */
130 // private static boolean isElementInCurrentTreePart(NodeContentProvider
132 // Object parentElement, NodParente searchedElement) {
133 // boolean found = false;
134 // if (parentElement instanceof WorkspaceNode) {
135 // WorkspaceNode wn = (WorkspaceNode) parentElement;
136 // Object[] children = wn.getChildren();
137 // int i = children.length - 1;
138 // while (!found && i >= 0) {
139 // found = isElementInCurrentTreePart(ncp, children[i],
143 // } else if (parentElement instanceof RepositoryNode) {
144 // RepositoryNode rn = (RepositoryNode) parentElement;
145 // Object[] children = rn.getChildren();
146 // int i = children.length - 1;
147 // while (!found && i >= 0) {
148 // found = isElementInCurrentTreePart(ncp, children[i],
153 // Node node = (Node) parentElement;
154 // if (node.equals(searchedElement))
158 // ni = node.getNodes();
159 // while (!found && ni.hasNext()) {
160 // found = isElementInCurrentTreePart(ncp, ni.nextNode(),
163 // } catch (RepositoryException e) {
164 // throw new ArgeoException("unexpected erreur while recursively"
165 // + " recovering RepositoryNode for selected object", e);