View Javadoc

    1   /*
    2    *  soapUI, copyright (C) 2004-2007 eviware.com
    3    *
    4    *  soapUI is free software; you can redistribute it and/or modify it under the
    5    *  terms of version 2.1 of the GNU Lesser General Public License as published by
    6    *  the Free Software Foundation.
    7    *
    8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
    9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    10   *  See the GNU Lesser General Public License for more details at gnu.org.
    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  }