]> git.argeo.org Git - gpl/argeo-slc.git/blob - plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/DisplayRepoInformation.java
a5b7f14885782900b6a4760ba2c062a5d98ba42c
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui.dist / src / main / java / org / argeo / slc / client / ui / 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 * Create a new empty workspace in the current repository.
46 */
47
48 public class DisplayRepoInformation extends AbstractHandler {
49 public final static String ID = DistPlugin.ID + ".displayRepoInformation";
50 public final static String DEFAULT_LABEL = "Repository infos...";
51 public final static ImageDescriptor DEFAULT_ICON = DistPlugin
52 .getImageDescriptor("icons/help.gif");
53
54 // public final static String DEFAULT_ICON_PATH = "icons/help.gif";
55
56 public Object execute(ExecutionEvent event) throws ExecutionException {
57
58 IStructuredSelection iss = (IStructuredSelection) HandlerUtil
59 .getActiveSite(event).getSelectionProvider().getSelection();
60
61 if (iss.getFirstElement() instanceof RepoElem) {
62 RepoElem re = (RepoElem) iss.getFirstElement();
63 InformationDialog inputDialog = new InformationDialog(HandlerUtil
64 .getActiveSite(event).getShell());
65 inputDialog.create();
66 Session session = null;
67 try {
68 session = re.getRepository().login(re.getCredentials());
69 inputDialog.loginTxt.setText(session.getUserID());
70 inputDialog.nameTxt.setText(re.getLabel());
71 inputDialog.uriTxt.setText(re.getUri());
72 inputDialog.readOnlyBtn.setSelection(re.isReadOnly());
73 } catch (RepositoryException e) {
74 throw new SlcException("Unexpected error while "
75 + "getting repository infos.", e);
76 } finally {
77 JcrUtils.logoutQuietly(session);
78 }
79 inputDialog.open();
80 }
81 return null;
82 }
83
84 public class InformationDialog extends Dialog {
85 Text nameTxt;
86 Text uriTxt;
87 Text loginTxt;
88 Button readOnlyBtn;
89
90 @Override
91 protected void createButtonsForButtonBar(Composite parent) {
92 // No Cancel button
93 createButton(parent, IDialogConstants.OK_ID, "OK", true);
94 }
95
96 public InformationDialog(Shell parentShell) {
97 super(parentShell);
98 }
99
100 protected Point getInitialSize() {
101 return new Point(500, 250);
102 }
103
104 protected Control createDialogArea(Composite parent) {
105
106 Composite dialogarea = (Composite) super.createDialogArea(parent);
107 dialogarea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
108 true));
109 Composite composite = new Composite(dialogarea, SWT.NONE);
110 GridLayout layout = new GridLayout(2, false);
111 layout.horizontalSpacing = 15;
112 composite.setLayout(layout);
113 GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
114 composite.setLayoutData(gd);
115
116 nameTxt = createLT(composite, "Name");
117 uriTxt = createLT(composite, "URI");
118 loginTxt = createLT(composite, "Logged as");
119 readOnlyBtn = createLC(composite, "Read only");
120 parent.pack();
121 return composite;
122 }
123
124 /** Creates label and text. */
125 protected Text createLT(Composite parent, String label) {
126 new Label(parent, SWT.NONE).setText(label);
127 Text text = new Text(parent, SWT.SINGLE | SWT.LEAD | SWT.NONE);
128 text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
129 text.setEditable(false);
130 return text;
131 }
132
133 /** Creates label and check. */
134 protected Button createLC(Composite parent, String label) {
135 new Label(parent, SWT.NONE).setText(label);
136 Button check = new Button(parent, SWT.CHECK);
137 check.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
138 check.setEnabled(false);
139 return check;
140 }
141
142 protected void configureShell(Shell shell) {
143 super.configureShell(shell);
144 shell.setText("Repository information");
145 }
146 }
147 }