Moved error reporting method into utility class.

git-svn-id: https://samskivert.googlecode.com/svn/trunk@1120 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2003-05-07 17:27:12 +00:00
parent 8e2c73b379
commit c5f3d888b4
2 changed files with 43 additions and 23 deletions
@@ -1,5 +1,5 @@
//
// $Id: Chooser.java,v 1.11 2003/05/04 18:16:06 mdb Exp $
// $Id: Chooser.java,v 1.12 2003/05/07 17:27:12 mdb Exp $
package robodj.chooser;
@@ -21,6 +21,7 @@ import com.samskivert.util.PropertiesUtil;
import robodj.Log;
import robodj.repository.Model;
import robodj.repository.Repository;
import robodj.util.ErrorUtil;
import robodj.util.RDJPrefs;
import robodj.util.RDJPrefsPanel;
import robodj.util.ServerControl;
@@ -61,8 +62,8 @@ public class Chooser
model = new Model(repository);
} catch (PersistenceException pe) {
if (reportError("Unable to establish communication " +
"with database:", pe)) {
String errmsg = "Unable to communicate with database:";
if (ErrorUtil.reportError(errmsg, pe)) {
System.exit(-1);
}
continue;
@@ -78,9 +79,9 @@ public class Chooser
scontrol = new ServerControl(
host, RDJPrefs.getMusicDaemonPort());
} catch (IOException ioe) {
if (reportError("Unable to establish communication with " +
"music server on host '" +
RDJPrefs.getMusicDaemonHost() + "' ", ioe)) {
String errmsg = "Unable to communicate with music " +
"server on host '" + RDJPrefs.getMusicDaemonHost() + "' ";
if (ErrorUtil.reportError(errmsg, ioe)) {
System.exit(-1);
}
continue;
@@ -96,21 +97,4 @@ public class Chooser
SwingUtil.centerWindow(frame);
frame.setVisible(true);
}
protected static boolean reportError (String error, Exception e)
{
String text = error;
if (e != null) {
text = text + "\n\n" + e.getMessage();
if (e.getCause() != null) {
text = text + "\n" + e.getCause().getMessage();
}
}
Object[] options = { "Edit configuration", "Exit" };
int choice = JOptionPane.showOptionDialog(
null, text, "Error", JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE, null, options, options[0]);
System.out.println("Chose " + choice + ".");
return (choice == 1 || choice == JOptionPane.CLOSED_OPTION);
}
}
@@ -0,0 +1,36 @@
//
// $Id: ErrorUtil.java,v 1.1 2003/05/07 17:27:12 mdb Exp $
package robodj.util;
import javax.swing.JOptionPane;
/**
* Contains a useful method for reporting errors.
*/
public class ErrorUtil
{
/**
* Reports an error, giving the details from the supplied (potentially
* nested) exception. The user is given the choice of editing their
* configuration or exiting the application.
*
* @return false if the user chose to edit the configuration, true if
* they chose to exit.
*/
public static boolean reportError (String error, Exception e)
{
String text = error;
if (e != null) {
text = text + "\n\n" + e.getMessage();
if (e.getCause() != null) {
text = text + "\n" + e.getCause().getMessage();
}
}
Object[] options = { "Edit configuration", "Exit" };
int choice = JOptionPane.showOptionDialog(
null, text, "Error", JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE, null, options, options[0]);
return (choice == 1 || choice == JOptionPane.CLOSED_OPTION);
}
}