diff options
author | James Moger <james.moger@gitblit.com> | 2011-11-07 22:12:38 -0500 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2011-11-07 22:12:38 -0500 |
commit | ee458f82b8502e238a96e6582e910cb366059ead (patch) | |
tree | 4d18f0cbc1c77611ca48851a79495388a5186a65 | |
parent | 143fc9d357c174a56340052618d481617686fc72 (diff) | |
download | gitblit-ee458f82b8502e238a96e6582e910cb366059ead.tar.gz gitblit-ee458f82b8502e238a96e6582e910cb366059ead.zip |
Log feature based on Search dialog. Renamed some classes.
-rw-r--r-- | build.xml | 1 | ||||
-rw-r--r-- | src/com/gitblit/SyndicationServlet.java | 6 | ||||
-rw-r--r-- | src/com/gitblit/client/FeedEntryTableModel.java (renamed from src/com/gitblit/client/SyndicatedEntryTableModel.java) | 18 | ||||
-rw-r--r-- | src/com/gitblit/client/FeedsPanel.java | 52 | ||||
-rw-r--r-- | src/com/gitblit/client/GitblitClient.java | 22 | ||||
-rw-r--r-- | src/com/gitblit/client/MessageRenderer.java | 4 | ||||
-rw-r--r-- | src/com/gitblit/client/RepositoriesPanel.java | 28 | ||||
-rw-r--r-- | src/com/gitblit/client/SearchDialog.java | 106 | ||||
-rw-r--r-- | src/com/gitblit/models/FeedEntryModel.java (renamed from src/com/gitblit/models/SyndicatedEntryModel.java) | 10 | ||||
-rw-r--r-- | src/com/gitblit/utils/SyndicationUtils.java | 16 | ||||
-rw-r--r-- | tests/com/gitblit/tests/SyndicationUtilsTest.java | 12 |
11 files changed, 156 insertions, 119 deletions
@@ -455,6 +455,7 @@ <resource file="${basedir}/resources/feed_16x16.png" />
<resource file="${basedir}/resources/bullet_feed.png" />
<resource file="${basedir}/resources/search-icon.png" />
+ <resource file="${basedir}/resources/commit_changes_16x16.png" />
<resource file="${basedir}/resources/blank.png" />
<resource file="${basedir}/src/com/gitblit/wicket/GitBlitWebApp.properties" />
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<ObjectId, List<RefModel>> allRefs = JGitUtils.getAllRefs(repository);
- List<SyndicatedEntryModel> entries = new ArrayList<SyndicatedEntryModel>();
+ List<FeedEntryModel> entries = new ArrayList<FeedEntryModel>();
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 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<SyndicatedEntryModel> entries;
+ List<FeedEntryModel> entries;
enum Columns {
Date, Repository, Branch, Author, Message;
@@ -45,11 +45,11 @@ public class SyndicatedEntryTableModel extends AbstractTableModel { }
}
- public SyndicatedEntryTableModel() {
- this.entries = new ArrayList<SyndicatedEntryModel>();
+ public FeedEntryTableModel() {
+ this.entries = new ArrayList<FeedEntryModel>();
}
- public void setEntries(List<SyndicatedEntryModel> entries) {
+ public void setEntries(List<FeedEntryModel> 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<SyndicatedEntryTableModel> defaultSorter;
+ private TableRowSorter<FeedEntryTableModel> 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<SyndicatedEntryTableModel>(tableModel);
- String name = table.getColumnName(SyndicatedEntryTableModel.Columns.Author.ordinal());
+ defaultSorter = new TableRowSorter<FeedEntryTableModel>(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<String> uniqueRepositories = new HashSet<String>();
- 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<String> uniqueAuthors = new HashSet<String>();
- 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<SyndicatedEntryTableModel, Object> containsFilter;
+ final int repositoryIndex = FeedEntryTableModel.Columns.Repository.ordinal();
+ final int authorIndex = FeedEntryTableModel.Columns.Author.ordinal();
+ RowFilter<FeedEntryTableModel, Object> containsFilter;
if (repository.equals(ALL)) {
// author filter
- containsFilter = new RowFilter<SyndicatedEntryTableModel, Object>() {
+ containsFilter = new RowFilter<FeedEntryTableModel, Object>() {
public boolean include(
- Entry<? extends SyndicatedEntryTableModel, ? extends Object> entry) {
+ Entry<? extends FeedEntryTableModel, ? extends Object> entry) {
return entry.getStringValue(authorIndex).equalsIgnoreCase(author);
}
};
} else if (author.equals(ALL)) {
// repository filter
- containsFilter = new RowFilter<SyndicatedEntryTableModel, Object>() {
+ containsFilter = new RowFilter<FeedEntryTableModel, Object>() {
public boolean include(
- Entry<? extends SyndicatedEntryTableModel, ? extends Object> entry) {
+ Entry<? extends FeedEntryTableModel, ? extends Object> entry) {
return entry.getStringValue(repositoryIndex).equalsIgnoreCase(repository);
}
};
} else {
// repository-author filter
- containsFilter = new RowFilter<SyndicatedEntryTableModel, Object>() {
+ containsFilter = new RowFilter<FeedEntryTableModel, Object>() {
public boolean include(
- Entry<? extends SyndicatedEntryTableModel, ? extends Object> entry) {
+ Entry<? extends FeedEntryTableModel, ? extends Object> entry) {
boolean authorMatch = entry.getStringValue(authorIndex)
.equalsIgnoreCase(author);
boolean repositoryMatch = entry.getStringValue(repositoryIndex)
@@ -398,7 +398,7 @@ public abstract class FeedsPanel extends JPanel { }
};
}
- TableRowSorter<SyndicatedEntryTableModel> sorter = new TableRowSorter<SyndicatedEntryTableModel>(
+ TableRowSorter<FeedEntryTableModel> sorter = new TableRowSorter<FeedEntryTableModel>(
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<FeedModel> availableFeeds;
- private final List<SyndicatedEntryModel> syndicatedEntries;
+ private final List<FeedEntryModel> syndicatedEntries;
private final Set<String> subscribedRepositories;
@@ -93,7 +93,7 @@ public class GitblitClient implements Serializable { this.allRepositories = new ArrayList<RepositoryModel>();
this.federationRegistrations = new ArrayList<FederationModel>();
this.availableFeeds = new ArrayList<FeedModel>();
- this.syndicatedEntries = new ArrayList<SyndicatedEntryModel>();
+ this.syndicatedEntries = new ArrayList<FeedEntryModel>();
this.subscribedRepositories = new HashSet<String>();
}
@@ -247,13 +247,13 @@ public class GitblitClient implements Serializable { return availableFeeds;
}
- public List<SyndicatedEntryModel> refreshSubscribedFeeds(int page) throws IOException {
- Set<SyndicatedEntryModel> allEntries = new HashSet<SyndicatedEntryModel>();
+ public List<FeedEntryModel> refreshSubscribedFeeds(int page) throws IOException {
+ Set<FeedEntryModel> allEntries = new HashSet<FeedEntryModel>();
if (reg.feeds.size() > 0) {
for (FeedModel feed : reg.feeds) {
feed.lastRefreshDate = feed.currentRefreshDate;
feed.currentRefreshDate = new Date();
- List<SyndicatedEntryModel> entries = SyndicationUtils.readFeed(url,
+ List<FeedEntryModel> 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<SyndicatedEntryModel> getSyndicatedEntries() {
+ public List<FeedEntryModel> getSyndicatedEntries() {
return syndicatedEntries;
}
- public List<SyndicatedEntryModel> search(String repository, String branch, String fragment,
+ public List<FeedEntryModel> log(String repository, String branch, int numberOfEntries,
+ int page) throws IOException {
+ return SyndicationUtils.readFeed(url, repository, branch, numberOfEntries, page, account,
+ password);
+ }
+
+ public List<FeedEntryModel> 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<List<SyndicatedEntryModel>, Void> worker = new SwingWorker<List<SyndicatedEntryModel>, Void>() {
+ SwingWorker<List<FeedEntryModel>, Void> worker = new SwingWorker<List<FeedEntryModel>, Void>() {
@Override
- protected List<SyndicatedEntryModel> doInBackground() throws IOException {
- return gitblit
- .search(repository, branch, fragment, searchType, maxEntryCount, page);
+ protected List<FeedEntryModel> 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<SyndicatedEntryModel> results = get();
- updateTable(true, fragment, results);
+ List<FeedEntryModel> 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<SyndicatedEntryModel> entries) {
+ protected void updateTable(boolean pack, String text, List<FeedEntryModel> 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 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<SyndicatedEntryModel> {
+public class FeedEntryModel implements Serializable, Comparable<FeedEntryModel> {
public String repository;
public String branch;
@@ -38,11 +38,11 @@ public class SyndicatedEntryModel implements Serializable, Comparable<Syndicated private static final long serialVersionUID = 1L;
- public SyndicatedEntryModel() {
+ public FeedEntryModel() {
}
@Override
- public int compareTo(SyndicatedEntryModel o) {
+ public int compareTo(FeedEntryModel o) {
return o.published.compareTo(published);
}
@@ -53,7 +53,7 @@ public class SyndicatedEntryModel implements Serializable, Comparable<Syndicated @Override
public boolean equals(Object o) {
- if (o instanceof SyndicatedEntryModel) {
+ if (o instanceof FeedEntryModel) {
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<SyndicatedEntryModel> entryModels, OutputStream os)
+ String repository, List<FeedEntryModel> entryModels, OutputStream os)
throws IOException, FeedException {
SyndFeed feed = new SyndFeedImpl();
@@ -79,7 +79,7 @@ public class SyndicationUtils { feed.setImage(image);
List<SyndEntry> entries = new ArrayList<SyndEntry>();
- 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<SyndicatedEntryModel> readFeed(String url, String repository, String branch,
+ public static List<FeedEntryModel> readFeed(String url, String repository, String branch,
int numberOfEntries, int page, String username, char[] password) throws IOException {
// build feed url
List<String> parameters = new ArrayList<String>();
@@ -167,7 +167,7 @@ public class SyndicationUtils { * @return a list of SyndicationModel entries
* @throws {@link IOException}
*/
- public static List<SyndicatedEntryModel> readSearchFeed(String url, String repository,
+ public static List<FeedEntryModel> 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<SyndicatedEntryModel> readFeed(String url, List<String> parameters,
+ private static List<FeedEntryModel> readFeed(String url, List<String> 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<SyndicatedEntryModel> entries = new ArrayList<SyndicatedEntryModel>();
+ List<FeedEntryModel> entries = new ArrayList<FeedEntryModel>();
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<SyndicatedEntryModel> entries = new ArrayList<SyndicatedEntryModel>();
+ List<FeedEntryModel> entries = new ArrayList<FeedEntryModel>();
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<String> links = new HashSet<String>();
for (int i = 0; i < 2; i++) {
- List<SyndicatedEntryModel> feed = SyndicationUtils.readFeed(GitBlitSuite.url,
+ List<FeedEntryModel> 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<SyndicatedEntryModel> feed = SyndicationUtils.readSearchFeed(GitBlitSuite.url,
+ List<FeedEntryModel> feed = SyndicationUtils.readSearchFeed(GitBlitSuite.url,
"ticgit.git", null, "test", null, 5, 0, GitBlitSuite.account,
GitBlitSuite.password.toCharArray());
assertTrue(feed != null);
|