]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/commands/AddRemoteRepository.java
Add dep folder
[lgpl/argeo-commons.git] / server / plugins / org.argeo.jcr.ui.explorer / src / main / java / org / argeo / jcr / ui / explorer / commands / AddRemoteRepository.java
index 332e94444812628401438299ad94dab68850ec4c..e41edfca875163fa11fdd3353442e08f0e0fd1f2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007-2012 Mathieu Baudier
+ * Copyright (C) 2007-2012 Argeo GmbH
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -26,14 +26,14 @@ import javax.jcr.SimpleCredentials;
 
 import org.argeo.ArgeoException;
 import org.argeo.eclipse.ui.ErrorFeedback;
+import org.argeo.eclipse.ui.utils.CommandUtils;
 import org.argeo.jcr.ArgeoJcrConstants;
 import org.argeo.jcr.ArgeoNames;
 import org.argeo.jcr.ArgeoTypes;
 import org.argeo.jcr.JcrUtils;
 import org.argeo.jcr.UserJcrUtils;
-import org.argeo.jcr.security.JcrKeyring;
-import org.argeo.jcr.security.SecurityJcrUtils;
 import org.argeo.jcr.ui.explorer.JcrExplorerConstants;
+import org.argeo.util.security.Keyring;
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
@@ -63,12 +63,14 @@ public class AddRemoteRepository extends AbstractHandler implements
                JcrExplorerConstants, ArgeoNames {
 
        private RepositoryFactory repositoryFactory;
-       private JcrKeyring keyring;
+       private Repository nodeRepository;
+       private Keyring keyring;
 
        public Object execute(ExecutionEvent event) throws ExecutionException {
                RemoteRepositoryLoginDialog dlg = new RemoteRepositoryLoginDialog(
                                Display.getDefault().getActiveShell());
                if (dlg.open() == Dialog.OK) {
+                       CommandUtils.callCommand(Refresh.ID);
                }
                return null;
        }
@@ -77,10 +79,14 @@ public class AddRemoteRepository extends AbstractHandler implements
                this.repositoryFactory = repositoryFactory;
        }
 
-       public void setKeyring(JcrKeyring keyring) {
+       public void setKeyring(Keyring keyring) {
                this.keyring = keyring;
        }
 
+       public void setNodeRepository(Repository nodeRepository) {
+               this.nodeRepository = nodeRepository;
+       }
+
        class RemoteRepositoryLoginDialog extends TitleAreaDialog {
                private Text name;
                private Text uri;
@@ -107,7 +113,7 @@ public class AddRemoteRepository extends AbstractHandler implements
                        setMessage("Login to remote repository", IMessageProvider.NONE);
                        name = createLT(composite, "Name", "remoteRepository");
                        uri = createLT(composite, "URI",
-                                       "http://localhost:7070/org.argeo.jcr.webapp/remoting/node");
+                                       "http://localhost:7070/data/jcr/node");
                        username = createLT(composite, "User", "");
                        password = createLP(composite, "Password");
 
@@ -158,15 +164,11 @@ public class AddRemoteRepository extends AbstractHandler implements
 
                @Override
                protected void okPressed() {
+                       Session nodeSession = null;
                        try {
-                               Session nodeSession = keyring.getSession();
+                               nodeSession = nodeRepository.login();
                                Node home = UserJcrUtils.getUserHome(nodeSession);
 
-                               // FIXME better deal with non existing home dir
-                               if (home == null)
-                                       home = SecurityJcrUtils.createUserHomeIfNeeded(nodeSession,
-                                                       nodeSession.getUserID());
-
                                Node remote = home.hasNode(ARGEO_REMOTE) ? home
                                                .getNode(ARGEO_REMOTE) : home.addNode(ARGEO_REMOTE);
                                if (remote.hasNode(name.getText()))
@@ -177,11 +179,13 @@ public class AddRemoteRepository extends AbstractHandler implements
                                                ArgeoTypes.ARGEO_REMOTE_REPOSITORY);
                                remoteRepository.setProperty(ARGEO_URI, uri.getText());
                                remoteRepository.setProperty(ARGEO_USER_ID, username.getText());
-                               Node pwd = remoteRepository.addNode(ARGEO_PASSWORD);
-                               pwd.getSession().save();
-                               if (saveInKeyring.getSelection())
-                                       keyring.set(pwd.getPath(), password.getText().toCharArray());
-                               keyring.getSession().save();
+                               nodeSession.save();
+                               if (saveInKeyring.getSelection()) {
+                                       String pwdPath = remoteRepository.getPath() + '/'
+                                                       + ARGEO_PASSWORD;
+                                       keyring.set(pwdPath, password.getText().toCharArray());
+                               }
+                               nodeSession.save();
                                MessageDialog.openInformation(
                                                getParentShell(),
                                                "Repository Added",
@@ -191,6 +195,8 @@ public class AddRemoteRepository extends AbstractHandler implements
                                super.okPressed();
                        } catch (Exception e) {
                                ErrorFeedback.show("Cannot add remote repository", e);
+                       } finally {
+                               JcrUtils.logoutQuietly(nodeSession);
                        }
                }