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

index 2f4391dae1e2e43268dab4a4fcc53909e331608b..0492b95ac4ef14420ed74dd5e584971e51390c94 100644 (file)
@@ -24,6 +24,7 @@ import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;\r
 import java.io.IOException;\r
 import java.util.ArrayList;\r
+import java.util.Collections;\r
 import java.util.HashSet;\r
 import java.util.List;\r
 import java.util.Set;\r
@@ -58,7 +59,7 @@ public abstract class FeedsPanel extends JPanel {
 \r
        private final GitblitClient gitblit;\r
 \r
-       private final String ALL = "ALL";\r
+       private final String ALL = "*";\r
 \r
        private SyndicatedEntryTableModel tableModel;\r
 \r
@@ -70,6 +71,12 @@ public abstract class FeedsPanel extends JPanel {
 \r
        private DefaultComboBoxModel repositoryChoices;\r
 \r
+       private JComboBox repositorySelector;\r
+\r
+       private DefaultComboBoxModel authorChoices;\r
+\r
+       private JComboBox authorSelector;\r
+\r
        public FeedsPanel(GitblitClient gitblit) {\r
                super();\r
                this.gitblit = gitblit;\r
@@ -162,21 +169,28 @@ public abstract class FeedsPanel extends JPanel {
                });\r
 \r
                repositoryChoices = new DefaultComboBoxModel();\r
-               final JComboBox repositorySelector = new JComboBox(repositoryChoices);\r
+               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
+                               filterFeeds();\r
+                       }\r
+               });\r
+               authorChoices = new DefaultComboBoxModel();\r
+               authorSelector = new JComboBox(authorChoices);\r
+               authorSelector.setRenderer(nameRenderer);\r
+               authorSelector.setForeground(nameRenderer.getForeground());\r
+               authorSelector.addActionListener(new ActionListener() {\r
+                       public void actionPerformed(ActionEvent event) {\r
+                               filterFeeds();\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
+               northControls.add(new JLabel(Translation.get("gb.author")));\r
+               northControls.add(authorSelector);\r
 \r
                JPanel northPanel = new JPanel(new BorderLayout(0, Utils.MARGIN));\r
                northPanel.add(header, BorderLayout.NORTH);\r
@@ -221,10 +235,15 @@ public abstract class FeedsPanel extends JPanel {
                if (pack) {\r
                        Utils.packColumns(table, Utils.MARGIN);\r
                }\r
+               // determine unique repositories and authors\r
                Set<String> uniqueRepositories = new HashSet<String>();\r
+               Set<String> uniqueAuthors = new HashSet<String>();\r
                for (SyndicatedEntryModel entry : tableModel.entries) {\r
                        uniqueRepositories.add(entry.repository);\r
+                       uniqueAuthors.add(entry.author);\r
                }\r
+\r
+               // repositories\r
                List<String> sortedRespositories = new ArrayList<String>(uniqueRepositories);\r
                StringUtils.sortRepositorynames(sortedRespositories);\r
                repositoryChoices.removeAllElements();\r
@@ -232,6 +251,15 @@ public abstract class FeedsPanel extends JPanel {
                for (String repo : sortedRespositories) {\r
                        repositoryChoices.addElement(repo);\r
                }\r
+\r
+               // authors\r
+               List<String> sortedAuthors = new ArrayList<String>(uniqueAuthors);\r
+               Collections.sort(sortedAuthors);\r
+               authorChoices.removeAllElements();\r
+               authorChoices.addElement(ALL);\r
+               for (String author : sortedAuthors) {\r
+                       authorChoices.addElement(author);\r
+               }\r
        }\r
 \r
        protected SyndicatedEntryModel getSelectedSyndicatedEntry() {\r
@@ -256,18 +284,57 @@ public abstract class FeedsPanel extends JPanel {
                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
+       protected void filterFeeds() {\r
+               final String repository;\r
+               if (repositorySelector.getSelectedIndex() > -1) {\r
+                       repository = repositorySelector.getSelectedItem().toString();\r
+               } else {\r
+                       repository = ALL;\r
+               }\r
+\r
+               final String author;\r
+               if (authorSelector.getSelectedIndex() > -1) {\r
+                       author = authorSelector.getSelectedItem().toString();\r
+               } else {\r
+                       author = ALL;\r
+               }\r
+\r
+               if (repository.equals(ALL) && author.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
+               final int repositoryIndex = SyndicatedEntryTableModel.Columns.Repository.ordinal();\r
+               final int authorIndex = SyndicatedEntryTableModel.Columns.Author.ordinal();\r
+               RowFilter<SyndicatedEntryTableModel, Object> containsFilter;\r
+               if (repository.equals(ALL)) {\r
+                       // author filter\r
+                       containsFilter = new RowFilter<SyndicatedEntryTableModel, Object>() {\r
+                               public boolean include(\r
+                                               Entry<? extends SyndicatedEntryTableModel, ? extends Object> entry) {\r
+                                       return entry.getStringValue(authorIndex).equalsIgnoreCase(author);\r
+                               }\r
+                       };\r
+               } else if (author.equals(ALL)) {\r
+                       // repository filter\r
+                       containsFilter = new RowFilter<SyndicatedEntryTableModel, Object>() {\r
+                               public boolean include(\r
+                                               Entry<? extends SyndicatedEntryTableModel, ? extends Object> entry) {\r
+                                       return entry.getStringValue(repositoryIndex).equalsIgnoreCase(repository);\r
+                               }\r
+                       };\r
+               } else {\r
+                       // repository-author filter\r
+                       containsFilter = new RowFilter<SyndicatedEntryTableModel, Object>() {\r
+                               public boolean include(\r
+                                               Entry<? extends SyndicatedEntryTableModel, ? extends Object> entry) {\r
+                                       boolean authorMatch = entry.getStringValue(authorIndex)\r
+                                                       .equalsIgnoreCase(author);\r
+                                       boolean repositoryMatch = entry.getStringValue(repositoryIndex)\r
+                                                       .equalsIgnoreCase(repository);\r
+                                       return authorMatch && repositoryMatch;\r
+                               }\r
+                       };\r
+               }\r
                TableRowSorter<SyndicatedEntryTableModel> sorter = new TableRowSorter<SyndicatedEntryTableModel>(\r
                                tableModel);\r
                sorter.setRowFilter(containsFilter);\r