2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.slc
.client
.ui
.dist
.commands
;
18 import javax
.jcr
.Repository
;
19 import javax
.jcr
.Session
;
21 import org
.argeo
.jcr
.JcrUtils
;
22 import org
.argeo
.slc
.client
.ui
.dist
.DistPlugin
;
23 import org
.argeo
.slc
.client
.ui
.dist
.model
.RepoElem
;
24 import org
.argeo
.slc
.repo
.RepoService
;
25 import org
.eclipse
.core
.commands
.AbstractHandler
;
26 import org
.eclipse
.core
.commands
.ExecutionEvent
;
27 import org
.eclipse
.core
.commands
.ExecutionException
;
28 import org
.eclipse
.jface
.dialogs
.Dialog
;
29 import org
.eclipse
.jface
.dialogs
.IDialogConstants
;
30 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
31 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
32 import org
.eclipse
.swt
.SWT
;
33 import org
.eclipse
.swt
.graphics
.Point
;
34 import org
.eclipse
.swt
.layout
.GridData
;
35 import org
.eclipse
.swt
.layout
.GridLayout
;
36 import org
.eclipse
.swt
.widgets
.Button
;
37 import org
.eclipse
.swt
.widgets
.Composite
;
38 import org
.eclipse
.swt
.widgets
.Control
;
39 import org
.eclipse
.swt
.widgets
.Label
;
40 import org
.eclipse
.swt
.widgets
.Shell
;
41 import org
.eclipse
.swt
.widgets
.Text
;
42 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
45 * Open a dialog that displays various information on the current repository.
47 public class DisplayRepoInformation
extends AbstractHandler
{
48 public final static String ID
= DistPlugin
.ID
+ ".displayRepoInformation";
49 public final static String DEFAULT_LABEL
= "Information";
50 public final static ImageDescriptor DEFAULT_ICON
= DistPlugin
51 .getImageDescriptor("icons/help.gif");
53 /* DEPENDENCY INJECTION */
54 private RepoService repoService
;
55 private Repository nodeRepository
;
57 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
58 IStructuredSelection iss
= (IStructuredSelection
) HandlerUtil
59 .getActiveSite(event
).getSelectionProvider().getSelection();
60 if (iss
.getFirstElement() instanceof RepoElem
) {
61 RepoElem re
= (RepoElem
) iss
.getFirstElement();
63 Session defaultSession
= null;
65 defaultSession
= repoService
.getRemoteSession(re
.getRepoNodePath(),
68 InformationDialog inputDialog
= new InformationDialog(
69 HandlerUtil
.getActiveSite(event
).getShell());
71 // TODO add more information.
72 inputDialog
.loginTxt
.setText(defaultSession
.getUserID());
73 inputDialog
.nameTxt
.setText(re
.getLabel());
74 inputDialog
.uriTxt
.setText(re
.getUri());
75 inputDialog
.readOnlyBtn
.setSelection(re
.isReadOnly());
78 // } catch (RepositoryException e) {
79 // throw new SlcException("Unexpected error while "
80 // + "getting repository information.", e);
82 JcrUtils
.logoutQuietly(defaultSession
);
88 private class InformationDialog
extends Dialog
{
95 protected void createButtonsForButtonBar(Composite parent
) {
97 createButton(parent
, IDialogConstants
.OK_ID
, "OK", true);
100 public InformationDialog(Shell parentShell
) {
104 protected Point
getInitialSize() {
105 return new Point(500, 250);
108 protected Control
createDialogArea(Composite parent
) {
109 Composite dialogarea
= (Composite
) super.createDialogArea(parent
);
110 dialogarea
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true,
112 Composite composite
= new Composite(dialogarea
, SWT
.NONE
);
113 GridLayout layout
= new GridLayout(2, false);
114 layout
.horizontalSpacing
= 15;
115 composite
.setLayout(layout
);
116 GridData gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false);
117 composite
.setLayoutData(gd
);
119 nameTxt
= createLT(composite
, "Name");
120 uriTxt
= createLT(composite
, "URI");
121 loginTxt
= createLT(composite
, "Logged as");
122 readOnlyBtn
= createLC(composite
, "Read only");
127 /** Creates label and text. */
128 protected Text
createLT(Composite parent
, String label
) {
129 new Label(parent
, SWT
.RIGHT
).setText(label
);
130 Text text
= new Text(parent
, SWT
.SINGLE
| SWT
.LEAD
| SWT
.NONE
);
131 text
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
132 text
.setEditable(false);
136 /** Creates label and check. */
137 protected Button
createLC(Composite parent
, String label
) {
138 new Label(parent
, SWT
.RIGHT
).setText(label
);
139 Button check
= new Button(parent
, SWT
.CHECK
);
140 check
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
141 check
.setEnabled(false);
145 protected void configureShell(Shell shell
) {
146 super.configureShell(shell
);
147 shell
.setText("Repository information");
151 /* DEPENDENCY INJECTION */
152 public void setRepoService(RepoService repoService
) {
153 this.repoService
= repoService
;
156 public void setNodeRepository(Repository nodeRepository
) {
157 this.nodeRepository
= nodeRepository
;