1 package org
.argeo
.slc
.client
.ui
.dist
.commands
;
3 import javax
.jcr
.Repository
;
4 import javax
.jcr
.Session
;
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
;
30 * Open a dialog that displays various information on the current repository.
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");
38 /* DEPENDENCY INJECTION */
39 private RepoService repoService
;
40 private Repository nodeRepository
;
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();
48 Session defaultSession
= null;
50 defaultSession
= repoService
.getRemoteSession(re
.getRepoNodePath(),
53 InformationDialog inputDialog
= new InformationDialog(
54 HandlerUtil
.getActiveSite(event
).getShell());
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());
63 // } catch (RepositoryException e) {
64 // throw new SlcException("Unexpected error while "
65 // + "getting repository information.", e);
67 JcrUtils
.logoutQuietly(defaultSession
);
73 private class InformationDialog
extends Dialog
{
80 protected void createButtonsForButtonBar(Composite parent
) {
82 createButton(parent
, IDialogConstants
.OK_ID
, "OK", true);
85 public InformationDialog(Shell parentShell
) {
89 protected Point
getInitialSize() {
90 return new Point(500, 250);
93 protected Control
createDialogArea(Composite parent
) {
94 Composite dialogarea
= (Composite
) super.createDialogArea(parent
);
95 dialogarea
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, 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
);
104 nameTxt
= createLT(composite
, "Name");
105 uriTxt
= createLT(composite
, "URI");
106 loginTxt
= createLT(composite
, "Logged as");
107 readOnlyBtn
= createLC(composite
, "Read only");
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);
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);
130 protected void configureShell(Shell shell
) {
131 super.configureShell(shell
);
132 shell
.setText("Repository information");
136 /* DEPENDENCY INJECTION */
137 public void setRepoService(RepoService repoService
) {
138 this.repoService
= repoService
;
141 public void setNodeRepository(Repository nodeRepository
) {
142 this.nodeRepository
= nodeRepository
;