]> git.argeo.org Git - gpl/argeo-slc.git/blob - plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/WorkspaceElem.java
Remove unused ModulesView
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui.dist / src / main / java / org / argeo / slc / client / ui / dist / model / WorkspaceElem.java
1 package org.argeo.slc.client.ui.dist.model;
2
3 import javax.jcr.NodeIterator;
4 import javax.jcr.RepositoryException;
5 import javax.jcr.Session;
6 import javax.jcr.query.Query;
7
8 import org.argeo.ArgeoException;
9 import org.argeo.jcr.JcrUtils;
10 import org.argeo.slc.jcr.SlcNames;
11 import org.argeo.slc.jcr.SlcTypes;
12
13 /** Abstract a workspace that contains a software distribution */
14 public class WorkspaceElem extends DistParentElem {
15 private final RepoElem repoElem;
16 private String workspaceName;
17 private Session defaultSession;
18
19 public WorkspaceElem(WkspGroupElem parent, RepoElem repoElem,
20 String workspaceName) {
21 super(workspaceName, repoElem.inHome(), repoElem.isReadOnly());
22 this.repoElem = repoElem;
23 this.workspaceName = workspaceName;
24 setParent(parent);
25 }
26
27 public String getWorkspaceName() {
28 return workspaceName;
29 }
30
31 public RepoElem getRepoElem() {
32 return repoElem;
33 }
34
35 public Boolean isConnected() {
36 if (defaultSession != null && defaultSession.isLive())
37 return true;
38 else
39 return false;
40 }
41
42 public void login() {
43 defaultSession = repoElem.repositoryLogin(getName());
44 }
45
46 public boolean hasChildren() {
47 try {
48 if (isConnected())
49 return defaultSession.getRootNode().hasNodes();
50 else
51 return false;
52 } catch (RepositoryException re) {
53 throw new ArgeoException(
54 "Unexpected error while checking children node existence",
55 re);
56 }
57 }
58
59 /** Override normal behaviour to initialize display of the workspace */
60 @Override
61 public synchronized Object[] getChildren() {
62 if (isLoaded()) {
63 return super.getChildren();
64 } else {
65 // initialize current object
66 try {
67 if (defaultSession == null)
68 return null;
69 else {
70 Query groupQuery = defaultSession
71 .getWorkspace()
72 .getQueryManager()
73 .createQuery(
74 "select * from [" + SlcTypes.SLC_GROUP_BASE
75 + "] as group order by group.["
76 + SlcNames.SLC_GROUP_BASE_ID + "]",
77 Query.JCR_SQL2);
78 NodeIterator groups = groupQuery.execute().getNodes();
79 while (groups.hasNext()) {
80 addChild(new GroupBaseElem(WorkspaceElem.this, groups
81 .nextNode()
82 .getProperty(SlcNames.SLC_GROUP_BASE_ID)
83 .getString()));
84 }
85 }
86 return super.getChildren();
87 } catch (RepositoryException e) {
88 throw new ArgeoException(
89 "Cannot initialize WorkspaceNode UI object."
90 + getName(), e);
91 }
92 }
93 }
94
95 @Override
96 public synchronized void dispose() {
97 JcrUtils.logoutQuietly(defaultSession);
98 super.dispose();
99 }
100 }