From ee458f82b8502e238a96e6582e910cb366059ead Mon Sep 17 00:00:00 2001 From: James Moger Date: Mon, 7 Nov 2011 22:12:38 -0500 Subject: [PATCH] Log feature based on Search dialog. Renamed some classes. --- build.xml | 1 + src/com/gitblit/SyndicationServlet.java | 6 +- ...bleModel.java => FeedEntryTableModel.java} | 18 +-- src/com/gitblit/client/FeedsPanel.java | 52 ++++----- src/com/gitblit/client/GitblitClient.java | 22 ++-- src/com/gitblit/client/MessageRenderer.java | 4 +- src/com/gitblit/client/RepositoriesPanel.java | 28 +++-- src/com/gitblit/client/SearchDialog.java | 106 ++++++++++-------- ...tedEntryModel.java => FeedEntryModel.java} | 10 +- src/com/gitblit/utils/SyndicationUtils.java | 16 +-- .../gitblit/tests/SyndicationUtilsTest.java | 12 +- 11 files changed, 156 insertions(+), 119 deletions(-) rename src/com/gitblit/client/{SyndicatedEntryTableModel.java => FeedEntryTableModel.java} (81%) rename src/com/gitblit/models/{SyndicatedEntryModel.java => FeedEntryModel.java} (77%) diff --git a/build.xml b/build.xml index 085bc280..a896cb27 100644 --- a/build.xml +++ b/build.xml @@ -455,6 +455,7 @@ + diff --git a/src/com/gitblit/SyndicationServlet.java b/src/com/gitblit/SyndicationServlet.java index 39e37ca9..66415d10 100644 --- a/src/com/gitblit/SyndicationServlet.java +++ b/src/com/gitblit/SyndicationServlet.java @@ -30,7 +30,7 @@ import org.slf4j.LoggerFactory; import com.gitblit.models.RefModel; import com.gitblit.models.RepositoryModel; -import com.gitblit.models.SyndicatedEntryModel; +import com.gitblit.models.FeedEntryModel; import com.gitblit.utils.HttpUtils; import com.gitblit.utils.JGitUtils; import com.gitblit.utils.StringUtils; @@ -169,7 +169,7 @@ public class SyndicationServlet extends HttpServlet { offset, length); } Map> allRefs = JGitUtils.getAllRefs(repository); - List entries = new ArrayList(); + List entries = new ArrayList(); boolean mountParameters = GitBlit.getBoolean(Keys.web.mountParameters, true); String urlPattern; @@ -183,7 +183,7 @@ public class SyndicationServlet extends HttpServlet { String gitblitUrl = HttpUtils.getGitblitURL(request); // convert RevCommit to SyndicatedEntryModel for (RevCommit commit : commits) { - SyndicatedEntryModel entry = new SyndicatedEntryModel(); + FeedEntryModel entry = new FeedEntryModel(); entry.title = commit.getShortMessage(); entry.author = commit.getAuthorIdent().getName(); entry.link = MessageFormat.format(urlPattern, gitblitUrl, diff --git a/src/com/gitblit/client/SyndicatedEntryTableModel.java b/src/com/gitblit/client/FeedEntryTableModel.java similarity index 81% rename from src/com/gitblit/client/SyndicatedEntryTableModel.java rename to src/com/gitblit/client/FeedEntryTableModel.java index 8fcdb47d..0b0ef178 100644 --- a/src/com/gitblit/client/SyndicatedEntryTableModel.java +++ b/src/com/gitblit/client/FeedEntryTableModel.java @@ -22,7 +22,7 @@ import java.util.List; import javax.swing.table.AbstractTableModel; -import com.gitblit.models.SyndicatedEntryModel; +import com.gitblit.models.FeedEntryModel; /** * Table model for a list of retrieved feed entries. @@ -30,11 +30,11 @@ import com.gitblit.models.SyndicatedEntryModel; * @author James Moger * */ -public class SyndicatedEntryTableModel extends AbstractTableModel { +public class FeedEntryTableModel extends AbstractTableModel { private static final long serialVersionUID = 1L; - List entries; + List entries; enum Columns { Date, Repository, Branch, Author, Message; @@ -45,11 +45,11 @@ public class SyndicatedEntryTableModel extends AbstractTableModel { } } - public SyndicatedEntryTableModel() { - this.entries = new ArrayList(); + public FeedEntryTableModel() { + this.entries = new ArrayList(); } - public void setEntries(List entries) { + public void setEntries(List entries) { this.entries = entries; Collections.sort(entries); } @@ -93,14 +93,14 @@ public class SyndicatedEntryTableModel extends AbstractTableModel { if (Columns.Date.ordinal() == columnIndex) { return Date.class; } else if (Columns.Message.ordinal() == columnIndex) { - return SyndicatedEntryModel.class; + return FeedEntryModel.class; } return String.class; } @Override public Object getValueAt(int rowIndex, int columnIndex) { - SyndicatedEntryModel entry = entries.get(rowIndex); + FeedEntryModel entry = entries.get(rowIndex); Columns col = Columns.values()[columnIndex]; switch (col) { case Date: @@ -117,7 +117,7 @@ public class SyndicatedEntryTableModel extends AbstractTableModel { return null; } - public SyndicatedEntryModel get(int modelRow) { + public FeedEntryModel get(int modelRow) { return entries.get(modelRow); } } diff --git a/src/com/gitblit/client/FeedsPanel.java b/src/com/gitblit/client/FeedsPanel.java index 97764db7..9f8de8c3 100644 --- a/src/com/gitblit/client/FeedsPanel.java +++ b/src/com/gitblit/client/FeedsPanel.java @@ -43,7 +43,7 @@ import javax.swing.event.ListSelectionListener; import javax.swing.table.TableRowSorter; import com.gitblit.models.FeedModel; -import com.gitblit.models.SyndicatedEntryModel; +import com.gitblit.models.FeedEntryModel; import com.gitblit.utils.StringUtils; /** @@ -61,9 +61,9 @@ public abstract class FeedsPanel extends JPanel { private final String ALL = "*"; - private SyndicatedEntryTableModel tableModel; + private FeedEntryTableModel tableModel; - private TableRowSorter defaultSorter; + private TableRowSorter defaultSorter; private HeaderPanel header; @@ -155,20 +155,20 @@ public abstract class FeedsPanel extends JPanel { controls.add(viewTree); NameRenderer nameRenderer = new NameRenderer(); - tableModel = new SyndicatedEntryTableModel(); + tableModel = new FeedEntryTableModel(); header = new HeaderPanel(Translation.get("gb.activity"), "feed_16x16.png"); table = Utils.newTable(tableModel, Utils.DATE_FORMAT); - defaultSorter = new TableRowSorter(tableModel); - String name = table.getColumnName(SyndicatedEntryTableModel.Columns.Author.ordinal()); + defaultSorter = new TableRowSorter(tableModel); + String name = table.getColumnName(FeedEntryTableModel.Columns.Author.ordinal()); table.setRowHeight(nameRenderer.getFont().getSize() + 8); table.getColumn(name).setCellRenderer(nameRenderer); - name = table.getColumnName(SyndicatedEntryTableModel.Columns.Repository.ordinal()); + name = table.getColumnName(FeedEntryTableModel.Columns.Repository.ordinal()); table.getColumn(name).setCellRenderer(nameRenderer); - name = table.getColumnName(SyndicatedEntryTableModel.Columns.Branch.ordinal()); + name = table.getColumnName(FeedEntryTableModel.Columns.Branch.ordinal()); table.getColumn(name).setCellRenderer(new BranchRenderer()); - name = table.getColumnName(SyndicatedEntryTableModel.Columns.Message.ordinal()); + name = table.getColumnName(FeedEntryTableModel.Columns.Message.ordinal()); table.getColumn(name).setCellRenderer(new MessageRenderer(gitblit)); table.addMouseListener(new MouseAdapter() { @@ -283,7 +283,7 @@ public abstract class FeedsPanel extends JPanel { if (page == 0) { // determine unique repositories Set uniqueRepositories = new HashSet(); - for (SyndicatedEntryModel entry : tableModel.entries) { + for (FeedEntryModel entry : tableModel.entries) { uniqueRepositories.add(entry.repository); } @@ -310,7 +310,7 @@ public abstract class FeedsPanel extends JPanel { // determine unique repositories and authors Set uniqueAuthors = new HashSet(); - for (SyndicatedEntryModel entry : tableModel.entries) { + for (FeedEntryModel entry : tableModel.entries) { if (repository.equals(ALL) || entry.repository.equalsIgnoreCase(repository)) { uniqueAuthors.add(entry.author); } @@ -325,25 +325,25 @@ public abstract class FeedsPanel extends JPanel { } } - protected SyndicatedEntryModel getSelectedSyndicatedEntry() { + protected FeedEntryModel getSelectedSyndicatedEntry() { int viewRow = table.getSelectedRow(); int modelRow = table.convertRowIndexToModel(viewRow); - SyndicatedEntryModel entry = tableModel.get(modelRow); + FeedEntryModel entry = tableModel.get(modelRow); return entry; } protected void viewCommit() { - SyndicatedEntryModel entry = getSelectedSyndicatedEntry(); + FeedEntryModel entry = getSelectedSyndicatedEntry(); Utils.browse(entry.link); } protected void viewCommitDiff() { - SyndicatedEntryModel entry = getSelectedSyndicatedEntry(); + FeedEntryModel entry = getSelectedSyndicatedEntry(); Utils.browse(entry.link.replace("/commit/", "/commitdiff/")); } protected void viewTree() { - SyndicatedEntryModel entry = getSelectedSyndicatedEntry(); + FeedEntryModel entry = getSelectedSyndicatedEntry(); Utils.browse(entry.link.replace("/commit/", "/tree/")); } @@ -366,30 +366,30 @@ public abstract class FeedsPanel extends JPanel { table.setRowSorter(defaultSorter); return; } - final int repositoryIndex = SyndicatedEntryTableModel.Columns.Repository.ordinal(); - final int authorIndex = SyndicatedEntryTableModel.Columns.Author.ordinal(); - RowFilter containsFilter; + final int repositoryIndex = FeedEntryTableModel.Columns.Repository.ordinal(); + final int authorIndex = FeedEntryTableModel.Columns.Author.ordinal(); + RowFilter containsFilter; if (repository.equals(ALL)) { // author filter - containsFilter = new RowFilter() { + containsFilter = new RowFilter() { public boolean include( - Entry entry) { + Entry entry) { return entry.getStringValue(authorIndex).equalsIgnoreCase(author); } }; } else if (author.equals(ALL)) { // repository filter - containsFilter = new RowFilter() { + containsFilter = new RowFilter() { public boolean include( - Entry entry) { + Entry entry) { return entry.getStringValue(repositoryIndex).equalsIgnoreCase(repository); } }; } else { // repository-author filter - containsFilter = new RowFilter() { + containsFilter = new RowFilter() { public boolean include( - Entry entry) { + Entry entry) { boolean authorMatch = entry.getStringValue(authorIndex) .equalsIgnoreCase(author); boolean repositoryMatch = entry.getStringValue(repositoryIndex) @@ -398,7 +398,7 @@ public abstract class FeedsPanel extends JPanel { } }; } - TableRowSorter sorter = new TableRowSorter( + TableRowSorter sorter = new TableRowSorter( tableModel); sorter.setRowFilter(containsFilter); table.setRowSorter(sorter); diff --git a/src/com/gitblit/client/GitblitClient.java b/src/com/gitblit/client/GitblitClient.java index 588b6d80..c590dccc 100644 --- a/src/com/gitblit/client/GitblitClient.java +++ b/src/com/gitblit/client/GitblitClient.java @@ -36,7 +36,7 @@ import com.gitblit.models.FeedModel; import com.gitblit.models.RepositoryModel; import com.gitblit.models.ServerSettings; import com.gitblit.models.ServerStatus; -import com.gitblit.models.SyndicatedEntryModel; +import com.gitblit.models.FeedEntryModel; import com.gitblit.models.UserModel; import com.gitblit.utils.RpcUtils; import com.gitblit.utils.StringUtils; @@ -77,7 +77,7 @@ public class GitblitClient implements Serializable { private final List availableFeeds; - private final List syndicatedEntries; + private final List syndicatedEntries; private final Set subscribedRepositories; @@ -93,7 +93,7 @@ public class GitblitClient implements Serializable { this.allRepositories = new ArrayList(); this.federationRegistrations = new ArrayList(); this.availableFeeds = new ArrayList(); - this.syndicatedEntries = new ArrayList(); + this.syndicatedEntries = new ArrayList(); this.subscribedRepositories = new HashSet(); } @@ -247,13 +247,13 @@ public class GitblitClient implements Serializable { return availableFeeds; } - public List refreshSubscribedFeeds(int page) throws IOException { - Set allEntries = new HashSet(); + public List refreshSubscribedFeeds(int page) throws IOException { + Set allEntries = new HashSet(); if (reg.feeds.size() > 0) { for (FeedModel feed : reg.feeds) { feed.lastRefreshDate = feed.currentRefreshDate; feed.currentRefreshDate = new Date(); - List entries = SyndicationUtils.readFeed(url, + List entries = SyndicationUtils.readFeed(url, feed.repository, feed.branch, -1, page, account, password); allEntries.addAll(entries); } @@ -297,11 +297,17 @@ public class GitblitClient implements Serializable { return subscribedRepositories.contains(repository.name.toLowerCase()); } - public List getSyndicatedEntries() { + public List getSyndicatedEntries() { return syndicatedEntries; } - public List search(String repository, String branch, String fragment, + public List log(String repository, String branch, int numberOfEntries, + int page) throws IOException { + return SyndicationUtils.readFeed(url, repository, branch, numberOfEntries, page, account, + password); + } + + public List search(String repository, String branch, String fragment, Constants.SearchType type, int numberOfEntries, int page) throws IOException { return SyndicationUtils.readSearchFeed(url, repository, branch, fragment, type, numberOfEntries, page, account, password); diff --git a/src/com/gitblit/client/MessageRenderer.java b/src/com/gitblit/client/MessageRenderer.java index 3629e21d..9769c196 100644 --- a/src/com/gitblit/client/MessageRenderer.java +++ b/src/com/gitblit/client/MessageRenderer.java @@ -28,7 +28,7 @@ import javax.swing.border.Border; import javax.swing.border.LineBorder; import javax.swing.table.TableCellRenderer; -import com.gitblit.models.SyndicatedEntryModel; +import com.gitblit.models.FeedEntryModel; /** * Message renderer displays the short log message and then any refs in a style @@ -81,7 +81,7 @@ public class MessageRenderer extends JPanel implements TableCellRenderer, Serial if (value == null) { return this; } - SyndicatedEntryModel entry = (SyndicatedEntryModel) value; + FeedEntryModel entry = (FeedEntryModel) value; if (gitblit == null) { // no gitblit client, just display message diff --git a/src/com/gitblit/client/RepositoriesPanel.java b/src/com/gitblit/client/RepositoriesPanel.java index 3e156e97..70ff6cfb 100644 --- a/src/com/gitblit/client/RepositoriesPanel.java +++ b/src/com/gitblit/client/RepositoriesPanel.java @@ -134,12 +134,21 @@ public abstract class RepositoriesPanel extends JPanel { } }); + final JButton logRepository = new JButton(Translation.get("gb.log") + "..."); + logRepository.setEnabled(false); + logRepository.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + RepositoryModel model = getSelectedRepositories().get(0); + showSearchDialog(false, model); + } + }); + final JButton searchRepository = new JButton(Translation.get("gb.search") + "..."); searchRepository.setEnabled(false); searchRepository.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { RepositoryModel model = getSelectedRepositories().get(0); - searchRepository(model); + showSearchDialog(true, model); } }); @@ -173,18 +182,20 @@ public abstract class RepositoriesPanel extends JPanel { return; } boolean singleSelection = table.getSelectedRowCount() == 1; - boolean selected = table.getSelectedRow() > -1; + boolean selected = table.getSelectedRow() > -1; if (singleSelection) { RepositoryModel repository = getSelectedRepositories().get(0); browseRepository.setEnabled(repository.hasCommits); + logRepository.setEnabled(repository.hasCommits); searchRepository.setEnabled(repository.hasCommits); subscribeRepository.setEnabled(repository.hasCommits); } else { browseRepository.setEnabled(false); + logRepository.setEnabled(false); searchRepository.setEnabled(false); subscribeRepository.setEnabled(false); } - delRepository.setEnabled(selected); + delRepository.setEnabled(selected); if (selected) { int viewRow = table.getSelectedRow(); int modelRow = table.convertRowIndexToModel(viewRow); @@ -233,6 +244,7 @@ public abstract class RepositoriesPanel extends JPanel { repositoryControls.add(editRepository); repositoryControls.add(delRepository); repositoryControls.add(subscribeRepository); + repositoryControls.add(logRepository); repositoryControls.add(searchRepository); setLayout(new BorderLayout(Utils.MARGIN, Utils.MARGIN)); @@ -467,12 +479,12 @@ public abstract class RepositoriesPanel extends JPanel { } } - protected void searchRepository(final RepositoryModel repository) { - SearchDialog searchDialog = new SearchDialog(gitblit); + private void showSearchDialog(boolean isSearch, final RepositoryModel repository) { + final SearchDialog dialog = new SearchDialog(gitblit, isSearch); if (repository != null) { - searchDialog.selectRepository(repository); + dialog.selectRepository(repository); } - searchDialog.setLocationRelativeTo(this); - searchDialog.setVisible(true); + dialog.setLocationRelativeTo(this); + dialog.setVisible(true); } } diff --git a/src/com/gitblit/client/SearchDialog.java b/src/com/gitblit/client/SearchDialog.java index 448aaef8..8c94a5bb 100644 --- a/src/com/gitblit/client/SearchDialog.java +++ b/src/com/gitblit/client/SearchDialog.java @@ -44,7 +44,7 @@ import javax.swing.event.ListSelectionListener; import com.gitblit.Constants; import com.gitblit.models.RepositoryModel; -import com.gitblit.models.SyndicatedEntryModel; +import com.gitblit.models.FeedEntryModel; import com.gitblit.utils.StringUtils; /** @@ -58,9 +58,11 @@ public class SearchDialog extends JFrame { private static final long serialVersionUID = 1L; + private final boolean isSearch; + private final GitblitClient gitblit; - private SyndicatedEntryTableModel tableModel; + private FeedEntryTableModel tableModel; private HeaderPanel header; @@ -84,13 +86,15 @@ public class SearchDialog extends JFrame { private JButton next; - public SearchDialog(GitblitClient gitblit) { + public SearchDialog(GitblitClient gitblit, boolean isSearch) { super(); this.gitblit = gitblit; - setTitle(Translation.get("gb.search")); - setIconImage(new ImageIcon(getClass().getResource("/gitblt-favicon.png")).getImage()); + this.isSearch = isSearch; + setTitle(Translation.get(isSearch ? "gb.search" : "gb.log")); + setIconImage(new ImageIcon(getClass().getResource( + isSearch ? "/gitblt-favicon.png" : "/commit_changes_16x16.png")).getImage()); initialize(); - setSize(900, 400); + setSize(900, 550); } private void initialize() { @@ -113,7 +117,7 @@ public class SearchDialog extends JFrame { } }); - final JButton search = new JButton(Translation.get("gb.search")); + final JButton search = new JButton(Translation.get(isSearch ? "gb.search" : "gb.refresh")); search.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { search(0); @@ -150,20 +154,21 @@ public class SearchDialog extends JFrame { controls.add(viewTree); NameRenderer nameRenderer = new NameRenderer(); - tableModel = new SyndicatedEntryTableModel(); - header = new HeaderPanel(Translation.get("gb.search"), "search-icon.png"); + tableModel = new FeedEntryTableModel(); + header = new HeaderPanel(Translation.get(isSearch ? "gb.search" : "gb.log"), + isSearch ? "search-icon.png" : "commit_changes_16x16.png"); table = Utils.newTable(tableModel, Utils.DATE_FORMAT); - String name = table.getColumnName(SyndicatedEntryTableModel.Columns.Author.ordinal()); + String name = table.getColumnName(FeedEntryTableModel.Columns.Author.ordinal()); table.setRowHeight(nameRenderer.getFont().getSize() + 8); table.getColumn(name).setCellRenderer(nameRenderer); - name = table.getColumnName(SyndicatedEntryTableModel.Columns.Repository.ordinal()); + name = table.getColumnName(FeedEntryTableModel.Columns.Repository.ordinal()); table.getColumn(name).setCellRenderer(nameRenderer); - name = table.getColumnName(SyndicatedEntryTableModel.Columns.Branch.ordinal()); + name = table.getColumnName(FeedEntryTableModel.Columns.Branch.ordinal()); table.getColumn(name).setCellRenderer(new BranchRenderer()); - name = table.getColumnName(SyndicatedEntryTableModel.Columns.Message.ordinal()); + name = table.getColumnName(FeedEntryTableModel.Columns.Message.ordinal()); table.getColumn(name).setCellRenderer(new MessageRenderer()); table.addMouseListener(new MouseAdapter() { @@ -220,7 +225,7 @@ public class SearchDialog extends JFrame { branchChoices = new DefaultComboBoxModel(); branchSelector = new JComboBox(branchChoices); - branchSelector.setRenderer(new BranchRenderer()); + branchSelector.setRenderer(new BranchRenderer()); searchTypeSelector = new JComboBox(Constants.SearchType.values()); searchTypeSelector.setSelectedItem(Constants.SearchType.COMMIT); @@ -240,8 +245,10 @@ public class SearchDialog extends JFrame { queryPanel.add(repositorySelector); queryPanel.add(new JLabel(Translation.get("gb.branch"))); queryPanel.add(branchSelector); - queryPanel.add(new JLabel(Translation.get("gb.type"))); - queryPanel.add(searchTypeSelector); + if (isSearch) { + queryPanel.add(new JLabel(Translation.get("gb.type"))); + queryPanel.add(searchTypeSelector); + } queryPanel.add(new JLabel(Translation.get("gb.maxHits"))); queryPanel.add(maxHitsSelector); @@ -252,9 +259,10 @@ public class SearchDialog extends JFrame { JPanel northControls = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN)); northControls.add(queryPanel, BorderLayout.WEST); - northControls.add(searchFragment, BorderLayout.CENTER); + if (isSearch) { + northControls.add(searchFragment, BorderLayout.CENTER); + } northControls.add(actionsPanel, BorderLayout.EAST); - JPanel northPanel = new JPanel(new BorderLayout(0, Utils.MARGIN)); northPanel.add(header, BorderLayout.NORTH); @@ -275,17 +283,19 @@ public class SearchDialog extends JFrame { contentPanel.add(controls, BorderLayout.SOUTH); setLayout(new BorderLayout()); add(contentPanel, BorderLayout.CENTER); - addWindowListener(new WindowAdapter() { - @Override - public void windowOpened(WindowEvent event) { - searchFragment.requestFocus(); - } + if (isSearch) { + addWindowListener(new WindowAdapter() { + @Override + public void windowOpened(WindowEvent event) { + searchFragment.requestFocus(); + } - @Override - public void windowActivated(WindowEvent event) { - searchFragment.requestFocus(); - } - }); + @Override + public void windowActivated(WindowEvent event) { + searchFragment.requestFocus(); + } + }); + } } public void selectRepository(RepositoryModel repository) { @@ -311,25 +321,33 @@ public class SearchDialog extends JFrame { .getSelectedItem().toString() : null; final Constants.SearchType searchType = (Constants.SearchType) searchTypeSelector .getSelectedItem(); - final String fragment = searchFragment.getText(); + final String fragment = isSearch ? searchFragment.getText() : null; final int maxEntryCount = maxHitsSelector.getSelectedIndex() > -1 ? ((Integer) maxHitsSelector .getSelectedItem()) : -1; - if (StringUtils.isEmpty(fragment)) { + if (isSearch && StringUtils.isEmpty(fragment)) { return; } - SwingWorker, Void> worker = new SwingWorker, Void>() { + SwingWorker, Void> worker = new SwingWorker, Void>() { @Override - protected List doInBackground() throws IOException { - return gitblit - .search(repository, branch, fragment, searchType, maxEntryCount, page); + protected List doInBackground() throws IOException { + if (isSearch) { + return gitblit.search(repository, branch, fragment, searchType, maxEntryCount, + page); + } else { + return gitblit.log(repository, branch, maxEntryCount, page); + } } @Override protected void done() { try { - List results = get(); - updateTable(true, fragment, results); + List results = get(); + if (isSearch) { + updateTable(true, fragment, results); + } else { + updateTable(true, branch == null ? "" : branch, results); + } } catch (Throwable t) { Utils.showException(SearchDialog.this, t); } @@ -338,12 +356,12 @@ public class SearchDialog extends JFrame { worker.execute(); } - protected void updateTable(boolean pack, String fragment, List entries) { + protected void updateTable(boolean pack, String text, List entries) { tableModel.entries.clear(); tableModel.entries.addAll(entries); tableModel.fireTableDataChanged(); - setTitle(Translation.get("gb.search") + ": " + fragment + " (" + entries.size() - + (page > 0 ? (", pg " + (page + 1)) : "") + ")"); + setTitle(Translation.get(isSearch ? "gb.search" : "gb.log") + ": " + text + " (" + + entries.size() + (page > 0 ? (", pg " + (page + 1)) : "") + ")"); header.setText(getTitle()); if (pack) { Utils.packColumns(table, Utils.MARGIN); @@ -356,25 +374,25 @@ public class SearchDialog extends JFrame { prev.setEnabled(page > 0); } - protected SyndicatedEntryModel getSelectedSyndicatedEntry() { + protected FeedEntryModel getSelectedSyndicatedEntry() { int viewRow = table.getSelectedRow(); int modelRow = table.convertRowIndexToModel(viewRow); - SyndicatedEntryModel entry = tableModel.get(modelRow); + FeedEntryModel entry = tableModel.get(modelRow); return entry; } protected void viewCommit() { - SyndicatedEntryModel entry = getSelectedSyndicatedEntry(); + FeedEntryModel entry = getSelectedSyndicatedEntry(); Utils.browse(entry.link); } protected void viewCommitDiff() { - SyndicatedEntryModel entry = getSelectedSyndicatedEntry(); + FeedEntryModel entry = getSelectedSyndicatedEntry(); Utils.browse(entry.link.replace("/commit/", "/commitdiff/")); } protected void viewTree() { - SyndicatedEntryModel entry = getSelectedSyndicatedEntry(); + FeedEntryModel entry = getSelectedSyndicatedEntry(); Utils.browse(entry.link.replace("/commit/", "/tree/")); } } diff --git a/src/com/gitblit/models/SyndicatedEntryModel.java b/src/com/gitblit/models/FeedEntryModel.java similarity index 77% rename from src/com/gitblit/models/SyndicatedEntryModel.java rename to src/com/gitblit/models/FeedEntryModel.java index f59418ed..e1c00c38 100644 --- a/src/com/gitblit/models/SyndicatedEntryModel.java +++ b/src/com/gitblit/models/FeedEntryModel.java @@ -20,11 +20,11 @@ import java.util.Date; import java.util.List; /** - * SyndicationEntryModel represents an entry in a syndication (RSS) feed. + * FeedEntryModel represents an entry in a syndication (RSS) feed. * * @author James Moger */ -public class SyndicatedEntryModel implements Serializable, Comparable { +public class FeedEntryModel implements Serializable, Comparable { public String repository; public String branch; @@ -38,11 +38,11 @@ public class SyndicatedEntryModel implements Serializable, Comparable entryModels, OutputStream os) + String repository, List entryModels, OutputStream os) throws IOException, FeedException { SyndFeed feed = new SyndFeedImpl(); @@ -79,7 +79,7 @@ public class SyndicationUtils { feed.setImage(image); List entries = new ArrayList(); - for (SyndicatedEntryModel entryModel : entryModels) { + for (FeedEntryModel entryModel : entryModels) { SyndEntry entry = new SyndEntryImpl(); entry.setTitle(entryModel.title); entry.setAuthor(entryModel.author); @@ -130,7 +130,7 @@ public class SyndicationUtils { * @return a list of SyndicationModel entries * @throws {@link IOException} */ - public static List readFeed(String url, String repository, String branch, + public static List readFeed(String url, String repository, String branch, int numberOfEntries, int page, String username, char[] password) throws IOException { // build feed url List parameters = new ArrayList(); @@ -167,7 +167,7 @@ public class SyndicationUtils { * @return a list of SyndicationModel entries * @throws {@link IOException} */ - public static List readSearchFeed(String url, String repository, + public static List readSearchFeed(String url, String repository, String branch, String fragment, Constants.SearchType searchType, int numberOfEntries, int page, String username, char[] password) throws IOException { // determine parameters @@ -202,7 +202,7 @@ public class SyndicationUtils { * @return a list of SyndicationModel entries * @throws {@link IOException} */ - private static List readFeed(String url, List parameters, + private static List readFeed(String url, List parameters, String repository, String branch, String username, char[] password) throws IOException { // build url StringBuilder sb = new StringBuilder(); @@ -230,10 +230,10 @@ public class SyndicationUtils { throw new GitBlitException(f); } is.close(); - List entries = new ArrayList(); + List entries = new ArrayList(); for (Object o : feed.getEntries()) { SyndEntryImpl entry = (SyndEntryImpl) o; - SyndicatedEntryModel model = new SyndicatedEntryModel(); + FeedEntryModel model = new FeedEntryModel(); model.repository = repository; model.branch = branch; model.title = entry.getTitle(); diff --git a/tests/com/gitblit/tests/SyndicationUtilsTest.java b/tests/com/gitblit/tests/SyndicationUtilsTest.java index 0746642c..0a2420f6 100644 --- a/tests/com/gitblit/tests/SyndicationUtilsTest.java +++ b/tests/com/gitblit/tests/SyndicationUtilsTest.java @@ -25,15 +25,15 @@ import java.util.Set; import junit.framework.TestCase; import com.gitblit.Constants.SearchType; -import com.gitblit.models.SyndicatedEntryModel; +import com.gitblit.models.FeedEntryModel; import com.gitblit.utils.SyndicationUtils; public class SyndicationUtilsTest extends TestCase { public void testSyndication() throws Exception { - List entries = new ArrayList(); + List entries = new ArrayList(); for (int i = 0; i < 10; i++) { - SyndicatedEntryModel entry = new SyndicatedEntryModel(); + FeedEntryModel entry = new FeedEntryModel(); entry.title = "Title " + i; entry.author = "Author " + i; entry.link = "Link " + i; @@ -61,13 +61,13 @@ public class SyndicationUtilsTest extends TestCase { public void testFeedRead() throws Exception { Set links = new HashSet(); for (int i = 0; i < 2; i++) { - List feed = SyndicationUtils.readFeed(GitBlitSuite.url, + List feed = SyndicationUtils.readFeed(GitBlitSuite.url, "ticgit.git", "master", 5, i, GitBlitSuite.account, GitBlitSuite.password.toCharArray()); assertTrue(feed != null); assertTrue(feed.size() > 0); assertEquals(5, feed.size()); - for (SyndicatedEntryModel entry : feed) { + for (FeedEntryModel entry : feed) { links.add(entry.link); } } @@ -76,7 +76,7 @@ public class SyndicationUtilsTest extends TestCase { } public void testSearchFeedRead() throws Exception { - List feed = SyndicationUtils.readSearchFeed(GitBlitSuite.url, + List feed = SyndicationUtils.readSearchFeed(GitBlitSuite.url, "ticgit.git", null, "test", null, 5, 0, GitBlitSuite.account, GitBlitSuite.password.toCharArray()); assertTrue(feed != null); -- 2.39.5