From a5e762ba4ab82f0c6ef71d853c5103f19bbf8e22 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Thu, 11 Oct 2012 08:10:20 -0400
Subject: [PATCH] Tweak canFork description

---
 src/com/gitblit/client/EditRepositoryDialog.java |  139 +++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 130 insertions(+), 9 deletions(-)

diff --git a/src/com/gitblit/client/EditRepositoryDialog.java b/src/com/gitblit/client/EditRepositoryDialog.java
index 156de15..840281b 100644
--- a/src/com/gitblit/client/EditRepositoryDialog.java
+++ b/src/com/gitblit/client/EditRepositoryDialog.java
@@ -29,9 +29,13 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashSet;
+import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
+import javax.swing.BoxLayout;
+import javax.swing.ButtonGroup;
 import javax.swing.DefaultComboBoxModel;
 import javax.swing.ImageIcon;
 import javax.swing.JButton;
@@ -43,13 +47,17 @@
 import javax.swing.JList;
 import javax.swing.JOptionPane;
 import javax.swing.JPanel;
+import javax.swing.JRadioButton;
 import javax.swing.JRootPane;
+import javax.swing.JScrollPane;
 import javax.swing.JTabbedPane;
 import javax.swing.JTextField;
 import javax.swing.KeyStroke;
 import javax.swing.ListCellRenderer;
+import javax.swing.ScrollPaneConstants;
 
 import com.gitblit.Constants.AccessRestrictionType;
+import com.gitblit.Constants.AuthorizationControl;
 import com.gitblit.Constants.FederationStrategy;
 import com.gitblit.models.RepositoryModel;
 import com.gitblit.utils.ArrayUtils;
@@ -93,6 +101,12 @@
 	private JTextField mailingListsField;
 
 	private JComboBox accessRestriction;
+	
+	private JRadioButton allowAuthenticated;
+	
+	private JRadioButton allowNamed;
+	
+	private JCheckBox allowForks;
 
 	private JComboBox federationStrategy;
 
@@ -117,6 +131,10 @@
 	private JLabel postReceiveInherited;
 
 	private Set<String> repositoryNames;
+	
+	private JPanel customFieldsPanel;
+	
+	private List<JTextField> customTextfields;
 
 	public EditRepositoryDialog(int protocolVersion) {
 		this(protocolVersion, new RepositoryModel());
@@ -197,6 +215,23 @@
 		accessRestriction = new JComboBox(AccessRestrictionType.values());
 		accessRestriction.setRenderer(new AccessRestrictionRenderer());
 		accessRestriction.setSelectedItem(anRepository.accessRestriction);
+		
+		boolean authenticated = anRepository.authorizationControl != null 
+				&& AuthorizationControl.AUTHENTICATED.equals(anRepository.authorizationControl);
+		allowAuthenticated = new JRadioButton(Translation.get("gb.allowAuthenticatedDescription"));
+		allowAuthenticated.setSelected(authenticated);
+		allowNamed = new JRadioButton(Translation.get("gb.allowNamedDescription"));
+		allowNamed.setSelected(!authenticated);
+		
+		ButtonGroup group = new ButtonGroup();
+		group.add(allowAuthenticated);
+		group.add(allowNamed);
+		
+		JPanel authorizationPanel = new JPanel(new GridLayout(0, 1));
+		authorizationPanel.add(allowAuthenticated);
+		authorizationPanel.add(allowNamed);
+		
+		allowForks = new JCheckBox(Translation.get("gb.allowForks"), anRepository.allowForks);
 
 		// federation strategies - remove ORIGIN choice if this repository has
 		// no origin.
@@ -231,18 +266,26 @@
 						skipSizeCalculation));
 		fieldsPanel.add(newFieldPanel(Translation.get("gb.skipSummaryMetrics"),
 				skipSummaryMetrics));
-		fieldsPanel
-				.add(newFieldPanel(Translation.get("gb.isFrozen"), isFrozen));
 		fieldsPanel.add(newFieldPanel(Translation.get("gb.mailingLists"),
 				mailingListsField));
 
+		JPanel clonePushPanel = new JPanel(new GridLayout(0, 1));
+		clonePushPanel
+		.add(newFieldPanel(Translation.get("gb.isFrozen"), isFrozen));
+		clonePushPanel
+		.add(newFieldPanel(Translation.get("gb.allowForks"), allowForks));
+
 		usersPalette = new JPalette<String>();
+		JPanel northAccessPanel = new JPanel(new BorderLayout(5, 5));
+		northAccessPanel.add(newFieldPanel(Translation.get("gb.accessRestriction"),
+				accessRestriction), BorderLayout.NORTH);
+		northAccessPanel.add(newFieldPanel(Translation.get("gb.authorizationControl"),
+				authorizationPanel), BorderLayout.CENTER);
+		northAccessPanel.add(clonePushPanel, BorderLayout.SOUTH);
+
 		JPanel accessPanel = new JPanel(new BorderLayout(5, 5));
-		accessPanel.add(
-				newFieldPanel(Translation.get("gb.accessRestriction"),
-						accessRestriction), BorderLayout.NORTH);
-		accessPanel.add(
-				newFieldPanel(Translation.get("gb.permittedUsers"),
+		accessPanel.add(northAccessPanel, BorderLayout.NORTH);
+		accessPanel.add(newFieldPanel(Translation.get("gb.permittedUsers"),
 						usersPalette), BorderLayout.CENTER);
 
 		teamsPalette = new JPalette<String>();
@@ -277,6 +320,12 @@
 		JPanel postReceivePanel = new JPanel(new BorderLayout(5, 5));
 		postReceivePanel.add(postReceivePalette, BorderLayout.CENTER);
 		postReceivePanel.add(postReceiveInherited, BorderLayout.WEST);
+		
+		customFieldsPanel = new JPanel();
+		customFieldsPanel.setLayout(new BoxLayout(customFieldsPanel, BoxLayout.Y_AXIS));
+		JScrollPane customFieldsScrollPane = new JScrollPane(customFieldsPanel);
+		customFieldsScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
+		customFieldsScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
 
 		JTabbedPane panel = new JTabbedPane(JTabbedPane.TOP);
 		panel.addTab(Translation.get("gb.general"), fieldsPanel);
@@ -290,6 +339,9 @@
 		}
 		panel.addTab(Translation.get("gb.preReceiveScripts"), preReceivePanel);
 		panel.addTab(Translation.get("gb.postReceiveScripts"), postReceivePanel);
+		
+		panel.addTab(Translation.get("gb.customFields"), customFieldsScrollPane);
+		
 
 		JButton createButton = new JButton(Translation.get("gb.save"));
 		createButton.addActionListener(new ActionListener() {
@@ -331,11 +383,15 @@
 		pack();
 		nameField.requestFocus();
 	}
-
+	
 	private JPanel newFieldPanel(String label, JComponent comp) {
+		return newFieldPanel(label, 150, comp);
+	}
+
+	private JPanel newFieldPanel(String label, int labelSize, JComponent comp) {
 		JLabel fieldLabel = new JLabel(label);
 		fieldLabel.setFont(fieldLabel.getFont().deriveFont(Font.BOLD));
-		fieldLabel.setPreferredSize(new Dimension(150, 20));
+		fieldLabel.setPreferredSize(new Dimension(labelSize, 20));
 		JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 0));
 		panel.add(fieldLabel);
 		panel.add(comp);
@@ -366,6 +422,9 @@
 		if (rname.contains("/../")) {
 			error("Relative folder references (../) are prohibited.");
 			return false;
+		}
+		if (rname.endsWith("/")) {
+			rname = rname.substring(0, rname.length() - 1);
 		}
 
 		// confirm valid characters in repository name
@@ -422,7 +481,9 @@
 		repository.showReadme = showReadme.isSelected();
 		repository.skipSizeCalculation = skipSizeCalculation.isSelected();
 		repository.skipSummaryMetrics = skipSummaryMetrics.isSelected();
+		
 		repository.isFrozen = isFrozen.isSelected();
+		repository.allowForks = allowForks.isSelected();
 
 		String ml = mailingListsField.getText();
 		if (!StringUtils.isEmpty(ml)) {
@@ -438,6 +499,8 @@
 
 		repository.accessRestriction = (AccessRestrictionType) accessRestriction
 				.getSelectedItem();
+		repository.authorizationControl = allowAuthenticated.isSelected() ? 
+				AuthorizationControl.AUTHENTICATED : AuthorizationControl.NAMED;
 		repository.federationStrategy = (FederationStrategy) federationStrategy
 				.getSelectedItem();
 
@@ -448,12 +511,32 @@
 		repository.indexedBranches = indexedBranchesPalette.getSelections();
 		repository.preReceiveScripts = preReceivePalette.getSelections();
 		repository.postReceiveScripts = postReceivePalette.getSelections();
+		
+		// Custom Fields
+		repository.customFields = new LinkedHashMap<String, String>();
+		if (customTextfields != null) {
+			for (JTextField field : customTextfields) {
+				String key = field.getName();
+				String value = field.getText();
+				repository.customFields.put(key, value);
+			}
+		}
 		return true;
 	}
 
 	private void error(String message) {
 		JOptionPane.showMessageDialog(EditRepositoryDialog.this, message,
 				Translation.get("gb.error"), JOptionPane.ERROR_MESSAGE);
+	}
+	
+	public void setAccessRestriction(AccessRestrictionType restriction) {
+		this.accessRestriction.setSelectedItem(restriction);
+	}
+
+	public void setAuthorizationControl(AuthorizationControl authorization) {
+		boolean authenticated = authorization != null && AuthorizationControl.AUTHENTICATED.equals(authorization);
+		this.allowAuthenticated.setSelected(authenticated);
+		this.allowNamed.setSelected(!authenticated);
 	}
 
 	public void setUsers(String owner, List<String> all, List<String> selected) {
@@ -525,6 +608,44 @@
 	public List<String> getPermittedTeams() {
 		return teamsPalette.getSelections();
 	}
+	
+	public void setCustomFields(RepositoryModel repository, Map<String, String> customFields) {
+		customFieldsPanel.removeAll();
+		customTextfields = new ArrayList<JTextField>();
+		
+		final Insets insets = new Insets(5, 5, 5, 5);
+		JPanel fields = new JPanel(new GridLayout(0, 1, 0, 5)) {
+
+			private static final long serialVersionUID = 1L;
+
+			@Override
+			public Insets getInsets() {
+				return insets;
+			}
+		};		
+		
+		for (Map.Entry<String, String> entry : customFields.entrySet()) {
+			String field = entry.getKey();
+			String value = "";
+			if (repository.customFields != null && repository.customFields.containsKey(field)) {
+				value = repository.customFields.get(field);
+			}
+			JTextField textField = new JTextField(value);
+			textField.setName(field);
+			
+			textField.setPreferredSize(new Dimension(450, 26));
+			
+			fields.add(newFieldPanel(entry.getValue(), 250, textField));
+			
+			customTextfields.add(textField);
+		}
+		JScrollPane jsp = new JScrollPane(fields);		
+		jsp.getVerticalScrollBar().setBlockIncrement(100);
+		jsp.getVerticalScrollBar().setUnitIncrement(100);
+		jsp.setViewportBorder(null);
+		customFieldsPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
+		customFieldsPanel.add(jsp);
+	}
 
 	/**
 	 * ListCellRenderer to display descriptive text about the access

--
Gitblit v1.9.1