]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/model/WorkspaceNode.java
2 * Copyright (C) 2007-2012 Mathieu Baudier
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
.jcr
.ui
.explorer
.model
;
18 import javax
.jcr
.Node
;
19 import javax
.jcr
.NodeIterator
;
20 import javax
.jcr
.RepositoryException
;
21 import javax
.jcr
.Session
;
22 import javax
.jcr
.Workspace
;
23 import javax
.jcr
.observation
.EventIterator
;
24 import javax
.jcr
.observation
.EventListener
;
26 import org
.argeo
.ArgeoException
;
27 import org
.argeo
.eclipse
.ui
.TreeParent
;
30 * UI Tree component. Wraps the root node of a JCR {@link Workspace}. It also
31 * keeps a reference to its parent {@link RepositoryNode}, to be able to
32 * retrieve alias of the current used repository
34 public class WorkspaceNode
extends TreeParent
implements EventListener
, UiNode
{
35 private Session session
= null;
37 public WorkspaceNode(RepositoryNode parent
, String name
) {
38 this(parent
, name
, null);
41 public WorkspaceNode(RepositoryNode parent
, String name
, Session session
) {
43 this.session
= session
;
45 processNewSession(session
);
49 public Session
getSession() {
53 public Node
getRootNode() {
56 return session
.getRootNode();
59 } catch (RepositoryException e
) {
60 throw new ArgeoException("Cannot get root node of workspace "
68 session
= ((RepositoryNode
) getParent()).repositoryLogin(getName());
69 processNewSession(session
);
71 } catch (RepositoryException e
) {
72 throw new ArgeoException("Cannot connect to repository "
78 public synchronized void dispose() {
83 /** Logouts the session, does not nothing if there is no live session. */
84 public void logout() {
86 if (session
!= null && session
.isLive()) {
87 session
.getWorkspace().getObservationManager()
88 .removeEventListener(this);
91 } catch (RepositoryException e
) {
92 throw new ArgeoException("Cannot connect to repository "
97 /** Returns the alias of the parent Repository */
98 public String
getAlias() {
99 return ((UiNode
) getParent()).getAlias();
103 public boolean hasChildren() {
108 return session
.getRootNode().hasNodes();
109 } catch (RepositoryException re
) {
110 throw new ArgeoException(
111 "Unexpected error while checking children node existence",
116 /** Override normal behaviour to initialize display of the workspace */
118 public synchronized Object
[] getChildren() {
120 return super.getChildren();
122 // initialize current object
128 rootNode
= session
.getRootNode();
129 NodeIterator ni
= rootNode
.getNodes();
130 while (ni
.hasNext()) {
131 Node node
= ni
.nextNode();
132 addChild(new SingleJcrNode(this, node
, node
.getName()));
134 return super.getChildren();
135 } catch (RepositoryException e
) {
136 throw new ArgeoException(
137 "Cannot initialize WorkspaceNode UI object."
143 public void onEvent(final EventIterator events
) {
144 // if (session == null)
146 // Display.getDefault().syncExec(new Runnable() {
147 // public void run() {
148 // while (events.hasNext()) {
149 // Event event = events.nextEvent();
151 // String path = event.getPath();
152 // String parentPath = path.substring(0,
153 // path.lastIndexOf('/'));
154 // final Object parent;
155 // if (parentPath.equals("/") || parentPath.equals(""))
157 // else if (session.itemExists(parentPath)){
158 // parent = session.getItem(parentPath);
159 // ((Item)parent).refresh(false);
163 // if (parent != null) {
164 // nodesViewer.refresh(parent);
167 // } catch (RepositoryException e) {
168 // log.warn("Error processing event " + event, e);
175 protected void processNewSession(Session session
) {
177 // ObservationManager observationManager = session.getWorkspace()
178 // .getObservationManager();
179 // observationManager.addEventListener(this, Event.NODE_ADDED
180 // | Event.NODE_REMOVED, "/", true, null, null, false);
181 // } catch (RepositoryException e) {
182 // throw new ArgeoException("Cannot process new session "