]> git.argeo.org Git - gpl/argeo-slc.git/blob - DisplayRepoInformation.java
7bc06084feaf6071e64a62fc5376b3490020679d
[gpl/argeo-slc.git] / 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,
97 IDialogConstants.OK_LABEL, 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
110 Composite dialogarea = (Composite) super.createDialogArea(parent);
111 dialogarea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
112 true));
113 Composite composite = new Composite(dialogarea, SWT.NONE);
114 GridLayout layout = new GridLayout(2, false);
115 layout.horizontalSpacing = 15;
116 composite.setLayout(layout);
117 GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
118 composite.setLayoutData(gd);
119
120 nameTxt = createLT(composite, "Name");
121 uriTxt = createLT(composite, "URI");
122 loginTxt = createLT(composite, "Logged as");
123 readOnlyBtn = createLC(composite, "Read only");
124 parent.pack();
125 return composite;
126 }
127
128 /** Creates label and text. */
129 protected Text createLT(Composite parent, String label) {
130 new Label(parent, SWT.NONE).setText(label);
131 Text text = new Text(parent, SWT.SINGLE | SWT.LEAD | SWT.NONE);
132 text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
133 text.setEditable(false);
134 return text;
135 }
136
137 /** Creates label and check. */
138 protected Button createLC(Composite parent, String label) {
139 new Label(parent, SWT.NONE).setText(label);
140 Button check = new Button(parent, SWT.CHECK);
141 check.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
142 check.setEnabled(false);
143 return check;
144 }
145
146 protected void configureShell(Shell shell) {
147 super.configureShell(shell);
148 shell.setText("Repository information");
149 }
150 }
151 }