]> source.dussan.org Git - gitblit.git/commitdiff
Functional edit setting feature for Manager. Wrote stacktrace viewer.
authorJames Moger <james.moger@gitblit.com>
Tue, 25 Oct 2011 02:45:37 +0000 (22:45 -0400)
committerJames Moger <james.moger@gitblit.com>
Tue, 25 Oct 2011 02:45:37 +0000 (22:45 -0400)
Trap connect exceptions.

src/com/gitblit/client/GitblitClient.java
src/com/gitblit/client/GitblitManager.java
src/com/gitblit/client/GitblitPanel.java
src/com/gitblit/client/SettingPanel.java
src/com/gitblit/client/Utils.java
src/com/gitblit/wicket/GitBlitWebApp.properties

index 79914232a296df54912dcfc1d66712e27809ebfb..d3a92b0ddef48c8d8022df983a030ce905f4bdce 100644 (file)
@@ -48,7 +48,7 @@ public class GitblitClient implements Serializable {
        public final String account;\r
 \r
        private final char[] password;\r
-       \r
+\r
        private volatile boolean allowManagement;\r
 \r
        private volatile boolean allowAdministration;\r
@@ -100,7 +100,7 @@ public class GitblitClient implements Serializable {
        public boolean allowManagement() {\r
                return allowManagement;\r
        }\r
-       \r
+\r
        public boolean allowAdministration() {\r
                return allowAdministration;\r
        }\r
@@ -136,7 +136,7 @@ public class GitblitClient implements Serializable {
                allUsers.addAll(users);\r
                return allUsers;\r
        }\r
-       \r
+\r
        public ServerSettings refreshSettings() throws IOException {\r
                settings = RpcUtils.getSettings(url, account, password);\r
                return settings;\r
@@ -217,4 +217,8 @@ public class GitblitClient implements Serializable {
        public boolean deleteUser(UserModel user) throws IOException {\r
                return RpcUtils.deleteUser(user, url, account, password);\r
        }\r
+\r
+       public boolean updateSettings(Map<String, String> newSettings) throws IOException {\r
+               return RpcUtils.updateSettings(newSettings, url, account, password);\r
+       }\r
 }\r
index 43cdab36d411ca3796b4e01ef37de51c0bfaa7fb..d902c590112c444b50fbc4f544e22df481aed408 100644 (file)
@@ -29,6 +29,7 @@ import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;\r
 import java.io.File;\r
 import java.io.IOException;\r
+import java.net.ConnectException;\r
 import java.text.MessageFormat;\r
 import java.text.SimpleDateFormat;\r
 import java.util.ArrayList;\r
@@ -272,7 +273,13 @@ public class GitblitManager extends JFrame implements RegistrationsDialog.Regist
                                        registrations.put(reg.name, reg);\r
                                        rebuildRecentMenu();\r
                                } catch (Throwable t) {\r
-                                       Utils.showException(GitblitManager.this, t);\r
+                                       Throwable cause = t.getCause();\r
+                                       if (cause instanceof ConnectException) {\r
+                                               JOptionPane.showMessageDialog(GitblitManager.this, cause.getMessage(),\r
+                                                               Translation.get("gb.error"), JOptionPane.ERROR_MESSAGE);\r
+                                       } else {\r
+                                               Utils.showException(GitblitManager.this, t);\r
+                                       }\r
                                } finally {\r
                                        setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));\r
                                }\r
@@ -338,7 +345,7 @@ public class GitblitManager extends JFrame implements RegistrationsDialog.Regist
                        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
+                       // 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
index a9d7b466bf29a99411d7303e5e1d6ab9d86c5b26..6772c3d8db1dd637b793b73f021d84559bdc87da 100644 (file)
@@ -19,7 +19,9 @@ import java.awt.BorderLayout;
 import java.awt.Color;\r
 import java.awt.Component;\r
 import java.awt.Desktop;\r
+import java.awt.Dimension;\r
 import java.awt.FlowLayout;\r
+import java.awt.GridLayout;\r
 import java.awt.Insets;\r
 import java.awt.event.ActionEvent;\r
 import java.awt.event.ActionListener;\r
@@ -31,8 +33,11 @@ import java.io.IOException;
 import java.net.URI;\r
 import java.text.MessageFormat;\r
 import java.util.ArrayList;\r
+import java.util.HashMap;\r
 import java.util.List;\r
+import java.util.Map;\r
 \r
+import javax.swing.ImageIcon;\r
 import javax.swing.JButton;\r
 import javax.swing.JLabel;\r
 import javax.swing.JOptionPane;\r
@@ -395,6 +400,17 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
                        }\r
                });\r
 \r
+               final JButton editSetting = new JButton(Translation.get("gb.edit"));\r
+               editSetting.addActionListener(new ActionListener() {\r
+                       public void actionPerformed(ActionEvent e) {\r
+                               int viewRow = settingsTable.getSelectedRow();\r
+                               int modelRow = settingsTable.convertRowIndexToModel(viewRow);\r
+                               String key = settingsModel.keys.get(modelRow);\r
+                               SettingModel setting = settingsModel.settings.get(key);\r
+                               editSetting(setting);\r
+                       }\r
+               });\r
+\r
                final SettingPanel settingPanel = new SettingPanel();\r
                settingsModel = new SettingsTableModel();\r
                defaultSettingsSorter = new TableRowSorter<SettingsTableModel>(settingsModel);\r
@@ -412,9 +428,8 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
                                if (e.getValueIsAdjusting()) {\r
                                        return;\r
                                }\r
-                               boolean selected = settingsTable.getSelectedRow() > -1;\r
                                boolean singleSelection = settingsTable.getSelectedRows().length == 1;\r
-                               // TODO enable/disable setting buttons\r
+                               editSetting.setEnabled(singleSelection);\r
                                if (singleSelection) {\r
                                        int viewRow = settingsTable.getSelectedRow();\r
                                        int modelRow = settingsTable.convertRowIndexToModel(viewRow);\r
@@ -449,7 +464,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
 \r
                JPanel settingsControls = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 0));\r
                settingsControls.add(refreshSettings);\r
-               // TODO update setting?\r
+               settingsControls.add(editSetting);\r
 \r
                JPanel settingsPanel = new JPanel(new BorderLayout(margin, margin)) {\r
 \r
@@ -917,4 +932,53 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
                };\r
                worker.execute();\r
        }\r
+\r
+       protected void editSetting(final SettingModel settingModel) {\r
+               final JTextField textField = new JTextField(settingModel.currentValue);\r
+               JPanel editPanel = new JPanel(new GridLayout(0, 1));\r
+               editPanel.add(new JLabel("New Value"));\r
+               editPanel.add(textField);\r
+\r
+               JPanel settingPanel = new JPanel(new BorderLayout());\r
+               settingPanel.add(new SettingPanel(settingModel), BorderLayout.CENTER);\r
+               settingPanel.add(editPanel, BorderLayout.SOUTH);\r
+               settingPanel.setPreferredSize(new Dimension(800, 200));\r
+\r
+               String[] options;\r
+               if (settingModel.currentValue.equals(settingModel.defaultValue)) {\r
+                       options = new String[] { Translation.get("gb.cancel"), Translation.get("gb.save") };\r
+               } else {\r
+                       options = new String[] { Translation.get("gb.cancel"), Translation.get("gb.setDefault"),\r
+                                       Translation.get("gb.save") };\r
+               }\r
+               String defaultOption = options[0];\r
+               int selection = JOptionPane.showOptionDialog(GitblitPanel.this, settingPanel,\r
+                               settingModel.name, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,\r
+                               new ImageIcon(getClass().getResource("/settings_16x16.png")), options,\r
+                               defaultOption);\r
+               if (selection <= 0) {\r
+                       return;\r
+               }\r
+               if (options[selection].equals(Translation.get("gb.setDefault"))) {\r
+                       textField.setText(settingModel.defaultValue);\r
+               }\r
+               final Map<String, String> newSettings = new HashMap<String, String>();\r
+               newSettings.put(settingModel.name, textField.getText().trim());\r
+               GitblitWorker worker = new GitblitWorker(GitblitPanel.this, RpcRequest.EDIT_SETTINGS) {\r
+                       @Override\r
+                       protected Boolean doRequest() throws IOException {\r
+                               boolean success = gitblit.updateSettings(newSettings);\r
+                               if (success) {\r
+                                       gitblit.refreshSettings();\r
+                               }\r
+                               return success;\r
+                       }\r
+\r
+                       @Override\r
+                       protected void onSuccess() {\r
+                               updateSettingsTable();\r
+                       }\r
+               };\r
+               worker.execute();\r
+       }\r
 }
\ No newline at end of file
index 8d07dc8300e4d2cf16426ad625c59c4e285a4ba4..6da09e188346e515b32d8a41d3084b6d3ec024dc 100644 (file)
@@ -50,10 +50,16 @@ public class SettingPanel extends JPanel {
                initialize();\r
        }\r
 \r
+       public SettingPanel(SettingModel setting) {\r
+               this();\r
+               setSetting(setting);\r
+       }\r
+\r
        private void initialize() {\r
                descriptionArea = new JTextArea();\r
                descriptionArea.setRows(6);\r
                descriptionArea.setFont(new Font("monospaced", Font.PLAIN, 11));\r
+               descriptionArea.setEditable(false);\r
 \r
                settingName = new JLabel(" ");\r
                settingName.setFont(settingName.getFont().deriveFont(Font.BOLD));\r
@@ -83,10 +89,10 @@ public class SettingPanel extends JPanel {
                settingName.setText(setting.name);\r
                if (setting.since == null) {\r
                        sinceVersion.setText("custom");\r
-               } else {                        \r
+               } else {\r
                        sinceVersion.setText("since " + setting.since);\r
                }\r
-               settingDefault.setText("default: " + setting.defaultValue);\r
+               settingDefault.setText(Translation.get("gb.default") + ": " + setting.defaultValue);\r
 \r
                List<String> values = new ArrayList<String>();\r
                if (setting.caseSensitive) {\r
index c83757982d0d5e50c7340e1262b09596446a4915..ae81e7ff4da075af649c477f7b7e9cf3484afbbb 100644 (file)
@@ -17,11 +17,17 @@ package com.gitblit.client;
 \r
 import java.awt.Color;\r
 import java.awt.Component;\r
+import java.awt.Dimension;\r
+import java.awt.Font;\r
+import java.io.PrintWriter;\r
+import java.io.StringWriter;\r
 import java.text.MessageFormat;\r
 import java.util.Date;\r
 \r
 import javax.swing.JOptionPane;\r
+import javax.swing.JScrollPane;\r
 import javax.swing.JTable;\r
+import javax.swing.JTextArea;\r
 import javax.swing.table.DefaultTableColumnModel;\r
 import javax.swing.table.TableCellRenderer;\r
 import javax.swing.table.TableColumn;\r
@@ -55,8 +61,19 @@ public class Utils {
        }\r
 \r
        public static void showException(Component c, Throwable t) {\r
-               // TODO show the unexpected exception\r
-               t.printStackTrace();\r
+               StringWriter writer = new StringWriter();\r
+               t.printStackTrace(new PrintWriter(writer));\r
+               String stacktrace = writer.toString();\r
+               try {\r
+                       writer.close();\r
+               } catch (Throwable x) {\r
+               }\r
+               JTextArea textArea = new JTextArea(stacktrace);\r
+               textArea.setFont(new Font("monospaced", Font.PLAIN, 11));\r
+               JScrollPane jsp = new JScrollPane(textArea);\r
+               jsp.setPreferredSize(new Dimension(800, 400));\r
+               JOptionPane.showMessageDialog(c, jsp, Translation.get("gb.error"),\r
+                               JOptionPane.ERROR_MESSAGE);\r
        }\r
 \r
        public static void packColumns(JTable table, int margin) {\r
index 4314cf9e11ca5f0327f53b26b74902bbd30a660a..bbbd81cd0b70cd720d87ae7b7c1a52a690d7dab1 100644 (file)
@@ -163,4 +163,6 @@ gb.skipSizeCalculation = skip size calculation
 gb.skipSizeCalculationDescription = do not calculate the repository size (reduces page load time)\r
 gb.skipSummaryMetrics = skip summary metrics\r
 gb.skipSummaryMetricsDescription = do not calculate metrics on the summary page (reduces page load time)\r
-gb.accessLevel = access level
\ No newline at end of file
+gb.accessLevel = access level\r
+gb.default = default\r
+gb.setDefault = set default
\ No newline at end of file