]>
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
.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 if (rn
.isConnected()) {
51 String
[] wkpNames
= rn
.getAccessibleWorkspaceNames();
52 if (element
.getChildren().length
!= wkpNames
.length
)
55 } else if (element
instanceof RepositoriesNode
) {
56 RepositoriesNode rn
= (RepositoriesNode
) element
;
57 if (element
.getChildren().length
!= rn
.getRepositoryRegister()
58 .getRepositories().size())
62 element
.clearChildren();
63 element
.getChildren();
65 } catch (RepositoryException re
) {
66 throw new ArgeoException(
67 "Unexpected error while synchronising the UI with the JCR repository",
73 * Insure that a model element is inline with the underlying data by
74 * cleaning the corresponding subtree and building it again.
76 public static void forceRebuild(TreeParent element
) {
77 // TODO implement this method if needed.
80 * Workaround to get the alias of the repository that contains the given
81 * element. As we cannot browse the UI tree upward we recursively browse it
82 * downward until we find the given element
84 // public static String getRepositoryAliasFromITreeElement(
85 // NodeContentProvider ncp, Object element) {
86 // RepositoryNode repositoryNode = null;
87 // if (element instanceof RepositoryNode)
88 // return ((RepositoryNode) element).getName();
89 // else if (element instanceof RepositoryRegister)
90 // throw new ArgeoException(
91 // "Cannot get alias for a repository register");
93 // // Get root elements
94 // Object[] elements = ncp.getElements(null);
97 // for (int i = 0; i < elements.length; i++) {
98 // if (elements[i] instanceof Node) {
99 // Node curNode = (Node) elements[i];
100 // if (curNode.isNodeType(ArgeoTypes.ARGEO_USER_HOME)) {
101 // // Do nothing, we'll find the node in the "normal" tree
103 // // get corresponding alias this way round
105 // throw new ArgeoException(
106 // "Normal nodes should not be at the root of NodeTreeViewer");
107 // } else if (elements[i] instanceof RepositoryRegister) {
108 // RepositoryRegister repositoryRegister = (RepositoryRegister) elements[i];
109 // Map<String, Repository> repositories = repositoryRegister
110 // .getRepositories();
112 // for (String name : repositories.keySet()) {
113 // boolean found = isElementInCurrentTreePart(
115 // new RepositoryNode(name, repositories.get(name)),
121 // throw new ArgeoException(
122 // "Unexpected object class at the root of NodeTreeViewer");
124 // } catch (RepositoryException re) {
125 // throw new ArgeoException(
126 // "Unexpected error while retrieving Alias name", re);
131 // /** implements the recursivity */
132 // private static boolean isElementInCurrentTreePart(NodeContentProvider
134 // Object parentElement, NodParente searchedElement) {
135 // boolean found = false;
136 // if (parentElement instanceof WorkspaceNode) {
137 // WorkspaceNode wn = (WorkspaceNode) parentElement;
138 // Object[] children = wn.getChildren();
139 // int i = children.length - 1;
140 // while (!found && i >= 0) {
141 // found = isElementInCurrentTreePart(ncp, children[i],
145 // } else if (parentElement instanceof RepositoryNode) {
146 // RepositoryNode rn = (RepositoryNode) parentElement;
147 // Object[] children = rn.getChildren();
148 // int i = children.length - 1;
149 // while (!found && i >= 0) {
150 // found = isElementInCurrentTreePart(ncp, children[i],
155 // Node node = (Node) parentElement;
156 // if (node.equals(searchedElement))
160 // ni = node.getNodes();
161 // while (!found && ni.hasNext()) {
162 // found = isElementInCurrentTreePart(ncp, ni.nextNode(),
165 // } catch (RepositoryException e) {
166 // throw new ArgeoException("unexpected erreur while recursively"
167 // + " recovering RepositoryNode for selected object", e);