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