From: James Moger Date: Tue, 8 Nov 2011 03:12:38 +0000 (-0500) Subject: Log feature based on Search dialog. Renamed some classes. X-Git-Tag: v0.7.0~11 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ee458f82b8502e238a96e6582e910cb366059ead;p=gitblit.git Log feature based on Search dialog. Renamed some classes. --- 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/FeedEntryTableModel.java b/src/com/gitblit/client/FeedEntryTableModel.java new file mode 100644 index 00000000..0b0ef178 --- /dev/null +++ b/src/com/gitblit/client/FeedEntryTableModel.java @@ -0,0 +1,123 @@ +/* + * Copyright 2011 gitblit.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gitblit.client; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.List; + +import javax.swing.table.AbstractTableModel; + +import com.gitblit.models.FeedEntryModel; + +/** + * Table model for a list of retrieved feed entries. + * + * @author James Moger + * + */ +public class FeedEntryTableModel extends AbstractTableModel { + + private static final long serialVersionUID = 1L; + + List entries; + + enum Columns { + Date, Repository, Branch, Author, Message; + + @Override + public String toString() { + return name().replace('_', ' '); + } + } + + public FeedEntryTableModel() { + this.entries = new ArrayList(); + } + + public void setEntries(List entries) { + this.entries = entries; + Collections.sort(entries); + } + + @Override + public int getRowCount() { + return entries.size(); + } + + @Override + public int getColumnCount() { + return Columns.values().length; + } + + @Override + public String getColumnName(int column) { + Columns col = Columns.values()[column]; + switch (col) { + case Date: + return Translation.get("gb.date"); + case Repository: + return Translation.get("gb.repository"); + case Branch: + return Translation.get("gb.branch"); + case Author: + return Translation.get("gb.author"); + case Message: + return Translation.get("gb.message"); + } + return ""; + } + + /** + * Returns Object.class regardless of columnIndex. + * + * @param columnIndex + * the column being queried + * @return the Object.class + */ + public Class getColumnClass(int columnIndex) { + if (Columns.Date.ordinal() == columnIndex) { + return Date.class; + } else if (Columns.Message.ordinal() == columnIndex) { + return FeedEntryModel.class; + } + return String.class; + } + + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + FeedEntryModel entry = entries.get(rowIndex); + Columns col = Columns.values()[columnIndex]; + switch (col) { + case Date: + return entry.published; + case Repository: + return entry.repository; + case Branch: + return entry.branch; + case Author: + return entry.author; + case Message: + return entry; + } + return null; + } + + 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/client/SyndicatedEntryTableModel.java b/src/com/gitblit/client/SyndicatedEntryTableModel.java deleted file mode 100644 index 8fcdb47d..00000000 --- a/src/com/gitblit/client/SyndicatedEntryTableModel.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright 2011 gitblit.com. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.gitblit.client; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.List; - -import javax.swing.table.AbstractTableModel; - -import com.gitblit.models.SyndicatedEntryModel; - -/** - * Table model for a list of retrieved feed entries. - * - * @author James Moger - * - */ -public class SyndicatedEntryTableModel extends AbstractTableModel { - - private static final long serialVersionUID = 1L; - - List entries; - - enum Columns { - Date, Repository, Branch, Author, Message; - - @Override - public String toString() { - return name().replace('_', ' '); - } - } - - public SyndicatedEntryTableModel() { - this.entries = new ArrayList(); - } - - public void setEntries(List entries) { - this.entries = entries; - Collections.sort(entries); - } - - @Override - public int getRowCount() { - return entries.size(); - } - - @Override - public int getColumnCount() { - return Columns.values().length; - } - - @Override - public String getColumnName(int column) { - Columns col = Columns.values()[column]; - switch (col) { - case Date: - return Translation.get("gb.date"); - case Repository: - return Translation.get("gb.repository"); - case Branch: - return Translation.get("gb.branch"); - case Author: - return Translation.get("gb.author"); - case Message: - return Translation.get("gb.message"); - } - return ""; - } - - /** - * Returns Object.class regardless of columnIndex. - * - * @param columnIndex - * the column being queried - * @return the Object.class - */ - public Class getColumnClass(int columnIndex) { - if (Columns.Date.ordinal() == columnIndex) { - return Date.class; - } else if (Columns.Message.ordinal() == columnIndex) { - return SyndicatedEntryModel.class; - } - return String.class; - } - - @Override - public Object getValueAt(int rowIndex, int columnIndex) { - SyndicatedEntryModel entry = entries.get(rowIndex); - Columns col = Columns.values()[columnIndex]; - switch (col) { - case Date: - return entry.published; - case Repository: - return entry.repository; - case Branch: - return entry.branch; - case Author: - return entry.author; - case Message: - return entry; - } - return null; - } - - public SyndicatedEntryModel get(int modelRow) { - return entries.get(modelRow); - } -} diff --git a/src/com/gitblit/models/FeedEntryModel.java b/src/com/gitblit/models/FeedEntryModel.java new file mode 100644 index 00000000..e1c00c38 --- /dev/null +++ b/src/com/gitblit/models/FeedEntryModel.java @@ -0,0 +1,61 @@ +/* + * Copyright 2011 gitblit.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gitblit.models; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +/** + * FeedEntryModel represents an entry in a syndication (RSS) feed. + * + * @author James Moger + */ +public class FeedEntryModel implements Serializable, Comparable { + + public String repository; + public String branch; + public String title; + public String author; + public Date published; + public String link; + public String content; + public String contentType; + public List tags; + + private static final long serialVersionUID = 1L; + + public FeedEntryModel() { + } + + @Override + public int compareTo(FeedEntryModel o) { + return o.published.compareTo(published); + } + + @Override + public int hashCode() { + return link.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (o instanceof FeedEntryModel) { + return hashCode() == o.hashCode(); + } + return false; + } +} diff --git a/src/com/gitblit/models/SyndicatedEntryModel.java b/src/com/gitblit/models/SyndicatedEntryModel.java deleted file mode 100644 index f59418ed..00000000 --- a/src/com/gitblit/models/SyndicatedEntryModel.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2011 gitblit.com. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.gitblit.models; - -import java.io.Serializable; -import java.util.Date; -import java.util.List; - -/** - * SyndicationEntryModel represents an entry in a syndication (RSS) feed. - * - * @author James Moger - */ -public class SyndicatedEntryModel implements Serializable, Comparable { - - public String repository; - public String branch; - public String title; - public String author; - public Date published; - public String link; - public String content; - public String contentType; - public List tags; - - private static final long serialVersionUID = 1L; - - public SyndicatedEntryModel() { - } - - @Override - public int compareTo(SyndicatedEntryModel o) { - return o.published.compareTo(published); - } - - @Override - public int hashCode() { - return link.hashCode(); - } - - @Override - public boolean equals(Object o) { - if (o instanceof SyndicatedEntryModel) { - return hashCode() == o.hashCode(); - } - return false; - } -} diff --git a/src/com/gitblit/utils/SyndicationUtils.java b/src/com/gitblit/utils/SyndicationUtils.java index 6919cd24..6ba8d738 100644 --- a/src/com/gitblit/utils/SyndicationUtils.java +++ b/src/com/gitblit/utils/SyndicationUtils.java @@ -26,7 +26,7 @@ import java.util.List; import com.gitblit.Constants; import com.gitblit.GitBlitException; -import com.gitblit.models.SyndicatedEntryModel; +import com.gitblit.models.FeedEntryModel; import com.sun.syndication.feed.synd.SyndCategory; import com.sun.syndication.feed.synd.SyndCategoryImpl; import com.sun.syndication.feed.synd.SyndContent; @@ -63,7 +63,7 @@ public class SyndicationUtils { * @throws FeedException */ public static void toRSS(String hostUrl, String feedLink, String title, String description, - String repository, List 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);