Bonjour à tous,

Après lecture de plusieurs sujets postés et de tutos sur les JOptionPane et les jDialog, je fais appel à votre aide.

J'ai en effet le code suivant :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
 
//differents import
public class FenetreSaisie extends JFrame{
	private JLabel label_presentation_fenetre;
	private JLabel label_entree;
	private JLabel label_sortie;
	private JTextField txtlocalPath = new JTextField(25);
	private JTextField txtSortie = new JTextField(25);
	private JDialog error = new JDialog();
 
	//creation du panel 
	JPanel panel = new JPanel();
 
	public FenetreSaisie(){
		super();
 
		build();//On initialise notre fenêtre
	}
 
	//initialisation Fenetre
	private void build(){
		setTitle("Utilitaire de conversion"); //On donne un titre à l'application
		setSize(450,300); //On donne une taille à notre fenêtre
		setLocationRelativeTo(null); //On centre la fenêtre sur l'écran
		setResizable(true); //On permet le redimensionnement
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //On dit à l'application de se fermer lors du clic sur la croix
		setContentPane(buildContentPane());
	}
 
	private JPanel buildContentPane(){
 
 
		//affectation du Layout GridBagLayout au panel
		panel.setLayout(new GridBagLayout());
 
 
		//création des composants
		label_presentation_fenetre = new JLabel("Utilitaire de conversion");
			//creation du bouton Parcourir afin de chercher la source
		JButton btnparcourir = new JButton("Parcourir...");	 
		btnparcourir.addActionListener(new BoutonParcourirListener());
 
			//creation de labels pour informer l'utilisateur
		label_entree = new JLabel("Fichier à traduire");
		label_sortie = new JLabel("Saisir le nom du fichier XML de sortie");
 
			//creation du bouton Traduire ebXML vers XML
		JButton btntradsimple = new JButton("ebXML -> XML");
		btntradsimple.addActionListener(new BoutonTradSimpleListener());
		btntradsimple.setToolTipText("Traduit du ebXML vers le XML simplifié");	
 
			//creation du bouton traduire XML vers ebXML
		JButton btntradcomplique = new JButton("XML -> ebXML");
		btntradcomplique.addActionListener(new BoutonTradCompliqueListener());		
		btntradcomplique.setToolTipText("Traduit du XML simplifié vers le ebXML");		
 
		//Ajout des composants en spécifiant les contraintes
        GridBagConstraints gbc = new GridBagConstraints();        
 
        gbc.gridx =0;
        gbc.gridy = 0;
        gbc.gridwidth = 10;
        gbc.gridheight = 1;       	
        gbc.anchor = GridBagConstraints.NORTH;
        gbc.fill = GridBagConstraints.CENTER;
        panel.add(label_presentation_fenetre, gbc);
 
        gbc.gridx = 0;
        gbc.gridy = 1;        
        gbc.gridwidth =10 ;
        gbc.gridheight =1; 
        gbc.anchor = GridBagConstraints.CENTER;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        panel.add(label_entree, gbc);
 
 
        gbc.gridx = 0;
        gbc.gridy = 2;        
        gbc.gridwidth = 1;
        gbc.gridheight = 1;
        gbc.anchor = GridBagConstraints.WEST;
        gbc.fill = GridBagConstraints.NONE;
        panel.add(txtlocalPath, gbc);
 
 
        gbc.gridx = 3;
        gbc.gridy = 2;
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.gridheight = 1;
        gbc.anchor = GridBagConstraints.BASELINE_LEADING;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        panel.add(btnparcourir, gbc);
 
 
        gbc.gridx = 0;
        gbc.gridy = 3;
        gbc.gridwidth = 1;
        gbc.gridheight =1;
        gbc.anchor = GridBagConstraints.BASELINE_LEADING;
        gbc.fill = GridBagConstraints.NONE;
        panel.add(label_sortie, gbc);
 
 
        gbc.gridx = 0;
        gbc.gridy = 4;
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.gridheight = 1;
        gbc.anchor = GridBagConstraints.BASELINE_LEADING;
        gbc.fill = GridBagConstraints.NONE;
        panel.add(txtSortie, gbc);
 
        gbc.gridx = 0;
        gbc.gridy = 6;         
        gbc.gridwidth = 1;
        gbc.gridheight =1;
        gbc.anchor = GridBagConstraints.BASELINE_LEADING;
        gbc.fill = GridBagConstraints.NONE;
        panel.add(btntradsimple, gbc);
 
        gbc.gridx = 3;
        gbc.gridy = 6;
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.gridheight = 1;
        gbc.anchor = GridBagConstraints.BASELINE_LEADING;
        gbc.fill = GridBagConstraints.NONE;
        panel.add(btntradcomplique, gbc);               
 
        return panel;
	}
 
 
 
	//classe interne permettant d'écouter le bouton Parcourir
	class BoutonParcourirListener  implements ActionListener{
 
		public void actionPerformed(ActionEvent event)
		{
			FileSystemView vueSysteme = FileSystemView.getFileSystemView(); 
			File defaut = vueSysteme.getDefaultDirectory();  
			JFileChooser defautChooser = new JFileChooser(defaut);
			defautChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
			defautChooser.showOpenDialog(null);
			File file = defautChooser.getSelectedFile();
			txtlocalPath.setText(file.getPath());
 
		}
 
	}//fin classe BoutonParcourirListener	
 
	//classe BoutonTradSimpleListener permettant d'écouter le bouton btntradsimple : pour passer du ebXML vers le XML simple
	class BoutonTradSimpleListener  implements ActionListener{
 
		public void actionPerformed(ActionEvent arg0) {
		//récupérer le contenu de la textBox et traduire	
 
		 System.setProperty("javax.xml.transform.TransformerFactory",
		"net.sf.saxon.TransformerFactoryImpl");
 
		//on crée une fabrique de transformeurs 
		TransformerFactory factory = TransformerFactory.newInstance();
 
		//fichier xsl de transformation
		File fxsl = new File("transfo.xsl");
 
		//fichier xml source de type source
 
			Source xmlSource = new StreamSource(decoupeURL());
 
		//nom du fichier de sortie de type Result			
			Result sortie = new StreamResult(txtSortie.getText());
 
		//transformer
		Transformer transformer;
		try {
			//on récupère un transformeur à partir d'une fabrique de transformeurs
			transformer = factory.newTransformer(new StreamSource(fxsl));
 
			//encoding
			// transformer.setOutputProperty("encoding", "ISO-8859-1");
			transformer.setOutputProperty("encoding", "UTF-8");
 
			//pour l'indentation
			transformer.setOutputProperty(OutputKeys.INDENT,"yes");
 
			//transformation en prenant en paramètre le fichier xml source et fait le fichier xml de sortie			
			transformer.transform(xmlSource, sortie );
 
		} catch (TransformerConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (TransformerException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
 
		}
 
	}//fin de la classe BoutonTradSimpleListener
 
 
	//classe BoutonTradCompliqueListener permettant d'écouter le bouton btntradcomplique : pour passer du XML simple au ebXML
	class BoutonTradCompliqueListener  implements ActionListener{
 
		public void actionPerformed(ActionEvent arg0) {
			//récupérer le contenu de la textBox et traduire	
			 System.setProperty("javax.xml.transform.TransformerFactory",
				"net.sf.saxon.TransformerFactoryImpl");
 
				//on crée une fabrique de transformeurs 
				TransformerFactory factory = TransformerFactory.newInstance();
 
				//fichier xsl de transformation
				File fxsl = new File("transfo_eb.xsl");				
 
				//fichier xml source de type source
				Source xmlSource = new StreamSource(decoupeURL());
 
				//nom du fichier de sortie de type Result
 
				Result sortie = new StreamResult(txtSortie.getText());
 
				//transformer
				Transformer transformer;
				try {
					//on récupère un transformeur à partir d'une fabrique de transformeurs
					transformer = factory.newTransformer(new StreamSource(fxsl));
 
					//encoding
					// transformer.setOutputProperty("encoding", "ISO-8859-1");
					transformer.setOutputProperty("encoding", "UTF-8");
 
					//pour l'indentation
					transformer.setOutputProperty(OutputKeys.INDENT,"yes");
 
					//transformation en prenant en paramètre le fichier xml source et fait le fichier xml de sortie			
					transformer.transform(xmlSource, sortie );
 
				} catch (TransformerConfigurationException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (TransformerException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}	
		}
 
	}//fin de la classe BoutonTradCompliqueListener
 
 
	public static void main(String[] args) {
		//On crée une nouvelle instance de notre FenetreTexte
		FenetreSaisie fenetre = new FenetreSaisie();
		fenetre.setVisible(true);//On la rend visible
	}
 
 
	public String decoupeURL(){
		blabla
 
	}
 
	public static String getFileExtension(String NomFichier) {
	    File tmpFichier = new File(NomFichier);
	    tmpFichier.getName();
	    int posPoint = tmpFichier.getName().lastIndexOf('.');
	    if (0 < posPoint && posPoint <= tmpFichier.getName().length() - 2 ) {
	        return tmpFichier.getName().substring(posPoint + 1);
	    }   
	    return "";
	}	
 
}//fin de la classe
jusqu'ici, tout va bien, seulement dans mes 2 boutons de traduction btntradsimple et btntradcomplique, j'aimerais faire appel à ma méthode getFileExtension,afin de contrôler si mon fichier d'entrée et mon fichier de sortie sont bien des .xml.

J'ai commencé dans un premier temps de passer par les JOptionPane, en faisant la chose suivante :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
 
if(getFileExtension(decoupeURL())!="xml"){
				JOptionPane.showMessageDialog(panel,
                        "Saisir un Fichier d'extension .xml por favor",
                        "Message d'erreur",
                        JOptionPane.ERROR_MESSAGE); 
			}
Mon test marche, seulement, quand je clique sur le bouton OK, tout se bloque et plein de messages d'erreur s'affichent

Après recherche google, j'ai vu qu'il était possible de passer par les JDIalog, notamment par la méthode setModal, qui permettait d'éviter ce blocage.
J'ai donc tenté la chose suivante, sans succès...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
 
if(getFileExtension(txtSortie.getText())!="xml"){
				error.setContentPane(panel);
				error.setModal(false);			
			}
En fait, ce que j'aimerais, c'est que la boite de dialogue s'affiche et qu'une fois que l'utilisateur clique sur OK, on retombe sur la fenêtre de saisie, sanc blocage...

Pourriez-vous m'éclairer s'il vous plait???
merci d'avance