]> git.argeo.org Git - gpl/argeo-slc.git/blob - dist/commands/DisplayRepoInformation.java
Prepare next development cycle
[gpl/argeo-slc.git] / dist / commands / DisplayRepoInformation.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16 package org.argeo.slc.client.ui.dist.commands;
17
18 import javax.jcr.RepositoryException;
19 import javax.jcr.Session;
20
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;
43
44 /**
45 * Opens a popup that displays various information on the current reppository.
46 */
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");
52
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());
60 inputDialog.create();
61 Session session = null;
62 try {
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);
71 } finally {
72 JcrUtils.logoutQuietly(session);
73 }
74 inputDialog.open();
75 }
76 return null;
77 }
78
79 private class InformationDialog extends Dialog {
80 Text nameTxt;
81 Text uriTxt;
82 Text loginTxt;
83 Button readOnlyBtn;
84
85 @Override
86 protected void createButtonsForButtonBar(Composite parent) {
87 // No Cancel button
88 createButton(parent, IDialogConstants.OK_ID, "OK", true);
89 }
90
91 public InformationDialog(Shell parentShell) {
92 super(parentShell);
93 }
94
95 protected Point getInitialSize() {
96 return new Point(500, 250);
97 }
98
99 protected Control createDialogArea(Composite parent) {
100 Composite dialogarea = (Composite) super.createDialogArea(parent);
101 dialogarea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
102 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);
109
110 nameTxt = createLT(composite, "Name");
111 uriTxt = createLT(composite, "URI");
112 loginTxt = createLT(composite, "Logged as");
113 readOnlyBtn = createLC(composite, "Read only");
114 parent.pack();
115 return composite;
116 }
117
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);
124 return text;
125 }
126
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);
133 return check;
134 }
135
136 protected void configureShell(Shell shell) {
137 super.configureShell(shell);
138 shell.setText("Repository information");
139 }
140 }
141 }