1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.support.xml.actions;
14
15 import java.awt.event.ActionEvent;
16 import java.io.File;
17 import java.io.FileInputStream;
18 import java.io.IOException;
19
20 import javax.swing.AbstractAction;
21 import javax.swing.Action;
22
23 import com.eviware.soapui.support.Tools;
24 import com.eviware.soapui.support.UISupport;
25 import com.eviware.soapui.support.xml.JXEditTextArea;
26
27 /***
28 * Loads XML into a JXmlTextArea from a file
29 *
30 * @author Ole.Matzura
31 */
32
33 public class LoadXmlTextAreaAction extends AbstractAction
34 {
35 private final JXEditTextArea textArea;
36 private String dialogTitle;
37
38 public LoadXmlTextAreaAction( JXEditTextArea textArea, String dialogTitle )
39 {
40 super( "Load from.." );
41 this.textArea = textArea;
42 this.dialogTitle = dialogTitle;
43 putValue( Action.ACCELERATOR_KEY, UISupport.getKeyStroke( "menu L" ) );
44 }
45
46 public void actionPerformed( ActionEvent e )
47 {
48 File file = UISupport.getFileDialogs().open( this, dialogTitle, ".xml", "XML Files (*.xml)", null );
49 if( file == null )
50 return;
51
52 try
53 {
54 textArea.setText( Tools.readAll( new FileInputStream( file ), 0 ).toString() );
55 }
56 catch( IOException e1 )
57 {
58 UISupport.showErrorMessage( "Error loading xml from file: " + e1.getMessage() );
59 }
60 }
61 }