commit | author | age
|
da0269
|
1 |
/*
|
JM |
2 |
* Copyright 2011 gitblit.com.
|
|
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 com.gitblit.client;
|
|
17 |
|
|
18 |
import java.awt.BorderLayout;
|
b7f591
|
19 |
import java.awt.Component;
|
da0269
|
20 |
import java.awt.Dimension;
|
JM |
21 |
import java.awt.FlowLayout;
|
|
22 |
import java.awt.Font;
|
|
23 |
import java.awt.GridLayout;
|
|
24 |
import java.awt.Insets;
|
|
25 |
import java.awt.event.ActionEvent;
|
|
26 |
import java.awt.event.ActionListener;
|
f14f76
|
27 |
import java.awt.event.KeyEvent;
|
bcc616
|
28 |
import java.text.MessageFormat;
|
JM |
29 |
import java.util.ArrayList;
|
|
30 |
import java.util.Arrays;
|
|
31 |
import java.util.HashSet;
|
a5b159
|
32 |
import java.util.LinkedHashMap;
|
da0269
|
33 |
import java.util.List;
|
a5b159
|
34 |
import java.util.Map;
|
bcc616
|
35 |
import java.util.Set;
|
da0269
|
36 |
|
022ebb
|
37 |
import javax.swing.BoxLayout;
|
6adf56
|
38 |
import javax.swing.ButtonGroup;
|
bcc616
|
39 |
import javax.swing.DefaultComboBoxModel;
|
da0269
|
40 |
import javax.swing.ImageIcon;
|
JM |
41 |
import javax.swing.JButton;
|
|
42 |
import javax.swing.JCheckBox;
|
|
43 |
import javax.swing.JComboBox;
|
|
44 |
import javax.swing.JComponent;
|
|
45 |
import javax.swing.JDialog;
|
|
46 |
import javax.swing.JLabel;
|
b7f591
|
47 |
import javax.swing.JList;
|
da0269
|
48 |
import javax.swing.JOptionPane;
|
JM |
49 |
import javax.swing.JPanel;
|
6adf56
|
50 |
import javax.swing.JRadioButton;
|
f14f76
|
51 |
import javax.swing.JRootPane;
|
0e6eac
|
52 |
import javax.swing.JScrollPane;
|
55a46b
|
53 |
import javax.swing.JTabbedPane;
|
da0269
|
54 |
import javax.swing.JTextField;
|
f14f76
|
55 |
import javax.swing.KeyStroke;
|
b7f591
|
56 |
import javax.swing.ListCellRenderer;
|
0e6eac
|
57 |
import javax.swing.ScrollPaneConstants;
|
da0269
|
58 |
|
JM |
59 |
import com.gitblit.Constants.AccessRestrictionType;
|
6adf56
|
60 |
import com.gitblit.Constants.AuthorizationControl;
|
da0269
|
61 |
import com.gitblit.Constants.FederationStrategy;
|
822dfe
|
62 |
import com.gitblit.models.RegistrantAccessPermission;
|
da0269
|
63 |
import com.gitblit.models.RepositoryModel;
|
0db5c4
|
64 |
import com.gitblit.utils.ArrayUtils;
|
da0269
|
65 |
import com.gitblit.utils.StringUtils;
|
JM |
66 |
|
b7f591
|
67 |
/**
|
JM |
68 |
* Dialog to create/edit a repository.
|
|
69 |
*
|
|
70 |
* @author James Moger
|
|
71 |
*/
|
da0269
|
72 |
public class EditRepositoryDialog extends JDialog {
|
JM |
73 |
|
|
74 |
private static final long serialVersionUID = 1L;
|
|
75 |
|
16038c
|
76 |
private final String repositoryName;
|
JM |
77 |
|
da0269
|
78 |
private final RepositoryModel repository;
|
bcc616
|
79 |
|
JM |
80 |
private boolean isCreate;
|
da0269
|
81 |
|
JM |
82 |
private boolean canceled = true;
|
|
83 |
|
|
84 |
private JTextField nameField;
|
|
85 |
|
|
86 |
private JTextField descriptionField;
|
|
87 |
|
|
88 |
private JCheckBox useTickets;
|
|
89 |
|
|
90 |
private JCheckBox useDocs;
|
|
91 |
|
|
92 |
private JCheckBox showRemoteBranches;
|
|
93 |
|
|
94 |
private JCheckBox showReadme;
|
|
95 |
|
3d293a
|
96 |
private JCheckBox skipSizeCalculation;
|
JM |
97 |
|
fe3262
|
98 |
private JCheckBox skipSummaryMetrics;
|
JM |
99 |
|
da0269
|
100 |
private JCheckBox isFrozen;
|
4bd203
|
101 |
|
eb96ea
|
102 |
private JTextField mailingListsField;
|
da0269
|
103 |
|
JM |
104 |
private JComboBox accessRestriction;
|
6adf56
|
105 |
|
JM |
106 |
private JRadioButton allowAuthenticated;
|
|
107 |
|
|
108 |
private JRadioButton allowNamed;
|
a03ece
|
109 |
|
JM |
110 |
private JCheckBox allowForks;
|
da0269
|
111 |
|
476269
|
112 |
private JCheckBox verifyCommitter;
|
JM |
113 |
|
da0269
|
114 |
private JComboBox federationStrategy;
|
JM |
115 |
|
bcc616
|
116 |
private JComboBox ownerField;
|
da0269
|
117 |
|
90b8d7
|
118 |
private JComboBox headRefField;
|
df0292
|
119 |
|
822dfe
|
120 |
private RegistrantPermissionsPanel usersPalette;
|
4bd203
|
121 |
|
da0269
|
122 |
private JPalette<String> setsPalette;
|
4bd203
|
123 |
|
822dfe
|
124 |
private RegistrantPermissionsPanel teamsPalette;
|
e9de3f
|
125 |
|
JM |
126 |
private JPalette<String> indexedBranchesPalette;
|
4bd203
|
127 |
|
JM |
128 |
private JPalette<String> preReceivePalette;
|
0db5c4
|
129 |
|
f2dff4
|
130 |
private JLabel preReceiveInherited;
|
4bd203
|
131 |
|
JM |
132 |
private JPalette<String> postReceivePalette;
|
0db5c4
|
133 |
|
f2dff4
|
134 |
private JLabel postReceiveInherited;
|
da0269
|
135 |
|
bcc616
|
136 |
private Set<String> repositoryNames;
|
0e6eac
|
137 |
|
JC |
138 |
private JPanel customFieldsPanel;
|
a5b159
|
139 |
|
JM |
140 |
private List<JTextField> customTextfields;
|
bcc616
|
141 |
|
f08aab
|
142 |
public EditRepositoryDialog(int protocolVersion) {
|
JM |
143 |
this(protocolVersion, new RepositoryModel());
|
bcc616
|
144 |
this.isCreate = true;
|
b7f591
|
145 |
setTitle(Translation.get("gb.newRepository"));
|
da0269
|
146 |
}
|
JM |
147 |
|
f08aab
|
148 |
public EditRepositoryDialog(int protocolVersion, RepositoryModel aRepository) {
|
da0269
|
149 |
super();
|
16038c
|
150 |
this.repositoryName = aRepository.name;
|
da0269
|
151 |
this.repository = new RepositoryModel();
|
bcc616
|
152 |
this.repositoryNames = new HashSet<String>();
|
JM |
153 |
this.isCreate = false;
|
f08aab
|
154 |
initialize(protocolVersion, aRepository);
|
da0269
|
155 |
setModal(true);
|
55a46b
|
156 |
setResizable(false);
|
b7f591
|
157 |
setTitle(Translation.get("gb.edit") + ": " + aRepository.name);
|
df0292
|
158 |
setIconImage(new ImageIcon(getClass()
|
JM |
159 |
.getResource("/gitblt-favicon.png")).getImage());
|
f14f76
|
160 |
}
|
16038c
|
161 |
|
f14f76
|
162 |
@Override
|
JM |
163 |
protected JRootPane createRootPane() {
|
|
164 |
KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
|
|
165 |
JRootPane rootPane = new JRootPane();
|
|
166 |
rootPane.registerKeyboardAction(new ActionListener() {
|
|
167 |
public void actionPerformed(ActionEvent actionEvent) {
|
|
168 |
setVisible(false);
|
|
169 |
}
|
|
170 |
}, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
|
|
171 |
return rootPane;
|
da0269
|
172 |
}
|
JM |
173 |
|
f08aab
|
174 |
private void initialize(int protocolVersion, RepositoryModel anRepository) {
|
df0292
|
175 |
nameField = new JTextField(anRepository.name == null ? ""
|
JM |
176 |
: anRepository.name, 35);
|
da0269
|
177 |
descriptionField = new JTextField(anRepository.description == null ? ""
|
JM |
178 |
: anRepository.description, 35);
|
55a46b
|
179 |
|
df0292
|
180 |
JTextField originField = new JTextField(
|
JM |
181 |
anRepository.origin == null ? "" : anRepository.origin, 40);
|
55a46b
|
182 |
originField.setEditable(false);
|
df0292
|
183 |
|
90b8d7
|
184 |
if (ArrayUtils.isEmpty(anRepository.availableRefs)) {
|
JM |
185 |
headRefField = new JComboBox();
|
|
186 |
headRefField.setEnabled(false);
|
df0292
|
187 |
} else {
|
90b8d7
|
188 |
headRefField = new JComboBox(
|
JM |
189 |
anRepository.availableRefs.toArray());
|
|
190 |
headRefField.setSelectedItem(anRepository.HEAD);
|
df0292
|
191 |
}
|
da0269
|
192 |
|
bcc616
|
193 |
ownerField = new JComboBox();
|
da0269
|
194 |
|
b7f591
|
195 |
useTickets = new JCheckBox(Translation.get("gb.useTicketsDescription"),
|
JM |
196 |
anRepository.useTickets);
|
df0292
|
197 |
useDocs = new JCheckBox(Translation.get("gb.useDocsDescription"),
|
JM |
198 |
anRepository.useDocs);
|
|
199 |
showRemoteBranches = new JCheckBox(
|
|
200 |
Translation.get("gb.showRemoteBranchesDescription"),
|
b7f591
|
201 |
anRepository.showRemoteBranches);
|
JM |
202 |
showReadme = new JCheckBox(Translation.get("gb.showReadmeDescription"),
|
da0269
|
203 |
anRepository.showReadme);
|
df0292
|
204 |
skipSizeCalculation = new JCheckBox(
|
JM |
205 |
Translation.get("gb.skipSizeCalculationDescription"),
|
3d293a
|
206 |
anRepository.skipSizeCalculation);
|
df0292
|
207 |
skipSummaryMetrics = new JCheckBox(
|
JM |
208 |
Translation.get("gb.skipSummaryMetricsDescription"),
|
fe3262
|
209 |
anRepository.skipSummaryMetrics);
|
df0292
|
210 |
isFrozen = new JCheckBox(Translation.get("gb.isFrozenDescription"),
|
JM |
211 |
anRepository.isFrozen);
|
da0269
|
212 |
|
df0292
|
213 |
mailingListsField = new JTextField(
|
JM |
214 |
ArrayUtils.isEmpty(anRepository.mailingLists) ? ""
|
|
215 |
: StringUtils.flattenStrings(anRepository.mailingLists,
|
|
216 |
" "), 50);
|
4bd203
|
217 |
|
da0269
|
218 |
accessRestriction = new JComboBox(AccessRestrictionType.values());
|
b7f591
|
219 |
accessRestriction.setRenderer(new AccessRestrictionRenderer());
|
da0269
|
220 |
accessRestriction.setSelectedItem(anRepository.accessRestriction);
|
6adf56
|
221 |
|
JM |
222 |
boolean authenticated = anRepository.authorizationControl != null
|
|
223 |
&& AuthorizationControl.AUTHENTICATED.equals(anRepository.authorizationControl);
|
|
224 |
allowAuthenticated = new JRadioButton(Translation.get("gb.allowAuthenticatedDescription"));
|
|
225 |
allowAuthenticated.setSelected(authenticated);
|
|
226 |
allowNamed = new JRadioButton(Translation.get("gb.allowNamedDescription"));
|
|
227 |
allowNamed.setSelected(!authenticated);
|
|
228 |
|
|
229 |
ButtonGroup group = new ButtonGroup();
|
|
230 |
group.add(allowAuthenticated);
|
|
231 |
group.add(allowNamed);
|
|
232 |
|
|
233 |
JPanel authorizationPanel = new JPanel(new GridLayout(0, 1));
|
|
234 |
authorizationPanel.add(allowAuthenticated);
|
|
235 |
authorizationPanel.add(allowNamed);
|
a03ece
|
236 |
|
476269
|
237 |
allowForks = new JCheckBox(Translation.get("gb.allowForksDescription"), anRepository.allowForks);
|
JM |
238 |
verifyCommitter = new JCheckBox(Translation.get("gb.verifyCommitterDescription"), anRepository.verifyCommitter);
|
da0269
|
239 |
|
bcc616
|
240 |
// federation strategies - remove ORIGIN choice if this repository has
|
JM |
241 |
// no origin.
|
|
242 |
List<FederationStrategy> federationStrategies = new ArrayList<FederationStrategy>(
|
|
243 |
Arrays.asList(FederationStrategy.values()));
|
|
244 |
if (StringUtils.isEmpty(anRepository.origin)) {
|
|
245 |
federationStrategies.remove(FederationStrategy.FEDERATE_ORIGIN);
|
|
246 |
}
|
|
247 |
federationStrategy = new JComboBox(federationStrategies.toArray());
|
b7f591
|
248 |
federationStrategy.setRenderer(new FederationStrategyRenderer());
|
da0269
|
249 |
federationStrategy.setSelectedItem(anRepository.federationStrategy);
|
JM |
250 |
|
|
251 |
JPanel fieldsPanel = new JPanel(new GridLayout(0, 1));
|
b7f591
|
252 |
fieldsPanel.add(newFieldPanel(Translation.get("gb.name"), nameField));
|
df0292
|
253 |
fieldsPanel.add(newFieldPanel(Translation.get("gb.description"),
|
JM |
254 |
descriptionField));
|
|
255 |
fieldsPanel
|
|
256 |
.add(newFieldPanel(Translation.get("gb.origin"), originField));
|
aebae0
|
257 |
fieldsPanel.add(newFieldPanel(Translation.get("gb.headRef"), headRefField));
|
bcc616
|
258 |
fieldsPanel.add(newFieldPanel(Translation.get("gb.owner"), ownerField));
|
da0269
|
259 |
|
df0292
|
260 |
fieldsPanel.add(newFieldPanel(Translation.get("gb.enableTickets"),
|
JM |
261 |
useTickets));
|
b7f591
|
262 |
fieldsPanel
|
df0292
|
263 |
.add(newFieldPanel(Translation.get("gb.enableDocs"), useDocs));
|
JM |
264 |
fieldsPanel.add(newFieldPanel(Translation.get("gb.showRemoteBranches"),
|
|
265 |
showRemoteBranches));
|
|
266 |
fieldsPanel.add(newFieldPanel(Translation.get("gb.showReadme"),
|
|
267 |
showReadme));
|
fe3262
|
268 |
fieldsPanel
|
df0292
|
269 |
.add(newFieldPanel(Translation.get("gb.skipSizeCalculation"),
|
JM |
270 |
skipSizeCalculation));
|
|
271 |
fieldsPanel.add(newFieldPanel(Translation.get("gb.skipSummaryMetrics"),
|
|
272 |
skipSummaryMetrics));
|
|
273 |
fieldsPanel.add(newFieldPanel(Translation.get("gb.mailingLists"),
|
|
274 |
mailingListsField));
|
a03ece
|
275 |
|
JM |
276 |
JPanel clonePushPanel = new JPanel(new GridLayout(0, 1));
|
|
277 |
clonePushPanel
|
|
278 |
.add(newFieldPanel(Translation.get("gb.isFrozen"), isFrozen));
|
|
279 |
clonePushPanel
|
|
280 |
.add(newFieldPanel(Translation.get("gb.allowForks"), allowForks));
|
476269
|
281 |
clonePushPanel
|
JM |
282 |
.add(newFieldPanel(Translation.get("gb.verifyCommitter"), verifyCommitter));
|
da0269
|
283 |
|
822dfe
|
284 |
usersPalette = new RegistrantPermissionsPanel();
|
6adf56
|
285 |
JPanel northAccessPanel = new JPanel(new BorderLayout(5, 5));
|
JM |
286 |
northAccessPanel.add(newFieldPanel(Translation.get("gb.accessRestriction"),
|
|
287 |
accessRestriction), BorderLayout.NORTH);
|
|
288 |
northAccessPanel.add(newFieldPanel(Translation.get("gb.authorizationControl"),
|
|
289 |
authorizationPanel), BorderLayout.CENTER);
|
a03ece
|
290 |
northAccessPanel.add(clonePushPanel, BorderLayout.SOUTH);
|
6adf56
|
291 |
|
da0269
|
292 |
JPanel accessPanel = new JPanel(new BorderLayout(5, 5));
|
6adf56
|
293 |
accessPanel.add(northAccessPanel, BorderLayout.NORTH);
|
822dfe
|
294 |
accessPanel.add(newFieldPanel(Translation.get("gb.userPermissions"),
|
df0292
|
295 |
usersPalette), BorderLayout.CENTER);
|
da0269
|
296 |
|
822dfe
|
297 |
teamsPalette = new RegistrantPermissionsPanel();
|
f08aab
|
298 |
JPanel teamsPanel = new JPanel(new BorderLayout(5, 5));
|
df0292
|
299 |
teamsPanel.add(
|
822dfe
|
300 |
newFieldPanel(Translation.get("gb.teamPermissions"),
|
df0292
|
301 |
teamsPalette), BorderLayout.CENTER);
|
f08aab
|
302 |
|
da0269
|
303 |
setsPalette = new JPalette<String>();
|
JM |
304 |
JPanel federationPanel = new JPanel(new BorderLayout(5, 5));
|
b7f591
|
305 |
federationPanel.add(
|
df0292
|
306 |
newFieldPanel(Translation.get("gb.federationStrategy"),
|
JM |
307 |
federationStrategy), BorderLayout.NORTH);
|
|
308 |
federationPanel
|
|
309 |
.add(newFieldPanel(Translation.get("gb.federationSets"),
|
|
310 |
setsPalette), BorderLayout.CENTER);
|
da0269
|
311 |
|
e9de3f
|
312 |
indexedBranchesPalette = new JPalette<String>();
|
JM |
313 |
JPanel indexedBranchesPanel = new JPanel(new BorderLayout(5, 5));
|
|
314 |
indexedBranchesPanel
|
|
315 |
.add(newFieldPanel(Translation.get("gb.indexedBranches"),
|
|
316 |
indexedBranchesPalette), BorderLayout.CENTER);
|
|
317 |
|
4bd203
|
318 |
preReceivePalette = new JPalette<String>(true);
|
f2dff4
|
319 |
preReceiveInherited = new JLabel();
|
4bd203
|
320 |
JPanel preReceivePanel = new JPanel(new BorderLayout(5, 5));
|
f2dff4
|
321 |
preReceivePanel.add(preReceivePalette, BorderLayout.CENTER);
|
JM |
322 |
preReceivePanel.add(preReceiveInherited, BorderLayout.WEST);
|
4bd203
|
323 |
|
JM |
324 |
postReceivePalette = new JPalette<String>(true);
|
f2dff4
|
325 |
postReceiveInherited = new JLabel();
|
4bd203
|
326 |
JPanel postReceivePanel = new JPanel(new BorderLayout(5, 5));
|
f2dff4
|
327 |
postReceivePanel.add(postReceivePalette, BorderLayout.CENTER);
|
JM |
328 |
postReceivePanel.add(postReceiveInherited, BorderLayout.WEST);
|
0e6eac
|
329 |
|
022ebb
|
330 |
customFieldsPanel = new JPanel();
|
JC |
331 |
customFieldsPanel.setLayout(new BoxLayout(customFieldsPanel, BoxLayout.Y_AXIS));
|
0e6eac
|
332 |
JScrollPane customFieldsScrollPane = new JScrollPane(customFieldsPanel);
|
JC |
333 |
customFieldsScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
|
334 |
customFieldsScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
|
4bd203
|
335 |
|
55a46b
|
336 |
JTabbedPane panel = new JTabbedPane(JTabbedPane.TOP);
|
JM |
337 |
panel.addTab(Translation.get("gb.general"), fieldsPanel);
|
|
338 |
panel.addTab(Translation.get("gb.accessRestriction"), accessPanel);
|
f08aab
|
339 |
if (protocolVersion >= 2) {
|
JM |
340 |
panel.addTab(Translation.get("gb.teams"), teamsPanel);
|
|
341 |
}
|
55a46b
|
342 |
panel.addTab(Translation.get("gb.federation"), federationPanel);
|
e9de3f
|
343 |
if (protocolVersion >= 3) {
|
JM |
344 |
panel.addTab(Translation.get("gb.indexedBranches"), indexedBranchesPanel);
|
|
345 |
}
|
4bd203
|
346 |
panel.addTab(Translation.get("gb.preReceiveScripts"), preReceivePanel);
|
JM |
347 |
panel.addTab(Translation.get("gb.postReceiveScripts"), postReceivePanel);
|
0e6eac
|
348 |
|
JC |
349 |
panel.addTab(Translation.get("gb.customFields"), customFieldsScrollPane);
|
|
350 |
|
da0269
|
351 |
|
b7f591
|
352 |
JButton createButton = new JButton(Translation.get("gb.save"));
|
da0269
|
353 |
createButton.addActionListener(new ActionListener() {
|
JM |
354 |
public void actionPerformed(ActionEvent event) {
|
|
355 |
if (validateFields()) {
|
|
356 |
canceled = false;
|
|
357 |
setVisible(false);
|
|
358 |
}
|
|
359 |
}
|
|
360 |
});
|
|
361 |
|
b7f591
|
362 |
JButton cancelButton = new JButton(Translation.get("gb.cancel"));
|
da0269
|
363 |
cancelButton.addActionListener(new ActionListener() {
|
JM |
364 |
public void actionPerformed(ActionEvent event) {
|
|
365 |
canceled = true;
|
|
366 |
setVisible(false);
|
|
367 |
}
|
|
368 |
});
|
|
369 |
|
|
370 |
JPanel controls = new JPanel();
|
|
371 |
controls.add(cancelButton);
|
|
372 |
controls.add(createButton);
|
|
373 |
|
|
374 |
final Insets _insets = new Insets(5, 5, 5, 5);
|
|
375 |
JPanel centerPanel = new JPanel(new BorderLayout(5, 5)) {
|
|
376 |
|
|
377 |
private static final long serialVersionUID = 1L;
|
|
378 |
|
|
379 |
@Override
|
|
380 |
public Insets getInsets() {
|
|
381 |
return _insets;
|
|
382 |
}
|
|
383 |
};
|
|
384 |
centerPanel.add(panel, BorderLayout.CENTER);
|
|
385 |
centerPanel.add(controls, BorderLayout.SOUTH);
|
|
386 |
|
|
387 |
getContentPane().setLayout(new BorderLayout(5, 5));
|
|
388 |
getContentPane().add(centerPanel, BorderLayout.CENTER);
|
|
389 |
pack();
|
38688b
|
390 |
nameField.requestFocus();
|
da0269
|
391 |
}
|
0e6eac
|
392 |
|
da0269
|
393 |
private JPanel newFieldPanel(String label, JComponent comp) {
|
0e6eac
|
394 |
return newFieldPanel(label, 150, comp);
|
JC |
395 |
}
|
|
396 |
|
|
397 |
private JPanel newFieldPanel(String label, int labelSize, JComponent comp) {
|
da0269
|
398 |
JLabel fieldLabel = new JLabel(label);
|
JM |
399 |
fieldLabel.setFont(fieldLabel.getFont().deriveFont(Font.BOLD));
|
0e6eac
|
400 |
fieldLabel.setPreferredSize(new Dimension(labelSize, 20));
|
da0269
|
401 |
JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 0));
|
JM |
402 |
panel.add(fieldLabel);
|
|
403 |
panel.add(comp);
|
|
404 |
return panel;
|
|
405 |
}
|
|
406 |
|
|
407 |
private boolean validateFields() {
|
bcc616
|
408 |
String rname = nameField.getText();
|
JM |
409 |
if (StringUtils.isEmpty(rname)) {
|
|
410 |
error("Please enter a repository name!");
|
|
411 |
return false;
|
|
412 |
}
|
|
413 |
|
|
414 |
// automatically convert backslashes to forward slashes
|
|
415 |
rname = rname.replace('\\', '/');
|
|
416 |
// Automatically replace // with /
|
|
417 |
rname = rname.replace("//", "/");
|
|
418 |
|
|
419 |
// prohibit folder paths
|
|
420 |
if (rname.startsWith("/")) {
|
|
421 |
error("Leading root folder references (/) are prohibited.");
|
|
422 |
return false;
|
|
423 |
}
|
|
424 |
if (rname.startsWith("../")) {
|
|
425 |
error("Relative folder references (../) are prohibited.");
|
|
426 |
return false;
|
|
427 |
}
|
|
428 |
if (rname.contains("/../")) {
|
|
429 |
error("Relative folder references (../) are prohibited.");
|
|
430 |
return false;
|
|
431 |
}
|
3fb41f
|
432 |
if (rname.endsWith("/")) {
|
JM |
433 |
rname = rname.substring(0, rname.length() - 1);
|
|
434 |
}
|
bcc616
|
435 |
|
JM |
436 |
// confirm valid characters in repository name
|
|
437 |
Character c = StringUtils.findInvalidCharacter(rname);
|
|
438 |
if (c != null) {
|
df0292
|
439 |
error(MessageFormat.format(
|
JM |
440 |
"Illegal character ''{0}'' in repository name!", c));
|
bcc616
|
441 |
return false;
|
JM |
442 |
}
|
|
443 |
|
|
444 |
// verify repository name uniqueness on create
|
|
445 |
if (isCreate) {
|
|
446 |
// force repo names to lowercase
|
|
447 |
// this means that repository name checking for rpc creation
|
|
448 |
// is case-insensitive, regardless of the Gitblit server's
|
|
449 |
// filesystem
|
|
450 |
if (repositoryNames.contains(rname.toLowerCase())) {
|
df0292
|
451 |
error(MessageFormat
|
JM |
452 |
.format("Can not create repository ''{0}'' because it already exists.",
|
|
453 |
rname));
|
bcc616
|
454 |
return false;
|
JM |
455 |
}
|
16038c
|
456 |
} else {
|
JM |
457 |
// check rename collision
|
|
458 |
if (!repositoryName.equalsIgnoreCase(rname)) {
|
|
459 |
if (repositoryNames.contains(rname.toLowerCase())) {
|
df0292
|
460 |
error(MessageFormat
|
JM |
461 |
.format("Failed to rename ''{0}'' because ''{1}'' already exists.",
|
|
462 |
repositoryName, rname));
|
16038c
|
463 |
return false;
|
JM |
464 |
}
|
|
465 |
}
|
bcc616
|
466 |
}
|
JM |
467 |
|
|
468 |
if (accessRestriction.getSelectedItem() == null) {
|
|
469 |
error("Please select access restriction!");
|
|
470 |
return false;
|
|
471 |
}
|
|
472 |
|
|
473 |
if (federationStrategy.getSelectedItem() == null) {
|
|
474 |
error("Please select federation strategy!");
|
|
475 |
return false;
|
|
476 |
}
|
|
477 |
|
|
478 |
repository.name = rname;
|
|
479 |
repository.description = descriptionField.getText();
|
df0292
|
480 |
repository.owner = ownerField.getSelectedItem() == null ? null
|
JM |
481 |
: ownerField.getSelectedItem().toString();
|
90b8d7
|
482 |
repository.HEAD = headRefField.getSelectedItem() == null ? null
|
JM |
483 |
: headRefField.getSelectedItem().toString();
|
bcc616
|
484 |
repository.useTickets = useTickets.isSelected();
|
JM |
485 |
repository.useDocs = useDocs.isSelected();
|
|
486 |
repository.showRemoteBranches = showRemoteBranches.isSelected();
|
|
487 |
repository.showReadme = showReadme.isSelected();
|
3d293a
|
488 |
repository.skipSizeCalculation = skipSizeCalculation.isSelected();
|
fe3262
|
489 |
repository.skipSummaryMetrics = skipSummaryMetrics.isSelected();
|
a03ece
|
490 |
|
bcc616
|
491 |
repository.isFrozen = isFrozen.isSelected();
|
a03ece
|
492 |
repository.allowForks = allowForks.isSelected();
|
476269
|
493 |
repository.verifyCommitter = verifyCommitter.isSelected();
|
4bd203
|
494 |
|
eb96ea
|
495 |
String ml = mailingListsField.getText();
|
JM |
496 |
if (!StringUtils.isEmpty(ml)) {
|
|
497 |
Set<String> list = new HashSet<String>();
|
|
498 |
for (String address : ml.split("(,|\\s)")) {
|
|
499 |
if (StringUtils.isEmpty(address)) {
|
|
500 |
continue;
|
|
501 |
}
|
|
502 |
list.add(address.toLowerCase());
|
|
503 |
}
|
|
504 |
repository.mailingLists = new ArrayList<String>(list);
|
|
505 |
}
|
bcc616
|
506 |
|
df0292
|
507 |
repository.accessRestriction = (AccessRestrictionType) accessRestriction
|
JM |
508 |
.getSelectedItem();
|
6adf56
|
509 |
repository.authorizationControl = allowAuthenticated.isSelected() ?
|
JM |
510 |
AuthorizationControl.AUTHENTICATED : AuthorizationControl.NAMED;
|
df0292
|
511 |
repository.federationStrategy = (FederationStrategy) federationStrategy
|
JM |
512 |
.getSelectedItem();
|
bcc616
|
513 |
|
JM |
514 |
if (repository.federationStrategy.exceeds(FederationStrategy.EXCLUDE)) {
|
|
515 |
repository.federationSets = setsPalette.getSelections();
|
|
516 |
}
|
e9de3f
|
517 |
|
JM |
518 |
repository.indexedBranches = indexedBranchesPalette.getSelections();
|
4bd203
|
519 |
repository.preReceiveScripts = preReceivePalette.getSelections();
|
JM |
520 |
repository.postReceiveScripts = postReceivePalette.getSelections();
|
0e6eac
|
521 |
|
JC |
522 |
// Custom Fields
|
a5b159
|
523 |
repository.customFields = new LinkedHashMap<String, String>();
|
JM |
524 |
if (customTextfields != null) {
|
|
525 |
for (JTextField field : customTextfields) {
|
|
526 |
String key = field.getName();
|
|
527 |
String value = field.getText();
|
|
528 |
repository.customFields.put(key, value);
|
|
529 |
}
|
0e6eac
|
530 |
}
|
da0269
|
531 |
return true;
|
JM |
532 |
}
|
|
533 |
|
bcc616
|
534 |
private void error(String message) {
|
b7f591
|
535 |
JOptionPane.showMessageDialog(EditRepositoryDialog.this, message,
|
JM |
536 |
Translation.get("gb.error"), JOptionPane.ERROR_MESSAGE);
|
da0269
|
537 |
}
|
94dcbd
|
538 |
|
JM |
539 |
public void setAccessRestriction(AccessRestrictionType restriction) {
|
|
540 |
this.accessRestriction.setSelectedItem(restriction);
|
|
541 |
}
|
da0269
|
542 |
|
6adf56
|
543 |
public void setAuthorizationControl(AuthorizationControl authorization) {
|
JM |
544 |
boolean authenticated = authorization != null && AuthorizationControl.AUTHENTICATED.equals(authorization);
|
|
545 |
this.allowAuthenticated.setSelected(authenticated);
|
|
546 |
this.allowNamed.setSelected(!authenticated);
|
|
547 |
}
|
|
548 |
|
822dfe
|
549 |
public void setUsers(String owner, List<String> all, List<RegistrantAccessPermission> permissions) {
|
bcc616
|
550 |
ownerField.setModel(new DefaultComboBoxModel(all.toArray()));
|
JM |
551 |
if (!StringUtils.isEmpty(owner)) {
|
|
552 |
ownerField.setSelectedItem(owner);
|
|
553 |
}
|
822dfe
|
554 |
usersPalette.setObjects(all, permissions);
|
bcc616
|
555 |
}
|
4bd203
|
556 |
|
822dfe
|
557 |
public void setTeams(List<String> all, List<RegistrantAccessPermission> permissions) {
|
JM |
558 |
teamsPalette.setObjects(all, permissions);
|
f08aab
|
559 |
}
|
bcc616
|
560 |
|
JM |
561 |
public void setRepositories(List<RepositoryModel> repositories) {
|
|
562 |
repositoryNames.clear();
|
|
563 |
for (RepositoryModel repository : repositories) {
|
|
564 |
// force repo names to lowercase
|
|
565 |
// this means that repository name checking for rpc creation
|
|
566 |
// is case-insensitive, regardless of the Gitblit server's
|
|
567 |
// filesystem
|
|
568 |
repositoryNames.add(repository.name.toLowerCase());
|
|
569 |
}
|
da0269
|
570 |
}
|
JM |
571 |
|
|
572 |
public void setFederationSets(List<String> all, List<String> selected) {
|
|
573 |
setsPalette.setObjects(all, selected);
|
|
574 |
}
|
e9de3f
|
575 |
|
JM |
576 |
public void setIndexedBranches(List<String> all, List<String> selected) {
|
|
577 |
indexedBranchesPalette.setObjects(all, selected);
|
|
578 |
}
|
da0269
|
579 |
|
df0292
|
580 |
public void setPreReceiveScripts(List<String> all, List<String> inherited,
|
JM |
581 |
List<String> selected) {
|
4bd203
|
582 |
preReceivePalette.setObjects(all, selected);
|
f2dff4
|
583 |
showInherited(inherited, preReceiveInherited);
|
4bd203
|
584 |
}
|
JM |
585 |
|
f2dff4
|
586 |
public void setPostReceiveScripts(List<String> all, List<String> inherited,
|
JM |
587 |
List<String> selected) {
|
4bd203
|
588 |
postReceivePalette.setObjects(all, selected);
|
f2dff4
|
589 |
showInherited(inherited, postReceiveInherited);
|
JM |
590 |
}
|
|
591 |
|
|
592 |
private void showInherited(List<String> list, JLabel label) {
|
|
593 |
StringBuilder sb = new StringBuilder();
|
|
594 |
if (list != null && list.size() > 0) {
|
|
595 |
sb.append("<html><body><b>INHERITED</b><ul style=\"margin-left:5px;list-style-type: none;\">");
|
|
596 |
for (String script : list) {
|
|
597 |
sb.append("<li>").append(script).append("</li>");
|
|
598 |
}
|
|
599 |
sb.append("</ul></body></html>");
|
|
600 |
}
|
|
601 |
label.setText(sb.toString());
|
4bd203
|
602 |
}
|
JM |
603 |
|
da0269
|
604 |
public RepositoryModel getRepository() {
|
JM |
605 |
if (canceled) {
|
|
606 |
return null;
|
|
607 |
}
|
|
608 |
return repository;
|
|
609 |
}
|
b7f591
|
610 |
|
822dfe
|
611 |
public List<RegistrantAccessPermission> getUserAccessPermissions() {
|
JM |
612 |
return usersPalette.getPermissions();
|
bcc616
|
613 |
}
|
JM |
614 |
|
822dfe
|
615 |
public List<RegistrantAccessPermission> getTeamAccessPermissions() {
|
JM |
616 |
return teamsPalette.getPermissions();
|
f08aab
|
617 |
}
|
0e6eac
|
618 |
|
a5b159
|
619 |
public void setCustomFields(RepositoryModel repository, Map<String, String> customFields) {
|
0e6eac
|
620 |
customFieldsPanel.removeAll();
|
a5b159
|
621 |
customTextfields = new ArrayList<JTextField>();
|
0e6eac
|
622 |
|
a5b159
|
623 |
final Insets insets = new Insets(5, 5, 5, 5);
|
JM |
624 |
JPanel fields = new JPanel(new GridLayout(0, 1, 0, 5)) {
|
|
625 |
|
|
626 |
private static final long serialVersionUID = 1L;
|
|
627 |
|
|
628 |
@Override
|
|
629 |
public Insets getInsets() {
|
|
630 |
return insets;
|
|
631 |
}
|
|
632 |
};
|
022ebb
|
633 |
|
a5b159
|
634 |
for (Map.Entry<String, String> entry : customFields.entrySet()) {
|
JM |
635 |
String field = entry.getKey();
|
|
636 |
String value = "";
|
|
637 |
if (repository.customFields != null && repository.customFields.containsKey(field)) {
|
|
638 |
value = repository.customFields.get(field);
|
|
639 |
}
|
|
640 |
JTextField textField = new JTextField(value);
|
|
641 |
textField.setName(field);
|
|
642 |
|
|
643 |
textField.setPreferredSize(new Dimension(450, 26));
|
|
644 |
|
|
645 |
fields.add(newFieldPanel(entry.getValue(), 250, textField));
|
|
646 |
|
|
647 |
customTextfields.add(textField);
|
022ebb
|
648 |
}
|
a5b159
|
649 |
JScrollPane jsp = new JScrollPane(fields);
|
JM |
650 |
jsp.getVerticalScrollBar().setBlockIncrement(100);
|
|
651 |
jsp.getVerticalScrollBar().setUnitIncrement(100);
|
|
652 |
jsp.setViewportBorder(null);
|
|
653 |
customFieldsPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
|
|
654 |
customFieldsPanel.add(jsp);
|
0e6eac
|
655 |
}
|
f08aab
|
656 |
|
b7f591
|
657 |
/**
|
JM |
658 |
* ListCellRenderer to display descriptive text about the access
|
|
659 |
* restriction.
|
|
660 |
*
|
|
661 |
*/
|
df0292
|
662 |
private class AccessRestrictionRenderer extends JLabel implements
|
JM |
663 |
ListCellRenderer {
|
b7f591
|
664 |
|
JM |
665 |
private static final long serialVersionUID = 1L;
|
|
666 |
|
|
667 |
@Override
|
df0292
|
668 |
public Component getListCellRendererComponent(JList list, Object value,
|
JM |
669 |
int index, boolean isSelected, boolean cellHasFocus) {
|
b7f591
|
670 |
if (value instanceof AccessRestrictionType) {
|
JM |
671 |
AccessRestrictionType restriction = (AccessRestrictionType) value;
|
|
672 |
switch (restriction) {
|
|
673 |
case NONE:
|
|
674 |
setText(Translation.get("gb.notRestricted"));
|
|
675 |
break;
|
|
676 |
case PUSH:
|
|
677 |
setText(Translation.get("gb.pushRestricted"));
|
|
678 |
break;
|
|
679 |
case CLONE:
|
|
680 |
setText(Translation.get("gb.cloneRestricted"));
|
|
681 |
break;
|
|
682 |
case VIEW:
|
|
683 |
setText(Translation.get("gb.viewRestricted"));
|
|
684 |
break;
|
|
685 |
}
|
|
686 |
} else {
|
|
687 |
setText(value.toString());
|
|
688 |
}
|
|
689 |
return this;
|
|
690 |
}
|
|
691 |
}
|
|
692 |
|
|
693 |
/**
|
|
694 |
* ListCellRenderer to display descriptive text about the federation
|
|
695 |
* strategy.
|
|
696 |
*/
|
df0292
|
697 |
private class FederationStrategyRenderer extends JLabel implements
|
JM |
698 |
ListCellRenderer {
|
b7f591
|
699 |
|
JM |
700 |
private static final long serialVersionUID = 1L;
|
|
701 |
|
|
702 |
@Override
|
df0292
|
703 |
public Component getListCellRendererComponent(JList list, Object value,
|
JM |
704 |
int index, boolean isSelected, boolean cellHasFocus) {
|
b7f591
|
705 |
if (value instanceof FederationStrategy) {
|
JM |
706 |
FederationStrategy strategy = (FederationStrategy) value;
|
|
707 |
switch (strategy) {
|
|
708 |
case EXCLUDE:
|
|
709 |
setText(Translation.get("gb.excludeFromFederation"));
|
|
710 |
break;
|
|
711 |
case FEDERATE_THIS:
|
|
712 |
setText(Translation.get("gb.federateThis"));
|
|
713 |
break;
|
|
714 |
case FEDERATE_ORIGIN:
|
|
715 |
setText(Translation.get("gb.federateOrigin"));
|
|
716 |
break;
|
|
717 |
}
|
|
718 |
} else {
|
|
719 |
setText(value.toString());
|
|
720 |
}
|
|
721 |
return this;
|
|
722 |
}
|
|
723 |
}
|
da0269
|
724 |
}
|