]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms.ui/src/org/argeo/cms/ui/jcr/JcrBrowserUtils.java
2 * Copyright (C) 2007-2012 Argeo GmbH
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
.cms
.ui
.jcr
;
18 import javax
.jcr
.Node
;
19 import javax
.jcr
.Property
;
20 import javax
.jcr
.PropertyType
;
21 import javax
.jcr
.RepositoryException
;
23 import org
.argeo
.cms
.ui
.jcr
.model
.RepositoriesElem
;
24 import org
.argeo
.cms
.ui
.jcr
.model
.RepositoryElem
;
25 import org
.argeo
.cms
.ui
.jcr
.model
.SingleJcrNodeElem
;
26 import org
.argeo
.cms
.ui
.jcr
.model
.WorkspaceElem
;
27 import org
.argeo
.eclipse
.ui
.EclipseUiException
;
28 import org
.argeo
.eclipse
.ui
.TreeParent
;
30 /** Useful methods to manage the JCR Browser */
31 public class JcrBrowserUtils
{
33 public static String
getPropertyTypeAsString(Property prop
) {
35 return PropertyType
.nameFromValue(prop
.getType());
36 } catch (RepositoryException e
) {
37 throw new EclipseUiException("Cannot check type for " + prop
, e
);
41 /** Insure that the UI component is not stale, refresh if needed */
42 public static void forceRefreshIfNeeded(TreeParent element
) {
45 boolean doRefresh
= false;
48 if (element
instanceof SingleJcrNodeElem
) {
49 curNode
= ((SingleJcrNodeElem
) element
).getNode();
50 } else if (element
instanceof WorkspaceElem
) {
51 curNode
= ((WorkspaceElem
) element
).getRootNode();
54 if (curNode
!= null && element
.getChildren().length
!= curNode
.getNodes().getSize())
56 else if (element
instanceof RepositoryElem
) {
57 RepositoryElem rn
= (RepositoryElem
) element
;
58 if (rn
.isConnected()) {
59 String
[] wkpNames
= rn
.getAccessibleWorkspaceNames();
60 if (element
.getChildren().length
!= wkpNames
.length
)
63 } else if (element
instanceof RepositoriesElem
) {
65 // Always force refresh for RepositoriesElem : the condition
66 // below does not take remote repository into account and it is
67 // not trivial to do so.
69 // RepositoriesElem rn = (RepositoriesElem) element;
70 // if (element.getChildren().length !=
71 // rn.getRepositoryRegister()
72 // .getRepositories().size())
76 element
.clearChildren();
77 element
.getChildren();
79 } catch (RepositoryException re
) {
80 throw new EclipseUiException("Unexpected error while synchronising the UI with the JCR repository", re
);