]> source.dussan.org Git - gitblit.git/commitdiff
New login/edit registration dialog. Added url to status panel.
authorJames Moger <james.moger@gitblit.com>
Fri, 28 Oct 2011 12:09:24 +0000 (08:09 -0400)
committerJames Moger <james.moger@gitblit.com>
Fri, 28 Oct 2011 12:09:24 +0000 (08:09 -0400)
src/com/gitblit/client/DateCellRenderer.java
src/com/gitblit/client/EditRegistrationDialog.java [new file with mode: 0644]
src/com/gitblit/client/GitblitManager.java
src/com/gitblit/client/GitblitPanel.java
src/com/gitblit/client/GitblitRegistration.java
src/com/gitblit/client/RegistrationsDialog.java
src/com/gitblit/client/StatusPanel.java

index 053cf52f11f4d799d1f384049497fa789edab51a..f30b05f54dcfd77231d09fa0dceae9db31c700b3 100644 (file)
@@ -49,8 +49,16 @@ public class DateCellRenderer extends DefaultTableCellRenderer {
                super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);\r
                if (value instanceof Date) {\r
                        Date date = (Date) value;\r
-                       String timeAgo = TimeUtils.timeAgo(date);\r
-                       String strDate = new SimpleDateFormat(pattern).format((Date) value);\r
+                       String timeAgo;\r
+                       String strDate;\r
+                       if (date.getTime() == 0) {\r
+                               timeAgo = "--";\r
+                               strDate = "never";\r
+                       } else {\r
+                               timeAgo = TimeUtils.timeAgo(date);\r
+                               strDate = new SimpleDateFormat(pattern).format((Date) value);\r
+                       }\r
+\r
                        this.setText(timeAgo);\r
                        this.setToolTipText(strDate);\r
                }\r
diff --git a/src/com/gitblit/client/EditRegistrationDialog.java b/src/com/gitblit/client/EditRegistrationDialog.java
new file mode 100644 (file)
index 0000000..99cd36f
--- /dev/null
@@ -0,0 +1,196 @@
+/*\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.Dimension;\r
+import java.awt.Font;\r
+import java.awt.GridLayout;\r
+import java.awt.Insets;\r
+import java.awt.Window;\r
+import java.awt.event.ActionEvent;\r
+import java.awt.event.ActionListener;\r
+import java.awt.event.KeyEvent;\r
+\r
+import javax.swing.ImageIcon;\r
+import javax.swing.JButton;\r
+import javax.swing.JCheckBox;\r
+import javax.swing.JComponent;\r
+import javax.swing.JDialog;\r
+import javax.swing.JLabel;\r
+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.utils.StringUtils;\r
+\r
+/**\r
+ * Dialog to create or edit a Gitblit registration.\r
+ * \r
+ * @author James Moger\r
+ * \r
+ */\r
+public class EditRegistrationDialog extends JDialog {\r
+\r
+       private static final long serialVersionUID = 1L;\r
+       private JTextField urlField;\r
+       private JTextField nameField;\r
+       private JTextField accountField;\r
+       private JPasswordField passwordField;\r
+       private JCheckBox savePassword;\r
+       private boolean canceled;\r
+       private HeaderPanel headerPanel;\r
+\r
+       public EditRegistrationDialog(Window owner) {\r
+               this(owner, null, false);\r
+       }\r
+\r
+       public EditRegistrationDialog(Window owner, GitblitRegistration reg, boolean isLogin) {\r
+               super(owner);\r
+               initialize(reg, isLogin);\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(GitblitRegistration reg, boolean isLogin) {\r
+               setIconImage(new ImageIcon(getClass().getResource("/gitblt-favicon.png")).getImage());\r
+               canceled = true;\r
+               urlField = new JTextField(reg == null ? "" : reg.url, 30);\r
+               nameField = new JTextField(reg == null ? "" : reg.name);\r
+               accountField = new JTextField(reg == null ? "" : reg.account);\r
+               passwordField = new JPasswordField(reg == null ? "" : new String(reg.password));\r
+               savePassword = new JCheckBox("save password (passwords are NOT encrypted!)");\r
+               savePassword.setSelected(reg == null ? false\r
+                               : (reg.password != null && reg.password.length > 0));\r
+\r
+               JPanel panel = new JPanel(new GridLayout(0, 1, 5, 5));\r
+               panel.add(newLabelPanel(Translation.get("gb.name"), nameField));\r
+               panel.add(newLabelPanel(Translation.get("gb.url"), urlField));\r
+               panel.add(newLabelPanel(Translation.get("gb.username"), accountField));\r
+               panel.add(newLabelPanel(Translation.get("gb.password"), passwordField));\r
+               panel.add(newLabelPanel("", savePassword));\r
+\r
+               JButton cancel = new JButton(Translation.get("gb.cancel"));\r
+               cancel.addActionListener(new ActionListener() {\r
+                       public void actionPerformed(ActionEvent event) {\r
+                               setVisible(false);\r
+                       }\r
+               });\r
+\r
+               final JButton save = new JButton(Translation.get(isLogin ? "gb.login" : "gb.save"));\r
+               save.addActionListener(new ActionListener() {\r
+                       public void actionPerformed(ActionEvent event) {\r
+                               if (validateFields()) {\r
+                                       canceled = false;\r
+                                       setVisible(false);\r
+                               }\r
+                       }\r
+               });\r
+\r
+               // on enter in password field, save or login\r
+               passwordField.addActionListener(new ActionListener() {\r
+                       public void actionPerformed(ActionEvent event) {\r
+                               save.doClick();\r
+                       }\r
+               });\r
+\r
+               JPanel controls = new JPanel();\r
+               controls.add(cancel);\r
+               controls.add(save);\r
+\r
+               if (reg == null) {\r
+                       this.setTitle(Translation.get("gb.create"));\r
+                       headerPanel = new HeaderPanel(Translation.get("gb.create"), null);\r
+               } else {\r
+                       this.setTitle(Translation.get(isLogin ? "gb.login" : "gb.edit"));\r
+                       headerPanel = new HeaderPanel(reg.name, null);\r
+               }\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
+                       @Override\r
+                       public Insets getInsets() {\r
+                               return insets;\r
+                       }\r
+               };\r
+               centerPanel.add(headerPanel, BorderLayout.NORTH);\r
+               centerPanel.add(panel, BorderLayout.CENTER);\r
+               centerPanel.add(controls, BorderLayout.SOUTH);\r
+\r
+               getContentPane().setLayout(new BorderLayout());\r
+               getContentPane().add(centerPanel, BorderLayout.CENTER);\r
+               pack();\r
+               setModal(true);\r
+               if (isLogin) {\r
+                       passwordField.requestFocus();\r
+               }\r
+       }\r
+\r
+       private JPanel newLabelPanel(String text, JComponent field) {\r
+               JLabel label = new JLabel(text);\r
+               label.setFont(label.getFont().deriveFont(Font.BOLD));\r
+               label.setPreferredSize(new Dimension(75, 10));\r
+               JPanel jpanel = new JPanel(new BorderLayout());\r
+               jpanel.add(label, BorderLayout.WEST);\r
+               jpanel.add(field, BorderLayout.CENTER);\r
+               return jpanel;\r
+       }\r
+\r
+       private boolean validateFields() {\r
+               String name = nameField.getText();\r
+               if (StringUtils.isEmpty(name)) {\r
+                       error("Please enter a name for this registration!");\r
+                       return false;\r
+               }\r
+               String url = urlField.getText();\r
+               if (StringUtils.isEmpty(url)) {\r
+                       error("Please enter a url for this registration!");\r
+                       return false;\r
+               }\r
+               return true;\r
+       }\r
+\r
+       private void error(String message) {\r
+               JOptionPane.showMessageDialog(EditRegistrationDialog.this, message,\r
+                               Translation.get("gb.error"), JOptionPane.ERROR_MESSAGE);\r
+       }\r
+\r
+       public GitblitRegistration getRegistration() {\r
+               if (canceled) {\r
+                       return null;\r
+               }\r
+               GitblitRegistration reg = new GitblitRegistration(nameField.getText(), urlField.getText(),\r
+                               accountField.getText(), passwordField.getPassword());\r
+               reg.savePassword = savePassword.isSelected();\r
+               return reg;\r
+       }\r
+}\r
index 49750b1896d67f792468fdc7f16d01e728203cf3..f16616a3bf7d04dfdb0fca9d3c1b49e8086399e7 100644 (file)
@@ -19,8 +19,6 @@ import java.awt.BorderLayout;
 import java.awt.Cursor;\r
 import java.awt.Dimension;\r
 import java.awt.EventQueue;\r
-import java.awt.Font;\r
-import java.awt.GridLayout;\r
 import java.awt.Point;\r
 import java.awt.event.ActionEvent;\r
 import java.awt.event.ActionListener;\r
@@ -45,15 +43,12 @@ import java.util.TimeZone;
 \r
 import javax.swing.ImageIcon;\r
 import javax.swing.JFrame;\r
-import javax.swing.JLabel;\r
 import javax.swing.JMenu;\r
 import javax.swing.JMenuBar;\r
 import javax.swing.JMenuItem;\r
 import javax.swing.JOptionPane;\r
 import javax.swing.JPanel;\r
-import javax.swing.JPasswordField;\r
 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
@@ -101,7 +96,7 @@ public class GitblitManager extends JFrame implements RegistrationsDialog.Regist
                        public void windowClosing(WindowEvent event) {\r
                                saveSizeAndPosition();\r
                        }\r
-                       \r
+\r
                        @Override\r
                        public void windowOpened(WindowEvent event) {\r
                                manageRegistrations();\r
@@ -177,27 +172,9 @@ public class GitblitManager extends JFrame implements RegistrationsDialog.Regist
                });\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(GitblitRegistration.LOCALHOST);\r
-                       }\r
-               });\r
-               serversMenu.add(login);\r
                return menuBar;\r
        }\r
 \r
-       private JPanel newLabelPanel(String text, JTextField field) {\r
-               JLabel label = new JLabel(text);\r
-               label.setFont(label.getFont().deriveFont(Font.BOLD));\r
-               label.setPreferredSize(new Dimension(75, 10));\r
-               JPanel jpanel = new JPanel(new BorderLayout());\r
-               jpanel.add(label, BorderLayout.WEST);\r
-               jpanel.add(field, BorderLayout.CENTER);\r
-               return jpanel;\r
-       }\r
-\r
        private JPanel getCenterPanel() {\r
                serverTabs = new JTabbedPane(JTabbedPane.TOP);\r
                JMenuBar menubar = setupMenu();\r
@@ -215,48 +192,23 @@ public class GitblitManager extends JFrame implements RegistrationsDialog.Regist
        }\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
-               JPasswordField passwordField = new JPasswordField(new String(reg.password));\r
-\r
-               JPanel panel = new JPanel(new GridLayout(0, 1, 5, 5));\r
-               panel.add(newLabelPanel(Translation.get("gb.name"), nameField));\r
-               panel.add(newLabelPanel(Translation.get("gb.url"), urlField));\r
-               panel.add(newLabelPanel(Translation.get("gb.username"), accountField));\r
-               panel.add(newLabelPanel(Translation.get("gb.password"), passwordField));\r
-\r
-               int result = JOptionPane.showConfirmDialog(GitblitManager.this, panel,\r
-                               Translation.get("gb.login"), JOptionPane.OK_CANCEL_OPTION);\r
-               if (result != JOptionPane.OK_OPTION) {\r
-                       return;\r
-               }\r
-               String url = urlField.getText();\r
-               if (StringUtils.isEmpty(url)) {\r
-                       return;\r
-               }\r
-               String originalName = reg.name;\r
-               reg = new GitblitRegistration(nameField.getText(), url, accountField.getText(),\r
-                               passwordField.getPassword());\r
-               if (!StringUtils.isEmpty(originalName) && !originalName.equals(reg.name)) {\r
-                       // delete old registration\r
-                       registrations.remove(originalName);\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
+       public void login(GitblitRegistration reg) {\r
+               if (!reg.savePassword && (reg.password == null || reg.password.length == 0)) {\r
+                       // prompt for password\r
+                       EditRegistrationDialog dialog = new EditRegistrationDialog(this, reg, true);\r
+                       dialog.setLocationRelativeTo(GitblitManager.this);\r
+                       dialog.setVisible(true);\r
+                       reg = dialog.getRegistration();\r
+                       if (reg == null) {\r
+                               // user canceled\r
+                               return;\r
                        }\r
                }\r
-               login(reg);\r
-       }\r
-\r
-       @Override\r
-       public void login(final GitblitRegistration reg) {\r
+               \r
+               // login\r
                setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));\r
-               final GitblitPanel panel = new GitblitPanel(reg);\r
+               final GitblitRegistration registration = reg;\r
+               final GitblitPanel panel = new GitblitPanel(registration);\r
                SwingWorker<Boolean, Void> worker = new SwingWorker<Boolean, Void>() {\r
 \r
                        @Override\r
@@ -269,15 +221,19 @@ public class GitblitManager extends JFrame implements RegistrationsDialog.Regist
                        protected void done() {\r
                                try {\r
                                        boolean success = get();\r
-                                       serverTabs.addTab(reg.name, panel);\r
+                                       serverTabs.addTab(registration.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
+                                       serverTabs.setTabComponentAt(idx, new ClosableTabComponent(registration.name,\r
+                                                       null, serverTabs, panel));\r
+                                       registration.lastLogin = new Date();\r
+                                       saveRegistration(registration.name, registration);\r
+                                       registrations.put(registration.name, registration);\r
                                        rebuildRecentMenu();\r
+                                       if (!registration.savePassword) {\r
+                                               // clear password\r
+                                               registration.password = null;\r
+                                       }\r
                                } catch (Throwable t) {\r
                                        Throwable cause = t.getCause();\r
                                        if (cause instanceof ConnectException) {\r
@@ -332,7 +288,11 @@ public class GitblitManager extends JFrame implements RegistrationsDialog.Regist
                        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
+                               Date lastLogin = new Date(0);\r
+                               String date = config.getString("servers", 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
                                char[] password;\r
@@ -340,7 +300,6 @@ public class GitblitManager extends JFrame implements RegistrationsDialog.Regist
                                if (StringUtils.isEmpty(pw)) {\r
                                        password = new char[0];\r
                                } else {\r
-                                       // FIXME this is pretty lame\r
                                        password = new String(Base64.decode(pw)).toCharArray();\r
                                }\r
                                GitblitRegistration reg = new GitblitRegistration(server, url, account, password);\r
@@ -352,21 +311,37 @@ public class GitblitManager extends JFrame implements RegistrationsDialog.Regist
                }\r
        }\r
 \r
-       private void saveRegistration(GitblitRegistration reg) {\r
+       @Override\r
+       public boolean saveRegistration(String name, GitblitRegistration reg) {\r
                try {\r
                        StoredConfig config = getConfig();\r
+                       if (!StringUtils.isEmpty(name) && !name.equals(reg.name)) {\r
+                               // delete old registration\r
+                               registrations.remove(name);\r
+                               config.unsetSection("servers", 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
-                       // 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
+                       if (reg.savePassword) {\r
+                               config.setString("servers", reg.name, "password",\r
+                                               Base64.encodeBytes(new String(reg.password).getBytes("UTF-8")));\r
+                       } else {\r
+                               config.setString("servers", reg.name, "password", "");\r
+                       }\r
+                       if (reg.lastLogin != null) {\r
+                               config.setString("servers", reg.name, "lastLogin", dateFormat.format(reg.lastLogin));\r
+                       }\r
                        config.save();\r
+                       return true;\r
                } catch (Throwable t) {\r
                        Utils.showException(GitblitManager.this, t);\r
                }\r
+               return false;\r
        }\r
 \r
+       @Override\r
        public boolean deleteRegistrations(List<GitblitRegistration> list) {\r
                boolean success = false;\r
                try {\r
index 23aadb863e57b086b5f9cf7894b80bdcc3d6edbc..03ddfb3a1558348ccbb737ac07902b6ff1f687ba 100644 (file)
@@ -564,7 +564,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
        }\r
 \r
        private void updateStatusPanel() {\r
-               statusPanel.setStatus(gitblit.getStatus());\r
+               statusPanel.setStatus(gitblit.url, gitblit.getStatus());\r
        }\r
 \r
        private void filterRepositories(final String fragment) {\r
index bdd8b23b3c04d8e309720b5602b4161fb908a24e..0463c12b81a8d57f74552dcc93398006481c458b 100644 (file)
@@ -28,20 +28,20 @@ import com.gitblit.utils.StringUtils;
  */\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
        String name;\r
        String url;\r
        String account;\r
        char[] password;\r
+       boolean savePassword;\r
        Date lastLogin;\r
 \r
        public GitblitRegistration(String name, String url, String account, char[] password) {\r
                this.url = url;\r
                this.account = account;\r
                this.password = password;\r
+               this.savePassword = password != null && password.length > 0;\r
                if (StringUtils.isEmpty(name)) {\r
                        this.name = url.substring(url.indexOf("//") + 2);\r
                } else {\r
@@ -51,6 +51,6 @@ public class GitblitRegistration implements Serializable, Comparable<GitblitRegi
 \r
        @Override\r
        public int compareTo(GitblitRegistration o) {\r
-               return name.compareTo(o.name);\r
+               return name.toLowerCase().compareTo(o.name.toLowerCase());\r
        }\r
 }\r
index 71178f3054235896c4d28037d28ad86b655c0977..0b87bb47587756bbb29679c3b9d03a6eb9832b28 100644 (file)
@@ -38,14 +38,22 @@ import javax.swing.KeyStroke;
 import javax.swing.event.ListSelectionEvent;\r
 import javax.swing.event.ListSelectionListener;\r
 \r
+/**\r
+ * Displays a list of registrations and allows management of server\r
+ * registrations.\r
+ * \r
+ * @author James Moger\r
+ * \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
+               boolean saveRegistration(String name, GitblitRegistration reg);\r
+\r
+               boolean deleteRegistrations(List<GitblitRegistration> list);\r
        }\r
 \r
        private static final long serialVersionUID = 1L;\r
@@ -87,12 +95,13 @@ public class RegistrationsDialog extends JDialog {
                registrationsTable = Utils.newTable(model);\r
                registrationsTable.setRowHeight(nameRenderer.getFont().getSize() + 8);\r
 \r
-               String id = registrationsTable.getColumnName(RegistrationsTableModel.Columns.Name.ordinal());\r
+               String id = registrationsTable\r
+                               .getColumnName(RegistrationsTableModel.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
+                                       login();\r
                                }\r
                        }\r
                });\r
@@ -100,8 +109,7 @@ public class RegistrationsDialog extends JDialog {
                final JButton create = new JButton(Translation.get("gb.create"));\r
                create.addActionListener(new ActionListener() {\r
                        public void actionPerformed(ActionEvent event) {\r
-                               RegistrationsDialog.this.setVisible(false);\r
-                               listener.loginPrompt(GitblitRegistration.LOCALHOST);\r
+                               create();\r
                        }\r
                });\r
 \r
@@ -109,15 +117,15 @@ public class RegistrationsDialog extends JDialog {
                login.setEnabled(false);\r
                login.addActionListener(new ActionListener() {\r
                        public void actionPerformed(ActionEvent event) {\r
-                               login(false);\r
+                               login();\r
                        }\r
                });\r
 \r
-               final JButton loginPrompt = new JButton(Translation.get("gb.login") + "...");\r
-               loginPrompt.setEnabled(false);\r
-               loginPrompt.addActionListener(new ActionListener() {\r
+               final JButton edit = new JButton(Translation.get("gb.edit"));\r
+               edit.setEnabled(false);\r
+               edit.addActionListener(new ActionListener() {\r
                        public void actionPerformed(ActionEvent event) {\r
-                               login(true);\r
+                               edit();\r
                        }\r
                });\r
 \r
@@ -139,7 +147,7 @@ public class RegistrationsDialog extends JDialog {
                                                boolean singleSelection = registrationsTable.getSelectedRowCount() == 1;\r
                                                boolean selected = registrationsTable.getSelectedRow() > -1;\r
                                                login.setEnabled(singleSelection);\r
-                                               loginPrompt.setEnabled(singleSelection);\r
+                                               edit.setEnabled(singleSelection);\r
                                                delete.setEnabled(selected);\r
                                        }\r
                                });\r
@@ -147,7 +155,7 @@ public class RegistrationsDialog extends JDialog {
                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(edit);\r
                controls.add(delete);\r
 \r
                final Insets insets = new Insets(5, 5, 5, 5);\r
@@ -159,6 +167,7 @@ public class RegistrationsDialog extends JDialog {
                                return insets;\r
                        }\r
                };\r
+               centerPanel.add(new HeaderPanel(Translation.get("gb.servers"), null), BorderLayout.NORTH);\r
                centerPanel.add(new JScrollPane(registrationsTable), BorderLayout.CENTER);\r
                centerPanel.add(controls, BorderLayout.SOUTH);\r
 \r
@@ -166,15 +175,42 @@ public class RegistrationsDialog extends JDialog {
                getContentPane().add(centerPanel, BorderLayout.CENTER);\r
        }\r
 \r
-       private void login(boolean prompt) {\r
+       private void login() {\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
+               listener.login(reg);\r
+       }\r
+\r
+       private void create() {\r
+               EditRegistrationDialog dialog = new EditRegistrationDialog(getOwner());\r
+               dialog.setLocationRelativeTo(this);\r
+               dialog.setVisible(true);\r
+               GitblitRegistration reg = dialog.getRegistration();\r
+               if (reg == null) {\r
+                       return;\r
+               }\r
+               if (listener.saveRegistration(reg.name, reg)) {\r
+                       model.list.add(reg);\r
+                       model.fireTableDataChanged();\r
+               }\r
+       }\r
+\r
+       private void edit() {\r
+               int viewRow = registrationsTable.getSelectedRow();\r
+               int modelRow = registrationsTable.convertRowIndexToModel(viewRow);\r
+               GitblitRegistration reg = registrations.get(modelRow);\r
+               String originalName = reg.name;\r
+               EditRegistrationDialog dialog = new EditRegistrationDialog(getOwner(), reg, false);\r
+               dialog.setLocationRelativeTo(this);\r
+               dialog.setVisible(true);\r
+               reg = dialog.getRegistration();\r
+               if (reg == null) {\r
+                       return;\r
+               }\r
+               if (listener.saveRegistration(originalName, reg)) {\r
+                       model.fireTableDataChanged();\r
                }\r
        }\r
 \r
index 0cc530ef3d8607542c2c8800fcec7615e1ca1f55..b85d87afb4558b7a719d5cc6021719b00ffa482e 100644 (file)
@@ -42,6 +42,7 @@ public class StatusPanel extends JPanel {
        private static final long serialVersionUID = 1L;\r
        private final Insets insets = new Insets(5, 5, 5, 5);\r
        private JLabel bootDate;\r
+       private JLabel url;\r
        private JLabel servletContainer;\r
        private JLabel heapMaximum;\r
        private JLabel heapAllocated;\r
@@ -56,15 +57,16 @@ public class StatusPanel extends JPanel {
                initialize();\r
        }\r
 \r
-       public StatusPanel(ServerStatus status) {\r
+       public StatusPanel(String url, ServerStatus status) {\r
                this();\r
-               setStatus(status);\r
+               setStatus(url, status);\r
        }\r
 \r
        private void initialize() {\r
                version = new JLabel();\r
                releaseDate = new JLabel();\r
                bootDate = new JLabel();\r
+               url = new JLabel();\r
                servletContainer = new JLabel();\r
 \r
                heapMaximum = new JLabel();\r
@@ -72,7 +74,7 @@ public class StatusPanel extends JPanel {
                heapUsed = new JLabel();\r
 \r
                JPanel fieldsPanel = new JPanel(new GridLayout(0, 1, 0, 5)) {\r
-               \r
+\r
                        private static final long serialVersionUID = 1L;\r
 \r
                        @Override\r
@@ -83,6 +85,7 @@ public class StatusPanel extends JPanel {
                fieldsPanel.add(createFieldPanel("gb.version", version));\r
                fieldsPanel.add(createFieldPanel("gb.releaseDate", releaseDate));\r
                fieldsPanel.add(createFieldPanel("gb.bootDate", bootDate));\r
+               fieldsPanel.add(createFieldPanel("gb.url", url));\r
                fieldsPanel.add(createFieldPanel("gb.servletContainer", servletContainer));\r
                fieldsPanel.add(createFieldPanel("gb.heapUsed", heapUsed));\r
                fieldsPanel.add(createFieldPanel("gb.heapAllocated", heapAllocated));\r
@@ -120,12 +123,13 @@ public class StatusPanel extends JPanel {
                return insets;\r
        }\r
 \r
-       public void setStatus(ServerStatus status) {\r
+       public void setStatus(String url, ServerStatus status) {\r
                headerPanel.setText(Translation.get("gb.status"));\r
                version.setText(Constants.NAME + (status.isGO ? " GO v" : " WAR v") + status.version);\r
                releaseDate.setText(status.releaseDate);\r
                bootDate.setText(status.bootDate.toString() + " (" + TimeUtils.timeAgo(status.bootDate)\r
                                + ")");\r
+               this.url.setText(url);\r
                servletContainer.setText(status.servletContainer);\r
                ByteFormat byteFormat = new ByteFormat();\r
                heapMaximum.setText(byteFormat.format(status.heapMaximum));\r