]> 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
fix grouping issue for workspaces that have the same prefix.
[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.RepositoryFactory;
19 import javax.jcr.Session;
20
21 import org.argeo.jcr.JcrUtils;
22 import org.argeo.slc.client.ui.dist.DistPlugin;
23 import org.argeo.slc.client.ui.dist.model.RepoElem;
24 import org.argeo.slc.repo.RepoUtils;
25 import org.argeo.util.security.Keyring;
26 import org.eclipse.core.commands.AbstractHandler;
27 import org.eclipse.core.commands.ExecutionEvent;
28 import org.eclipse.core.commands.ExecutionException;
29 import org.eclipse.jface.dialogs.Dialog;
30 import org.eclipse.jface.dialogs.IDialogConstants;
31 import org.eclipse.jface.resource.ImageDescriptor;
32 import org.eclipse.jface.viewers.IStructuredSelection;
33 import org.eclipse.swt.SWT;
34 import org.eclipse.swt.graphics.Point;
35 import org.eclipse.swt.layout.GridData;
36 import org.eclipse.swt.layout.GridLayout;
37 import org.eclipse.swt.widgets.Button;
38 import org.eclipse.swt.widgets.Composite;
39 import org.eclipse.swt.widgets.Control;
40 import org.eclipse.swt.widgets.Label;
41 import org.eclipse.swt.widgets.Shell;
42 import org.eclipse.swt.widgets.Text;
43 import org.eclipse.ui.handlers.HandlerUtil;
44
45 /**
46 * Open a dialog that displays various information on the current repository.
47 */
48 public class DisplayRepoInformation extends AbstractHandler {
49 public final static String ID = DistPlugin.ID + ".displayRepoInformation";
50 public final static String DEFAULT_LABEL = "Information";
51 public final static ImageDescriptor DEFAULT_ICON = DistPlugin
52 .getImageDescriptor("icons/help.gif");
53
54 /* DEPENDENCY INJECTION */
55 private RepositoryFactory repositoryFactory;
56 private Keyring keyring;
57
58 public Object execute(ExecutionEvent event) throws ExecutionException {
59 IStructuredSelection iss = (IStructuredSelection) HandlerUtil
60 .getActiveSite(event).getSelectionProvider().getSelection();
61 if (iss.getFirstElement() instanceof RepoElem) {
62 RepoElem re = (RepoElem) iss.getFirstElement();
63
64 Session defaultSession = null;
65 try{
66 defaultSession = RepoUtils.getCorrespondingSession(repositoryFactory, keyring, re.getRepoNode(), re.getUri(), null);
67
68
69 InformationDialog inputDialog = new InformationDialog(HandlerUtil
70 .getActiveSite(event).getShell());
71 inputDialog.create();
72 inputDialog.loginTxt.setText(defaultSession.getUserID());
73 inputDialog.nameTxt.setText(re.getLabel());
74 inputDialog.uriTxt.setText(re.getUri());
75 inputDialog.readOnlyBtn.setSelection(re.isReadOnly());
76
77 inputDialog.open();
78 // } catch (RepositoryException e) {
79 // throw new SlcException("Unexpected error while "
80 // + "getting repository information.", e);
81 } finally {
82 JcrUtils.logoutQuietly(defaultSession);
83 }
84 }
85 return null;
86 }
87
88 private class InformationDialog extends Dialog {
89 Text nameTxt;
90 Text uriTxt;
91 Text loginTxt;
92 Button readOnlyBtn;
93
94 @Override
95 protected void createButtonsForButtonBar(Composite parent) {
96 // No Cancel button
97 createButton(parent, IDialogConstants.OK_ID, "OK", true);
98 }
99
100 public InformationDialog(Shell parentShell) {
101 super(parentShell);
102 }
103
104 protected Point getInitialSize() {
105 return new Point(500, 250);
106 }
107
108 protected Control createDialogArea(Composite parent) {
109 Composite dialogarea = (Composite) super.createDialogArea(parent);
110 dialogarea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
111 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);
118
119 nameTxt = createLT(composite, "Name");
120 uriTxt = createLT(composite, "URI");
121 loginTxt = createLT(composite, "Logged as");
122 readOnlyBtn = createLC(composite, "Read only");
123 parent.pack();
124 return composite;
125 }
126
127 /** Creates label and text. */
128 protected Text createLT(Composite parent, String label) {
129 new Label(parent, SWT.RIGHT).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);
133 return text;
134 }
135
136 /** Creates label and check. */
137 protected Button createLC(Composite parent, String label) {
138 new Label(parent, SWT.RIGHT).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);
142 return check;
143 }
144
145 protected void configureShell(Shell shell) {
146 super.configureShell(shell);
147 shell.setText("Repository information");
148 }
149 }
150
151 /* DEPENDENCY INJECTION */
152 public void setRepositoryFactory(RepositoryFactory repositoryFactory) {
153 this.repositoryFactory = repositoryFactory;
154 }
155
156 public void setKeyring(Keyring keyring) {
157 this.keyring = keyring;
158 }
159
160 }