]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/wizards/RegisterRepoWizard.java
Migrate SLC modules
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui.dist / src / main / java / org / argeo / slc / client / ui / dist / wizards / RegisterRepoWizard.java
index fb80ac3cf5d7076821fd39178fb55eb6fff22962..3f7f30c6588b7ebd5484c115be5007daa2b1f8f0 100644 (file)
@@ -19,6 +19,7 @@ import java.net.URI;
 import java.util.Hashtable;
 
 import javax.jcr.Node;
+import javax.jcr.NodeIterator;
 import javax.jcr.Property;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryFactory;
@@ -26,7 +27,6 @@ import javax.jcr.Session;
 import javax.jcr.SimpleCredentials;
 import javax.jcr.nodetype.NodeType;
 
-import org.argeo.ArgeoException;
 import org.argeo.eclipse.ui.ErrorFeedback;
 import org.argeo.jcr.ArgeoJcrConstants;
 import org.argeo.jcr.ArgeoJcrUtils;
@@ -113,9 +113,26 @@ public class RegisterRepoWizard extends Wizard {
                        Node repos = nodeSession.getNode(reposPath);
                        String repoNodeName = JcrUtils.replaceInvalidChars(name.getText());
                        if (repos.hasNode(repoNodeName))
-                               throw new ArgeoException(
+                               throw new SlcException(
                                                "There is already a remote repository named "
                                                                + repoNodeName);
+
+                       // check if the same URI has already been registered
+                       NodeIterator ni = repos.getNodes();
+                       while (ni.hasNext()) {
+                               Node node = ni.nextNode();
+                               if (node.isNodeType(ArgeoTypes.ARGEO_REMOTE_REPOSITORY)
+                                               && node.hasProperty(ArgeoNames.ARGEO_URI)
+                                               && node.getProperty(ArgeoNames.ARGEO_URI).getString()
+                                                               .equals(uri.getText()))
+                                       throw new SlcException(
+                                                       "This URI "
+                                                                       + uri.getText()
+                                                                       + " is already registered, "
+                                                                       + "for the time being, only one instance of a single "
+                                                                       + "repository at a time is implemented.");
+                       }
+
                        Node repoNode = repos.addNode(repoNodeName,
                                        ArgeoTypes.ARGEO_REMOTE_REPOSITORY);
                        repoNode.setProperty(ArgeoNames.ARGEO_URI, uri.getText());
@@ -160,7 +177,7 @@ public class RegisterRepoWizard extends Wizard {
                        uri = createLT(composite, "URI", DEFAULT_URI);
 
                        final Button anonymousLogin = createLC(composite,
-                                       "log as anonymous", true);
+                                       "Log as anonymous", true);
                        anonymousLogin.addSelectionListener(new SelectionListener() {
                                public void widgetSelected(SelectionEvent e) {
                                        if (anonymousLogin.getSelection()) {
@@ -207,7 +224,7 @@ public class RegisterRepoWizard extends Wizard {
 
                /** Creates label and text. */
                protected Text createLT(Composite parent, String label, String initial) {
-                       new Label(parent, SWT.NONE).setText(label);
+                       new Label(parent, SWT.RIGHT).setText(label);
                        Text text = new Text(parent, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
                        text.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true));
                        text.setText(initial);
@@ -217,7 +234,7 @@ public class RegisterRepoWizard extends Wizard {
                /** Creates label and check. */
                protected Button createLC(Composite parent, String label,
                                Boolean initial) {
-                       new Label(parent, SWT.NONE).setText(label);
+                       new Label(parent, SWT.RIGHT).setText(label);
                        Button check = new Button(parent, SWT.CHECK);
                        check.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
                        check.setSelection(initial);