View Javadoc

1   /*
2    *  soapUI, copyright (C) 2006 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of the GNU Lesser General Public License as published by the Free Software Foundation; 
6    *  either version 2.1 of the License, or (at your option) any later version.
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.Dimension;
17  import java.awt.event.ActionEvent;
18  import java.util.Arrays;
19  
20  import javax.swing.AbstractAction;
21  import javax.swing.JComponent;
22  import javax.swing.JPanel;
23  import javax.swing.JScrollPane;
24  import javax.swing.JTable;
25  import javax.swing.table.AbstractTableModel;
26  
27  import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStepResult;
28  import com.eviware.soapui.impl.wsdl.teststeps.TransferResponseValuesTestStep.ValueTransferResult;
29  import com.eviware.soapui.support.UISupport;
30  import com.eviware.soapui.ui.desktop.DesktopPanel;
31  import com.eviware.soapui.ui.support.DefaultDesktopPanel;
32  
33  /***
34   * Shows a desktop-panel with the TestStepResult for a ValueTransferResult
35   * 
36   * @author Ole.Matzura
37   */
38  
39  public class ShowTransferValuesResultsAction extends AbstractAction
40  {
41  	private final ValueTransferResult result;
42  	private DefaultDesktopPanel desktopPanel;
43  
44  	public ShowTransferValuesResultsAction(WsdlTestStepResult result)
45  	{
46  		this.result = (ValueTransferResult) result;
47  	}
48  
49  	public void actionPerformed(ActionEvent e)
50  	{
51  		try
52  		{
53  			if( result.isDiscarded() )
54  				UISupport.showInfoMessage( "Request has been discarded.." );
55  			else
56  				UISupport.showDesktopPanel(buildFrame());
57  		}
58  		catch (Exception ex)
59  		{
60  			ex.printStackTrace();
61  		}		
62  	}
63  	
64  	private DesktopPanel buildFrame()
65  	{
66  		if( desktopPanel == null )
67  		{
68  			desktopPanel = new DefaultDesktopPanel( "TestStep Result", 
69  						"TestStep result for " + result.getTestStep().getName(), buildContent() );
70  		}
71  		
72  		return desktopPanel;
73  	}
74  
75  	private JComponent buildContent()
76  	{
77  		JPanel panel = new JPanel( new BorderLayout() );
78  		JTable table = new JTable( new TransfersTableModel() );
79  		
80  		table.getColumnModel().getColumn( 0 ).setPreferredWidth( 150 );
81  		table.getColumnModel().getColumn( 1 ).setPreferredWidth( 400 );
82  		
83  		panel.add( new JScrollPane( table), BorderLayout.CENTER );
84  		panel.setPreferredSize( new Dimension( 550, 300 ));
85  		
86  		return panel;
87  	}
88  
89  	private class TransfersTableModel extends AbstractTableModel
90  	{
91  		public int getRowCount()
92  		{
93  			return result.getTransferCount();
94  		}
95  
96  		public int getColumnCount()
97  		{
98  			return 2;
99  		}
100 		
101 		public String getColumnName(int column)
102 		{
103 			switch( column )
104 			{
105 			case 0 : return "Transfer Name";
106 			case 1 : return "Transferred Values";
107 			}
108 			
109 			return null;
110 		}
111 
112 		public Object getValueAt(int rowIndex, int columnIndex)
113 		{
114 			switch( columnIndex )
115 			{
116 			case 0 : return result.getTransferAt( rowIndex ).getName();
117 			case 1 : return Arrays.toString( result.getTransferredValuesAt( rowIndex ) );
118 			}
119 			
120 			return null;
121 		}
122 		
123 	}
124 	
125 }