Trap connect exceptions.
public final String account;\r
\r
private final char[] password;\r
- \r
+\r
private volatile boolean allowManagement;\r
\r
private volatile boolean allowAdministration;\r
public boolean allowManagement() {\r
return allowManagement;\r
}\r
- \r
+\r
public boolean allowAdministration() {\r
return allowAdministration;\r
}\r
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
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
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
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
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
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
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
}\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
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
\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
};\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
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
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
\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
}\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
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