/*
* SalomeTMF is a Test Management Framework
* Copyright (C) 2007 EDF / France Telecom R&D
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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 along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @author Jrmie DEFAYE
*
* Contact: mikael.marche@rd.francetelecom.com
*/
package salomeTMF_plug.pluginxlsxml.Commun;
import java.io.IOException;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.net.URL;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import jxl.write.WriteException;
import org.objectweb.salome_tmf.ihm.main.SalomeTMFContext;
import org.objectweb.salome_tmf.ihm.models.ScriptFileFilter;
import org.objectweb.salome_tmf.plugins.IPlugObject;
import salomeTMF_plug.pluginxlsxml.language.Language;
/**
* /**
*
* @author adm_dfej
*/
public class PopUpFormalismeExcel extends JDialog {
private File fichierDeSortieXLS;
private JButton genererModele;
private JButton annuler;
private JLabel explicationsTestsLabel;
private JLabel explicationsExigencesLabel;
private JLabel explicationsParametresLabel;
private JLabel explicationsEnvironnementsLabel;
private JLabel explicationsCampagnesLabel;
private JLabel explicationsExecutionsCampagnesLabel;
private JLabel laiusExigencesLabel;
private JLabel laiusTestsLabel;
private JLabel laiusParametresLabel;
private JLabel laiusEnvironnementsLabel;
private JLabel laiusCampagnesLabel;
private JLabel laiusExecutionsCampagnesLabel;
private String xlsFile;
private int numeroColonne = 0;
private int numeroLigne = 0;
private int nombreLigneRequirementLu = 0;
private int numeroColonneExigence = 0;
private boolean selectionExportExigence = true;
private boolean selectionExportTest = true;
private boolean selectionExportParametre = true;
private boolean selectionExportEnvironnement = true;
private boolean selectionExportCampagne = true;
private boolean selectionExportExecutionCampagne = true;
private boolean masquageColonnes = false;
private boolean presenceFeuilleAnomalie= false;
// Salome GUI
private IPlugObject pIhm = null;
private URL urlBase;
private String url_txt;
/**
* Creates a new instance of PopUpFormalismeExcel
*
* @param vt
* Interface Homme Machine
*/
public PopUpFormalismeExcel(IPlugObject vt) {
super(SalomeTMFContext.getInstance().getSalomeFrame(), true);
if (vt != null) {
this.pIhm = vt;
}
explicationsExigencesLabel = new JLabel(Language.getInstance().getText("Explications_Exigences_Label"));
explicationsTestsLabel = new JLabel(Language.getInstance().getText("Explications_Tests_Label"));
explicationsParametresLabel = new JLabel(Language.getInstance().getText("Explications_Parametres_Label"));
explicationsEnvironnementsLabel = new JLabel(Language.getInstance().getText("Explications_Environnements_Label"));
explicationsCampagnesLabel = new JLabel(Language.getInstance().getText("Explications_Campagnes_Label"));
explicationsExecutionsCampagnesLabel = new JLabel(Language.getInstance().getText("Explications_Executions_Campagnes_Label"));
laiusExigencesLabel = new JLabel(Language.getInstance().getText("Laius_Exigences_Label"));
laiusTestsLabel = new JLabel(Language.getInstance().getText("Laius_Tests_Label"));
laiusParametresLabel = new JLabel(Language.getInstance().getText("Laius_Parametres_Label"));
laiusEnvironnementsLabel = new JLabel(Language.getInstance().getText("Laius_Environnements_Label"));
laiusCampagnesLabel = new JLabel(Language.getInstance().getText("Laius_Campagnes_Label"));
laiusExecutionsCampagnesLabel = new JLabel(Language.getInstance().getText("Laius_Executions_Campagnes_Label"));
genererModele = new JButton(Language.getInstance().getText("Generer_Modele"));
genererModele.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Ouvrir boite dialogue Choix fichier excel
JFileChooser fileChooser = new JFileChooser();
fileChooser.addChoosableFileFilter(new ScriptFileFilter(Language.getInstance().getText("Fichier_XLS_[*.xls]"),".xls"));
int returnVal = fileChooser.showDialog(PopUpFormalismeExcel.this, Language.getInstance().getText("Slectionner"));
if (returnVal == JFileChooser.APPROVE_OPTION) {
xlsFile = fileChooser.getSelectedFile().getAbsolutePath();
if (xlsFile.indexOf(".") != -1) {
if (!xlsFile.substring(xlsFile.lastIndexOf(".")).equals(".xls")) {
xlsFile += ".xls";
}
} else {
xlsFile += ".xls";
}
// Cree fichier excel
String nomFichierSortie = xlsFile;
// Tente de crer le fichier excel
fichierDeSortieXLS = new File(nomFichierSortie);
int i = 0;
while (fichierDeSortieXLS.exists()) {
if (i == 0) {
System.out.println(Language.getInstance().getText("FileName_Already_Exists"));
nomFichierSortie = nomFichierSortie.substring(0, nomFichierSortie.lastIndexOf(".")) + "_" + Integer.toString(i) + ".xls";
} else {
nomFichierSortie = nomFichierSortie.substring(0, nomFichierSortie.lastIndexOf("_")) + "_" + Integer.toString(i) + ".xls";
}
fichierDeSortieXLS = new File(nomFichierSortie);
i++;
}
System.out.println(Language.getInstance().getText("Fichier_Sortie_XLS") + fichierDeSortieXLS.toString());
try {
fichierDeSortieXLS.createNewFile();
} catch (IOException ex) {
System.out.println(Language.getInstance().getText("Erreur_Fichier_Sortie_XML") + fichierDeSortieXLS.toString());
ex.printStackTrace();
}
try {
int NombreBrancheExigence=2;
EcritEntete EcritEntete = new EcritEntete(NombreBrancheExigence, fichierDeSortieXLS, presenceFeuilleAnomalie);
EcritEntete.getWorkbookHeading();
EcritEntete.makeExample();
EcritEntete.organizeXLSfile(selectionExportExigence, selectionExportTest, selectionExportParametre, selectionExportEnvironnement, selectionExportCampagne, selectionExportExecutionCampagne, presenceFeuilleAnomalie, masquageColonnes);
EcritEntete.closeWorkbook(presenceFeuilleAnomalie);
} catch (WriteException ex) {
ex.printStackTrace();
}
// Ferme la fenetre
PopUpFormalismeExcel.this.dispose();
}
}
});
annuler = new JButton(Language.getInstance().getText("Annuler"));
annuler.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
PopUpFormalismeExcel.this.dispose();
}
});
JPanel texte = new JPanel();
texte.setLayout(new FlowLayout(FlowLayout.LEFT));
texte.add(explicationsTestsLabel);
JPanel texte2 = new JPanel();
texte2.setLayout(new FlowLayout(FlowLayout.LEFT));
texte2.add(laiusTestsLabel);
JPanel texte3 = new JPanel();
texte3.setLayout(new FlowLayout(FlowLayout.LEFT));
texte3.add(explicationsExigencesLabel);
JPanel texte4 = new JPanel();
texte4.setLayout(new FlowLayout(FlowLayout.LEFT));
texte4.add(laiusExigencesLabel);
JPanel texte5 = new JPanel();
texte5.setLayout(new FlowLayout(FlowLayout.LEFT));
texte5.add(explicationsParametresLabel);
JPanel texte6 = new JPanel();
texte6.setLayout(new FlowLayout(FlowLayout.LEFT));
texte6.add(laiusParametresLabel);
JPanel texte7 = new JPanel();
texte7.setLayout(new FlowLayout(FlowLayout.LEFT));
texte7.add(explicationsEnvironnementsLabel);
JPanel texte8 = new JPanel();
texte8.setLayout(new FlowLayout(FlowLayout.LEFT));
texte8.add(laiusEnvironnementsLabel);
JPanel texte9 = new JPanel();
texte9.setLayout(new FlowLayout(FlowLayout.LEFT));
texte9.add(explicationsCampagnesLabel);
JPanel texte10 = new JPanel();
texte10.setLayout(new FlowLayout(FlowLayout.LEFT));
texte10.add(laiusCampagnesLabel);
JPanel texte11 = new JPanel();
texte11.setLayout(new FlowLayout(FlowLayout.LEFT));
texte11.add(explicationsExecutionsCampagnesLabel);
JPanel texte12 = new JPanel();
texte12.setLayout(new FlowLayout(FlowLayout.LEFT));
texte12.add(laiusExecutionsCampagnesLabel);
JPanel buttons = new JPanel();
buttons.add(genererModele);
buttons.add(annuler);
JPanel page = new JPanel();
page.setLayout(new BoxLayout(page, BoxLayout.Y_AXIS));
if (TestPresencePlugin.testDeLaPresenceDuPluginRequirement()){
page.add(texte3);
page.add(Box.createVerticalStrut(10));
page.add(texte4);
page.add(Box.createVerticalStrut(10));
}
page.add(texte);
page.add(Box.createVerticalStrut(3));
page.add(texte2);
page.add(Box.createVerticalStrut(10));
page.add(texte5);
page.add(Box.createVerticalStrut(3));
page.add(texte6);
page.add(Box.createVerticalStrut(10));
page.add(texte7);
page.add(Box.createVerticalStrut(3));
page.add(texte8);
page.add(Box.createVerticalStrut(10));
page.add(texte9);
page.add(Box.createVerticalStrut(3));
page.add(texte10);
page.add(Box.createVerticalStrut(10));
page.add(texte11);
page.add(Box.createVerticalStrut(3));
page.add(texte12);
page.add(Box.createVerticalStrut(10));
page.add(buttons);
Container contentPaneFrame = this.getContentPane();
contentPaneFrame.add(page, BorderLayout.CENTER);
setLocation(400, 100);
setTitle(Language.getInstance().getText("Generation_modele_Excel"));
pack();
setVisible(true);
}
}
|