1   /**
2    * JHylaFax - A java client for HylaFAX.
3    *
4    * Copyright (C) 2005 by Steffen Pingel <steffenp@gmx.de>
5    *
6    * This program is free software; you can redistribute it and/or modify
7    * it under the terms of the GNU General Public License as published by
8    * the Free Software Foundation; either version 2 of the License, or
9    * (at your option) any later version.
10   *
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   *
16   * You should have received a copy of the GNU General Public License
17   * along with this program; if not, write to the Free Software
18   * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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  public class EditDialog extends AbstractFaxDialog {
35  
36  	private final static Log logger = LogFactory.getLog(EditDialog.class);
37  	
38  	public EditDialog(JFrame owner, FaxJob job) {
39  		super(owner);
40  		
41  		addNumberTextField();
42  		addDateControls();
43  		
44  		setJob(job);
45  		revert();
46  		
47  		updateLabels();
48  		pack();
49  	}
50  	
51  	@Override
52  	public boolean apply() {
53  		if (!super.apply()) {
54  			return false;
55  		}
56  	
57  		Job<?> ioJob = new Job() {
58  			public Object run(ProgressMonitor monitor) throws Exception
59  			{
60  				monitor.setTotalSteps(4);
61  				
62  				HylaFAXClient client = JHylaFAX.getInstance().getConnection(monitor);
63  				monitor.work(1);
64  				
65  				gnu.hylafax.Job editJob = client.getJob(getJob().getID());
66  				client.suspend(editJob);
67  				HylaFAXClientHelper.applyParameter(editJob, getJob());
68  				monitor.work(1);
69  								
70  				client.submit(editJob);
71  				monitor.work(2);
72  				
73  				return null;
74  			}
75  		};
76  		
77  		try {
78  			JHylaFAX.getInstance().runJob(EditDialog.this, ioJob);
79  			JHylaFAX.getInstance().updateTables();
80  		} catch (UserAbortException e) {
81  			return false;
82  		} catch (Exception e) {
83  			logger.debug("Error setting job parameter", e);
84  			ErrorDialog.showError(this, i18n.tr("Could not set job parameter"), 
85  					i18n.tr("JHylaFAX Error"),
86  					e);
87  			return false;
88  		}
89  		return true;
90  	}
91  
92  	public void updateLabels() {
93  		super.updateLabels();
94  		
95  		setTitle(i18n.tr("Edit Job"));
96  	}
97  
98  }