/*******************************************************************************
 * This file is part of GECAMed.
 * 
 * GECAMed is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License (L-GPL) as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * GECAMed is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License (L-GPL)
 * along with GECAMed.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * GECAMed is Copyrighted by the Centre de Recherche Public Henri Tudor (http://www.tudor.lu)
 * (c) CRP Henri Tudor, Luxembourg, 2008
 *******************************************************************************/
//package lu.tudor.santec.gecamed.letter.gui.listeners;
//
//import java.awt.event.ActionEvent;
//import java.awt.event.ActionListener;
//import java.io.File;
//import java.util.Date;
//
//import javax.swing.AbstractAction;
//import javax.swing.JOptionPane;
//
//import lu.tudor.santec.gecamed.core.gui.GECAMedModule;
//import lu.tudor.santec.gecamed.core.gui.MainFrame;
//import lu.tudor.santec.gecamed.core.utils.ManagerFactory;
//import lu.tudor.santec.gecamed.letter.ejb.session.beans.LetterTemplateBean;
//import lu.tudor.santec.gecamed.letter.ejb.session.interfaces.LetterTemplateInterface;
//import lu.tudor.santec.gecamed.letter.gui.ControllerConfig;
//import lu.tudor.santec.gecamed.letter.gui.LetterPanel;
//import lu.tudor.santec.gecamed.letter.gui.LetterTemplateModule;
//import lu.tudor.santec.gecamed.letter.gui.controller.IController;
//import lu.tudor.santec.gecamed.patient.ejb.entity.beans.IncidentEntry;
//import lu.tudor.santec.gecamed.patient.ejb.session.beans.IncidentManagerBean;
//import lu.tudor.santec.gecamed.patient.ejb.session.interfaces.IncidentManager;
//import lu.tudor.santec.gecamed.patient.gui.PatientManagerModule;
//import lu.tudor.santec.gecamed.patient.gui.history.table.HistoryTableModel.HistRow;
//import lu.tudor.santec.i18n.Translatrix;
//
//
///**
// * Modifies the content of a letter without creating a new letter
// * 
// * 
// * @author herve.weitz@tudor.lu
// * 01.07.2008
// * 10:04:36
// *
// *
// * @version
// * <br>$Log: ModifyLetterListener.java,v $
// * <br>Revision 1.4  2008-09-25 09:43:08  heinemann
// * <br>fixed copyrights
// * <br>
// * <br>Revision 1.3  2008-07-03 11:59:57  heinemann
// * <br>*** empty log message ***
// * <br>
// *   
// */
//public class ModifyLetterListener extends AbstractAction {
//
//	/**
//	 * 
//	 */
//	private static final long serialVersionUID = 1L;
//	
//	private HistRow row;
//	private IncidentEntry entry;
//	private IncidentManager iManager;
//
//	public void actionPerformed(ActionEvent e) {
//		/* ================================================== */
//		// get the selected row
//		/* ------------------------------------------------------- */
//		int row_number = LetterPanel.getInstance().getTable().getSelectedRow();
//		
//		if (row_number > -1) {
//			row = LetterPanel.getInstance().getTableData().get(row_number);
//			iManager = (IncidentManager) ManagerFactory.getRemote(IncidentManagerBean.class);
//
//			entry = row.getEntry();
//			MainFrame.getInstance().setWaitCursor(true);
//			final IController controller = ControllerConfig.getController();
//			new Thread() {
//				public void run() {
//					try {
//						LetterTemplateInterface manager = (LetterTemplateInterface) ManagerFactory
//						.getRemote(LetterTemplateBean.class);
////						byte[] filebytes = FileUtils.getGECAMedPatientFile(
////								entry.getOriginalFilename(),
////								ServerConfig.PATIENT_FILES_DIR, GECAMedModule
////										.getCurrentPatient().getId());
//						byte[] filebytes = manager.getFile(entry.getOriginalFilename(),  GECAMedModule.getCurrentPatient().getId());
//
//						controller.setDocument(filebytes);
//						controller.open();
//						MainFrame.getInstance().setWaitCursor(false);
//						controller.waitForUserInput();
//						lu.tudor.santec.gecamed.letter.gui.controller.data.State state = controller
//								.getState();
//						if (state.isSaved()) {
//							// Getting document from the client
//							File document = controller.getDocumentbyFile();
//
//							// Saving the file on the server
////							String generated_filename = FileUtils
////									.saveGECAMedPatientFile(controller
////											.getDocument(), document.getName(),
////											ServerConfig.PATIENT_FILES_DIR,
////											GECAMedModule.getCurrentPatient()
////													.getId());
//							
//							
//							String generated_filename = manager.saveFile(
//									controller.getDocument(),
//									document.getName(),
//									GECAMedModule
//											.getCurrentPatient()
//											.getId());
//							
//							
//							
//							if (ControllerConfig.deleteDocuments()) {
//								// Delete the local document
//								controller.deleteDocument();
//							}
//
//							entry.setModified(new Date());
//							entry.setModifiedBy(GECAMedModule
//									.getCurrentPhysician().getId());
//
//
//							// save
//							entry.setOriginalFilename(generated_filename);
//							iManager.saveEntry(entry, IncidentManager.LETTER);
//							
//						} else {
//							if (ControllerConfig.deleteDocuments()) {
//								// Delete the local document
//								controller.deleteDocument();
//							}
//						}
//						PatientManagerModule.getInstance().getPatientPanel()
//								.reloadHistory();
//
//					} catch (Exception e) {
//						MainFrame.getInstance().setWaitCursor(false);
//						JOptionPane
//						.showMessageDialog(
//								LetterTemplateModule.getInstance()
//										.getContentPane(),
//								Translatrix
//										.getTranslationString("LetterTemplateModule.dialog.error.open"),
//								Translatrix
//										.getTranslationString("LetterTemplateModule.dialog.error.title"),
//								JOptionPane.ERROR_MESSAGE);
//					}
//				}
//
//			}.start();
//		}
//		/* ================================================== */
//	}
//
//}
