]>
git.argeo.org Git - gpl/argeo-slc.git/blob - jcr/model/WorkspaceElem.java
1 package org
.argeo
.cms
.ui
.jcr
.model
;
3 import javax
.jcr
.AccessDeniedException
;
5 import javax
.jcr
.NodeIterator
;
6 import javax
.jcr
.RepositoryException
;
7 import javax
.jcr
.Session
;
8 // import javax.jcr.Workspace;
9 import javax
.jcr
.Workspace
;
11 import org
.argeo
.cms
.ux
.widgets
.TreeParent
;
12 import org
.argeo
.eclipse
.ui
.EclipseUiException
;
13 import org
.argeo
.jcr
.JcrUtils
;
16 * UI Tree component. Wraps the root node of a JCR {@link Workspace}. It also
17 * keeps a reference to its parent {@link RepositoryElem}, to be able to
18 * retrieve alias of the current used repository
20 public class WorkspaceElem
extends TreeParent
{
21 private Session session
= null;
23 public WorkspaceElem(RepositoryElem parent
, String name
) {
24 this(parent
, name
, null);
27 public WorkspaceElem(RepositoryElem parent
, String name
, Session session
) {
29 this.session
= session
;
33 public synchronized Session
getSession() {
37 public synchronized Node
getRootNode() {
40 return session
.getRootNode();
43 } catch (RepositoryException e
) {
44 throw new EclipseUiException("Cannot get root node of workspace " + getName(), e
);
48 public synchronized void login() {
50 session
= ((RepositoryElem
) getParent()).repositoryLogin(getName());
51 } catch (RepositoryException e
) {
52 throw new EclipseUiException("Cannot connect to repository " + getName(), e
);
56 public Boolean
isConnected() {
57 if (session
!= null && session
.isLive())
64 public synchronized void dispose() {
69 /** Logouts the session, does not nothing if there is no live session. */
70 public synchronized void logout() {
72 JcrUtils
.logoutQuietly(session
);
77 public synchronized boolean hasChildren() {
81 return session
.getRootNode().hasNodes();
82 } catch (AccessDeniedException e
) {
83 // current user may not have access to the root node
88 } catch (RepositoryException re
) {
89 throw new EclipseUiException("Unexpected error while checking children node existence", re
);
93 /** Override normal behaviour to initialize display of the workspace */
95 public synchronized Object
[] getChildren() {
97 return super.getChildren();
99 // initialize current object
105 rootNode
= session
.getRootNode();
106 NodeIterator ni
= rootNode
.getNodes();
107 while (ni
.hasNext()) {
108 Node node
= ni
.nextNode();
109 addChild(new SingleJcrNodeElem(this, node
, node
.getName()));
111 return super.getChildren();
112 } catch (RepositoryException e
) {
113 throw new EclipseUiException("Cannot initialize WorkspaceNode UI object." + getName(), e
);