import com.axyus.generator.pespj.GeneratorPesPjWizardProcess;
import com.axyus.generator.pespj.ui.ReferenceComptableUI;
import com.axyus.generator.pespj.ui.renderer.TableModelReferenceComptable;
+import com.axyus.generator.pespj.utils.Constants;
import com.axyus.generator.pespj.utils.DateUtils;
import com.axyus.generator.pespj.utils.GeneratePesUtils;
import com.axyus.swing.components.wizard.WizardProcess;
-import fr.gouv.minefi.cp.helios.pes_v2.facture.r0.aller.TPESFacture;
import fr.gouv.minefi.cp.helios.pes_v2.facture.r0.aller.TPESFactureOld;
import fr.gouv.minefi.cp.helios.pes_v2.rev0.aller.PESAller;
+import javax.swing.JOptionPane;
import org.apache.commons.io.FilenameUtils;
/**
* @author SME
*/
public class ReferenceComptableStep extends WizardProcess.Step<GeneratorPesPjWizardProcess> {
- private static Log logger = LogFactory.getLog(ReferenceComptableStep.class);
+ private static final String ENCODING = "ISO-8859-1";
+ private static Log logger = LogFactory.getLog(ReferenceComptableStep.class);
private ReferenceComptableUI referenceComptablePanelUI;
private File pesPjFile;
}
}
- JFileChooser chooseFileDialog = new JFileChooser(System.getProperty("user.home"));
+ String directoryPath = getWizardProcess().getProperties().getProperty(Constants.PROPERTIES_LAST_DIRECTORY_SAVE);
+ if(directoryPath == null){
+ directoryPath = System.getProperty("user.home");
+ }
+ JFileChooser chooseFileDialog = new JFileChooser(new File(directoryPath));
FileNameExtensionFilter xmlfilter = new FileNameExtensionFilter("xml files (*.xml)", "xml");
chooseFileDialog.setFileFilter(xmlfilter);
chooseFileDialog.setDialogTitle("Enregistrer sous ...");
- int response = chooseFileDialog.showDialog(getWizardProcess().getWizardDialog(), "Enregistrer");
-
- if (response == JFileChooser.APPROVE_OPTION) {
- this.referenceComptablePanelUI.setBusy(true);
- try{
- pesPjFile = chooseFileDialog.getSelectedFile();
+
+ int responseConfirm = JOptionPane.showConfirmDialog(getWizardProcess().getWizardDialog(),
+ "Vous êtes sur le point de générer le PES PJ, vous ne pourrez pas revenir en arrière.\n Etes-vous sûr de vouloir continuer ?",
+ "Confirmer la génération",
+ JOptionPane.YES_NO_OPTION);
+
+ if (responseConfirm == JOptionPane.YES_OPTION) {
+ int responseChooseFile = chooseFileDialog.showDialog(getWizardProcess().getWizardDialog(), "Enregistrer");
+ if(responseChooseFile == JFileChooser.APPROVE_OPTION) {
+ this.referenceComptablePanelUI.setBusy(true);
+ try{
+ pesPjFile = chooseFileDialog.getSelectedFile();
+ getWizardProcess().getProperties().setProperty(Constants.PROPERTIES_LAST_DIRECTORY_SAVE, pesPjFile.getParent());
- if(!FilenameUtils.isExtension(pesPjFile.getName(), "xml")){
- pesPjFile = new File(pesPjFile.getAbsolutePath()+".xml");
- if(!pesPjFile.exists()){
- pesPjFile.createNewFile();
+ if(!FilenameUtils.isExtension(pesPjFile.getName(), "xml")){
+ pesPjFile = new File(pesPjFile.getAbsolutePath()+".xml");
+ if(!pesPjFile.exists()){
+ pesPjFile.createNewFile();
+ }
}
- }
- PESAller pesAller = getWizardProcess().getPesAller();
- if(factureObj != null){
- pesAller.setPESFacture(factureObj);
- }
- pesAller.setPESPJ(GeneratePesUtils.generatePesPj(pesAller, getWizardProcess().getPjStep().getPjs()));
-
- FileOutputStream fos = new FileOutputStream(pesPjFile);
- // Génration du flux XML
- try {
- JAXBContext context = JAXBContext.newInstance(PESAller.class);
- pesPjFile = chooseFileDialog.getSelectedFile();
-
- Marshaller m = context.createMarshaller();
- m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
- logger.debug("Début de la génération : " + DateUtils.xmlFormatWithHours(new Date()));
- m.marshal(pesAller, fos);
- logger.debug("Fin de la génération : " + DateUtils.xmlFormatWithHours(new Date()));
- fos.flush();
+ PESAller pesAller = getWizardProcess().getPesAller();
+ if(factureObj != null){
+ pesAller.setPESFacture(factureObj);
+ }
+ pesAller.setPESPJ(GeneratePesUtils.generatePesPj(pesAller, getWizardProcess().getPjStep().getPjs()));
+
+ FileOutputStream fos = new FileOutputStream(pesPjFile);
+ // Génration du flux XML
+ try {
+ JAXBContext context = JAXBContext.newInstance(PESAller.class);
+ pesPjFile = chooseFileDialog.getSelectedFile();
+
+ Marshaller m = context.createMarshaller();
+ m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+ m.setProperty(Marshaller.JAXB_ENCODING, ENCODING);
+
+ logger.debug("Début de la génération : " + DateUtils.xmlFormatWithHours(new Date()));
+ m.marshal(pesAller, fos);
+ logger.debug("Fin de la génération : " + DateUtils.xmlFormatWithHours(new Date()));
+ fos.flush();
+ getWizardProcess().storeInPropertiesFile();
+ } finally {
+ fos.close();
+ }
+ } catch (Exception e) {
+ throw new StepValidationException("Probleme de génération du flux xml."+e.getLocalizedMessage());
} finally {
- fos.close();
+ this.referenceComptablePanelUI.setBusy(false);
}
- } catch (Exception e) {
- throw new StepValidationException("Probleme de génération du flux xml."+e.getLocalizedMessage());
- } finally {
- this.referenceComptablePanelUI.setBusy(false);
+ } else {
+ throw new StepValidationException("");
}
} else {
throw new StepValidationException("");