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
.ArgeoNames
;
22 import org
.argeo
.jcr
.JcrUtils
;
23 import org
.argeo
.slc
.SlcException
;
24 import org
.argeo
.slc
.client
.ui
.dist
.DistPlugin
;
25 import org
.argeo
.slc
.client
.ui
.dist
.views
.DistributionsView
;
26 import org
.argeo
.slc
.client
.ui
.dist
.views
.DistributionsView
.DistributionViewSelectedElement
;
27 import org
.eclipse
.core
.commands
.AbstractHandler
;
28 import org
.eclipse
.core
.commands
.ExecutionEvent
;
29 import org
.eclipse
.core
.commands
.ExecutionException
;
30 import org
.eclipse
.jface
.dialogs
.Dialog
;
31 import org
.eclipse
.jface
.dialogs
.IDialogConstants
;
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
.IWorkbenchPart
;
43 import org
.eclipse
.ui
.IWorkbenchWindow
;
46 * Create a new empty workspace in the current repository.
49 public class DisplayRepoInformation
extends AbstractHandler
{
50 public final static String ID
= DistPlugin
.ID
+ ".displayRepoInformation";
51 public final static String DEFAULT_LABEL
= "Repository infos...";
52 public final static String DEFAULT_ICON_PATH
= "icons/help.gif";
54 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
55 IWorkbenchWindow iww
= DistPlugin
.getDefault().getWorkbench()
56 .getActiveWorkbenchWindow();
57 IWorkbenchPart view
= iww
.getActivePage().getActivePart();
58 if (view
instanceof DistributionsView
) {
59 DistributionViewSelectedElement dvse
= ((DistributionsView
) view
)
60 .getSelectedElement();
61 if (dvse
!= null && (dvse
.isRepository
)) {
62 InformationDialog inputDialog
= new InformationDialog(
65 Session session
= null;
67 session
= dvse
.repository
.login(dvse
.credentials
);
68 inputDialog
.loginTxt
.setText(session
.getUserID());
70 inputDialog
.nameTxt
.setText(dvse
.repoNode
.getName());
71 inputDialog
.uriTxt
.setText(JcrUtils
.get(dvse
.repoNode
,
72 ArgeoNames
.ARGEO_URI
));
73 inputDialog
.readOnlyBtn
.setSelection(dvse
.isReadOnly
);
75 } catch (RepositoryException e
) {
76 throw new SlcException("Unexpected error while "
77 + "getting repository infos.", e
);
79 JcrUtils
.logoutQuietly(session
);
87 public class InformationDialog
extends Dialog
{
94 protected void createButtonsForButtonBar(Composite parent
) {
96 createButton(parent
, IDialogConstants
.OK_ID
, "OK", true);
99 public InformationDialog(Shell parentShell
) {
103 protected Point
getInitialSize() {
104 return new Point(500, 250);
107 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
.NONE
).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
.NONE
).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");