]> 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/commands/DisplayRepoInformation.java
git-svn-id: https://svn.argeo.org/slc/trunk@6893 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui.dist / src / main / java / org / argeo / slc / client / ui / dist / commands / DisplayRepoInformation.java
index f46b121cbe60e5a4c1d2672ea4677029475f8fbc..6ccd8d8eb3e196c6bb302a39108bc1b46cf853d5 100644 (file)
  */
 package org.argeo.slc.client.ui.dist.commands;
 
-import javax.jcr.RepositoryException;
+import javax.jcr.RepositoryFactory;
 import javax.jcr.Session;
 
 import org.argeo.jcr.JcrUtils;
-import org.argeo.slc.SlcException;
 import org.argeo.slc.client.ui.dist.DistPlugin;
 import org.argeo.slc.client.ui.dist.model.RepoElem;
+import org.argeo.slc.repo.RepoUtils;
+import org.argeo.util.security.Keyring;
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.jface.dialogs.Dialog;
 import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.graphics.Point;
@@ -41,43 +43,49 @@ import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.handlers.HandlerUtil;
 
 /**
- * Create a new empty workspace in the current repository.
+ * Open a dialog that displays various information on the current repository.
  */
-
 public class DisplayRepoInformation extends AbstractHandler {
        public final static String ID = DistPlugin.ID + ".displayRepoInformation";
-       public final static String DEFAULT_LABEL = "Repository infos...";
-       public final static String DEFAULT_ICON_PATH = "icons/help.gif";
-
+       public final static String DEFAULT_LABEL = "Information";
+       public final static ImageDescriptor DEFAULT_ICON = DistPlugin
+                       .getImageDescriptor("icons/help.gif");
+       
+       /* DEPENDENCY INJECTION */
+       private RepositoryFactory repositoryFactory;
+       private Keyring keyring;
+       
        public Object execute(ExecutionEvent event) throws ExecutionException {
-
                IStructuredSelection iss = (IStructuredSelection) HandlerUtil
                                .getActiveSite(event).getSelectionProvider().getSelection();
-
                if (iss.getFirstElement() instanceof RepoElem) {
                        RepoElem re = (RepoElem) iss.getFirstElement();
+               
+                       Session defaultSession =  null;
+                       try{
+                               defaultSession = RepoUtils.getCorrespondingSession(repositoryFactory, keyring, re.getRepoNode(), re.getUri(), null);
+                       
+                       
                        InformationDialog inputDialog = new InformationDialog(HandlerUtil
                                        .getActiveSite(event).getShell());
                        inputDialog.create();
-                       Session session = null;
-                       try {
-                               session = re.getRepository().login(re.getCredentials());
-                               inputDialog.loginTxt.setText(session.getUserID());
-                               inputDialog.nameTxt.setText(re.getLabel());
-                               inputDialog.uriTxt.setText(re.getUri());
-                               inputDialog.readOnlyBtn.setSelection(re.isReadOnly());
-                       } catch (RepositoryException e) {
-                               throw new SlcException("Unexpected error while "
-                                               + "getting repository infos.", e);
+                       inputDialog.loginTxt.setText(defaultSession.getUserID());
+                       inputDialog.nameTxt.setText(re.getLabel());
+                       inputDialog.uriTxt.setText(re.getUri());
+                       inputDialog.readOnlyBtn.setSelection(re.isReadOnly());
+               
+                       inputDialog.open();
+                               // } catch (RepositoryException e) {
+                               // throw new SlcException("Unexpected error while "
+                               // + "getting repository information.", e);
                        } finally {
-                               JcrUtils.logoutQuietly(session);
+                               JcrUtils.logoutQuietly(defaultSession);
                        }
-                       inputDialog.open();
                }
                return null;
        }
 
-       public class InformationDialog extends Dialog {
+       private class InformationDialog extends Dialog {
                Text nameTxt;
                Text uriTxt;
                Text loginTxt;
@@ -98,7 +106,6 @@ public class DisplayRepoInformation extends AbstractHandler {
                }
 
                protected Control createDialogArea(Composite parent) {
-
                        Composite dialogarea = (Composite) super.createDialogArea(parent);
                        dialogarea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
                                        true));
@@ -119,7 +126,7 @@ public class DisplayRepoInformation extends AbstractHandler {
 
                /** Creates label and text. */
                protected Text createLT(Composite parent, String label) {
-                       new Label(parent, SWT.NONE).setText(label);
+                       new Label(parent, SWT.RIGHT).setText(label);
                        Text text = new Text(parent, SWT.SINGLE | SWT.LEAD | SWT.NONE);
                        text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
                        text.setEditable(false);
@@ -128,7 +135,7 @@ public class DisplayRepoInformation extends AbstractHandler {
 
                /** Creates label and check. */
                protected Button createLC(Composite parent, String label) {
-                       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.setEnabled(false);
@@ -140,4 +147,14 @@ public class DisplayRepoInformation extends AbstractHandler {
                        shell.setText("Repository information");
                }
        }
+       
+       /* DEPENDENCY INJECTION */
+       public void setRepositoryFactory(RepositoryFactory repositoryFactory) {
+               this.repositoryFactory = repositoryFactory;
+       }
+
+       public void setKeyring(Keyring keyring) {
+               this.keyring = keyring;
+       }
+       
 }
\ No newline at end of file