1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package net.sf.jhylafax;
21
22 import static net.sf.jhylafax.JHylaFAX.i18n;
23 import gnu.hylafax.HylaFAXClient;
24 import javax.swing.JFrame;
25 import net.sf.jhylafax.fax.FaxJob;
26 import net.sf.jhylafax.fax.HylaFAXClientHelper;
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29 import org.xnap.commons.gui.ErrorDialog;
30 import org.xnap.commons.io.Job;
31 import org.xnap.commons.io.ProgressMonitor;
32 import org.xnap.commons.io.UserAbortException;
33
34
35
36
37
38
39 public class PollDialog extends AbstractFaxDialog {
40
41 private final static Log logger = LogFactory.getLog(PollDialog.class);
42
43 public PollDialog(JFrame owner) {
44 super(owner);
45
46 addNumberTextField();
47 addDateControls();
48
49 FaxJob job = new FaxJob();
50 HylaFAXClientHelper.initializeFromSettings(job);
51 setJob(job);
52
53 updateLabels();
54 pack();
55 }
56
57 @Override
58 public boolean apply() {
59 if (!super.apply()) {
60 return false;
61 }
62
63 Job<?> ioJob = new Job() {
64 public Object run(ProgressMonitor monitor) throws Exception
65 {
66 monitor.setTotalSteps(4);
67
68 HylaFAXClient client = JHylaFAX.getInstance().getConnection(monitor);
69 monitor.work(1);
70
71 gnu.hylafax.Job pollJob = client.createJob();
72 HylaFAXClientHelper.applyParameter(pollJob, getJob());
73 pollJob.setProperty("POLL", "\"\" \"\"");
74 monitor.work(1);
75
76 client.submit(pollJob);
77 monitor.work(2);
78
79 return null;
80 }
81 };
82
83 try {
84 JHylaFAX.getInstance().runJob(PollDialog.this, ioJob);
85 JHylaFAX.getInstance().updateTables();
86 }
87 catch (UserAbortException e) {
88 return false;
89 }
90 catch (Exception e) {
91 logger.debug("Error polling fax", e);
92 ErrorDialog.showError(this, i18n.tr("Could not poll fax"),
93 i18n.tr("JHylaFAX Error"),
94 e);
95 return false;
96 }
97 return true;
98 }
99
100 public void updateLabels() {
101 super.updateLabels();
102
103 setTitle(i18n.tr("Poll Fax"));
104 }
105
106 }