@Override
public Image getImage(Object element) {
if (element instanceof RemoteRepositoryNode) {
- if (((RemoteRepositoryNode) element).getDefaultSession() == null)
- return JcrImages.REMOTE_DISCONNECTED;
- else
+ if (((RemoteRepositoryNode) element).isConnected())
return JcrImages.REMOTE_CONNECTED;
- } else if (element instanceof RepositoryNode) {
- if (((RepositoryNode) element).getDefaultSession() == null)
- return JcrImages.REPOSITORY_DISCONNECTED;
else
+ return JcrImages.REMOTE_DISCONNECTED;
+ } else if (element instanceof RepositoryNode) {
+ if (((RepositoryNode) element).isConnected())
return JcrImages.REPOSITORY_CONNECTED;
- } else if (element instanceof WorkspaceNode) {
- if (((WorkspaceNode) element).getSession() == null)
- return JcrImages.WORKSPACE_DISCONNECTED;
else
+ return JcrImages.REPOSITORY_DISCONNECTED;
+ } else if (element instanceof WorkspaceNode) {
+ if (((WorkspaceNode) element).isConnected())
return JcrImages.WORKSPACE_CONNECTED;
+ else
+ return JcrImages.WORKSPACE_DISCONNECTED;
} else if (element instanceof RepositoriesNode) {
return JcrImages.REPOSITORIES;
} else if (element instanceof SingleJcrNode)
public void login() {
try {
- // SimpleCredentials sc = new SimpleCredentials("root",
- // "demo".toCharArray());
- // defaultSession = repository.login(sc);
defaultSession = repositoryLogin(null);
String[] wkpNames = defaultSession.getWorkspace()
.getAccessibleWorkspaceNames();
}
}
- /** Actual call to the {@link Repository#login(javax.jcr.Credentials, String)} method. To be overridden.*/
+ /**
+ * Actual call to the
+ * {@link Repository#login(javax.jcr.Credentials, String)} method. To be
+ * overridden.
+ */
protected Session repositoryLogin(String workspaceName)
throws RepositoryException {
return repository.login(workspaceName);
}
- public Session getDefaultSession() {
- return defaultSession;
+ public String[] getAccessibleWorkspaceNames() {
+ try {
+ return defaultSession.getWorkspace().getAccessibleWorkspaceNames();
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Cannot retrieve workspace names", e);
+ }
}
/** returns the {@link Repository} referenced by the current UI Node */
return alias;
}
+ public Boolean isConnected() {
+ if (defaultSession != null && defaultSession.isLive())
+ return true;
+ else
+ return false;
+ }
}
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.Workspace;
-import javax.jcr.observation.EventIterator;
-import javax.jcr.observation.EventListener;
import org.argeo.ArgeoException;
import org.argeo.eclipse.ui.TreeParent;
+import org.argeo.jcr.JcrUtils;
/**
* UI Tree component. Wraps the root node of a JCR {@link Workspace}. It also
* keeps a reference to its parent {@link RepositoryNode}, to be able to
* retrieve alias of the current used repository
*/
-public class WorkspaceNode extends TreeParent implements EventListener, UiNode {
+public class WorkspaceNode extends TreeParent implements UiNode {
private Session session = null;
public WorkspaceNode(RepositoryNode parent, String name) {
public WorkspaceNode(RepositoryNode parent, String name, Session session) {
super(name);
this.session = session;
- if (session != null)
- processNewSession(session);
setParent(parent);
}
public void login() {
try {
- logout();
session = ((RepositoryNode) getParent()).repositoryLogin(getName());
- processNewSession(session);
-
} catch (RepositoryException e) {
throw new ArgeoException("Cannot connect to repository "
+ getName(), e);
}
}
+ public Boolean isConnected() {
+ if (session != null && session.isLive())
+ return true;
+ else
+ return false;
+ }
+
@Override
public synchronized void dispose() {
logout();
/** Logouts the session, does not nothing if there is no live session. */
public void logout() {
- try {
- if (session != null && session.isLive()) {
- session.getWorkspace().getObservationManager()
- .removeEventListener(this);
- session.logout();
- }
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot connect to repository "
- + getName(), e);
- }
+ clearChildren();
+ JcrUtils.logoutQuietly(session);
}
/** Returns the alias of the parent Repository */
@Override
public boolean hasChildren() {
try {
- if (session == null)
- return false;
- else
+ if (isConnected())
return session.getRootNode().hasNodes();
+ else
+ return false;
} catch (RepositoryException re) {
throw new ArgeoException(
"Unexpected error while checking children node existence",
}
}
}
-
- public void onEvent(final EventIterator events) {
- // if (session == null)
- // return;
- // Display.getDefault().syncExec(new Runnable() {
- // public void run() {
- // while (events.hasNext()) {
- // Event event = events.nextEvent();
- // try {
- // String path = event.getPath();
- // String parentPath = path.substring(0,
- // path.lastIndexOf('/'));
- // final Object parent;
- // if (parentPath.equals("/") || parentPath.equals(""))
- // parent = this;
- // else if (session.itemExists(parentPath)){
- // parent = session.getItem(parentPath);
- // ((Item)parent).refresh(false);
- // }
- // else
- // parent = null;
- // if (parent != null) {
- // nodesViewer.refresh(parent);
- // }
- //
- // } catch (RepositoryException e) {
- // log.warn("Error processing event " + event, e);
- // }
- // }
- // }
- // });
- }
-
- protected void processNewSession(Session session) {
- // try {
- // ObservationManager observationManager = session.getWorkspace()
- // .getObservationManager();
- // observationManager.addEventListener(this, Event.NODE_ADDED
- // | Event.NODE_REMOVED, "/", true, null, null, false);
- // } catch (RepositoryException e) {
- // throw new ArgeoException("Cannot process new session "
- // + session, e);
- // }
- }
-
}