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
\r
private final GitblitClient gitblit;\r
\r
- private final String ALL = "ALL";\r
+ private final String ALL = "*";\r
\r
private SyndicatedEntryTableModel tableModel;\r
\r
\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
});\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
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
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
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