1 package org
.argeo
.jcr
.ui
.explorer
.model
;
3 import javax
.jcr
.Repository
;
4 import javax
.jcr
.RepositoryException
;
5 import javax
.jcr
.Session
;
7 import org
.argeo
.ArgeoException
;
8 import org
.argeo
.eclipse
.ui
.TreeParent
;
9 import org
.argeo
.eclipse
.ui
.jcr
.JcrUiPlugin
;
10 import org
.eclipse
.swt
.graphics
.Image
;
13 * UI Tree component. Wraps a JCR {@link Repository}. It also keeps a reference
14 * to its parent Tree Ui component; typically the unique {@link Repositories}
15 * object of the current view to enable bi-directionnal browsing in the tree.
18 public class RepositoryNode
extends TreeParent
implements UiNode
{
20 private final Repository repository
;
21 private Session defaultSession
= null;
22 public final static Image REPOSITORY_DISCONNECTED
= JcrUiPlugin
23 .getImageDescriptor("icons/repository_disconnected.gif")
25 public final static Image REPOSITORY_CONNECTED
= JcrUiPlugin
26 .getImageDescriptor("icons/repository_connected.gif").createImage();
28 /** Create a new repository with alias = name */
29 public RepositoryNode(String alias
, Repository repository
, TreeParent parent
) {
30 this(alias
, alias
, repository
, parent
);
33 /** Create a new repository with distinct name & alias */
34 public RepositoryNode(String alias
, String name
, Repository repository
,
37 this.repository
= repository
;
44 // SimpleCredentials sc = new SimpleCredentials("root",
45 // "demo".toCharArray());
46 // defaultSession = repository.login(sc);
47 defaultSession
= repository
.login();
48 String
[] wkpNames
= defaultSession
.getWorkspace()
49 .getAccessibleWorkspaceNames();
50 for (String wkpName
: wkpNames
) {
51 if (wkpName
.equals(defaultSession
.getWorkspace().getName()))
52 addChild(new WorkspaceNode(this, wkpName
, defaultSession
));
54 addChild(new WorkspaceNode(this, wkpName
));
56 } catch (RepositoryException e
) {
57 throw new ArgeoException("Cannot connect to repository " + alias
, e
);
61 public Session
getDefaultSession() {
62 return defaultSession
;
65 /** returns the {@link Repository} referenced by the current UI Node */
66 public Repository
getRepository() {
70 public String
getAlias() {