From 0e6eace75d39ef300891b529d471617b5da8cfaa Mon Sep 17 00:00:00 2001
From: John Crygier <john.crygier@aon.com>
Date: Mon, 07 May 2012 10:58:56 -0400
Subject: [PATCH] Add custom fields to the manager
---
src/com/gitblit/client/EditRepositoryDialog.java | 45 +++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/src/com/gitblit/client/EditRepositoryDialog.java b/src/com/gitblit/client/EditRepositoryDialog.java
index 156de15..6ad75c6 100644
--- a/src/com/gitblit/client/EditRepositoryDialog.java
+++ b/src/com/gitblit/client/EditRepositoryDialog.java
@@ -28,6 +28,7 @@
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -44,10 +45,12 @@
import javax.swing.JOptionPane;
import javax.swing.JPanel;
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.FederationStrategy;
@@ -117,6 +120,8 @@
private JLabel postReceiveInherited;
private Set<String> repositoryNames;
+
+ private JPanel customFieldsPanel;
public EditRepositoryDialog(int protocolVersion) {
this(protocolVersion, new RepositoryModel());
@@ -277,6 +282,11 @@
JPanel postReceivePanel = new JPanel(new BorderLayout(5, 5));
postReceivePanel.add(postReceivePalette, BorderLayout.CENTER);
postReceivePanel.add(postReceiveInherited, BorderLayout.WEST);
+
+ customFieldsPanel = new JPanel(new VerticalFlowLayout());
+ 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 +300,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 +344,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);
@@ -448,6 +465,15 @@
repository.indexedBranches = indexedBranchesPalette.getSelections();
repository.preReceiveScripts = preReceivePalette.getSelections();
repository.postReceiveScripts = postReceivePalette.getSelections();
+
+ // Custom Fields
+ repository.customFields = new HashMap<String, String>();
+
+ for (Component aCustomFieldPanel : customFieldsPanel.getComponents()) {
+ JTextField textField = (JTextField) ((JPanel)aCustomFieldPanel).getComponent(1);
+ repository.customFields.put(textField.getName(), textField.getText());
+ }
+
return true;
}
@@ -525,6 +551,21 @@
public List<String> getPermittedTeams() {
return teamsPalette.getSelections();
}
+
+ public void setCustomFields(RepositoryModel repository, List<String> customFields) {
+ customFieldsPanel.removeAll();
+
+ for (String customFieldDef : customFields) {
+ String[] customFieldProperty = customFieldDef.split("=");
+ String fieldName = customFieldProperty[0];
+ String fieldLabel = customFieldProperty[1];
+
+ JTextField textField = new JTextField(repository.customFields.get(fieldName), 50);
+ textField.setName(fieldName);
+
+ customFieldsPanel.add(newFieldPanel(fieldLabel, 250, textField));
+ }
+ }
/**
* ListCellRenderer to display descriptive text about the access
--
Gitblit v1.9.1