From 2a99c31201b7002e4dd827b226cf2112d17ca1e1 Mon Sep 17 00:00:00 2001 From: James Moger Date: Mon, 24 Oct 2011 22:45:37 -0400 Subject: [PATCH] Functional edit setting feature for Manager. Wrote stacktrace viewer. Trap connect exceptions. --- src/com/gitblit/client/GitblitClient.java | 10 ++- src/com/gitblit/client/GitblitManager.java | 11 ++- src/com/gitblit/client/GitblitPanel.java | 70 ++++++++++++++++++- src/com/gitblit/client/SettingPanel.java | 10 ++- src/com/gitblit/client/Utils.java | 21 +++++- .../gitblit/wicket/GitBlitWebApp.properties | 4 +- 6 files changed, 113 insertions(+), 13 deletions(-) diff --git a/src/com/gitblit/client/GitblitClient.java b/src/com/gitblit/client/GitblitClient.java index 79914232..d3a92b0d 100644 --- a/src/com/gitblit/client/GitblitClient.java +++ b/src/com/gitblit/client/GitblitClient.java @@ -48,7 +48,7 @@ public class GitblitClient implements Serializable { public final String account; private final char[] password; - + private volatile boolean allowManagement; private volatile boolean allowAdministration; @@ -100,7 +100,7 @@ public class GitblitClient implements Serializable { public boolean allowManagement() { return allowManagement; } - + public boolean allowAdministration() { return allowAdministration; } @@ -136,7 +136,7 @@ public class GitblitClient implements Serializable { allUsers.addAll(users); return allUsers; } - + public ServerSettings refreshSettings() throws IOException { settings = RpcUtils.getSettings(url, account, password); return settings; @@ -217,4 +217,8 @@ public class GitblitClient implements Serializable { public boolean deleteUser(UserModel user) throws IOException { return RpcUtils.deleteUser(user, url, account, password); } + + public boolean updateSettings(Map newSettings) throws IOException { + return RpcUtils.updateSettings(newSettings, url, account, password); + } } diff --git a/src/com/gitblit/client/GitblitManager.java b/src/com/gitblit/client/GitblitManager.java index 43cdab36..d902c590 100644 --- a/src/com/gitblit/client/GitblitManager.java +++ b/src/com/gitblit/client/GitblitManager.java @@ -29,6 +29,7 @@ import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.File; import java.io.IOException; +import java.net.ConnectException; import java.text.MessageFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -272,7 +273,13 @@ public class GitblitManager extends JFrame implements RegistrationsDialog.Regist registrations.put(reg.name, reg); rebuildRecentMenu(); } catch (Throwable t) { - Utils.showException(GitblitManager.this, t); + Throwable cause = t.getCause(); + if (cause instanceof ConnectException) { + JOptionPane.showMessageDialog(GitblitManager.this, cause.getMessage(), + Translation.get("gb.error"), JOptionPane.ERROR_MESSAGE); + } else { + Utils.showException(GitblitManager.this, t); + } } finally { setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } @@ -338,7 +345,7 @@ public class GitblitManager extends JFrame implements RegistrationsDialog.Regist StoredConfig config = getConfig(); config.setString("servers", reg.name, "url", reg.url); config.setString("servers", reg.name, "account", reg.account); - // FIXME this is pretty lame + // FIXME this is pretty lame config.setString("servers", reg.name, "password", Base64.encodeBytes(new String(reg.password).getBytes("UTF-8"))); config.setString("servers", reg.name, "lastLogin", dateFormat.format(reg.lastLogin)); diff --git a/src/com/gitblit/client/GitblitPanel.java b/src/com/gitblit/client/GitblitPanel.java index a9d7b466..6772c3d8 100644 --- a/src/com/gitblit/client/GitblitPanel.java +++ b/src/com/gitblit/client/GitblitPanel.java @@ -19,7 +19,9 @@ import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Desktop; +import java.awt.Dimension; import java.awt.FlowLayout; +import java.awt.GridLayout; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -31,8 +33,11 @@ import java.io.IOException; import java.net.URI; import java.text.MessageFormat; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JOptionPane; @@ -395,6 +400,17 @@ public class GitblitPanel extends JPanel implements CloseTabListener { } }); + final JButton editSetting = new JButton(Translation.get("gb.edit")); + editSetting.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + int viewRow = settingsTable.getSelectedRow(); + int modelRow = settingsTable.convertRowIndexToModel(viewRow); + String key = settingsModel.keys.get(modelRow); + SettingModel setting = settingsModel.settings.get(key); + editSetting(setting); + } + }); + final SettingPanel settingPanel = new SettingPanel(); settingsModel = new SettingsTableModel(); defaultSettingsSorter = new TableRowSorter(settingsModel); @@ -412,9 +428,8 @@ public class GitblitPanel extends JPanel implements CloseTabListener { if (e.getValueIsAdjusting()) { return; } - boolean selected = settingsTable.getSelectedRow() > -1; boolean singleSelection = settingsTable.getSelectedRows().length == 1; - // TODO enable/disable setting buttons + editSetting.setEnabled(singleSelection); if (singleSelection) { int viewRow = settingsTable.getSelectedRow(); int modelRow = settingsTable.convertRowIndexToModel(viewRow); @@ -449,7 +464,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener { JPanel settingsControls = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 0)); settingsControls.add(refreshSettings); - // TODO update setting? + settingsControls.add(editSetting); JPanel settingsPanel = new JPanel(new BorderLayout(margin, margin)) { @@ -917,4 +932,53 @@ public class GitblitPanel extends JPanel implements CloseTabListener { }; worker.execute(); } + + protected void editSetting(final SettingModel settingModel) { + final JTextField textField = new JTextField(settingModel.currentValue); + JPanel editPanel = new JPanel(new GridLayout(0, 1)); + editPanel.add(new JLabel("New Value")); + editPanel.add(textField); + + JPanel settingPanel = new JPanel(new BorderLayout()); + settingPanel.add(new SettingPanel(settingModel), BorderLayout.CENTER); + settingPanel.add(editPanel, BorderLayout.SOUTH); + settingPanel.setPreferredSize(new Dimension(800, 200)); + + String[] options; + if (settingModel.currentValue.equals(settingModel.defaultValue)) { + options = new String[] { Translation.get("gb.cancel"), Translation.get("gb.save") }; + } else { + options = new String[] { Translation.get("gb.cancel"), Translation.get("gb.setDefault"), + Translation.get("gb.save") }; + } + String defaultOption = options[0]; + int selection = JOptionPane.showOptionDialog(GitblitPanel.this, settingPanel, + settingModel.name, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, + new ImageIcon(getClass().getResource("/settings_16x16.png")), options, + defaultOption); + if (selection <= 0) { + return; + } + if (options[selection].equals(Translation.get("gb.setDefault"))) { + textField.setText(settingModel.defaultValue); + } + final Map newSettings = new HashMap(); + newSettings.put(settingModel.name, textField.getText().trim()); + GitblitWorker worker = new GitblitWorker(GitblitPanel.this, RpcRequest.EDIT_SETTINGS) { + @Override + protected Boolean doRequest() throws IOException { + boolean success = gitblit.updateSettings(newSettings); + if (success) { + gitblit.refreshSettings(); + } + return success; + } + + @Override + protected void onSuccess() { + updateSettingsTable(); + } + }; + worker.execute(); + } } \ No newline at end of file diff --git a/src/com/gitblit/client/SettingPanel.java b/src/com/gitblit/client/SettingPanel.java index 8d07dc83..6da09e18 100644 --- a/src/com/gitblit/client/SettingPanel.java +++ b/src/com/gitblit/client/SettingPanel.java @@ -50,10 +50,16 @@ public class SettingPanel extends JPanel { initialize(); } + public SettingPanel(SettingModel setting) { + this(); + setSetting(setting); + } + private void initialize() { descriptionArea = new JTextArea(); descriptionArea.setRows(6); descriptionArea.setFont(new Font("monospaced", Font.PLAIN, 11)); + descriptionArea.setEditable(false); settingName = new JLabel(" "); settingName.setFont(settingName.getFont().deriveFont(Font.BOLD)); @@ -83,10 +89,10 @@ public class SettingPanel extends JPanel { settingName.setText(setting.name); if (setting.since == null) { sinceVersion.setText("custom"); - } else { + } else { sinceVersion.setText("since " + setting.since); } - settingDefault.setText("default: " + setting.defaultValue); + settingDefault.setText(Translation.get("gb.default") + ": " + setting.defaultValue); List values = new ArrayList(); if (setting.caseSensitive) { diff --git a/src/com/gitblit/client/Utils.java b/src/com/gitblit/client/Utils.java index c8375798..ae81e7ff 100644 --- a/src/com/gitblit/client/Utils.java +++ b/src/com/gitblit/client/Utils.java @@ -17,11 +17,17 @@ package com.gitblit.client; import java.awt.Color; import java.awt.Component; +import java.awt.Dimension; +import java.awt.Font; +import java.io.PrintWriter; +import java.io.StringWriter; import java.text.MessageFormat; import java.util.Date; import javax.swing.JOptionPane; +import javax.swing.JScrollPane; import javax.swing.JTable; +import javax.swing.JTextArea; import javax.swing.table.DefaultTableColumnModel; import javax.swing.table.TableCellRenderer; import javax.swing.table.TableColumn; @@ -55,8 +61,19 @@ public class Utils { } public static void showException(Component c, Throwable t) { - // TODO show the unexpected exception - t.printStackTrace(); + StringWriter writer = new StringWriter(); + t.printStackTrace(new PrintWriter(writer)); + String stacktrace = writer.toString(); + try { + writer.close(); + } catch (Throwable x) { + } + JTextArea textArea = new JTextArea(stacktrace); + textArea.setFont(new Font("monospaced", Font.PLAIN, 11)); + JScrollPane jsp = new JScrollPane(textArea); + jsp.setPreferredSize(new Dimension(800, 400)); + JOptionPane.showMessageDialog(c, jsp, Translation.get("gb.error"), + JOptionPane.ERROR_MESSAGE); } public static void packColumns(JTable table, int margin) { diff --git a/src/com/gitblit/wicket/GitBlitWebApp.properties b/src/com/gitblit/wicket/GitBlitWebApp.properties index 4314cf9e..bbbd81cd 100644 --- a/src/com/gitblit/wicket/GitBlitWebApp.properties +++ b/src/com/gitblit/wicket/GitBlitWebApp.properties @@ -163,4 +163,6 @@ gb.skipSizeCalculation = skip size calculation gb.skipSizeCalculationDescription = do not calculate the repository size (reduces page load time) gb.skipSummaryMetrics = skip summary metrics gb.skipSummaryMetricsDescription = do not calculate metrics on the summary page (reduces page load time) -gb.accessLevel = access level \ No newline at end of file +gb.accessLevel = access level +gb.default = default +gb.setDefault = set default \ No newline at end of file -- 2.39.5