]> 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/RepositoryNode.java
+ refactoring of the JCR UI Model (in a MVC point of view)
[lgpl/argeo-commons.git] / server / plugins / org.argeo.jcr.ui.explorer / src / main / java / org / argeo / jcr / ui / explorer / model / RepositoryNode.java
1 package org.argeo.jcr.ui.explorer.model;
2
3 import javax.jcr.Repository;
4 import javax.jcr.RepositoryException;
5 import javax.jcr.Session;
6
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;
11
12 /**
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.
16 */
17
18 public class RepositoryNode extends TreeParent implements UiNode {
19 private String alias;
20 private final Repository repository;
21 private Session defaultSession = null;
22 public final static Image REPOSITORY_DISCONNECTED = JcrUiPlugin
23 .getImageDescriptor("icons/repository_disconnected.gif")
24 .createImage();
25 public final static Image REPOSITORY_CONNECTED = JcrUiPlugin
26 .getImageDescriptor("icons/repository_connected.gif").createImage();
27
28 /** Create a new repository with alias = name */
29 public RepositoryNode(String alias, Repository repository, TreeParent parent) {
30 this(alias, alias, repository, parent);
31 }
32
33 /** Create a new repository with distinct name & alias */
34 public RepositoryNode(String alias, String name, Repository repository,
35 TreeParent parent) {
36 super(name);
37 this.repository = repository;
38 setParent(parent);
39 this.alias = alias;
40 }
41
42 public void login() {
43 try {
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));
53 else
54 addChild(new WorkspaceNode(this, wkpName));
55 }
56 } catch (RepositoryException e) {
57 throw new ArgeoException("Cannot connect to repository " + alias, e);
58 }
59 }
60
61 public Session getDefaultSession() {
62 return defaultSession;
63 }
64
65 /** returns the {@link Repository} referenced by the current UI Node */
66 public Repository getRepository() {
67 return repository;
68 }
69
70 public String getAlias() {
71 return alias;
72 }
73
74 }