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.panels.loadtest;
    14
    15  import java.awt.Color;
    16  import java.awt.Dimension;
    17  import java.awt.event.ItemEvent;
    18  import java.awt.event.ItemListener;
    19  import java.beans.PropertyChangeEvent;
    20  import java.beans.PropertyChangeListener;
    21
    22  import javax.swing.DefaultComboBoxModel;
    23  import javax.swing.JButton;
    24  import javax.swing.JComboBox;
    25  import javax.swing.JComponent;
    26  import javax.swing.JPanel;
    27  import javax.swing.JScrollPane;
    28  import javax.swing.ScrollPaneConstants;
    29
    30  import com.eviware.soapui.impl.wsdl.actions.support.ShowOnlineHelpAction;
    31  import com.eviware.soapui.impl.wsdl.loadtest.WsdlLoadTest;
    32  import com.eviware.soapui.impl.wsdl.loadtest.data.LoadTestStatistics.Statistic;
    33  import com.eviware.soapui.impl.wsdl.loadtest.data.actions.ExportSamplesHistoryAction;
    34  import com.eviware.soapui.impl.wsdl.support.HelpUrls;
    35  import com.eviware.soapui.support.UISupport;
    36  import com.eviware.soapui.support.components.JXToolBar;
    37  import com.eviware.soapui.ui.support.DefaultDesktopPanel;
    38
    39  /***
    40   * DesktopPanel for StatisticsHistory Graphs
    41   *
    42   * @author Ole.Matzura
    43   */
    44
    45  public class StatisticsHistoryDesktopPanel extends DefaultDesktopPanel
    46  {
    47  	private JPanel panel;
    48  	private final WsdlLoadTest loadTest;
    49  	private JStatisticsHistoryGraph historyGraph;
    50  	private JButton exportButton;
    51  	private JComboBox selectStatisticCombo;
    52  	private StatisticsHistoryDesktopPanel.InternalPropertyChangeListener propertyChangeListener;
    53  	private JComboBox resolutionCombo;
    54
    55  	public StatisticsHistoryDesktopPanel( WsdlLoadTest loadTest )
    56  	{
    57  		super( "Statistics History for [" + loadTest.getName() + "]", null, null);
    58  		this.loadTest = loadTest;
    59
    60  		propertyChangeListener = new InternalPropertyChangeListener();
    61  		loadTest.addPropertyChangeListener( WsdlLoadTest.NAME_PROPERTY, propertyChangeListener);
    62
    63  		buildUI();
    64  	}
    65
    66  	private void buildUI()
    67  	{
    68  		historyGraph = new JStatisticsHistoryGraph( loadTest );
    69
    70  		JScrollPane scrollPane = new JScrollPane( historyGraph );
    71  		scrollPane.getViewport().setBackground( Color.WHITE );
    72  		scrollPane.setHorizontalScrollBarPolicy( ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS );
    73
    74  		panel = UISupport.buildPanelWithToolbarAndStatusBar( buildToolbar(),
    75  				scrollPane, historyGraph.getLegend() );
    76  		panel.setPreferredSize( new Dimension( 600, 400 ));
    77  	}
    78
    79  	private JComponent buildToolbar()
    80  	{
    81  		exportButton = UISupport.createToolbarButton( new ExportSamplesHistoryAction( historyGraph ) );
    82
    83  		JXToolBar toolbar = UISupport.createToolbar();
    84
    85  		toolbar.addSpace( 5 );
    86  		toolbar.addLabeledFixed( "Select Statistic:", buildSelectStatisticCombo() );
    87  		toolbar.addUnrelatedGap();
    88  		toolbar.addLabeledFixed( "Resolution:", buildResolutionCombo() );
    89  		toolbar.addGlue();
    90  		toolbar.addFixed( exportButton );
    91  		toolbar.addFixed( UISupport.createToolbarButton( new ShowOnlineHelpAction( HelpUrls.STATISTICSGRAPH_HELP_URL )));
    92
    93  		return toolbar;
    94  	}
    95
    96  	private JComponent buildResolutionCombo()
    97  	{
    98  		resolutionCombo = new JComboBox( new String[] {"data", "250", "500", "1000"} );
    99  		resolutionCombo.setEditable( true );
    100 		resolutionCombo.setToolTipText( "Sets update interval of graph in milliseconds" );
    101 		long resolution = historyGraph.getResolution();
    102 		resolutionCombo.setSelectedItem( resolution == 0 ? "data" : String.valueOf( resolution ));
    103 		resolutionCombo.addItemListener( new ItemListener() {
    104
    105 			public void itemStateChanged( ItemEvent e )
    106 			{
    107 				try
    108 				{
    109 					String value = resolutionCombo.getSelectedItem().toString();
    110 					long resolution = value.equals( "data" ) ? 0 : Long.parseLong( value );
    111 					if( resolution != historyGraph.getResolution() )
    112 					{
    113 						historyGraph.setResolution( resolution );
    114 					}
    115 				}
    116 				catch( Exception ex )
    117 				{
    118 					long resolution = historyGraph.getResolution();
    119 					resolutionCombo.setSelectedItem( resolution == 0 ? "data" : String.valueOf( resolution ));
    120 				}
    121 			}} );
    122 		return resolutionCombo;
    123 	}
    124
    125 	private JComponent buildSelectStatisticCombo()
    126 	{
    127 		DefaultComboBoxModel model = new DefaultComboBoxModel();
    128 		model.addElement( Statistic.AVERAGE );
    129 		model.addElement( Statistic.TPS );
    130 		model.addElement( Statistic.ERRORS );
    131 		model.addElement( Statistic.BPS );
    132
    133 		selectStatisticCombo = new JComboBox( model );
    134 		selectStatisticCombo.addItemListener( new ItemListener() {
    135
    136 			public void itemStateChanged(ItemEvent e)
    137 			{
    138 				historyGraph.setStatistic( Statistic.valueOf( selectStatisticCombo.getSelectedItem().toString() ));
    139 			}} );
    140
    141 		return selectStatisticCombo;
    142 	}
    143
    144 	public JComponent getComponent()
    145 	{
    146 		return panel;
    147 	}
    148
    149 	public boolean onClose(boolean canCancel)
    150 	{
    151 		loadTest.removePropertyChangeListener( WsdlLoadTest.NAME_PROPERTY, propertyChangeListener);
    152 		historyGraph.release();
    153
    154 		return super.onClose( canCancel );
    155 	}
    156
    157 	private final class InternalPropertyChangeListener implements PropertyChangeListener
    158 	{
    159 		public void propertyChange(PropertyChangeEvent evt)
    160 		{
    161 			setTitle( "Statistics History for [" + loadTest.getName() + "]" );
    162 		}
    163 	}
    164 }