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 public abstract class ShowConfigFileAction extends AbstractAction
34 {
35 private ContentDialog dialog;
36 private final String title;
37 private final String description;
38
39 public ShowConfigFileAction( String title, String description )
40 {
41 super( "Show Config" );
42
43 this.title = title;
44 this.description = description;
45 }
46
47 public void actionPerformed(ActionEvent e)
48 {
49 if( dialog == null )
50 dialog = new ContentDialog( title, description );
51
52 dialog.showDialog();
53 }
54
55 protected abstract String getConfigFile();
56
57 public class ContentDialog extends JDialog
58 {
59 private JTextArea contentArea;
60
61 public ContentDialog( String title, String description ) throws HeadlessException
62 {
63 super( UISupport.getMainFrame() );
64 setTitle( title );
65 setModal( true );
66
67 getContentPane().setLayout(new BorderLayout());
68 JLabel label = new JLabel( description );
69 label.setBorder( BorderFactory.createEmptyBorder(10, 10, 0, 10) );
70 getContentPane().add( label, BorderLayout.NORTH);
71 getContentPane().add( buildContent(), BorderLayout.CENTER );
72
73 ButtonBarBuilder builder = ButtonBarBuilder.createLeftToRightBuilder();
74 builder.addGlue();
75 builder.addFixed( new JButton( new CloseAction() ));
76
77 builder.setBorder( BorderFactory.createEmptyBorder(0, 10, 10, 10) );
78 getContentPane().add( builder.getPanel(), BorderLayout.SOUTH );
79
80 pack();
81 }
82
83 public void showDialog()
84 {
85 contentArea.setText( getConfigFile() );
86 setVisible( true );
87 }
88
89 private Component buildContent()
90 {
91 contentArea = new JTextArea();
92 contentArea.setEditable( false );
93 contentArea.setBackground( Color.WHITE );
94 JScrollPane scrollPane = new JScrollPane( contentArea );
95 scrollPane.setPreferredSize( new Dimension (500, 300 ));
96
97 return UISupport.wrapInEmptyPanel( scrollPane, BorderFactory.createEmptyBorder( 10, 10, 10, 10 ) );
98 }
99
100 private final class CloseAction extends AbstractAction
101 {
102 public CloseAction()
103 {
104 super( "Close" );
105 }
106
107 public void actionPerformed(ActionEvent e)
108 {
109 setVisible( false );
110 }
111 }
112 }
113 }