Test passes with query
authorJaroslav Tulach <jtulach@netbeans.org>
Sun, 01 Feb 2009 13:38:08 +0100
changeset 3091687adb2b7f0
parent 308 7f38f014244c
child 310 fba31e9504a1
Test passes with query
samples/exceptions/src/org/apidesign/exceptions/trycatchredo/IOManager.java
samples/exceptions/src/org/apidesign/exceptions/trycatchredo/SaveActionWithQuery.java
samples/exceptions/src/org/apidesign/exceptions/trycatchredo/UserQuestionException.java
     1.1 --- a/samples/exceptions/src/org/apidesign/exceptions/trycatchredo/IOManager.java	Sun Feb 01 13:27:04 2009 +0100
     1.2 +++ b/samples/exceptions/src/org/apidesign/exceptions/trycatchredo/IOManager.java	Sun Feb 01 13:38:08 2009 +0100
     1.3 @@ -12,6 +12,6 @@
     1.4      }
     1.5  
     1.6      public static Action createSaveAction(URL where, CharSequence what) {
     1.7 -        return new SaveAction(where, what);
     1.8 +        return new SaveActionWithQuery(where, what);
     1.9      }
    1.10  }
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/samples/exceptions/src/org/apidesign/exceptions/trycatchredo/SaveActionWithQuery.java	Sun Feb 01 13:38:08 2009 +0100
     2.3 @@ -0,0 +1,45 @@
     2.4 +package org.apidesign.exceptions.trycatchredo;
     2.5 +
     2.6 +import java.awt.EventQueue;
     2.7 +import java.awt.event.ActionEvent;
     2.8 +import java.io.IOException;
     2.9 +import java.io.OutputStream;
    2.10 +import java.net.URL;
    2.11 +import javax.swing.AbstractAction;
    2.12 +import javax.swing.JDialog;
    2.13 +import javax.swing.JOptionPane;
    2.14 +
    2.15 +/**
    2.16 + *
    2.17 + * @author Jaroslav Tulach
    2.18 + */
    2.19 +final class SaveActionWithQuery extends AbstractAction {
    2.20 +    private final URL where;
    2.21 +    private final CharSequence what;
    2.22 +    
    2.23 +    SaveActionWithQuery(URL where, CharSequence what) {
    2.24 +        this.where = where;
    2.25 +        this.what = what;
    2.26 +    }
    2.27 +    
    2.28 +    
    2.29 +    public void actionPerformed(ActionEvent ev) {
    2.30 +        assert EventQueue.isDispatchThread();
    2.31 +        for (;;) {
    2.32 +            try {
    2.33 +                OutputStream os = where.openConnection().getOutputStream();
    2.34 +                os.write(what.toString().getBytes());
    2.35 +                os.close();
    2.36 +            } catch (UserQuestionException ex) {
    2.37 +                JOptionPane p = ex.getQuestionPane();
    2.38 +                JDialog d = p.createDialog(ex.getLocalizedMessage());
    2.39 +                d.setVisible(true);
    2.40 +                ex.confirm(p.getValue());
    2.41 +                continue;
    2.42 +            } catch (IOException ex) {
    2.43 +                JOptionPane.showMessageDialog(null, ex);
    2.44 +            }
    2.45 +            break;
    2.46 +        }
    2.47 +    }
    2.48 +}
     3.1 --- a/samples/exceptions/src/org/apidesign/exceptions/trycatchredo/UserQuestionException.java	Sun Feb 01 13:27:04 2009 +0100
     3.2 +++ b/samples/exceptions/src/org/apidesign/exceptions/trycatchredo/UserQuestionException.java	Sun Feb 01 13:38:08 2009 +0100
     3.3 @@ -1,13 +1,13 @@
     3.4  package org.apidesign.exceptions.trycatchredo;
     3.5  
     3.6  import java.io.IOException;
     3.7 -import javax.swing.JComponent;
     3.8 +import javax.swing.JOptionPane;
     3.9  
    3.10  /**
    3.11   *
    3.12   * @author Jaroslav Tulach
    3.13   */
    3.14  public abstract class UserQuestionException extends IOException {
    3.15 -    public abstract JComponent getQuestionPane();
    3.16 -    public abstract void confirm();
    3.17 +    public abstract JOptionPane getQuestionPane();
    3.18 +    public abstract void confirm(Object option);
    3.19  }