From 5e010729291f732d4f31cbf66649dbac1e795a59 Mon Sep 17 00:00:00 2001 From: James Moger <james.moger@gitblit.com> Date: Fri, 27 Jul 2012 21:41:26 -0400 Subject: [PATCH] Fixes to relative path determination for symlinks (issue 116) --- src/com/gitblit/client/EditRepositoryDialog.java | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 106 insertions(+), 14 deletions(-) diff --git a/src/com/gitblit/client/EditRepositoryDialog.java b/src/com/gitblit/client/EditRepositoryDialog.java index eaf7e0c..77878cb 100644 --- a/src/com/gitblit/client/EditRepositoryDialog.java +++ b/src/com/gitblit/client/EditRepositoryDialog.java @@ -29,9 +29,12 @@ 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.DefaultComboBoxModel; import javax.swing.ImageIcon; import javax.swing.JButton; @@ -44,10 +47,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; @@ -98,13 +103,15 @@ private JComboBox ownerField; - private JComboBox defaultHeadField; + private JComboBox headRefField; private JPalette<String> usersPalette; private JPalette<String> setsPalette; private JPalette<String> teamsPalette; + + private JPalette<String> indexedBranchesPalette; private JPalette<String> preReceivePalette; @@ -115,6 +122,10 @@ private JLabel postReceiveInherited; private Set<String> repositoryNames; + + private JPanel customFieldsPanel; + + private List<JTextField> customTextfields; public EditRepositoryDialog(int protocolVersion) { this(protocolVersion, new RepositoryModel()); @@ -158,13 +169,13 @@ anRepository.origin == null ? "" : anRepository.origin, 40); originField.setEditable(false); - if (ArrayUtils.isEmpty(anRepository.availableHeads)) { - defaultHeadField = new JComboBox(); - defaultHeadField.setEnabled(false); + if (ArrayUtils.isEmpty(anRepository.availableRefs)) { + headRefField = new JComboBox(); + headRefField.setEnabled(false); } else { - defaultHeadField = new JComboBox( - anRepository.availableHeads.toArray()); - defaultHeadField.setSelectedItem(anRepository.defaultHead); + headRefField = new JComboBox( + anRepository.availableRefs.toArray()); + headRefField.setSelectedItem(anRepository.HEAD); } ownerField = new JComboBox(); @@ -213,8 +224,7 @@ descriptionField)); fieldsPanel .add(newFieldPanel(Translation.get("gb.origin"), originField)); - fieldsPanel.add(newFieldPanel(Translation.get("gb.defaultHead"), - defaultHeadField)); + fieldsPanel.add(newFieldPanel(Translation.get("gb.headRef"), headRefField)); fieldsPanel.add(newFieldPanel(Translation.get("gb.owner"), ownerField)); fieldsPanel.add(newFieldPanel(Translation.get("gb.enableTickets"), @@ -259,6 +269,12 @@ .add(newFieldPanel(Translation.get("gb.federationSets"), setsPalette), BorderLayout.CENTER); + indexedBranchesPalette = new JPalette<String>(); + JPanel indexedBranchesPanel = new JPanel(new BorderLayout(5, 5)); + indexedBranchesPanel + .add(newFieldPanel(Translation.get("gb.indexedBranches"), + indexedBranchesPalette), BorderLayout.CENTER); + preReceivePalette = new JPalette<String>(true); preReceiveInherited = new JLabel(); JPanel preReceivePanel = new JPanel(new BorderLayout(5, 5)); @@ -270,6 +286,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); @@ -278,8 +300,14 @@ panel.addTab(Translation.get("gb.teams"), teamsPanel); } panel.addTab(Translation.get("gb.federation"), federationPanel); + if (protocolVersion >= 3) { + panel.addTab(Translation.get("gb.indexedBranches"), indexedBranchesPanel); + } 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() { @@ -321,11 +349,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); @@ -356,6 +388,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 @@ -404,8 +439,8 @@ repository.description = descriptionField.getText(); repository.owner = ownerField.getSelectedItem() == null ? null : ownerField.getSelectedItem().toString(); - repository.defaultHead = defaultHeadField.getSelectedItem() == null ? null - : defaultHeadField.getSelectedItem().toString(); + repository.HEAD = headRefField.getSelectedItem() == null ? null + : headRefField.getSelectedItem().toString(); repository.useTickets = useTickets.isSelected(); repository.useDocs = useDocs.isSelected(); repository.showRemoteBranches = showRemoteBranches.isSelected(); @@ -434,15 +469,30 @@ if (repository.federationStrategy.exceeds(FederationStrategy.EXCLUDE)) { repository.federationSets = setsPalette.getSelections(); } - + + 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 setUsers(String owner, List<String> all, List<String> selected) { @@ -470,6 +520,10 @@ public void setFederationSets(List<String> all, List<String> selected) { setsPalette.setObjects(all, selected); + } + + public void setIndexedBranches(List<String> all, List<String> selected) { + indexedBranchesPalette.setObjects(all, selected); } public void setPreReceiveScripts(List<String> all, List<String> inherited, @@ -510,6 +564,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