Improve dist UI
authorMathieu Baudier <mbaudier@argeo.org>
Tue, 21 Aug 2012 15:01:10 +0000 (15:01 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Tue, 21 Aug 2012 15:01:10 +0000 (15:01 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@5529 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/ArtifactsBrowserPage.java
plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/DistributionEditor.java
plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/DistributionEditorInput.java
plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/ArtifactsBrowser.java
plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/DistributionsView.java

index 4fcd9632857bd0b7a1cb15eea631b7abb22b1493..f10a32e190f5d0b75c832e6cb4b25819841707bb 100644 (file)
@@ -110,7 +110,12 @@ public class ArtifactsBrowserPage extends FormPage implements DistConstants,
                // Model initialisation
                if (jcrSession != null) {
                        try {
-                               rootNode = jcrSession.getNode(ARTIFACTS_BASE_PATH);
+                               DistributionEditorInput dei = (DistributionEditorInput) getEditorInput();
+                               if (dei.getArtifactsBase().equals(DEFAULT_ARTIFACTS_BASE_PATH)) {
+                                       rootNode = jcrSession.getRootNode();
+                               } else {
+                                       rootNode = jcrSession.getNode(dei.getArtifactsBase());
+                               }
                                artifactTreeViewer.setInput(rootNode);
                        } catch (RepositoryException e) {
                                throw new ArgeoException("Cannot load base artifact nodes", e);
index 35eb045bc0de6c2fd75e4c2fcd696e7600384e10..4fd85c2c20b4a458f87a0e5c8770db75f7c517cb 100644 (file)
@@ -15,6 +15,8 @@
  */
 package org.argeo.slc.client.ui.dist.editors;
 
+import javax.jcr.Credentials;
+import javax.jcr.GuestCredentials;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 
@@ -43,7 +45,8 @@ public class DistributionEditor extends FormEditor implements SlcNames {
                        throws PartInitException {
                DistributionEditorInput dei = (DistributionEditorInput) input;
                try {
-                       session = dei.getRepository().login(dei.getWorkspaceName());
+                       session = dei.getRepository().login(dei.getCredentials(),
+                                       dei.getWorkspaceName());
                } catch (RepositoryException e) {
                        throw new PartInitException("Cannot log to workspace "
                                        + dei.getWorkspaceName(), e);
@@ -55,8 +58,8 @@ public class DistributionEditor extends FormEditor implements SlcNames {
        @Override
        protected void addPages() {
                try {
-                       addPage(new DistributionOverviewPage(this, "Overview", session));
                        addPage(new ArtifactsBrowserPage(this, "Browser", session));
+                       addPage(new DistributionOverviewPage(this, "Overview", session));
                } catch (PartInitException e) {
                        throw new ArgeoException("Cannot add distribution editor pages", e);
                }
index 38d92549cc44f3d942d5cdb33dede5b8532d11d5..883a20974546ab5bc51dd00c189586dcbe0f0e63 100644 (file)
  */
 package org.argeo.slc.client.ui.dist.editors;
 
+import javax.jcr.Credentials;
 import javax.jcr.Repository;
 
 import org.argeo.slc.jcr.SlcNames;
+import org.argeo.slc.repo.RepoConstants;
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IPersistableElement;
@@ -27,20 +29,27 @@ import org.eclipse.ui.IPersistableElement;
  * */
 public class DistributionEditorInput implements IEditorInput, SlcNames {
 
+       private String repositoryName;
        private Repository repository;
        private String workspaceName;
-       private String artifactsBase = "/";
+       private String artifactsBase = RepoConstants.DEFAULT_ARTIFACTS_BASE_PATH;
+       private Credentials credentials;
 
-       public DistributionEditorInput(Repository repository, String workspaceName,
-                       String artifactsBase) {
+       public DistributionEditorInput(String repositoryName,
+                       Repository repository, String workspaceName, String artifactsBase,
+                       Credentials credentials) {
                super();
                this.repository = repository;
+               this.repositoryName = repositoryName;
                this.workspaceName = workspaceName;
                this.artifactsBase = artifactsBase;
+               this.credentials = credentials;
        }
 
-       public DistributionEditorInput(Repository repository, String workspaceName) {
-               this(repository, workspaceName, "/");
+       public DistributionEditorInput(String repositoryName,
+                       Repository repository, String workspaceName, Credentials credentials) {
+               this(repositoryName, repository, workspaceName,
+                               RepoConstants.DEFAULT_ARTIFACTS_BASE_PATH, credentials);
        }
 
        public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
@@ -93,4 +102,12 @@ public class DistributionEditorInput implements IEditorInput, SlcNames {
                return artifactsBase;
        }
 
+       public String getRepositoryName() {
+               return repositoryName;
+       }
+
+       public Credentials getCredentials() {
+               return credentials;
+       }
+
 }
index 71cb36ed5d743fb63c31fb2e9886696d884285c0..de61b44a4c76109afebc601bf66e121fbfeea00a 100644 (file)
@@ -100,7 +100,7 @@ public class ArtifactsBrowser extends ViewPart implements DistConstants,
                // Model initialisation
                if (jcrSession != null) {
                        try {
-                               rootNode = jcrSession.getNode(ARTIFACTS_BASE_PATH);
+                               rootNode = jcrSession.getNode(DEFAULT_ARTIFACTS_BASE_PATH);
                                artifactTreeViewer.setInput(rootNode);
                        } catch (RepositoryException e) {
                                throw new ArgeoException("Cannot load base artifact nodes", e);
index c143fb2e0dd19cae8afa6647a84c51b408acf6ae..633f5df390462e73691923846690ec531d6e00b8 100644 (file)
@@ -20,6 +20,8 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import javax.jcr.Credentials;
+import javax.jcr.GuestCredentials;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.RepositoryFactory;
@@ -110,17 +112,31 @@ public class DistributionsView extends ViewPart implements SlcNames {
 
                // Initializes repositories
                // TODO make it more generic, with remote repositories etc.
-               repositories.add(new RepositoryElem("java", repository, false));
+               repositories.add(new RepositoryElem("java", repository, null));
 
                // Remote
-               /*
-               String uri = "http://localhost:7070/org.argeo.jcr.webapp/remoting/java";
-               //String uri = "http://dev.argeo.org/org.argeo.jcr.webapp/pub/java";
-               Repository remoteRepository = JcrUtils.getRepositoryByUri(
-                               repositoryFactory, uri);
-               repositories.add(new RepositoryElem("java@dev.argeo.org",
-                               remoteRepository, true));
-               */
+               String uri = null;
+               Credentials credentials = null;
+               Repository remoteRepository = null;
+
+               uri = "http://dev.argeo.org/org.argeo.jcr.webapp/pub/java";
+               credentials = new GuestCredentials();
+               remoteRepository = JcrUtils.getRepositoryByUri(repositoryFactory, uri);
+               repositories.add(new RepositoryElem("anonymous@dev.argeo.org//java",
+                               remoteRepository, credentials));
+
+               uri = "http://localhost:7070/org.argeo.jcr.webapp/pub/java";
+               credentials = new GuestCredentials();
+               remoteRepository = JcrUtils.getRepositoryByUri(repositoryFactory, uri);
+               repositories.add(new RepositoryElem("anonymous@localhost//java",
+                               remoteRepository, credentials));
+
+               uri = "http://localhost:7070/org.argeo.jcr.webapp/remoting/java";
+               credentials = new SimpleCredentials(System.getProperty("user.name"),
+                               "".toCharArray());
+               remoteRepository = JcrUtils.getRepositoryByUri(repositoryFactory, uri);
+               repositories.add(new RepositoryElem("@localhost//java",
+                               remoteRepository, credentials));
 
                viewer.setInput(getSite());
 
@@ -221,25 +237,17 @@ public class DistributionsView extends ViewPart implements SlcNames {
        private static class RepositoryElem extends TreeParent {
                // private final Repository repository;
                private Session defaultSession;
-               private final Boolean isRemote;
 
                public RepositoryElem(String name, Repository repository,
-                               Boolean isRemote) {
+                               Credentials credentials) {
                        super(name);
-                       // this.repository = repository;
-                       this.isRemote = isRemote;
                        try {
-                               if (isRemote) {
-                                       SimpleCredentials sc = new SimpleCredentials("root",
-                                                       "demo".toCharArray());
-                                       defaultSession = repository.login(sc);
-                               } else {
-                                       defaultSession = repository.login();
-                               }
+                               defaultSession = repository.login(credentials);
                                String[] workspaceNames = defaultSession.getWorkspace()
                                                .getAccessibleWorkspaceNames();
                                for (String workspace : workspaceNames)
-                                       addChild(new DistributionElem(repository, workspace));
+                                       addChild(new DistributionElem(repository, workspace,
+                                                       credentials));
                        } catch (RepositoryException e) {
                                ErrorFeedback.show("Cannot log to repository", e);
                        }
@@ -257,11 +265,14 @@ public class DistributionsView extends ViewPart implements SlcNames {
        private static class DistributionElem extends TreeParent {
                private final String workspaceName;
                private final Repository repository;
+               private final Credentials credentials;
 
-               public DistributionElem(Repository repository, String workspaceName) {
+               public DistributionElem(Repository repository, String workspaceName,
+                               Credentials credentials) {
                        super(workspaceName);
                        this.workspaceName = workspaceName;
                        this.repository = repository;
+                       this.credentials = credentials;
                }
 
                public String getWorkspaceName() {
@@ -271,6 +282,10 @@ public class DistributionsView extends ViewPart implements SlcNames {
                public Repository getRepository() {
                        return repository;
                }
+
+               public Credentials getCredentials() {
+                       return credentials;
+               }
        }
 
        @Override
@@ -290,8 +305,10 @@ public class DistributionsView extends ViewPart implements SlcNames {
                        if (obj instanceof DistributionElem) {
                                DistributionElem distributionElem = (DistributionElem) obj;
                                DistributionEditorInput dei = new DistributionEditorInput(
+                                               distributionElem.getName(),
                                                distributionElem.getRepository(),
-                                               distributionElem.getWorkspaceName());
+                                               distributionElem.getWorkspaceName(),
+                                               distributionElem.getCredentials());
                                try {
                                        DistPlugin.getDefault().getWorkbench()
                                                        .getActiveWorkbenchWindow().getActivePage()