X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=server%2Fplugins%2Forg.argeo.jcr.ui.explorer%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fjcr%2Fui%2Fexplorer%2Fcommands%2FAddRemoteRepository.java;h=6b5dfa8b0c490bafaa37059d6b38098b7e9e962b;hb=a093e5c849e70bbc754fa4462dbb6c2b59979973;hp=e691b8fb65dd4a3740b90164da8b7a2265b0174c;hpb=82e079d95c38d7136944d79394b9efd82a2864dd;p=lgpl%2Fargeo-commons.git diff --git a/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/commands/AddRemoteRepository.java b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/commands/AddRemoteRepository.java index e691b8fb6..6b5dfa8b0 100644 --- a/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/commands/AddRemoteRepository.java +++ b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/commands/AddRemoteRepository.java @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2007-2012 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.argeo.jcr.ui.explorer.commands; import java.net.URI; @@ -98,6 +113,7 @@ public class AddRemoteRepository extends AbstractHandler implements private Text uri; private Text username; private Text password; + private Button saveInKeyring; public RemoteRepositoryLoginDialog(Shell parentShell) { super(parentShell); @@ -121,6 +137,8 @@ public class AddRemoteRepository extends AbstractHandler implements "http://localhost:7070/org.argeo.jcr.webapp/remoting/node"); username = createLT(composite, "User", ""); password = createLP(composite, "Password"); + + saveInKeyring = createLC(composite, "Remember password", false); parent.pack(); return composite; } @@ -173,6 +191,12 @@ public class AddRemoteRepository extends AbstractHandler implements try { Session nodeSession = keyring.getSession(); Node home = JcrUtils.getUserHome(nodeSession); + + // FIXME better deal with non existing home dir + if (home == null) + home = JcrUtils.createUserHomeIfNeeded(nodeSession, + nodeSession.getUserID()); + Node remote = home.hasNode(ARGEO_REMOTE) ? home .getNode(ARGEO_REMOTE) : home.addNode(ARGEO_REMOTE); if (remote.hasNode(name.getText())) @@ -184,18 +208,20 @@ public class AddRemoteRepository extends AbstractHandler implements remoteRepository.setProperty(ARGEO_URI, uri.getText()); remoteRepository.setProperty(ARGEO_USER_ID, username.getText()); Node pwd = remoteRepository.addNode(ARGEO_PASSWORD); - keyring.set(pwd.getPath(), password.getText().toCharArray()); - nodeSession.save(); + pwd.getSession().save(); + if (saveInKeyring.getSelection()) + keyring.set(pwd.getPath(), password.getText().toCharArray()); + keyring.getSession().save(); MessageDialog.openInformation( getParentShell(), "Repository Added", "Remote repository '" + username.getText() + "@" + uri.getText() + "' added"); + + super.okPressed(); } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); + ErrorFeedback.show("Cannot add remote repository", e); } - super.okPressed(); } /** Creates label and text. */ @@ -207,6 +233,16 @@ public class AddRemoteRepository extends AbstractHandler implements return text; } + /** Creates label and check. */ + protected Button createLC(Composite parent, String label, + Boolean initial) { + new Label(parent, SWT.NONE).setText(label); + Button check = new Button(parent, SWT.CHECK); + check.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + check.setSelection(initial); + return check; + } + protected Text createLP(Composite parent, String label) { new Label(parent, SWT.NONE).setText(label); Text text = new Text(parent, SWT.SINGLE | SWT.LEAD | SWT.BORDER