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
.viewers
.IStructuredSelection
;
31 import org
.eclipse
.swt
.SWT
;
32 import org
.eclipse
.swt
.graphics
.Point
;
33 import org
.eclipse
.swt
.layout
.GridData
;
34 import org
.eclipse
.swt
.layout
.GridLayout
;
35 import org
.eclipse
.swt
.widgets
.Button
;
36 import org
.eclipse
.swt
.widgets
.Composite
;
37 import org
.eclipse
.swt
.widgets
.Control
;
38 import org
.eclipse
.swt
.widgets
.Label
;
39 import org
.eclipse
.swt
.widgets
.Shell
;
40 import org
.eclipse
.swt
.widgets
.Text
;
41 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
44 * Create a new empty workspace in 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
= "Repository infos...";
50 public final static String DEFAULT_ICON_PATH
= "icons/help.gif";
52 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
54 IStructuredSelection iss
= (IStructuredSelection
) HandlerUtil
55 .getActiveSite(event
).getSelectionProvider().getSelection();
57 if (iss
.getFirstElement() instanceof RepoElem
) {
58 RepoElem re
= (RepoElem
) iss
.getFirstElement();
59 InformationDialog inputDialog
= new InformationDialog(HandlerUtil
60 .getActiveSite(event
).getShell());
62 Session session
= null;
64 session
= re
.getRepository().login(re
.getCredentials());
65 inputDialog
.loginTxt
.setText(session
.getUserID());
66 inputDialog
.nameTxt
.setText(re
.getLabel());
67 inputDialog
.uriTxt
.setText(re
.getUri());
68 inputDialog
.readOnlyBtn
.setSelection(re
.isReadOnly());
69 } catch (RepositoryException e
) {
70 throw new SlcException("Unexpected error while "
71 + "getting repository infos.", e
);
73 JcrUtils
.logoutQuietly(session
);
80 public class InformationDialog
extends Dialog
{
87 protected void createButtonsForButtonBar(Composite parent
) {
89 createButton(parent
, IDialogConstants
.OK_ID
, "OK", true);
92 public InformationDialog(Shell parentShell
) {
96 protected Point
getInitialSize() {
97 return new Point(500, 250);
100 protected Control
createDialogArea(Composite parent
) {
102 Composite dialogarea
= (Composite
) super.createDialogArea(parent
);
103 dialogarea
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true,
105 Composite composite
= new Composite(dialogarea
, SWT
.NONE
);
106 GridLayout layout
= new GridLayout(2, false);
107 layout
.horizontalSpacing
= 15;
108 composite
.setLayout(layout
);
109 GridData gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, false);
110 composite
.setLayoutData(gd
);
112 nameTxt
= createLT(composite
, "Name");
113 uriTxt
= createLT(composite
, "URI");
114 loginTxt
= createLT(composite
, "Logged as");
115 readOnlyBtn
= createLC(composite
, "Read only");
120 /** Creates label and text. */
121 protected Text
createLT(Composite parent
, String label
) {
122 new Label(parent
, SWT
.NONE
).setText(label
);
123 Text text
= new Text(parent
, SWT
.SINGLE
| SWT
.LEAD
| SWT
.NONE
);
124 text
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
125 text
.setEditable(false);
129 /** Creates label and check. */
130 protected Button
createLC(Composite parent
, String label
) {
131 new Label(parent
, SWT
.NONE
).setText(label
);
132 Button check
= new Button(parent
, SWT
.CHECK
);
133 check
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
134 check
.setEnabled(false);
138 protected void configureShell(Shell shell
) {
139 super.configureShell(shell
);
140 shell
.setText("Repository information");