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
\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
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
}\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
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
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
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
* @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
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
} else {\r
this.setText(name);\r
}\r
- return this;\r
}\r
}
\ No newline at end of file