--- /dev/null
+/*\r
+ * Copyright 2011 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit.client;\r
+\r
+import java.awt.Color;\r
+import java.awt.Component;\r
+import java.awt.FlowLayout;\r
+import java.io.Serializable;\r
+\r
+import javax.swing.JLabel;\r
+import javax.swing.JPanel;\r
+import javax.swing.JTable;\r
+import javax.swing.border.Border;\r
+import javax.swing.border.LineBorder;\r
+import javax.swing.table.TableCellRenderer;\r
+\r
+/**\r
+ * Branch renderer displays refs/heads and refs/remotes in a style like the\r
+ * site.\r
+ * \r
+ * @author James Moger\r
+ * \r
+ */\r
+public class BranchRenderer extends JPanel implements TableCellRenderer, Serializable {\r
+\r
+ private static final long serialVersionUID = 1L;\r
+\r
+ private static final String R_HEADS = "refs/heads/";\r
+\r
+ private static final String R_REMOTES = "refs/remotes/";\r
+\r
+ private JLabel branchLabel;\r
+\r
+ public BranchRenderer() {\r
+ super(new FlowLayout(FlowLayout.CENTER, 0, 1));\r
+ branchLabel = new JLabel();\r
+ branchLabel.setOpaque(true);\r
+ add(branchLabel);\r
+ }\r
+\r
+ public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,\r
+ boolean hasFocus, int row, int column) {\r
+ if (isSelected)\r
+ setBackground(table.getSelectionBackground());\r
+ else\r
+ setBackground(table.getBackground());\r
+\r
+ String name = value.toString();\r
+ Color bg = getBackground();\r
+ Border border = null;\r
+ if (name.startsWith(R_HEADS)) {\r
+ bg = Color.decode("#CCFFCC");\r
+ name = name.substring(R_HEADS.length());\r
+ border = new LineBorder(Color.decode("#00CC33"), 1, true);\r
+ } else if (name.startsWith(R_REMOTES)) {\r
+ bg = Color.decode("#CAC2F5");\r
+ name = name.substring(R_REMOTES.length());\r
+ border = new LineBorder(Color.decode("#6C6CBF"), 1, true);\r
+ }\r
+ branchLabel.setText(" " + name + " ");\r
+ branchLabel.setBackground(bg);\r
+ branchLabel.setBorder(border);\r
+ return this;\r
+ }\r
+}
\ No newline at end of file
\r
NameRenderer nameRenderer = new NameRenderer();\r
tableModel = new SyndicatedEntryTableModel();\r
- header = new HeaderPanel(Translation.get("gb.recentActivity"), "feed_16x16.png");\r
+ header = new HeaderPanel(Translation.get("gb.timeline"), "feed_16x16.png");\r
table = Utils.newTable(tableModel, Utils.DATE_FORMAT);\r
String name = table.getColumnName(SyndicatedEntryTableModel.Columns.Author.ordinal());\r
table.setRowHeight(nameRenderer.getFont().getSize() + 8);\r
table.getColumn(name).setCellRenderer(nameRenderer);\r
\r
name = table.getColumnName(SyndicatedEntryTableModel.Columns.Branch.ordinal());\r
- table.getColumn(name).setCellRenderer(nameRenderer);\r
+ table.getColumn(name).setCellRenderer(new BranchRenderer());\r
\r
table.addMouseListener(new MouseAdapter() {\r
public void mouseClicked(MouseEvent e) {\r
tableModel.entries.clear();\r
tableModel.entries.addAll(gitblit.getSyndicatedEntries());\r
tableModel.fireTableDataChanged();\r
- header.setText(Translation.get("gb.recentActivity") + " ("\r
+ header.setText(Translation.get("gb.timeline") + " ("\r
+ gitblit.getSyndicatedEntries().size() + ")");\r
if (pack) {\r
Utils.packColumns(table, Utils.MARGIN);\r
for (FeedModel feed : reg.feeds) {\r
feed.lastRefresh = new Date();\r
List<SyndicatedEntryModel> entries = SyndicationUtils.readFeed(url,\r
- feed.repository, feed.branch, feed.maxRetrieval, account, password);\r
+ feed.repository, feed.branch, -1, account, password);\r
allEntries.addAll(entries);\r
}\r
}\r
public boolean createRepository(RepositoryModel repository, List<String> permittedUsers)\r
throws IOException {\r
boolean success = true;\r
- success &= RpcUtils.createRepository(repository, url, account, password); \r
+ success &= RpcUtils.createRepository(repository, url, account, password);\r
if (permittedUsers.size() > 0) {\r
// if new repository has named members, set them\r
success &= RpcUtils.setRepositoryMembers(repository, permittedUsers, url, account,\r
public class GitblitManager extends JFrame implements RegistrationsDialog.RegistrationListener {\r
\r
private static final long serialVersionUID = 1L;\r
+ private static final String SERVER = "server";\r
+ private static final String FEED = "feed";\r
private final SimpleDateFormat dateFormat;\r
private JTabbedPane serverTabs;\r
private File configFile = new File(System.getProperty("user.home"), ".gitblit/config");\r
private void loadRegistrations() {\r
try {\r
StoredConfig config = getConfig();\r
- Set<String> servers = config.getSubsections("servers");\r
+ Set<String> servers = config.getSubsections(SERVER);\r
for (String server : servers) {\r
Date lastLogin = new Date(0);\r
- String date = config.getString("servers", server, "lastLogin");\r
+ String date = config.getString(SERVER, server, "lastLogin");\r
if (!StringUtils.isEmpty(date)) {\r
lastLogin = dateFormat.parse(date);\r
}\r
- String url = config.getString("servers", server, "url");\r
- String account = config.getString("servers", server, "account");\r
+ String url = config.getString(SERVER, server, "url");\r
+ String account = config.getString(SERVER, server, "account");\r
char[] password;\r
- String pw = config.getString("servers", server, "password");\r
+ String pw = config.getString(SERVER, server, "password");\r
if (StringUtils.isEmpty(pw)) {\r
password = new char[0];\r
} else {\r
password = new String(Base64.decode(pw)).toCharArray();\r
}\r
GitblitRegistration reg = new GitblitRegistration(server, url, account, password);\r
- String[] feeds = config.getStringList("servers", server, "feeds");\r
+ String[] feeds = config.getStringList(SERVER, server, FEED);\r
if (feeds != null) {\r
// deserialize the field definitions\r
for (String definition : feeds) {\r
if (!StringUtils.isEmpty(name) && !name.equals(reg.name)) {\r
// delete old registration\r
registrations.remove(name);\r
- config.unsetSection("servers", name);\r
+ config.unsetSection(SERVER, name);\r
}\r
\r
// update registration\r
- config.setString("servers", reg.name, "url", reg.url);\r
- config.setString("servers", reg.name, "account", reg.account);\r
+ config.setString(SERVER, reg.name, "url", reg.url);\r
+ config.setString(SERVER, reg.name, "account", reg.account);\r
if (reg.savePassword) {\r
- config.setString("servers", reg.name, "password",\r
+ config.setString(SERVER, reg.name, "password",\r
Base64.encodeBytes(new String(reg.password).getBytes("UTF-8")));\r
} else {\r
- config.setString("servers", reg.name, "password", "");\r
+ config.setString(SERVER, reg.name, "password", "");\r
}\r
if (reg.lastLogin != null) {\r
- config.setString("servers", reg.name, "lastLogin", dateFormat.format(reg.lastLogin));\r
+ config.setString(SERVER, reg.name, "lastLogin", dateFormat.format(reg.lastLogin));\r
}\r
// serialize the feed definitions\r
List<String> definitions = new ArrayList<String>();\r
definitions.add(feed.toString());\r
}\r
if (definitions.size() > 0) {\r
- config.setStringList("servers", reg.name, "feeds", definitions);\r
+ config.setStringList(SERVER, reg.name, FEED, definitions);\r
}\r
config.save();\r
return true;\r
try {\r
StoredConfig config = getConfig();\r
for (GitblitRegistration reg : list) {\r
- config.unsetSection("servers", reg.name);\r
+ config.unsetSection(SERVER, reg.name);\r
registrations.remove(reg.name);\r
}\r
config.save();\r
import com.gitblit.models.FeedModel;\r
\r
/**\r
- * GitblitPanel performs the login, all business logic, and contains all widgets\r
- * to represent the state of a repository for the given account credentials.\r
+ * GitblitPanel is a container for the repository, users, settings, etc panels.\r
* \r
* @author James Moger\r
* \r
\r
tabs = new JTabbedPane(JTabbedPane.BOTTOM);\r
tabs.addTab(Translation.get("gb.repositories"), createRepositoriesPanel());\r
- tabs.addTab(Translation.get("gb.recentActivity"), createFeedsPanel());\r
+ tabs.addTab(Translation.get("gb.timeline"), createFeedsPanel());\r
tabs.addTab(Translation.get("gb.users"), createUsersPanel());\r
tabs.addTab(Translation.get("gb.settings"), createSettingsPanel());\r
tabs.addTab(Translation.get("gb.status"), createStatusPanel());\r
tabs.addChangeListener(new ChangeListener() {\r
public void stateChanged(ChangeEvent e) {\r
- tabs.getSelectedComponent().requestFocus(); \r
+ tabs.getSelectedComponent().requestFocus();\r
}\r
- }); \r
+ });\r
\r
setLayout(new BorderLayout());\r
add(tabs, BorderLayout.CENTER);\r
settingsPanel.updateTable(true);\r
statusPanel.updateTable(false);\r
} else {\r
- // remove the settings tab\r
+ // remove the settings and status tab\r
String[] titles = { Translation.get("gb.settings"), Translation.get("gb.status") };\r
for (String title : titles) {\r
for (int i = 0; i < tabs.getTabCount(); i++) {\r
List<SyndicatedEntryModel> entries;\r
\r
enum Columns {\r
- Date, Repository, Branch, Author, Message;\r
+ Date, Repository,Author, Message, Branch;\r
\r
@Override\r
public String toString() {\r
package com.gitblit.models;\r
\r
import java.io.Serializable;\r
-import java.text.MessageFormat;\r
-import java.text.ParseException;\r
-import java.text.SimpleDateFormat;\r
import java.util.Date;\r
\r
import com.gitblit.utils.StringUtils;\r
\r
public String repository;\r
public String branch;\r
- public int maxRetrieval;\r
public Date lastRefresh;\r
\r
public boolean subscribed;\r
\r
public FeedModel() {\r
this("");\r
+ subscribed = false;\r
}\r
\r
public FeedModel(String definition) {\r
- maxRetrieval = -1;\r
+ subscribed = true;\r
lastRefresh = new Date(0);\r
\r
String[] fields = definition.split(":");\r
repository = fields[0];\r
if (fields.length > 1) {\r
branch = fields[1];\r
- maxRetrieval = Integer.parseInt(fields[2]);\r
- try {\r
- lastRefresh = new SimpleDateFormat("yyyyMMddHHmmss").parse(fields[3]);\r
- } catch (ParseException e) {\r
- }\r
- subscribed = true;\r
}\r
}\r
\r
@Override\r
public String toString() {\r
- return MessageFormat.format("{0}:{1}:{2,number,0}:{3,date,yyyyMMddHHmmss}", repository,\r
- branch, maxRetrieval, lastRefresh);\r
+ if (StringUtils.isEmpty(branch)) {\r
+ return repository;\r
+ }\r
+ return repository + ":" + branch;\r
}\r
\r
@Override\r
*/\r
public static List<SyndicatedEntryModel> readFeed(String url, String repository, String branch,\r
int numberOfEntries, String username, char[] password) throws IOException {\r
- String feedUrl;\r
- if (StringUtils.isEmpty(branch)) {\r
- // no branch specified\r
- if (numberOfEntries > 0) {\r
- // fixed number of entries\r
- feedUrl = MessageFormat.format("{0}/feed/{1}?l={2,number,0}", url, repository);\r
- } else {\r
- // server default number of entries\r
- feedUrl = MessageFormat.format("{0}/feed/{1}", url, repository);\r
- }\r
- } else {\r
- // branch specified\r
- if (numberOfEntries > 0) {\r
- // fixed number of entries\r
- feedUrl = MessageFormat.format("{0}/feed/{1}?h={2}&l={3,number,0}", url,\r
- repository, branch, numberOfEntries);\r
- } else {\r
- // server default number of entries\r
- feedUrl = MessageFormat.format("{0}/feed/{1}?h={2}", url, repository, branch);\r
+ // build feed url\r
+ List<String> parameters = new ArrayList<String>();\r
+ if (numberOfEntries > 0) {\r
+ parameters.add("l=" + numberOfEntries);\r
+ }\r
+ if (!StringUtils.isEmpty(branch)) {\r
+ parameters.add("h=" + branch);\r
+ }\r
+ StringBuilder sb = new StringBuilder();\r
+ sb.append(MessageFormat.format("{0}/feed/{1}", url, repository));\r
+ if (parameters.size() > 0) {\r
+ boolean first = true;\r
+ for (String parameter : parameters) {\r
+ if (first) {\r
+ sb.append('?');\r
+ first = false;\r
+ } else {\r
+ sb.append('&');\r
+ }\r
+ sb.append(parameter);\r
}\r
}\r
+ String feedUrl = sb.toString();\r
+\r
URLConnection conn = ConnectionUtils.openReadConnection(feedUrl, username, password);\r
InputStream is = conn.getInputStream();\r
SyndFeedInput input = new SyndFeedInput();\r
gb.version = version\r
gb.releaseDate = release date\r
gb.date = date\r
-gb.recentActivity = recent activity\r
+gb.timeline = timeline\r
gb.subscribe = subscribe\r
gb.branch = branch
\ No newline at end of file