]> 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
Add anonymous perspective
[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.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;
44
45 /**
46 * Create a new empty workspace in the current repository.
47 */
48
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";
53
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(
63 iww.getShell());
64 inputDialog.create();
65 Session session = null;
66 try {
67 session = dvse.repository.login(dvse.credentials);
68 inputDialog.loginTxt.setText(session.getUserID());
69
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);
74
75 } catch (RepositoryException e) {
76 throw new SlcException("Unexpected error while "
77 + "getting repository infos.", e);
78 } finally {
79 JcrUtils.logoutQuietly(session);
80 }
81 inputDialog.open();
82 }
83 }
84 return null;
85 }
86
87 public class InformationDialog extends Dialog {
88 Text nameTxt;
89 Text uriTxt;
90 Text loginTxt;
91 Button readOnlyBtn;
92
93 @Override
94 protected void createButtonsForButtonBar(Composite parent) {
95 // No Cancel button
96 createButton(parent, IDialogConstants.OK_ID, "OK", true);
97 }
98
99 public InformationDialog(Shell parentShell) {
100 super(parentShell);
101 }
102
103 protected Point getInitialSize() {
104 return new Point(500, 250);
105 }
106
107 protected Control createDialogArea(Composite parent) {
108
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.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);
133 return text;
134 }
135
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);
142 return check;
143 }
144
145 protected void configureShell(Shell shell) {
146 super.configureShell(shell);
147 shell.setText("Repository information");
148 }
149 }
150 }