X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms.ui.workbench%2Fsrc%2Forg%2Fargeo%2Fcms%2Fui%2Fworkbench%2Finternal%2Fjcr%2Fcommands%2FAddRemoteRepository.java;h=3539cacc19145a45ff4afee6c54a803ca7816f05;hb=5b444174cd13680f99944026877f6cac2e1faba1;hp=1f572b304d1b9fe8e69a0c15f1e93fa98acbcbf8;hpb=0243aa5633af84d8608ba912483dbaaaefac42f1;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms.ui.workbench/src/org/argeo/cms/ui/workbench/internal/jcr/commands/AddRemoteRepository.java b/org.argeo.cms.ui.workbench/src/org/argeo/cms/ui/workbench/internal/jcr/commands/AddRemoteRepository.java index 1f572b304..3539cacc1 100644 --- a/org.argeo.cms.ui.workbench/src/org/argeo/cms/ui/workbench/internal/jcr/commands/AddRemoteRepository.java +++ b/org.argeo.cms.ui.workbench/src/org/argeo/cms/ui/workbench/internal/jcr/commands/AddRemoteRepository.java @@ -24,13 +24,13 @@ import javax.jcr.RepositoryFactory; import javax.jcr.Session; import javax.jcr.SimpleCredentials; +import org.argeo.cms.ArgeoNames; +import org.argeo.cms.ArgeoTypes; import org.argeo.cms.ui.workbench.internal.WorkbenchConstants; import org.argeo.cms.ui.workbench.util.CommandUtils; import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.dialogs.ErrorFeedback; import org.argeo.jcr.JcrUtils; -import org.argeo.node.ArgeoNames; -import org.argeo.node.ArgeoTypes; import org.argeo.node.NodeConstants; import org.argeo.node.NodeUtils; import org.argeo.node.security.Keyring; @@ -59,16 +59,14 @@ import org.eclipse.swt.widgets.Text; * Connect to a remote repository and, if successful publish it as an OSGi * service. */ -public class AddRemoteRepository extends AbstractHandler implements - WorkbenchConstants, ArgeoNames { +public class AddRemoteRepository extends AbstractHandler implements WorkbenchConstants, ArgeoNames { private RepositoryFactory repositoryFactory; private Repository nodeRepository; private Keyring keyring; public Object execute(ExecutionEvent event) throws ExecutionException { - RemoteRepositoryLoginDialog dlg = new RemoteRepositoryLoginDialog( - Display.getDefault().getActiveShell()); + RemoteRepositoryLoginDialog dlg = new RemoteRepositoryLoginDialog(Display.getDefault().getActiveShell()); if (dlg.open() == Dialog.OK) { CommandUtils.callCommand(Refresh.ID); } @@ -105,16 +103,13 @@ public class AddRemoteRepository extends AbstractHandler implements protected Control createDialogArea(Composite parent) { Composite dialogarea = (Composite) super.createDialogArea(parent); - dialogarea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, - true)); + dialogarea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); Composite composite = new Composite(dialogarea, SWT.NONE); composite.setLayout(new GridLayout(2, false)); - composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, - false)); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); setMessage("Login to remote repository", IMessageProvider.NONE); name = createLT(composite, "Name", "remoteRepository"); - uri = createLT(composite, "URI", - "http://localhost:7070/data/jcr/node"); + uri = createLT(composite, "URI", "http://localhost:7070/jcr/node"); username = createLT(composite, "User", ""); password = createLP(composite, "Password"); @@ -146,20 +141,19 @@ public class AddRemoteRepository extends AbstractHandler implements params.put(NodeConstants.LABELED_URI, checkedUriStr); Repository repository = repositoryFactory.getRepository(params); if (username.getText().trim().equals("")) {// anonymous - session = repository.login(); + // FIXME make it more generic + session = repository.login("main"); } else { // FIXME use getTextChars() when upgrading to 3.7 // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=297412 char[] pwd = password.getText().toCharArray(); - SimpleCredentials sc = new SimpleCredentials( - username.getText(), pwd); + SimpleCredentials sc = new SimpleCredentials(username.getText(), pwd); session = repository.login(sc, "main"); MessageDialog.openInformation(getParentShell(), "Success", "Connection to '" + uri.getText() + "' successful"); } } catch (Exception e) { - ErrorFeedback.show( - "Connection test failed for " + uri.getText(), e); + ErrorFeedback.show("Connection test failed for " + uri.getText(), e); } finally { JcrUtils.logoutQuietly(session); } @@ -172,28 +166,20 @@ public class AddRemoteRepository extends AbstractHandler implements nodeSession = nodeRepository.login(); Node home = NodeUtils.getUserHome(nodeSession); - Node remote = home.hasNode(ARGEO_REMOTE) ? home - .getNode(ARGEO_REMOTE) : home.addNode(ARGEO_REMOTE); + Node remote = home.hasNode(ARGEO_REMOTE) ? home.getNode(ARGEO_REMOTE) : home.addNode(ARGEO_REMOTE); if (remote.hasNode(name.getText())) - throw new EclipseUiException( - "There is already a remote repository named " - + name.getText()); - Node remoteRepository = remote.addNode(name.getText(), - ArgeoTypes.ARGEO_REMOTE_REPOSITORY); + throw new EclipseUiException("There is already a remote repository named " + name.getText()); + Node remoteRepository = remote.addNode(name.getText(), ArgeoTypes.ARGEO_REMOTE_REPOSITORY); remoteRepository.setProperty(ARGEO_URI, uri.getText()); remoteRepository.setProperty(ARGEO_USER_ID, username.getText()); nodeSession.save(); if (saveInKeyring.getSelection()) { - String pwdPath = remoteRepository.getPath() + '/' - + ARGEO_PASSWORD; + String pwdPath = remoteRepository.getPath() + '/' + ARGEO_PASSWORD; keyring.set(pwdPath, password.getText().toCharArray()); } nodeSession.save(); - MessageDialog.openInformation( - getParentShell(), - "Repository Added", - "Remote repository '" + username.getText() + "@" - + uri.getText() + "' added"); + MessageDialog.openInformation(getParentShell(), "Repository Added", + "Remote repository '" + username.getText() + "@" + uri.getText() + "' added"); super.okPressed(); } catch (Exception e) { @@ -213,8 +199,7 @@ public class AddRemoteRepository extends AbstractHandler implements } /** Creates label and check. */ - protected Button createLC(Composite parent, String label, - Boolean initial) { + 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)); @@ -224,8 +209,7 @@ public class AddRemoteRepository extends AbstractHandler implements 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 - | SWT.PASSWORD); + Text text = new Text(parent, SWT.SINGLE | SWT.LEAD | SWT.BORDER | SWT.PASSWORD); text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); return text; }