+ // ///////////////////////
+ // Local classes
+ private class WkspObject {
+ protected final String srcName;
+ protected String targetName;
+
+ protected WkspObject(String srcName) {
+ this.srcName = srcName;
+ this.targetName = srcName;
+ }
+
+ @Override
+ public String toString() {
+ return "[" + srcName + " to " + targetName + "]";
+ }
+ }
+
+ private class WkspContentProvider implements IStructuredContentProvider {
+ // caches current repo
+ private Node currSourceNodeRepo;
+ private Repository currSourceRepo;
+ private Credentials currSourceCred;
+
+ private List<WkspObject> workspaces = new ArrayList<WkspObject>();
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ if (newInput != null && newInput instanceof Node) {
+ Session session = null;
+ try {
+ Node newRepoNode = (Node) newInput;
+ if (currSourceNodeRepo == null
+ || !newRepoNode.getPath().equals(
+ currSourceNodeRepo.getPath())) {
+
+ // update cache
+ currSourceNodeRepo = newRepoNode;
+ currSourceRepo = RepoUtils.getRepository(
+ repositoryFactory, keyring, currSourceNodeRepo);
+ currSourceCred = RepoUtils.getRepositoryCredentials(
+ keyring, currSourceNodeRepo);
+
+ // reset workspace list
+ wkspViewer.setAllChecked(false);
+ workspaces.clear();
+ session = currSourceRepo.login(currSourceCred);
+ // remove unvalid elements
+ for (String name : session.getWorkspace()
+ .getAccessibleWorkspaceNames())
+ // TODO implement a cleaner way to filter
+ // workspaces out
+ if (name.lastIndexOf('-') > 0) {
+ WkspObject currWksp = new WkspObject(name);
+ // compute wkspace size
+ // TODO implement this
+ // Session currSession = null;
+ // try {
+ // currSession = currSourceRepo.login(
+ // currSourceCred, name);
+ // currWksp.size = JcrUtils
+ // .getNodeApproxSize(currSession
+ // .getNode("/"));
+ //
+ // } catch (RepositoryException re) {
+ // log.warn(
+ // "unable to compute size of workspace "
+ // + name, re);
+ // } finally {
+ // JcrUtils.logoutQuietly(currSession);
+ // }
+ workspaces.add(currWksp);
+ }
+ }
+
+ } catch (RepositoryException e) {
+ throw new SlcException("Unexpected error while "
+ + "initializing fetch wizard", e);
+ } finally {
+ JcrUtils.logoutQuietly(session);
+ }
+ viewer.refresh();
+ }
+ }
+
+ public void dispose() {
+ }
+
+ public Object[] getElements(Object obj) {
+ return workspaces.toArray();
+ }
+ }
+
+ // ////////////////////////////
+ // // Helpers
+
+ // populate available source repo list
+ private Map<String, Node> getSourceRepoUris() {
+ try {
+ Node repoList = currSession.getNode(UserJcrUtils.getUserHome(
+ currSession).getPath()
+ + RepoConstants.REPOSITORIES_BASE_PATH);
+
+ String targetRepoUri = null;
+ if (targetRepoNode != null) {
+ targetRepoUri = targetRepoNode
+ .getProperty(ArgeoNames.ARGEO_URI).getString();
+ }
+ NodeIterator ni = repoList.getNodes();
+ // List<String> sourceRepoNames = new ArrayList<String>();
+ // // caches a map of the source repo nodes with their URI as a key
+ // // to ease further processing
+ Map<String, Node> sourceReposMap = new HashMap<String, Node>();
+ while (ni.hasNext()) {
+ Node currNode = ni.nextNode();
+ if (currNode.isNodeType(ArgeoTypes.ARGEO_REMOTE_REPOSITORY)) {
+ String currUri = currNode.getProperty(ArgeoNames.ARGEO_URI)
+ .getString();
+ if (targetRepoUri == null || !targetRepoUri.equals(currUri)) {
+ sourceReposMap.put(currUri, currNode);
+ // sourceRepoNames.add(currUri);
+ }
+ }
+ }
+ return sourceReposMap;
+ // sourceRepoNames.toArray(new String[sourceRepoNames
+ // .size()]);
+ } catch (RepositoryException e) {
+ throw new SlcException("Error while getting repo aliases", e);
+ }
+ }
+