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.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  			builder.addFixed( new JButton( new CloseAction() ));
    82
    83  	      builder.setBorder( BorderFactory.createEmptyBorder(0, 10, 10, 10) );
    84  	      getContentPane().add( builder.getPanel(), BorderLayout.SOUTH );
    85
    86  	      pack();
    87  	   }
    88
    89  	   public void showDialog()
    90  	   {
    91  	   	contentArea.setText( getConfigFile() );
    92  	   	setVisible( true );
    93  	   }
    94
    95  	   private Component buildContent()
    96  		{
    97  	   	contentArea = new JTextArea();
    98  	   	contentArea.setEditable( false );
    99  	   	contentArea.setBackground( Color.WHITE );
    100 			JScrollPane scrollPane = new JScrollPane( contentArea );
    101 			scrollPane.setPreferredSize( new Dimension (500, 300 ));
    102
    103 			return UISupport.wrapInEmptyPanel( scrollPane, BorderFactory.createEmptyBorder( 10, 10, 10, 10 ) );
    104 		}
    105
    106 	   private final class CloseAction extends AbstractAction
    107 	   {
    108 	   	public CloseAction()
    109 	   	{
    110 	   		super( "Close" );
    111 	   	}
    112
    113 			public void actionPerformed(ActionEvent e)
    114 			{
    115 				setVisible( false );
    116 			}
    117 	   }
    118 	}
    119 }