]> source.dussan.org Git - gitblit.git/commitdiff
Management of registrations. Usability improvements.
authorJames Moger <james.moger@gitblit.com>
Wed, 19 Oct 2011 02:41:50 +0000 (22:41 -0400)
committerJames Moger <james.moger@gitblit.com>
Wed, 19 Oct 2011 02:41:50 +0000 (22:41 -0400)
src/com/gitblit/client/EditRepositoryDialog.java
src/com/gitblit/client/EditUserDialog.java
src/com/gitblit/client/GitblitManager.java
src/com/gitblit/client/GitblitPanel.java
src/com/gitblit/client/GitblitRegistration.java
src/com/gitblit/client/RegistrationsDialog.java [new file with mode: 0644]
src/com/gitblit/client/RegistrationsModel.java [new file with mode: 0644]
src/com/gitblit/wicket/GitBlitWebApp.properties

index 0955d7be27d7ad00c53f83fcde3fdbbe1b4d3a37..9fc8e5c931ae6bb9bdd18a11e20789516494bf42 100644 (file)
@@ -24,6 +24,7 @@ import java.awt.GridLayout;
 import java.awt.Insets;\r
 import java.awt.event.ActionEvent;\r
 import java.awt.event.ActionListener;\r
+import java.awt.event.KeyEvent;\r
 import java.text.MessageFormat;\r
 import java.util.ArrayList;\r
 import java.util.Arrays;\r
@@ -42,8 +43,10 @@ import javax.swing.JLabel;
 import javax.swing.JList;\r
 import javax.swing.JOptionPane;\r
 import javax.swing.JPanel;\r
+import javax.swing.JRootPane;\r
 import javax.swing.JTabbedPane;\r
 import javax.swing.JTextField;\r
+import javax.swing.KeyStroke;\r
 import javax.swing.ListCellRenderer;\r
 \r
 import com.gitblit.Constants.AccessRestrictionType;\r
@@ -109,6 +112,18 @@ public class EditRepositoryDialog extends JDialog {
                setTitle(Translation.get("gb.edit") + ": " + aRepository.name);\r
                setIconImage(new ImageIcon(getClass().getResource("/gitblt-favicon.png")).getImage());\r
        }\r
+       \r
+       @Override\r
+       protected JRootPane createRootPane() {\r
+               KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);\r
+               JRootPane rootPane = new JRootPane();\r
+               rootPane.registerKeyboardAction(new ActionListener() {\r
+                       public void actionPerformed(ActionEvent actionEvent) {\r
+                               setVisible(false);\r
+                       }\r
+               }, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);\r
+               return rootPane;\r
+       }\r
 \r
        private void initialize(RepositoryModel anRepository) {\r
                nameField = new JTextField(anRepository.name == null ? "" : anRepository.name, 35);\r
@@ -216,7 +231,6 @@ public class EditRepositoryDialog extends JDialog {
                getContentPane().setLayout(new BorderLayout(5, 5));\r
                getContentPane().add(centerPanel, BorderLayout.CENTER);\r
                pack();\r
-               setLocationRelativeTo(null);\r
        }\r
 \r
        private JPanel newFieldPanel(String label, JComponent comp) {\r
index c60b2b24e681c9cf32b78fb704817e7c9cd13d0d..eacef2491703f9f711c6673e66cd7343471ec2a1 100644 (file)
@@ -23,6 +23,7 @@ import java.awt.GridLayout;
 import java.awt.Insets;\r
 import java.awt.event.ActionEvent;\r
 import java.awt.event.ActionListener;\r
+import java.awt.event.KeyEvent;\r
 import java.text.MessageFormat;\r
 import java.util.ArrayList;\r
 import java.util.Arrays;\r
@@ -39,7 +40,9 @@ import javax.swing.JLabel;
 import javax.swing.JOptionPane;\r
 import javax.swing.JPanel;\r
 import javax.swing.JPasswordField;\r
+import javax.swing.JRootPane;\r
 import javax.swing.JTextField;\r
+import javax.swing.KeyStroke;\r
 \r
 import com.gitblit.Constants.AccessRestrictionType;\r
 import com.gitblit.IStoredSettings;\r
@@ -91,6 +94,18 @@ public class EditUserDialog extends JDialog {
                setTitle(Translation.get("gb.edit") + ": " + anUser.username);\r
                setIconImage(new ImageIcon(getClass().getResource("/gitblt-favicon.png")).getImage());\r
        }\r
+       \r
+       @Override\r
+       protected JRootPane createRootPane() {\r
+               KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);\r
+               JRootPane rootPane = new JRootPane();\r
+               rootPane.registerKeyboardAction(new ActionListener() {\r
+                       public void actionPerformed(ActionEvent actionEvent) {\r
+                               setVisible(false);\r
+                       }\r
+               }, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);\r
+               return rootPane;\r
+       }\r
 \r
        private void initialize(UserModel anUser) {\r
                usernameField = new JTextField(anUser.username == null ? "" : anUser.username, 25);\r
@@ -154,7 +169,6 @@ public class EditUserDialog extends JDialog {
                getContentPane().setLayout(new BorderLayout(5, 5));\r
                getContentPane().add(centerPanel, BorderLayout.CENTER);\r
                pack();\r
-               setLocationRelativeTo(null);\r
        }\r
 \r
        private JPanel newFieldPanel(String label, JComponent comp) {\r
index 47ff6eab4e3f4843a5eade9d76b7b479c5517620..51afbc5b0588f4507795cf8e51e384194162aa0e 100644 (file)
@@ -16,6 +16,7 @@
 package com.gitblit.client;\r
 \r
 import java.awt.BorderLayout;\r
+import java.awt.Cursor;\r
 import java.awt.Dimension;\r
 import java.awt.EventQueue;\r
 import java.awt.Font;\r
@@ -29,9 +30,17 @@ import java.awt.event.WindowEvent;
 import java.io.File;\r
 import java.io.IOException;\r
 import java.text.MessageFormat;\r
+import java.text.SimpleDateFormat;\r
+import java.util.ArrayList;\r
+import java.util.Collections;\r
+import java.util.Comparator;\r
+import java.util.Date;\r
 import java.util.LinkedHashMap;\r
+import java.util.List;\r
+import java.util.Locale;\r
 import java.util.Map;\r
 import java.util.Set;\r
+import java.util.TimeZone;\r
 \r
 import javax.swing.ImageIcon;\r
 import javax.swing.JFrame;\r
@@ -45,6 +54,7 @@ import javax.swing.JPasswordField;
 import javax.swing.JTabbedPane;\r
 import javax.swing.JTextField;\r
 import javax.swing.KeyStroke;\r
+import javax.swing.SwingWorker;\r
 import javax.swing.UIManager;\r
 \r
 import org.eclipse.jgit.errors.ConfigInvalidException;\r
@@ -62,19 +72,21 @@ import com.gitblit.utils.StringUtils;
  * @author James Moger\r
  * \r
  */\r
-public class GitblitManager extends JFrame {\r
+public class GitblitManager extends JFrame implements RegistrationsDialog.RegistrationListener {\r
 \r
        private static final long serialVersionUID = 1L;\r
+       private final SimpleDateFormat dateFormat;\r
        private JTabbedPane serverTabs;\r
        private File configFile = new File(System.getProperty("user.home"), ".gitblit/config");\r
-       private GitblitRegistration localhost = new GitblitRegistration("default",\r
-                       "https://localhost:8443", "admin", "admin".toCharArray());\r
 \r
        private Map<String, GitblitRegistration> registrations = new LinkedHashMap<String, GitblitRegistration>();\r
        private JMenu recentMenu;\r
+       private int maxRecentCount = 5;\r
 \r
        private GitblitManager() {\r
                super();\r
+               dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);\r
+               dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));\r
        }\r
 \r
        private void initialize() {\r
@@ -142,31 +154,27 @@ public class GitblitManager extends JFrame {
                }\r
        }\r
 \r
-       public void setVisible(boolean value) {\r
-               if (value) {\r
-                       if (registrations.size() == 0) {\r
-                               // default prompt\r
-                               loginPrompt(localhost);\r
-                       } else if (registrations.size() == 1) {\r
-                               // single registration prompt\r
-                               GitblitRegistration reg = registrations.values().iterator().next();\r
-                               loginPrompt(reg);\r
-                       }\r
-                       super.setVisible(value);\r
-               }\r
-       }\r
-\r
        private JMenuBar setupMenu() {\r
                JMenuBar menuBar = new JMenuBar();\r
                JMenu serversMenu = new JMenu(Translation.get("gb.servers"));\r
                menuBar.add(serversMenu);\r
                recentMenu = new JMenu(Translation.get("gb.recent"));\r
                serversMenu.add(recentMenu);\r
+\r
+               JMenuItem manage = new JMenuItem(Translation.get("gb.manage") + "...");\r
+               manage.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, KeyEvent.CTRL_DOWN_MASK, false));\r
+               manage.addActionListener(new ActionListener() {\r
+                       public void actionPerformed(ActionEvent event) {\r
+                               manageRegistrations();\r
+                       }\r
+               });\r
+               serversMenu.add(manage);\r
+\r
                JMenuItem login = new JMenuItem(Translation.get("gb.login") + "...");\r
                login.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, KeyEvent.CTRL_DOWN_MASK, false));\r
                login.addActionListener(new ActionListener() {\r
                        public void actionPerformed(ActionEvent event) {\r
-                               loginPrompt(localhost);\r
+                               loginPrompt(GitblitRegistration.LOCALHOST);\r
                        }\r
                });\r
                serversMenu.add(login);\r
@@ -192,7 +200,15 @@ public class GitblitManager extends JFrame {
                return panel;\r
        }\r
 \r
-       private boolean loginPrompt(GitblitRegistration reg) {\r
+       private void manageRegistrations() {\r
+               RegistrationsDialog dialog = new RegistrationsDialog(new ArrayList<GitblitRegistration>(\r
+                               registrations.values()), this);\r
+               dialog.setLocationRelativeTo(GitblitManager.this);\r
+               dialog.setVisible(true);\r
+       }\r
+\r
+       @Override\r
+       public void loginPrompt(GitblitRegistration reg) {\r
                JTextField urlField = new JTextField(reg.url, 30);\r
                JTextField nameField = new JTextField(reg.name);\r
                JTextField accountField = new JTextField(reg.account);\r
@@ -207,46 +223,81 @@ public class GitblitManager extends JFrame {
                int result = JOptionPane.showConfirmDialog(GitblitManager.this, panel,\r
                                Translation.get("gb.login"), JOptionPane.OK_CANCEL_OPTION);\r
                if (result != JOptionPane.OK_OPTION) {\r
-                       return false;\r
+                       return;\r
                }\r
                String url = urlField.getText();\r
                if (StringUtils.isEmpty(url)) {\r
-                       return false;\r
+                       return;\r
                }\r
+               String originalName = reg.name;\r
                reg = new GitblitRegistration(nameField.getText(), url, accountField.getText(),\r
                                passwordField.getPassword());\r
-               boolean success = login(reg);\r
-               registrations.put(reg.name, reg);\r
-               rebuildRecentMenu();\r
-               return success;\r
+               if (!StringUtils.isEmpty(originalName) && !originalName.equals(reg.name)) {\r
+                       // delete old registration\r
+                       try {\r
+                               StoredConfig config = getConfig();\r
+                               config.unsetSection("servers", originalName);\r
+                               config.save();\r
+                       } catch (Throwable t) {\r
+                               Utils.showException(GitblitManager.this, t);\r
+                       }\r
+               }\r
+               login(reg);\r
        }\r
 \r
-       private boolean login(GitblitRegistration reg) {\r
-               try {\r
-                       GitblitPanel panel = new GitblitPanel(reg);\r
-                       panel.login();\r
-                       serverTabs.addTab(reg.name, panel);\r
-                       int idx = serverTabs.getTabCount() - 1;\r
-                       serverTabs.setSelectedIndex(idx);\r
-                       serverTabs.setTabComponentAt(idx, new ClosableTabComponent(reg.name, null, serverTabs,\r
-                                       panel));\r
-                       saveRegistration(reg);\r
-                       return true;\r
-               } catch (IOException e) {\r
-                       JOptionPane.showMessageDialog(GitblitManager.this, e.getMessage(),\r
-                                       Translation.get("gb.error"), JOptionPane.ERROR_MESSAGE);\r
-               }\r
-               return false;\r
+       @Override\r
+       public void login(final GitblitRegistration reg) {\r
+               setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));\r
+               final GitblitPanel panel = new GitblitPanel(reg);\r
+               SwingWorker<Boolean, Void> worker = new SwingWorker<Boolean, Void>() {\r
+\r
+                       @Override\r
+                       protected Boolean doInBackground() throws IOException {\r
+                               panel.login();\r
+                               return true;\r
+                       }\r
+\r
+                       @Override\r
+                       protected void done() {\r
+                               try {\r
+                                       boolean success = get();\r
+                                       serverTabs.addTab(reg.name, panel);\r
+                                       int idx = serverTabs.getTabCount() - 1;\r
+                                       serverTabs.setSelectedIndex(idx);\r
+                                       serverTabs.setTabComponentAt(idx, new ClosableTabComponent(reg.name, null,\r
+                                                       serverTabs, panel));\r
+                                       reg.lastLogin = new Date();\r
+                                       saveRegistration(reg);\r
+                                       registrations.put(reg.name, reg);\r
+                                       rebuildRecentMenu();\r
+                               } catch (Throwable t) {\r
+                                       Utils.showException(GitblitManager.this, t);\r
+                               } finally {\r
+                                       setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));\r
+                               }\r
+                       }\r
+               };\r
+               worker.execute();\r
        }\r
 \r
        private void rebuildRecentMenu() {\r
                recentMenu.removeAll();\r
                ImageIcon icon = new ImageIcon(getClass().getResource("/gitblt-favicon.png"));\r
-               for (final GitblitRegistration reg : registrations.values()) {\r
+               List<GitblitRegistration> list = new ArrayList<GitblitRegistration>(registrations.values());\r
+               Collections.sort(list, new Comparator<GitblitRegistration>() {\r
+                       @Override\r
+                       public int compare(GitblitRegistration o1, GitblitRegistration o2) {\r
+                               return o2.lastLogin.compareTo(o1.lastLogin);\r
+                       }\r
+               });\r
+               if (list.size() > maxRecentCount) {\r
+                       list = list.subList(0, maxRecentCount);\r
+               }\r
+               for (final GitblitRegistration reg : list) {\r
                        JMenuItem item = new JMenuItem(reg.name, icon);\r
                        item.addActionListener(new ActionListener() {\r
                                public void actionPerformed(ActionEvent e) {\r
-                                       loginPrompt(reg);\r
+                                       login(reg);\r
                                }\r
                        });\r
                        recentMenu.add(item);\r
@@ -258,11 +309,14 @@ public class GitblitManager extends JFrame {
                        StoredConfig config = getConfig();\r
                        Set<String> servers = config.getSubsections("servers");\r
                        for (String server : servers) {\r
+                               Date lastLogin = dateFormat.parse(config.getString("servers", server, "lastLogin"));\r
                                String url = config.getString("servers", server, "url");\r
                                String account = config.getString("servers", server, "account");\r
+                               // FIXME this is pretty lame\r
                                char[] password = new String(Base64.decode(config.getString("servers", server,\r
                                                "password"))).toCharArray();\r
                                GitblitRegistration reg = new GitblitRegistration(server, url, account, password);\r
+                               reg.lastLogin = lastLogin;\r
                                registrations.put(reg.name, reg);\r
                        }\r
                } catch (Throwable t) {\r
@@ -275,14 +329,31 @@ public class GitblitManager extends JFrame {
                        StoredConfig config = getConfig();\r
                        config.setString("servers", reg.name, "url", reg.url);\r
                        config.setString("servers", reg.name, "account", reg.account);\r
+                       // FIXME this is pretty lame\r
                        config.setString("servers", reg.name, "password",\r
                                        Base64.encodeBytes(new String(reg.password).getBytes("UTF-8")));\r
+                       config.setString("servers", reg.name, "lastLogin", dateFormat.format(reg.lastLogin));\r
                        config.save();\r
                } catch (Throwable t) {\r
                        Utils.showException(GitblitManager.this, t);\r
                }\r
        }\r
 \r
+       public boolean deleteRegistrations(List<GitblitRegistration> list) {\r
+               boolean success = false;\r
+               try {\r
+                       StoredConfig config = getConfig();\r
+                       for (GitblitRegistration reg : list) {\r
+                               config.unsetSection("servers", reg.name);\r
+                       }\r
+                       config.save();\r
+                       success = true;\r
+               } catch (Throwable t) {\r
+                       Utils.showException(GitblitManager.this, t);\r
+               }\r
+               return success;\r
+       }\r
+\r
        private StoredConfig getConfig() throws IOException, ConfigInvalidException {\r
                FileBasedConfig config = new FileBasedConfig(configFile, FS.detect());\r
                config.load();\r
index 7bcaac5b36a652897d217f8a399792b72448753a..5e7cfe1019160cf636eeb5030c3f6bbf223e80c1 100644 (file)
@@ -25,6 +25,8 @@ import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;\r
 import java.awt.event.KeyAdapter;\r
 import java.awt.event.KeyEvent;\r
+import java.awt.event.MouseAdapter;\r
+import java.awt.event.MouseEvent;\r
 import java.io.IOException;\r
 import java.net.URI;\r
 import java.text.MessageFormat;\r
@@ -212,6 +214,14 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
                                }\r
                        }\r
                });\r
+               \r
+               repositoriesTable.addMouseListener(new MouseAdapter() {\r
+                       public void mouseClicked(MouseEvent e) {\r
+                               if (e.getClickCount() == 2) {\r
+                                       editRepository(getSelectedRepositories().get(0));\r
+                               }\r
+                       }\r
+               });\r
 \r
                final JTextField repositoryFilter = new JTextField();\r
                repositoryFilter.addActionListener(new ActionListener() {\r
@@ -318,6 +328,14 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
                                delUser.setEnabled(selected);\r
                        }\r
                });\r
+               \r
+               usersTable.addMouseListener(new MouseAdapter() {\r
+                       public void mouseClicked(MouseEvent e) {\r
+                               if (e.getClickCount() == 2) {\r
+                                       editUser(getSelectedUsers().get(0));\r
+                               }\r
+                       }\r
+               });\r
 \r
                final JTextField userFilter = new JTextField();\r
                userFilter.addActionListener(new ActionListener() {\r
@@ -553,7 +571,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
                gitblit = null;\r
        }\r
 \r
-       protected void refreshRepositories() {\r
+       protected void refreshRepositories() {          \r
                GitblitWorker worker = new GitblitWorker(GitblitPanel.this, RpcRequest.LIST_REPOSITORIES) {\r
                        @Override\r
                        protected Boolean doRequest() throws IOException {\r
@@ -576,6 +594,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
         */\r
        protected void createRepository() {\r
                EditRepositoryDialog dialog = new EditRepositoryDialog();\r
+               dialog.setLocationRelativeTo(GitblitPanel.this);\r
                dialog.setUsers(null, gitblit.getUsernames(), null);\r
                dialog.setRepositories(gitblit.getRepositories());\r
                dialog.setVisible(true);\r
@@ -622,6 +641,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
         */\r
        protected void editRepository(final RepositoryModel repository) {\r
                EditRepositoryDialog dialog = new EditRepositoryDialog(repository);\r
+               dialog.setLocationRelativeTo(GitblitPanel.this);\r
                List<String> usernames = gitblit.getUsernames();\r
                List<String> members = gitblit.getPermittedUsernames(repository);\r
                dialog.setUsers(repository.owner, usernames, members);\r
@@ -724,6 +744,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
         */\r
        protected void createUser() {\r
                EditUserDialog dialog = new EditUserDialog(gitblit.getSettings());\r
+               dialog.setLocationRelativeTo(GitblitPanel.this);\r
                dialog.setUsers(gitblit.getUsers());\r
                dialog.setRepositories(gitblit.getRepositories(), null);\r
                dialog.setVisible(true);\r
@@ -765,6 +786,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
         */\r
        protected void editUser(final UserModel user) {\r
                EditUserDialog dialog = new EditUserDialog(user, gitblit.getSettings());\r
+               dialog.setLocationRelativeTo(GitblitPanel.this);\r
                dialog.setRepositories(gitblit.getRepositories(), new ArrayList<String>(user.repositories));\r
                dialog.setVisible(true);\r
                final UserModel revisedUser = dialog.getUser();\r
index 482bf8f2ed35984576b17b1dcfa039325dcc66e1..bdd8b23b3c04d8e309720b5602b4161fb908a24e 100644 (file)
@@ -16,6 +16,7 @@
 package com.gitblit.client;\r
 \r
 import java.io.Serializable;\r
+import java.util.Date;\r
 \r
 import com.gitblit.utils.StringUtils;\r
 \r
@@ -25,14 +26,17 @@ import com.gitblit.utils.StringUtils;
  * @author James Moger\r
  * \r
  */\r
-public class GitblitRegistration implements Serializable {\r
-       \r
+public class GitblitRegistration implements Serializable, Comparable<GitblitRegistration> {\r
+\r
+       public static final GitblitRegistration LOCALHOST = new GitblitRegistration("localhost",\r
+                       "https://localhost:8443", "admin", "admin".toCharArray());\r
        private static final long serialVersionUID = 1L;\r
-       \r
+\r
        String name;\r
        String url;\r
        String account;\r
        char[] password;\r
+       Date lastLogin;\r
 \r
        public GitblitRegistration(String name, String url, String account, char[] password) {\r
                this.url = url;\r
@@ -44,4 +48,9 @@ public class GitblitRegistration implements Serializable {
                        this.name = name;\r
                }\r
        }\r
+\r
+       @Override\r
+       public int compareTo(GitblitRegistration o) {\r
+               return name.compareTo(o.name);\r
+       }\r
 }\r
diff --git a/src/com/gitblit/client/RegistrationsDialog.java b/src/com/gitblit/client/RegistrationsDialog.java
new file mode 100644 (file)
index 0000000..c55e8c4
--- /dev/null
@@ -0,0 +1,192 @@
+/*\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.BorderLayout;\r
+import java.awt.FlowLayout;\r
+import java.awt.Insets;\r
+import java.awt.event.ActionEvent;\r
+import java.awt.event.ActionListener;\r
+import java.awt.event.KeyEvent;\r
+import java.awt.event.MouseAdapter;\r
+import java.awt.event.MouseEvent;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import javax.swing.ImageIcon;\r
+import javax.swing.JButton;\r
+import javax.swing.JComponent;\r
+import javax.swing.JDialog;\r
+import javax.swing.JPanel;\r
+import javax.swing.JRootPane;\r
+import javax.swing.JScrollPane;\r
+import javax.swing.JTable;\r
+import javax.swing.KeyStroke;\r
+import javax.swing.event.ListSelectionEvent;\r
+import javax.swing.event.ListSelectionListener;\r
+\r
+public class RegistrationsDialog extends JDialog {\r
+\r
+       interface RegistrationListener {\r
+               boolean deleteRegistrations(List<GitblitRegistration> list);\r
+\r
+               void loginPrompt(GitblitRegistration reg);\r
+\r
+               void login(GitblitRegistration reg);\r
+       }\r
+\r
+       private static final long serialVersionUID = 1L;\r
+\r
+       private final List<GitblitRegistration> registrations;\r
+\r
+       private final RegistrationListener listener;\r
+\r
+       private JTable registrationsTable;\r
+\r
+       private RegistrationsModel model;\r
+\r
+       public RegistrationsDialog(List<GitblitRegistration> registrations,\r
+                       RegistrationListener listener) {\r
+               super();\r
+               this.registrations = registrations;\r
+               this.listener = listener;\r
+               setTitle(Translation.get("gb.manage"));\r
+               setIconImage(new ImageIcon(getClass().getResource("/gitblt-favicon.png")).getImage());\r
+               initialize();\r
+               setSize(600, 400);\r
+       }\r
+\r
+       @Override\r
+       protected JRootPane createRootPane() {\r
+               KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);\r
+               JRootPane rootPane = new JRootPane();\r
+               rootPane.registerKeyboardAction(new ActionListener() {\r
+                       public void actionPerformed(ActionEvent actionEvent) {\r
+                               setVisible(false);\r
+                       }\r
+               }, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);\r
+               return rootPane;\r
+       }\r
+\r
+       private void initialize() {\r
+               NameRenderer nameRenderer = new NameRenderer();\r
+               model = new RegistrationsModel(registrations);\r
+               registrationsTable = Utils.newTable(model);\r
+               registrationsTable.setRowHeight(nameRenderer.getFont().getSize() + 8);\r
+\r
+               String id = registrationsTable.getColumnName(RegistrationsModel.Columns.Name.ordinal());\r
+               registrationsTable.getColumn(id).setCellRenderer(nameRenderer);\r
+               registrationsTable.addMouseListener(new MouseAdapter() {\r
+                       public void mouseClicked(MouseEvent e) {\r
+                               if (e.getClickCount() == 2) {\r
+                                       login(false);\r
+                               }\r
+                       }\r
+               });\r
+\r
+               final JButton create = new JButton(Translation.get("gb.create"));\r
+               create.addActionListener(new ActionListener() {\r
+                       public void actionPerformed(ActionEvent event) {\r
+                               listener.loginPrompt(GitblitRegistration.LOCALHOST);\r
+                       }\r
+               });\r
+\r
+               final JButton login = new JButton(Translation.get("gb.login"));\r
+               login.setEnabled(false);\r
+               login.addActionListener(new ActionListener() {\r
+                       public void actionPerformed(ActionEvent event) {\r
+                               login(false);\r
+                       }\r
+               });\r
+\r
+               final JButton loginPrompt = new JButton(Translation.get("gb.login") + "...");\r
+               loginPrompt.setEnabled(false);\r
+               loginPrompt.addActionListener(new ActionListener() {\r
+                       public void actionPerformed(ActionEvent event) {\r
+                               login(true);\r
+                       }\r
+               });\r
+\r
+               final JButton delete = new JButton(Translation.get("gb.delete"));\r
+               delete.setEnabled(false);\r
+               delete.addActionListener(new ActionListener() {\r
+                       public void actionPerformed(ActionEvent event) {\r
+                               delete();\r
+                       }\r
+               });\r
+\r
+               registrationsTable.getSelectionModel().addListSelectionListener(\r
+                               new ListSelectionListener() {\r
+                                       @Override\r
+                                       public void valueChanged(ListSelectionEvent e) {\r
+                                               if (e.getValueIsAdjusting()) {\r
+                                                       return;\r
+                                               }\r
+                                               boolean singleSelection = registrationsTable.getSelectedRowCount() == 1;\r
+                                               boolean selected = registrationsTable.getSelectedRow() > -1;\r
+                                               login.setEnabled(singleSelection);\r
+                                               loginPrompt.setEnabled(singleSelection);\r
+                                               delete.setEnabled(selected);\r
+                                       }\r
+                               });\r
+\r
+               JPanel controls = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 0));\r
+               controls.add(create);\r
+               controls.add(login);\r
+               controls.add(loginPrompt);\r
+               controls.add(delete);\r
+\r
+               final Insets insets = new Insets(5, 5, 5, 5);\r
+               JPanel centerPanel = new JPanel(new BorderLayout(5, 5)) {\r
+\r
+                       private static final long serialVersionUID = 1L;\r
+\r
+                       public Insets getInsets() {\r
+                               return insets;\r
+                       }\r
+               };\r
+               centerPanel.add(new JScrollPane(registrationsTable), BorderLayout.CENTER);\r
+               centerPanel.add(controls, BorderLayout.SOUTH);\r
+\r
+               getContentPane().setLayout(new BorderLayout(5, 5));\r
+               getContentPane().add(centerPanel, BorderLayout.CENTER);\r
+       }\r
+\r
+       private void login(boolean prompt) {\r
+               int viewRow = registrationsTable.getSelectedRow();\r
+               int modelRow = registrationsTable.convertRowIndexToModel(viewRow);\r
+               GitblitRegistration reg = registrations.get(modelRow);\r
+               RegistrationsDialog.this.setVisible(false);\r
+               if (prompt) {\r
+                       listener.loginPrompt(reg);\r
+               } else {\r
+                       listener.login(reg);\r
+               }\r
+       }\r
+\r
+       private void delete() {\r
+               List<GitblitRegistration> list = new ArrayList<GitblitRegistration>();\r
+               for (int i : registrationsTable.getSelectedRows()) {\r
+                       int model = registrationsTable.convertRowIndexToModel(i);\r
+                       GitblitRegistration reg = registrations.get(model);\r
+                       list.add(reg);\r
+               }\r
+               if (listener.deleteRegistrations(list)) {\r
+                       registrations.removeAll(list);\r
+                       model.fireTableDataChanged();\r
+               }\r
+       }\r
+}\r
diff --git a/src/com/gitblit/client/RegistrationsModel.java b/src/com/gitblit/client/RegistrationsModel.java
new file mode 100644 (file)
index 0000000..8b4966c
--- /dev/null
@@ -0,0 +1,102 @@
+/*\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.util.Collections;\r
+import java.util.Date;\r
+import java.util.List;\r
+\r
+import javax.swing.table.AbstractTableModel;\r
+\r
+/**\r
+ * Table model of a list of Gitblit server registrations.\r
+ * \r
+ * @author James Moger\r
+ * \r
+ */\r
+public class RegistrationsModel extends AbstractTableModel {\r
+\r
+       private static final long serialVersionUID = 1L;\r
+\r
+       List<GitblitRegistration> list;\r
+\r
+       enum Columns {\r
+               Name, URL, Last_Login;\r
+\r
+               @Override\r
+               public String toString() {\r
+                       return name().replace('_', ' ');\r
+               }\r
+       }\r
+\r
+       public RegistrationsModel(List<GitblitRegistration> list) {\r
+               this.list = list;\r
+               Collections.sort(this.list);\r
+       }\r
+\r
+       @Override\r
+       public int getRowCount() {\r
+               return list.size();\r
+       }\r
+\r
+       @Override\r
+       public int getColumnCount() {\r
+               return Columns.values().length;\r
+       }\r
+\r
+       @Override\r
+       public String getColumnName(int column) {\r
+               Columns col = Columns.values()[column];\r
+               switch (col) {\r
+               case Name:\r
+                       return Translation.get("gb.name");\r
+               case URL:\r
+                       return Translation.get("gb.url");\r
+               case Last_Login:\r
+                       return Translation.get("gb.lastLogin");\r
+               }\r
+               return "";\r
+       }\r
+\r
+       /**\r
+        * Returns <code>Object.class</code> regardless of <code>columnIndex</code>.\r
+        * \r
+        * @param columnIndex\r
+        *            the column being queried\r
+        * @return the Object.class\r
+        */\r
+       public Class<?> getColumnClass(int columnIndex) {\r
+               if (columnIndex == Columns.Last_Login.ordinal()) {\r
+                       return Date.class;\r
+               }\r
+               return String.class;\r
+       }\r
+\r
+       @Override\r
+       public Object getValueAt(int rowIndex, int columnIndex) {\r
+               GitblitRegistration model = list.get(rowIndex);\r
+               Columns col = Columns.values()[columnIndex];\r
+               switch (col) {\r
+               case Name:\r
+                       return model.name;\r
+               case URL:\r
+                       return model.url;\r
+               case Last_Login:\r
+                       return model.lastLogin;\r
+               }\r
+               return null;\r
+       }\r
+}\r
index a811260a170355af9a8e41f0e941d6dcb80898e4..109f933a82de7ee190ebc2295e4198850500d3ce 100644 (file)
@@ -156,4 +156,6 @@ gb.downloading = downloading
 gb.loading = loading\r
 gb.starting = starting\r
 gb.general = general\r
-gb.settings = settings
\ No newline at end of file
+gb.settings = settings\r
+gb.manage = manage\r
+gb.lastLogin = last login
\ No newline at end of file