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.teststeps.actions;
    14
    15  import java.awt.BorderLayout;
    16  import java.awt.Component;
    17  import java.awt.Dimension;
    18  import java.awt.event.ActionEvent;
    19  import java.util.Arrays;
    20
    21  import javax.swing.AbstractAction;
    22  import javax.swing.BorderFactory;
    23  import javax.swing.JComponent;
    24  import javax.swing.JPanel;
    25  import javax.swing.JScrollPane;
    26  import javax.swing.table.AbstractTableModel;
    27
    28  import org.jdesktop.swingx.JXTable;
    29
    30  import com.eviware.soapui.SoapUI;
    31  import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStepResult;
    32  import com.eviware.soapui.impl.wsdl.teststeps.TransferResponseValuesTestStep.ValueTransferResult;
    33  import com.eviware.soapui.support.UISupport;
    34  import com.eviware.soapui.ui.desktop.DesktopPanel;
    35  import com.eviware.soapui.ui.support.DefaultDesktopPanel;
    36
    37  /***
    38   * Shows a desktop-panel with the TestStepResult for a ValueTransferResult
    39   *
    40   * @author Ole.Matzura
    41   */
    42
    43  public class ShowTransferValuesResultsAction extends AbstractAction
    44  {
    45  	private final ValueTransferResult result;
    46  	private DefaultDesktopPanel desktopPanel;
    47
    48  	public ShowTransferValuesResultsAction(WsdlTestStepResult result)
    49  	{
    50  		this.result = (ValueTransferResult) result;
    51  	}
    52
    53  	public void actionPerformed(ActionEvent e)
    54  	{
    55  		try
    56  		{
    57  			if( result.isDiscarded() )
    58  				UISupport.showInfoMessage( "Request has been discarded.." );
    59  			else
    60  				showDesktopPanel();
    61  		}
    62  		catch (Exception ex)
    63  		{
    64  			SoapUI.logError( ex );
    65  		}
    66  	}
    67
    68  	public DesktopPanel showDesktopPanel()
    69  	{
    70  		return UISupport.showDesktopPanel(buildFrame());
    71  	}
    72
    73  	private DesktopPanel buildFrame()
    74  	{
    75  		if( desktopPanel == null )
    76  		{
    77  			desktopPanel = new DefaultDesktopPanel( "TestStep Result",
    78  						"TestStep result for " + result.getTestStep().getName(), buildContent() );
    79  		}
    80
    81  		return desktopPanel;
    82  	}
    83
    84  	private JComponent buildContent()
    85  	{
    86  		JPanel panel = new JPanel( new BorderLayout() );
    87  		JXTable table = new JXTable( new TransfersTableModel() );
    88
    89  //		table.setColumnControlVisible( true );
    90  		table.setHorizontalScrollEnabled( true );
    91  		table.packAll();
    92
    93  		Component descriptionPanel = UISupport.buildDescription( "PropertyTransfer Results", "See the result of each performed transfer below", null );
    94  		panel.add( descriptionPanel, BorderLayout.NORTH );
    95
    96  		JScrollPane scrollPane = new JScrollPane( table);
    97  		scrollPane.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createEmptyBorder( 3, 3, 3, 3 ),
    98  					scrollPane.getBorder() ));
    99
    100 		panel.add( scrollPane, BorderLayout.CENTER );
    101 		panel.setPreferredSize( new Dimension( 550, 300 ));
    102
    103 		return panel;
    104 	}
    105
    106 	private class TransfersTableModel extends AbstractTableModel
    107 	{
    108 		public int getRowCount()
    109 		{
    110 			return result.getTransferCount();
    111 		}
    112
    113 		public int getColumnCount()
    114 		{
    115 			return 2;
    116 		}
    117
    118 		public String getColumnName(int column)
    119 		{
    120 			switch( column )
    121 			{
    122 			case 0 : return "Transfer Name";
    123 			case 1 : return "Transferred Values";
    124 			}
    125
    126 			return null;
    127 		}
    128
    129 		public Object getValueAt(int rowIndex, int columnIndex)
    130 		{
    131 			switch( columnIndex )
    132 			{
    133 			case 0 : return result.getTransferAt( rowIndex ).getName();
    134 			case 1 : return Arrays.toString( result.getTransferredValuesAt( rowIndex ) );
    135 			}
    136
    137 			return null;
    138 		}
    139
    140 	}
    141
    142 }