X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=server%2Fplugins%2Forg.argeo.jcr.ui.explorer%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fjcr%2Fui%2Fexplorer%2Fmodel%2FWorkspaceNode.java;h=22a7731c5db5491d08bce0e0edbeb014e1917da7;hb=cd50e3711d3b86921f11d9e021fc6a43bef0d400;hp=63c56349ae8d7e2badcbe873e357e33d92f4c0d6;hpb=82e079d95c38d7136944d79394b9efd82a2864dd;p=lgpl%2Fargeo-commons.git diff --git a/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/model/WorkspaceNode.java b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/model/WorkspaceNode.java index 63c56349a..22a7731c5 100644 --- a/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/model/WorkspaceNode.java +++ b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/model/WorkspaceNode.java @@ -1,3 +1,18 @@ +/* + * 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.jcr.ui.explorer.model; import javax.jcr.Node; @@ -5,19 +20,17 @@ import javax.jcr.NodeIterator; import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.Workspace; -import javax.jcr.observation.EventIterator; -import javax.jcr.observation.EventListener; import org.argeo.ArgeoException; import org.argeo.eclipse.ui.TreeParent; +import org.argeo.jcr.JcrUtils; /** * UI Tree component. Wraps the root node of a JCR {@link Workspace}. It also * keeps a reference to its parent {@link RepositoryNode}, to be able to * retrieve alias of the current used repository */ - -public class WorkspaceNode extends TreeParent implements EventListener, UiNode { +public class WorkspaceNode extends TreeParent implements UiNode { private Session session = null; public WorkspaceNode(RepositoryNode parent, String name) { @@ -27,8 +40,6 @@ public class WorkspaceNode extends TreeParent implements EventListener, UiNode { public WorkspaceNode(RepositoryNode parent, String name, Session session) { super(name); this.session = session; - if (session != null) - processNewSession(session); setParent(parent); } @@ -50,27 +61,30 @@ public class WorkspaceNode extends TreeParent implements EventListener, UiNode { public void login() { try { - logout(); session = ((RepositoryNode) getParent()).repositoryLogin(getName()); - processNewSession(session); - } catch (RepositoryException e) { throw new ArgeoException("Cannot connect to repository " + getName(), e); } } + public Boolean isConnected() { + if (session != null && session.isLive()) + return true; + else + return false; + } + + @Override + public synchronized void dispose() { + logout(); + super.dispose(); + } + + /** Logouts the session, does not nothing if there is no live session. */ public void logout() { - try { - if (session != null && session.isLive()) { - session.getWorkspace().getObservationManager() - .removeEventListener(this); - session.logout(); - } - } catch (RepositoryException e) { - throw new ArgeoException("Cannot connect to repository " - + getName(), e); - } + clearChildren(); + JcrUtils.logoutQuietly(session); } /** Returns the alias of the parent Repository */ @@ -81,10 +95,10 @@ public class WorkspaceNode extends TreeParent implements EventListener, UiNode { @Override public boolean hasChildren() { try { - if (session == null) - return false; - else + if (isConnected()) return session.getRootNode().hasNodes(); + else + return false; } catch (RepositoryException re) { throw new ArgeoException( "Unexpected error while checking children node existence", @@ -118,49 +132,4 @@ public class WorkspaceNode extends TreeParent implements EventListener, UiNode { } } } - - public void onEvent(final EventIterator events) { - // if (session == null) - // return; - // Display.getDefault().syncExec(new Runnable() { - // public void run() { - // while (events.hasNext()) { - // Event event = events.nextEvent(); - // try { - // String path = event.getPath(); - // String parentPath = path.substring(0, - // path.lastIndexOf('/')); - // final Object parent; - // if (parentPath.equals("/") || parentPath.equals("")) - // parent = this; - // else if (session.itemExists(parentPath)){ - // parent = session.getItem(parentPath); - // ((Item)parent).refresh(false); - // } - // else - // parent = null; - // if (parent != null) { - // nodesViewer.refresh(parent); - // } - // - // } catch (RepositoryException e) { - // log.warn("Error processing event " + event, e); - // } - // } - // } - // }); - } - - protected void processNewSession(Session session) { - // try { - // ObservationManager observationManager = session.getWorkspace() - // .getObservationManager(); - // observationManager.addEventListener(this, Event.NODE_ADDED - // | Event.NODE_REMOVED, "/", true, null, null, false); - // } catch (RepositoryException e) { - // throw new ArgeoException("Cannot process new session " - // + session, e); - // } - } - }