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