]> source.dussan.org Git - gitblit.git/commitdiff
Branch renderer. String change. Config section name changes.
authorJames Moger <james.moger@gitblit.com>
Tue, 1 Nov 2011 22:19:44 +0000 (18:19 -0400)
committerJames Moger <james.moger@gitblit.com>
Tue, 1 Nov 2011 22:19:44 +0000 (18:19 -0400)
src/com/gitblit/client/BranchRenderer.java [new file with mode: 0644]
src/com/gitblit/client/FeedsPanel.java
src/com/gitblit/client/GitblitClient.java
src/com/gitblit/client/GitblitManager.java
src/com/gitblit/client/GitblitPanel.java
src/com/gitblit/client/SyndicatedEntryTableModel.java
src/com/gitblit/models/FeedModel.java
src/com/gitblit/utils/SyndicationUtils.java
src/com/gitblit/wicket/GitBlitWebApp.properties

diff --git a/src/com/gitblit/client/BranchRenderer.java b/src/com/gitblit/client/BranchRenderer.java
new file mode 100644 (file)
index 0000000..f9c9f36
--- /dev/null
@@ -0,0 +1,78 @@
+/*\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
index e2b8527cb2e7b11dc2f5ed87e60616368524a69e..c6b464d6b86bb291d396b5fd1f466ea28004fb30 100644 (file)
@@ -109,7 +109,7 @@ public abstract class FeedsPanel extends JPanel {
 \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
@@ -118,7 +118,7 @@ public abstract class FeedsPanel extends JPanel {
                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
@@ -179,7 +179,7 @@ public abstract class FeedsPanel extends JPanel {
                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
index a432c1301b5f682882a36a6836fc9811cc8936be..2a08b85c1d990ecc0b97bd289e4c95159ec4ef52 100644 (file)
@@ -215,7 +215,7 @@ public class GitblitClient implements Serializable {
                        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
@@ -290,7 +290,7 @@ public class GitblitClient implements Serializable {
        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
index f4ca7c5c0194836a9e83106e43353936f9e1c480..22f98eb648b8096ab49bda4020c2003d2213acb6 100644 (file)
@@ -73,6 +73,8 @@ import com.gitblit.utils.StringUtils;
 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
@@ -292,24 +294,24 @@ public class GitblitManager extends JFrame implements RegistrationsDialog.Regist
        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
@@ -332,20 +334,20 @@ public class GitblitManager extends JFrame implements RegistrationsDialog.Regist
                        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
@@ -353,7 +355,7 @@ public class GitblitManager extends JFrame implements RegistrationsDialog.Regist
                                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
@@ -369,7 +371,7 @@ public class GitblitManager extends JFrame implements RegistrationsDialog.Regist
                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
index 6c65328b0a43ca28e6422c1fe32d00bd3acb5580..f675b4a60d8b2e85fea30fea5a5b4f7ed253515f 100644 (file)
@@ -30,8 +30,7 @@ import com.gitblit.client.ClosableTabComponent.CloseTabListener;
 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
@@ -62,15 +61,15 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
 \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
@@ -145,7 +144,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
                        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
index db62b1aeffdf7693b1156d79dcd837c791790be3..73783a5de41f24410d678d07380972ca9ee0ab1e 100644 (file)
@@ -37,7 +37,7 @@ public class SyndicatedEntryTableModel extends AbstractTableModel {
        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
index bed0a9cdf61f2773ad8475fcd1731a27d86f4cad..d5535850a4af73db088cb2d7512a8e916d750494 100644 (file)
@@ -16,9 +16,6 @@
 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
@@ -32,7 +29,6 @@ public class FeedModel implements Serializable, Comparable<FeedModel> {
 \r
        public String repository;\r
        public String branch;\r
-       public int maxRetrieval;\r
        public Date lastRefresh;\r
 \r
        public boolean subscribed;\r
@@ -41,29 +37,26 @@ public class FeedModel implements Serializable, Comparable<FeedModel> {
 \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
index 6ea5f0e10571688e922836516fa9dbca383b448d..9aedeb4cdfbd03b12b2cf075424025f942f0745f 100644 (file)
@@ -117,27 +117,30 @@ public class SyndicationUtils {
         */\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
index 6d20a72996ef563e76fc235745d475aad97896e9..96a5bc865532fc0f1575bb6e7bededcd7961f2ed 100644 (file)
@@ -177,6 +177,6 @@ gb.free = free
 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