]> git.argeo.org Git - gpl/argeo-slc.git/blob - cms/org.argeo.slc.client.ui.dist/src/org/argeo/slc/client/ui/dist/commands/DisplayRepoInformation.java
38e43671b469f01cca68e1a5e6d5da7fc22adfe3
[gpl/argeo-slc.git] / cms / org.argeo.slc.client.ui.dist / src / org / argeo / slc / client / ui / dist / commands / DisplayRepoInformation.java
1 package org.argeo.slc.client.ui.dist.commands;
2
3 import javax.jcr.Repository;
4 import javax.jcr.Session;
5
6 import org.argeo.jcr.JcrUtils;
7 import org.argeo.slc.client.ui.dist.DistPlugin;
8 import org.argeo.slc.client.ui.dist.model.RepoElem;
9 import org.argeo.slc.repo.RepoService;
10 import org.eclipse.core.commands.AbstractHandler;
11 import org.eclipse.core.commands.ExecutionEvent;
12 import org.eclipse.core.commands.ExecutionException;
13 import org.eclipse.jface.dialogs.Dialog;
14 import org.eclipse.jface.dialogs.IDialogConstants;
15 import org.eclipse.jface.resource.ImageDescriptor;
16 import org.eclipse.jface.viewers.IStructuredSelection;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.graphics.Point;
19 import org.eclipse.swt.layout.GridData;
20 import org.eclipse.swt.layout.GridLayout;
21 import org.eclipse.swt.widgets.Button;
22 import org.eclipse.swt.widgets.Composite;
23 import org.eclipse.swt.widgets.Control;
24 import org.eclipse.swt.widgets.Label;
25 import org.eclipse.swt.widgets.Shell;
26 import org.eclipse.swt.widgets.Text;
27 import org.eclipse.ui.handlers.HandlerUtil;
28
29 /**
30 * Open a dialog that displays various information on the current repository.
31 */
32 public class DisplayRepoInformation extends AbstractHandler {
33 public final static String ID = DistPlugin.PLUGIN_ID + ".displayRepoInformation";
34 public final static String DEFAULT_LABEL = "Information";
35 public final static ImageDescriptor DEFAULT_ICON = DistPlugin
36 .getImageDescriptor("icons/help.gif");
37
38 /* DEPENDENCY INJECTION */
39 private RepoService repoService;
40 private Repository nodeRepository;
41
42 public Object execute(ExecutionEvent event) throws ExecutionException {
43 IStructuredSelection iss = (IStructuredSelection) HandlerUtil
44 .getActiveSite(event).getSelectionProvider().getSelection();
45 if (iss.getFirstElement() instanceof RepoElem) {
46 RepoElem re = (RepoElem) iss.getFirstElement();
47
48 Session defaultSession = null;
49 try {
50 defaultSession = repoService.getRemoteSession(re.getRepoNodePath(),
51 re.getUri(), null);
52
53 InformationDialog inputDialog = new InformationDialog(
54 HandlerUtil.getActiveSite(event).getShell());
55 inputDialog.create();
56 // TODO add more information.
57 inputDialog.loginTxt.setText(defaultSession.getUserID());
58 inputDialog.nameTxt.setText(re.getLabel());
59 inputDialog.uriTxt.setText(re.getUri());
60 inputDialog.readOnlyBtn.setSelection(re.isReadOnly());
61
62 inputDialog.open();
63 // } catch (RepositoryException e) {
64 // throw new SlcException("Unexpected error while "
65 // + "getting repository information.", e);
66 } finally {
67 JcrUtils.logoutQuietly(defaultSession);
68 }
69 }
70 return null;
71 }
72
73 private class InformationDialog extends Dialog {
74 Text nameTxt;
75 Text uriTxt;
76 Text loginTxt;
77 Button readOnlyBtn;
78
79 @Override
80 protected void createButtonsForButtonBar(Composite parent) {
81 // No Cancel button
82 createButton(parent, IDialogConstants.OK_ID, "OK", true);
83 }
84
85 public InformationDialog(Shell parentShell) {
86 super(parentShell);
87 }
88
89 protected Point getInitialSize() {
90 return new Point(500, 250);
91 }
92
93 protected Control createDialogArea(Composite parent) {
94 Composite dialogarea = (Composite) super.createDialogArea(parent);
95 dialogarea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
96 true));
97 Composite composite = new Composite(dialogarea, SWT.NONE);
98 GridLayout layout = new GridLayout(2, false);
99 layout.horizontalSpacing = 15;
100 composite.setLayout(layout);
101 GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
102 composite.setLayoutData(gd);
103
104 nameTxt = createLT(composite, "Name");
105 uriTxt = createLT(composite, "URI");
106 loginTxt = createLT(composite, "Logged as");
107 readOnlyBtn = createLC(composite, "Read only");
108 parent.pack();
109 return composite;
110 }
111
112 /** Creates label and text. */
113 protected Text createLT(Composite parent, String label) {
114 new Label(parent, SWT.RIGHT).setText(label);
115 Text text = new Text(parent, SWT.SINGLE | SWT.LEAD | SWT.NONE);
116 text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
117 text.setEditable(false);
118 return text;
119 }
120
121 /** Creates label and check. */
122 protected Button createLC(Composite parent, String label) {
123 new Label(parent, SWT.RIGHT).setText(label);
124 Button check = new Button(parent, SWT.CHECK);
125 check.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
126 check.setEnabled(false);
127 return check;
128 }
129
130 protected void configureShell(Shell shell) {
131 super.configureShell(shell);
132 shell.setText("Repository information");
133 }
134 }
135
136 /* DEPENDENCY INJECTION */
137 public void setRepoService(RepoService repoService) {
138 this.repoService = repoService;
139 }
140
141 public void setNodeRepository(Repository nodeRepository) {
142 this.nodeRepository = nodeRepository;
143 }
144
145 }