X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms.ui.workbench%2Fsrc%2Forg%2Fargeo%2Feclipse%2Fui%2Fworkbench%2Finternal%2Fjcr%2FJcrBrowserUtils.java;fp=org.argeo.cms.ui.workbench%2Fsrc%2Forg%2Fargeo%2Feclipse%2Fui%2Fworkbench%2Finternal%2Fjcr%2FJcrBrowserUtils.java;h=9e3e31878896a4b0650b89af21a59f7911bb1ffe;hb=4338fa5772c552075801aa689e5c2488b85d6756;hp=0000000000000000000000000000000000000000;hpb=277bb126a4b8523b93c2cd9abd345833a8387eba;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/JcrBrowserUtils.java b/org.argeo.cms.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/JcrBrowserUtils.java new file mode 100644 index 000000000..9e3e31878 --- /dev/null +++ b/org.argeo.cms.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/JcrBrowserUtils.java @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.eclipse.ui.workbench.internal.jcr; + +import javax.jcr.Node; +import javax.jcr.RepositoryException; + +import org.argeo.eclipse.ui.EclipseUiException; +import org.argeo.eclipse.ui.TreeParent; +import org.argeo.eclipse.ui.workbench.internal.jcr.model.RepositoriesElem; +import org.argeo.eclipse.ui.workbench.internal.jcr.model.RepositoryElem; +import org.argeo.eclipse.ui.workbench.internal.jcr.model.SingleJcrNodeElem; +import org.argeo.eclipse.ui.workbench.internal.jcr.model.WorkspaceElem; + +/** Centralizes useful methods to manage the JCR Browser */ +public class JcrBrowserUtils { + + /** Insure that the UI component is not stale, refresh if needed */ + public static void forceRefreshIfNeeded(TreeParent element) { + Node curNode = null; + + boolean doRefresh = false; + + try { + if (element instanceof SingleJcrNodeElem) { + curNode = ((SingleJcrNodeElem) element).getNode(); + } else if (element instanceof WorkspaceElem) { + curNode = ((WorkspaceElem) element).getRootNode(); + } + + if (curNode != null + && element.getChildren().length != curNode.getNodes() + .getSize()) + doRefresh = true; + else if (element instanceof RepositoryElem) { + RepositoryElem rn = (RepositoryElem) element; + if (rn.isConnected()) { + String[] wkpNames = rn.getAccessibleWorkspaceNames(); + if (element.getChildren().length != wkpNames.length) + doRefresh = true; + } + } else if (element instanceof RepositoriesElem) { + doRefresh = true; + // Always force refresh for RepositoriesElem : the condition + // below does not take remote repository into account and it is + // not trivial to do so. + + // RepositoriesElem rn = (RepositoriesElem) element; + // if (element.getChildren().length != + // rn.getRepositoryRegister() + // .getRepositories().size()) + // doRefresh = true; + } + if (doRefresh) { + element.clearChildren(); + element.getChildren(); + } + } catch (RepositoryException re) { + throw new EclipseUiException( + "Unexpected error while synchronising the UI with the JCR repository", + re); + } + } +} \ No newline at end of file