View Javadoc

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