]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/model/WorkspaceElem.java
2 * Copyright (C) 2007-2012 Argeo GmbH
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
;
24 import org
.argeo
.ArgeoException
;
25 import org
.argeo
.eclipse
.ui
.TreeParent
;
26 import org
.argeo
.jcr
.JcrUtils
;
29 * UI Tree component. Wraps the root node of a JCR {@link Workspace}. It also
30 * keeps a reference to its parent {@link RepositoryElem}, to be able to
31 * retrieve alias of the current used repository
33 public class WorkspaceElem
extends TreeParent
{
34 private Session session
= null;
36 public WorkspaceElem(RepositoryElem parent
, String name
) {
37 this(parent
, name
, null);
40 public WorkspaceElem(RepositoryElem parent
, String name
, Session session
) {
42 this.session
= session
;
46 public Session
getSession() {
50 public Node
getRootNode() {
53 return session
.getRootNode();
56 } catch (RepositoryException e
) {
57 throw new ArgeoException("Cannot get root node of workspace "
64 session
= ((RepositoryElem
) getParent()).repositoryLogin(getName());
65 } catch (RepositoryException e
) {
66 throw new ArgeoException("Cannot connect to repository "
71 public Boolean
isConnected() {
72 if (session
!= null && session
.isLive())
79 public synchronized void dispose() {
84 /** Logouts the session, does not nothing if there is no live session. */
85 public void logout() {
87 JcrUtils
.logoutQuietly(session
);
91 public boolean hasChildren() {
94 return session
.getRootNode().hasNodes();
97 } catch (RepositoryException re
) {
98 throw new ArgeoException(
99 "Unexpected error while checking children node existence",
104 /** Override normal behaviour to initialize display of the workspace */
106 public synchronized Object
[] getChildren() {
108 return super.getChildren();
110 // initialize current object
116 rootNode
= session
.getRootNode();
117 NodeIterator ni
= rootNode
.getNodes();
118 while (ni
.hasNext()) {
119 Node node
= ni
.nextNode();
120 addChild(new SingleJcrNodeElem(this, node
, node
.getName()));
122 return super.getChildren();
123 } catch (RepositoryException e
) {
124 throw new ArgeoException(
125 "Cannot initialize WorkspaceNode UI object."