View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2009 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.PropertyTransfersTestStep.PropertyTransferResult;
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 PropertyTransferResult result;
46  	private DefaultDesktopPanel desktopPanel;
47  
48  	public ShowTransferValuesResultsAction( WsdlTestStepResult result )
49  	{
50  		this.result = ( PropertyTransferResult )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", "TestStep result for "
78  					+ 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",
94  				"See the result of each performed transfer below", null );
95  		panel.add( descriptionPanel, BorderLayout.NORTH );
96  
97  		JScrollPane scrollPane = new JScrollPane( table );
98  		scrollPane.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createEmptyBorder( 3, 3, 3, 3 ),
99  				scrollPane.getBorder() ) );
100 
101 		panel.add( scrollPane, BorderLayout.CENTER );
102 		panel.setPreferredSize( new Dimension( 550, 300 ) );
103 
104 		return panel;
105 	}
106 
107 	private class TransfersTableModel extends AbstractTableModel
108 	{
109 		public int getRowCount()
110 		{
111 			return result.getTransferCount();
112 		}
113 
114 		public int getColumnCount()
115 		{
116 			return 2;
117 		}
118 
119 		public String getColumnName( int column )
120 		{
121 			switch( column )
122 			{
123 			case 0 :
124 				return "Transfer Name";
125 			case 1 :
126 				return "Transferred Values";
127 			}
128 
129 			return null;
130 		}
131 
132 		public Object getValueAt( int rowIndex, int columnIndex )
133 		{
134 			switch( columnIndex )
135 			{
136 			case 0 :
137 				return result.getTransferAt( rowIndex ).getName();
138 			case 1 :
139 				return Arrays.toString( result.getTransferredValuesAt( rowIndex ) );
140 			}
141 
142 			return null;
143 		}
144 
145 	}
146 
147 }