1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.actions.iface.tools.support;
14
15 import java.awt.BorderLayout;
16 import java.awt.Color;
17 import java.awt.Component;
18 import java.awt.Dimension;
19 import java.awt.HeadlessException;
20 import java.awt.event.ActionEvent;
21
22 import javax.swing.AbstractAction;
23 import javax.swing.BorderFactory;
24 import javax.swing.JButton;
25 import javax.swing.JDialog;
26 import javax.swing.JLabel;
27 import javax.swing.JScrollPane;
28 import javax.swing.JTextArea;
29
30 import com.eviware.soapui.support.UISupport;
31 import com.jgoodies.forms.builder.ButtonBarBuilder;
32
33 /***
34 * Action to display the contents of a generated configuration file
35 *
36 * @author ole.matzura
37 */
38
39 public abstract class ShowConfigFileAction extends AbstractAction
40 {
41 private ContentDialog dialog;
42 private final String title;
43 private final String description;
44
45 public ShowConfigFileAction( String title, String description )
46 {
47 super( "Show Config" );
48
49 this.title = title;
50 this.description = description;
51 }
52
53 public void actionPerformed( ActionEvent e )
54 {
55 if( dialog == null )
56 dialog = new ContentDialog( title, description );
57
58 dialog.showDialog();
59 }
60
61 protected abstract String getConfigFile();
62
63 public class ContentDialog extends JDialog
64 {
65 private JTextArea contentArea;
66
67 public ContentDialog( String title, String description ) throws HeadlessException
68 {
69 super( UISupport.getMainFrame() );
70 setTitle( title );
71 setModal( true );
72
73 getContentPane().setLayout( new BorderLayout() );
74 JLabel label = new JLabel( description );
75 label.setBorder( BorderFactory.createEmptyBorder( 10, 10, 0, 10 ) );
76 getContentPane().add( label, BorderLayout.NORTH );
77 getContentPane().add( buildContent(), BorderLayout.CENTER );
78
79 ButtonBarBuilder builder = ButtonBarBuilder.createLeftToRightBuilder();
80 builder.addGlue();
81 JButton closeButton = new JButton( new CloseAction() );
82 builder.addFixed( closeButton );
83
84 builder.setBorder( BorderFactory.createEmptyBorder( 0, 10, 10, 10 ) );
85 getContentPane().add( builder.getPanel(), BorderLayout.SOUTH );
86
87 pack();
88
89 UISupport.initDialogActions( this, null, closeButton );
90 }
91
92 public void showDialog()
93 {
94 contentArea.setText( getConfigFile() );
95 setVisible( true );
96 }
97
98 private Component buildContent()
99 {
100 contentArea = new JTextArea();
101 contentArea.setEditable( false );
102 contentArea.setBackground( Color.WHITE );
103 JScrollPane scrollPane = new JScrollPane( contentArea );
104 scrollPane.setPreferredSize( new Dimension( 500, 300 ) );
105
106 return UISupport.wrapInEmptyPanel( scrollPane, BorderFactory.createEmptyBorder( 10, 10, 10, 10 ) );
107 }
108
109 private final class CloseAction extends AbstractAction
110 {
111 public CloseAction()
112 {
113 super( "Close" );
114 }
115
116 public void actionPerformed( ActionEvent e )
117 {
118 setVisible( false );
119 }
120 }
121 }
122 }