]> source.dussan.org Git - gitblit.git/commitdiff
Added repository selector to feeds panel
authorJames Moger <james.moger@gitblit.com>
Wed, 2 Nov 2011 21:26:42 +0000 (17:26 -0400)
committerJames Moger <james.moger@gitblit.com>
Wed, 2 Nov 2011 21:26:42 +0000 (17:26 -0400)
src/com/gitblit/client/BranchRenderer.java
src/com/gitblit/client/FeedsPanel.java
src/com/gitblit/client/NameRenderer.java
src/com/gitblit/utils/SyndicationUtils.java

index f9c9f3611fb35bf0b834a0198e15622df505e6a2..b8f55f09706fdc8ccd75d99b026df60ac8098bee 100644 (file)
@@ -64,11 +64,11 @@ public class BranchRenderer extends JPanel implements TableCellRenderer, Seriali
                if (name.startsWith(R_HEADS)) {\r
                        bg = Color.decode("#CCFFCC");\r
                        name = name.substring(R_HEADS.length());\r
-                       border = new LineBorder(Color.decode("#00CC33"), 1, true);\r
+                       border = new LineBorder(Color.decode("#00CC33"), 1);\r
                } else if (name.startsWith(R_REMOTES)) {\r
                        bg = Color.decode("#CAC2F5");\r
                        name = name.substring(R_REMOTES.length());\r
-                       border = new LineBorder(Color.decode("#6C6CBF"), 1, true);\r
+                       border = new LineBorder(Color.decode("#6C6CBF"), 1);\r
                }\r
                branchLabel.setText(" " + name + " ");\r
                branchLabel.setBackground(bg);\r
index c6b464d6b86bb291d396b5fd1f466ea28004fb30..2f4391dae1e2e43268dab4a4fcc53909e331608b 100644 (file)
@@ -23,18 +23,27 @@ import java.awt.event.ActionListener;
 import java.awt.event.MouseAdapter;\r
 import java.awt.event.MouseEvent;\r
 import java.io.IOException;\r
+import java.util.ArrayList;\r
+import java.util.HashSet;\r
 import java.util.List;\r
+import java.util.Set;\r
 \r
+import javax.swing.DefaultComboBoxModel;\r
 import javax.swing.JButton;\r
+import javax.swing.JComboBox;\r
+import javax.swing.JLabel;\r
 import javax.swing.JPanel;\r
 import javax.swing.JScrollPane;\r
 import javax.swing.JTable;\r
+import javax.swing.RowFilter;\r
 import javax.swing.event.ListSelectionEvent;\r
 import javax.swing.event.ListSelectionListener;\r
+import javax.swing.table.TableRowSorter;\r
 \r
 import com.gitblit.Constants.RpcRequest;\r
 import com.gitblit.models.FeedModel;\r
 import com.gitblit.models.SyndicatedEntryModel;\r
+import com.gitblit.utils.StringUtils;\r
 \r
 /**\r
  * RSS Feeds Panel displays recent entries and launches the browser to view the\r
@@ -49,12 +58,18 @@ public abstract class FeedsPanel extends JPanel {
 \r
        private final GitblitClient gitblit;\r
 \r
+       private final String ALL = "ALL";\r
+\r
        private SyndicatedEntryTableModel tableModel;\r
 \r
+       private TableRowSorter<SyndicatedEntryTableModel> defaultSorter;\r
+\r
        private HeaderPanel header;\r
 \r
        private JTable table;\r
 \r
+       private DefaultComboBoxModel repositoryChoices;\r
+\r
        public FeedsPanel(GitblitClient gitblit) {\r
                super();\r
                this.gitblit = gitblit;\r
@@ -111,6 +126,7 @@ public abstract class FeedsPanel extends JPanel {
                tableModel = new SyndicatedEntryTableModel();\r
                header = new HeaderPanel(Translation.get("gb.timeline"), "feed_16x16.png");\r
                table = Utils.newTable(tableModel, Utils.DATE_FORMAT);\r
+               defaultSorter = new TableRowSorter<SyndicatedEntryTableModel>(tableModel);\r
                String name = table.getColumnName(SyndicatedEntryTableModel.Columns.Author.ordinal());\r
                table.setRowHeight(nameRenderer.getFont().getSize() + 8);\r
                table.getColumn(name).setCellRenderer(nameRenderer);\r
@@ -145,8 +161,29 @@ public abstract class FeedsPanel extends JPanel {
                        }\r
                });\r
 \r
+               repositoryChoices = new DefaultComboBoxModel();\r
+               final JComboBox repositorySelector = new JComboBox(repositoryChoices);\r
+               repositorySelector.setRenderer(nameRenderer);\r
+               repositorySelector.setForeground(nameRenderer.getForeground());\r
+               repositorySelector.addActionListener(new ActionListener() {\r
+                       public void actionPerformed(ActionEvent event) {\r
+                               String repository = ALL;\r
+                               if (repositorySelector.getSelectedIndex() > -1) {\r
+                                       repository = repositorySelector.getSelectedItem().toString();\r
+                               }\r
+                               filterRepositories(repository);\r
+                       }\r
+               });\r
+               JPanel northControls = new JPanel(new FlowLayout(FlowLayout.LEFT, Utils.MARGIN, 0));\r
+               northControls.add(new JLabel(Translation.get("gb.repository")));\r
+               northControls.add(repositorySelector);\r
+\r
+               JPanel northPanel = new JPanel(new BorderLayout(0, Utils.MARGIN));\r
+               northPanel.add(header, BorderLayout.NORTH);\r
+               northPanel.add(northControls, BorderLayout.CENTER);\r
+\r
                setLayout(new BorderLayout(Utils.MARGIN, Utils.MARGIN));\r
-               add(header, BorderLayout.NORTH);\r
+               add(northPanel, BorderLayout.NORTH);\r
                add(new JScrollPane(table), BorderLayout.CENTER);\r
                add(controls, BorderLayout.SOUTH);\r
        }\r
@@ -184,6 +221,17 @@ public abstract class FeedsPanel extends JPanel {
                if (pack) {\r
                        Utils.packColumns(table, Utils.MARGIN);\r
                }\r
+               Set<String> uniqueRepositories = new HashSet<String>();\r
+               for (SyndicatedEntryModel entry : tableModel.entries) {\r
+                       uniqueRepositories.add(entry.repository);\r
+               }\r
+               List<String> sortedRespositories = new ArrayList<String>(uniqueRepositories);\r
+               StringUtils.sortRepositorynames(sortedRespositories);\r
+               repositoryChoices.removeAllElements();\r
+               repositoryChoices.addElement(ALL);\r
+               for (String repo : sortedRespositories) {\r
+                       repositoryChoices.addElement(repo);\r
+               }\r
        }\r
 \r
        protected SyndicatedEntryModel getSelectedSyndicatedEntry() {\r
@@ -207,4 +255,22 @@ public abstract class FeedsPanel extends JPanel {
                SyndicatedEntryModel entry = getSelectedSyndicatedEntry();\r
                Utils.browse(entry.link.replace("/commit/", "/tree/"));\r
        }\r
+\r
+       protected void filterRepositories(final String repository) {\r
+               if (StringUtils.isEmpty(repository) || repository.equals(ALL)) {\r
+                       table.setRowSorter(defaultSorter);\r
+                       return;\r
+               }\r
+               final int index = SyndicatedEntryTableModel.Columns.Repository.ordinal();\r
+               RowFilter<SyndicatedEntryTableModel, Object> containsFilter = new RowFilter<SyndicatedEntryTableModel, Object>() {\r
+                       public boolean include(\r
+                                       Entry<? extends SyndicatedEntryTableModel, ? extends Object> entry) {\r
+                               return entry.getStringValue(index).equalsIgnoreCase(repository);\r
+                       }\r
+               };\r
+               TableRowSorter<SyndicatedEntryTableModel> sorter = new TableRowSorter<SyndicatedEntryTableModel>(\r
+                               tableModel);\r
+               sorter.setRowFilter(containsFilter);\r
+               table.setRowSorter(sorter);\r
+       }\r
 }\r
index f334d42a4e3c9149a5988454c30a7f388895c0bd..8ba2e00a77f41c1b10ffc3e30023f16af659cb3e 100644 (file)
@@ -18,7 +18,9 @@ package com.gitblit.client;
 import java.awt.Color;\r
 import java.awt.Component;\r
 \r
+import javax.swing.JList;\r
 import javax.swing.JTable;\r
+import javax.swing.ListCellRenderer;\r
 import javax.swing.table.DefaultTableCellRenderer;\r
 \r
 /**\r
@@ -28,14 +30,16 @@ import javax.swing.table.DefaultTableCellRenderer;
  * @author James Moger\r
  * \r
  */\r
-public class NameRenderer extends DefaultTableCellRenderer {\r
+public class NameRenderer extends DefaultTableCellRenderer implements ListCellRenderer {\r
 \r
        private static final long serialVersionUID = 1L;\r
 \r
+       private static final Color CORNFLOWER = new Color(0x00, 0x69, 0xD6);\r
+\r
        private final String groupSpan;\r
 \r
        public NameRenderer() {\r
-               this(Color.gray, new Color(0x00, 0x69, 0xD6));\r
+               this(Color.gray, CORNFLOWER);\r
        }\r
 \r
        private NameRenderer(Color group, Color repo) {\r
@@ -55,6 +59,25 @@ public class NameRenderer extends DefaultTableCellRenderer {
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,\r
                        boolean hasFocus, int row, int column) {\r
                super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);\r
+               setValue(value, isSelected);\r
+               return this;\r
+       }\r
+\r
+       @Override\r
+       public Component getListCellRendererComponent(JList list, Object value, int index,\r
+                       boolean isSelected, boolean cellHasFocus) {\r
+               setValue(value, isSelected);\r
+               if (isSelected) {\r
+                       setBackground(list.getSelectionBackground());\r
+                       setForeground(list.getSelectionForeground());\r
+               } else {\r
+                       setBackground(list.getBackground());\r
+                       setForeground(CORNFLOWER);\r
+               }\r
+               return this;\r
+       }\r
+\r
+       private void setValue(Object value, boolean isSelected) {\r
                String name = value.toString();\r
                int lastSlash = name.lastIndexOf('/');\r
                if (!isSelected && lastSlash > -1) {\r
@@ -64,6 +87,5 @@ public class NameRenderer extends DefaultTableCellRenderer {
                } else {\r
                        this.setText(name);\r
                }\r
-               return this;\r
        }\r
 }
\ No newline at end of file
index 9aedeb4cdfbd03b12b2cf075424025f942f0745f..8987c269b50667d6e3cf5a1571d1507104c67e05 100644 (file)
@@ -126,7 +126,7 @@ public class SyndicationUtils {
                        parameters.add("h=" + branch);\r
                }\r
                StringBuilder sb = new StringBuilder();\r
-               sb.append(MessageFormat.format("{0}/feed/{1}", url, repository));\r
+               sb.append(MessageFormat.format("{0}" + Constants.SYNDICATION_PATH + "{1}", url, repository));\r
                if (parameters.size() > 0) {\r
                        boolean first = true;\r
                        for (String parameter : parameters) {\r