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
.RepositoryException
;
19 import javax
.jcr
.Session
;
21 import org
.argeo
.jcr
.JcrUtils
;
22 import org
.argeo
.slc
.SlcException
;
23 import org
.argeo
.slc
.client
.ui
.dist
.DistPlugin
;
24 import org
.argeo
.slc
.client
.ui
.dist
.model
.RepoElem
;
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 * Opens a popup that displays various information on the current reppository.
47 public class DisplayRepoInformation
extends AbstractHandler
{
48 public final static String ID
= DistPlugin
.ID
+ ".displayRepoInformation";
49 public final static String DEFAULT_LABEL
= "Repository infos";
50 public final static ImageDescriptor DEFAULT_ICON
= DistPlugin
51 .getImageDescriptor("icons/help.gif");
53 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
54 IStructuredSelection iss
= (IStructuredSelection
) HandlerUtil
55 .getActiveSite(event
).getSelectionProvider().getSelection();
56 if (iss
.getFirstElement() instanceof RepoElem
) {
57 RepoElem re
= (RepoElem
) iss
.getFirstElement();
58 InformationDialog inputDialog
= new InformationDialog(HandlerUtil
59 .getActiveSite(event
).getShell());
61 Session session
= null;
63 session
= re
.getRepository().login(re
.getCredentials());
64 inputDialog
.loginTxt
.setText(session
.getUserID());
65 inputDialog
.nameTxt
.setText(re
.getLabel());
66 inputDialog
.uriTxt
.setText(re
.getUri());
67 inputDialog
.readOnlyBtn
.setSelection(re
.isReadOnly());
68 } catch (RepositoryException e
) {
69 throw new SlcException("Unexpected error while "
70 + "getting repository information.", e
);
72 JcrUtils
.logoutQuietly(session
);
79 private class InformationDialog
extends Dialog
{
86 protected void createButtonsForButtonBar(Composite parent
) {
88 createButton(parent
, IDialogConstants
.OK_ID
, "OK", true);
91 public InformationDialog(Shell parentShell
) {
95 protected Point
getInitialSize() {
96 return new Point(500, 250);
99 protected Control
createDialogArea(Composite parent
) {
100 Composite dialogarea
= (Composite
) super.createDialogArea(parent
);
101 dialogarea
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true,
103 Composite composite
= new Composite(dialogarea
, SWT
.NONE
);
104 GridLayout layout
= new GridLayout(2, false);
105 layout
.horizontalSpacing
= 15;
106 composite
.setLayout(layout
);
107 GridData gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false);
108 composite
.setLayoutData(gd
);
110 nameTxt
= createLT(composite
, "Name");
111 uriTxt
= createLT(composite
, "URI");
112 loginTxt
= createLT(composite
, "Logged as");
113 readOnlyBtn
= createLC(composite
, "Read only");
118 /** Creates label and text. */
119 protected Text
createLT(Composite parent
, String label
) {
120 new Label(parent
, SWT
.NONE
).setText(label
);
121 Text text
= new Text(parent
, SWT
.SINGLE
| SWT
.LEAD
| SWT
.NONE
);
122 text
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
123 text
.setEditable(false);
127 /** Creates label and check. */
128 protected Button
createLC(Composite parent
, String label
) {
129 new Label(parent
, SWT
.NONE
).setText(label
);
130 Button check
= new Button(parent
, SWT
.CHECK
);
131 check
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
132 check
.setEnabled(false);
136 protected void configureShell(Shell shell
) {
137 super.configureShell(shell
);
138 shell
.setText("Repository information");