]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - model/WorkspaceNode.java
1 package org
.argeo
.jcr
.ui
.explorer
.model
;
4 import javax
.jcr
.NodeIterator
;
5 import javax
.jcr
.RepositoryException
;
6 import javax
.jcr
.Session
;
7 import javax
.jcr
.Workspace
;
8 import javax
.jcr
.observation
.EventIterator
;
9 import javax
.jcr
.observation
.EventListener
;
11 import org
.argeo
.ArgeoException
;
12 import org
.argeo
.eclipse
.ui
.TreeParent
;
15 * UI Tree component. Wraps the root node of a JCR {@link Workspace}. It also
16 * keeps a reference to its parent {@link RepositoryNode}, to be able to
17 * retrieve alias of the current used repository
20 public class WorkspaceNode
extends TreeParent
implements EventListener
, UiNode
{
21 private Session session
= null;
23 public WorkspaceNode(RepositoryNode parent
, String name
) {
24 this(parent
, name
, null);
27 public WorkspaceNode(RepositoryNode parent
, String name
, Session session
) {
29 this.session
= session
;
31 processNewSession(session
);
35 public Session
getSession() {
39 public Node
getRootNode() {
42 return session
.getRootNode();
45 } catch (RepositoryException e
) {
46 throw new ArgeoException("Cannot get root node of workspace "
54 session
= ((RepositoryNode
) getParent()).repositoryLogin(getName());
55 processNewSession(session
);
57 } catch (RepositoryException e
) {
58 throw new ArgeoException("Cannot connect to repository "
63 public void logout() {
65 if (session
!= null && session
.isLive()) {
66 session
.getWorkspace().getObservationManager()
67 .removeEventListener(this);
70 } catch (RepositoryException e
) {
71 throw new ArgeoException("Cannot connect to repository "
76 /** Returns the alias of the parent Repository */
77 public String
getAlias() {
78 return ((UiNode
) getParent()).getAlias();
82 public boolean hasChildren() {
87 return session
.getRootNode().hasNodes();
88 } catch (RepositoryException re
) {
89 throw new ArgeoException(
90 "Unexpected error while checking children node existence",
95 /** Override normal behaviour to initialize display of the workspace */
97 public synchronized Object
[] getChildren() {
99 return super.getChildren();
101 // initialize current object
107 rootNode
= session
.getRootNode();
108 NodeIterator ni
= rootNode
.getNodes();
109 while (ni
.hasNext()) {
110 Node node
= ni
.nextNode();
111 addChild(new SingleJcrNode(this, node
, node
.getName()));
113 return super.getChildren();
114 } catch (RepositoryException e
) {
115 throw new ArgeoException(
116 "Cannot initialize WorkspaceNode UI object."
122 public void onEvent(final EventIterator events
) {
123 // if (session == null)
125 // Display.getDefault().syncExec(new Runnable() {
126 // public void run() {
127 // while (events.hasNext()) {
128 // Event event = events.nextEvent();
130 // String path = event.getPath();
131 // String parentPath = path.substring(0,
132 // path.lastIndexOf('/'));
133 // final Object parent;
134 // if (parentPath.equals("/") || parentPath.equals(""))
136 // else if (session.itemExists(parentPath)){
137 // parent = session.getItem(parentPath);
138 // ((Item)parent).refresh(false);
142 // if (parent != null) {
143 // nodesViewer.refresh(parent);
146 // } catch (RepositoryException e) {
147 // log.warn("Error processing event " + event, e);
154 protected void processNewSession(Session session
) {
156 // ObservationManager observationManager = session.getWorkspace()
157 // .getObservationManager();
158 // observationManager.addEventListener(this, Event.NODE_ADDED
159 // | Event.NODE_REMOVED, "/", true, null, null, false);
160 // } catch (RepositoryException e) {
161 // throw new ArgeoException("Cannot process new session "