01: /*
02: * soapUI, copyright (C) 2004-2007 eviware.com
03: *
04: * soapUI is free software; you can redistribute it and/or modify it under the
05: * terms of version 2.1 of the GNU Lesser General Public License as published by
06: * the Free Software Foundation.
07: *
08: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
09: * 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: private final JXEditTextArea textArea;
35: private String dialogTitle;
36:
37: public LoadXmlTextAreaAction(JXEditTextArea textArea,
38: String dialogTitle) {
39: super ("Load from..");
40: this .textArea = textArea;
41: this .dialogTitle = dialogTitle;
42: putValue(Action.ACCELERATOR_KEY, UISupport
43: .getKeyStroke("menu L"));
44: }
45:
46: public void actionPerformed(ActionEvent e) {
47: File file = UISupport.getFileDialogs().open(this , dialogTitle,
48: ".xml", "XML Files (*.xml)", null);
49: if (file == null)
50: return;
51:
52: try {
53: textArea.setText(Tools
54: .readAll(new FileInputStream(file), 0).toString());
55: } catch (IOException e1) {
56: UISupport.showErrorMessage("Error loading xml from file: "
57: + e1.getMessage());
58: }
59: }
60: }
|