001: /*
002: * soapUI, copyright (C) 2004-2007 eviware.com
003: *
004: * soapUI is free software; you can redistribute it and/or modify it under the
005: * terms of version 2.1 of the GNU Lesser General Public License as published by
006: * the Free Software Foundation.
007: *
008: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
010: * See the GNU Lesser General Public License for more details at gnu.org.
011: */
012:
013: package com.eviware.soapui.impl.wsdl.panels.loadtest;
014:
015: import java.awt.Color;
016: import java.awt.Dimension;
017: import java.awt.event.ItemEvent;
018: import java.awt.event.ItemListener;
019: import java.beans.PropertyChangeEvent;
020: import java.beans.PropertyChangeListener;
021:
022: import javax.swing.DefaultComboBoxModel;
023: import javax.swing.JButton;
024: import javax.swing.JComboBox;
025: import javax.swing.JComponent;
026: import javax.swing.JPanel;
027: import javax.swing.JScrollPane;
028: import javax.swing.ScrollPaneConstants;
029:
030: import com.eviware.soapui.impl.wsdl.actions.support.ShowOnlineHelpAction;
031: import com.eviware.soapui.impl.wsdl.loadtest.WsdlLoadTest;
032: import com.eviware.soapui.impl.wsdl.loadtest.data.LoadTestStatistics.Statistic;
033: import com.eviware.soapui.impl.wsdl.loadtest.data.actions.ExportSamplesHistoryAction;
034: import com.eviware.soapui.impl.wsdl.support.HelpUrls;
035: import com.eviware.soapui.support.UISupport;
036: import com.eviware.soapui.support.components.JXToolBar;
037: import com.eviware.soapui.ui.support.DefaultDesktopPanel;
038:
039: /**
040: * DesktopPanel for StatisticsHistory Graphs
041: *
042: * @author Ole.Matzura
043: */
044:
045: public class StatisticsHistoryDesktopPanel extends DefaultDesktopPanel {
046: private JPanel panel;
047: private final WsdlLoadTest loadTest;
048: private JStatisticsHistoryGraph historyGraph;
049: private JButton exportButton;
050: private JComboBox selectStatisticCombo;
051: private StatisticsHistoryDesktopPanel.InternalPropertyChangeListener propertyChangeListener;
052: private JComboBox resolutionCombo;
053:
054: public StatisticsHistoryDesktopPanel(WsdlLoadTest loadTest) {
055: super ("Statistics History for [" + loadTest.getName() + "]",
056: null, null);
057: this .loadTest = loadTest;
058:
059: propertyChangeListener = new InternalPropertyChangeListener();
060: loadTest.addPropertyChangeListener(WsdlLoadTest.NAME_PROPERTY,
061: propertyChangeListener);
062:
063: buildUI();
064: }
065:
066: private void buildUI() {
067: historyGraph = new JStatisticsHistoryGraph(loadTest);
068:
069: JScrollPane scrollPane = new JScrollPane(historyGraph);
070: scrollPane.getViewport().setBackground(Color.WHITE);
071: scrollPane
072: .setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
073:
074: panel = UISupport.buildPanelWithToolbarAndStatusBar(
075: buildToolbar(), scrollPane, historyGraph.getLegend());
076: panel.setPreferredSize(new Dimension(600, 400));
077: }
078:
079: private JComponent buildToolbar() {
080: exportButton = UISupport
081: .createToolbarButton(new ExportSamplesHistoryAction(
082: historyGraph));
083:
084: JXToolBar toolbar = UISupport.createToolbar();
085:
086: toolbar.addSpace(5);
087: toolbar.addLabeledFixed("Select Statistic:",
088: buildSelectStatisticCombo());
089: toolbar.addUnrelatedGap();
090: toolbar.addLabeledFixed("Resolution:", buildResolutionCombo());
091: toolbar.addGlue();
092: toolbar.addFixed(exportButton);
093: toolbar.addFixed(UISupport
094: .createToolbarButton(new ShowOnlineHelpAction(
095: HelpUrls.STATISTICSGRAPH_HELP_URL)));
096:
097: return toolbar;
098: }
099:
100: private JComponent buildResolutionCombo() {
101: resolutionCombo = new JComboBox(new String[] { "data", "250",
102: "500", "1000" });
103: resolutionCombo.setEditable(true);
104: resolutionCombo
105: .setToolTipText("Sets update interval of graph in milliseconds");
106: long resolution = historyGraph.getResolution();
107: resolutionCombo.setSelectedItem(resolution == 0 ? "data"
108: : String.valueOf(resolution));
109: resolutionCombo.addItemListener(new ItemListener() {
110:
111: public void itemStateChanged(ItemEvent e) {
112: try {
113: String value = resolutionCombo.getSelectedItem()
114: .toString();
115: long resolution = value.equals("data") ? 0 : Long
116: .parseLong(value);
117: if (resolution != historyGraph.getResolution()) {
118: historyGraph.setResolution(resolution);
119: }
120: } catch (Exception ex) {
121: long resolution = historyGraph.getResolution();
122: resolutionCombo
123: .setSelectedItem(resolution == 0 ? "data"
124: : String.valueOf(resolution));
125: }
126: }
127: });
128: return resolutionCombo;
129: }
130:
131: private JComponent buildSelectStatisticCombo() {
132: DefaultComboBoxModel model = new DefaultComboBoxModel();
133: model.addElement(Statistic.AVERAGE);
134: model.addElement(Statistic.TPS);
135: model.addElement(Statistic.ERRORS);
136: model.addElement(Statistic.BPS);
137:
138: selectStatisticCombo = new JComboBox(model);
139: selectStatisticCombo.addItemListener(new ItemListener() {
140:
141: public void itemStateChanged(ItemEvent e) {
142: historyGraph.setStatistic(Statistic
143: .valueOf(selectStatisticCombo.getSelectedItem()
144: .toString()));
145: }
146: });
147:
148: return selectStatisticCombo;
149: }
150:
151: public JComponent getComponent() {
152: return panel;
153: }
154:
155: public boolean onClose(boolean canCancel) {
156: loadTest.removePropertyChangeListener(
157: WsdlLoadTest.NAME_PROPERTY, propertyChangeListener);
158: historyGraph.release();
159:
160: return super .onClose(canCancel);
161: }
162:
163: private final class InternalPropertyChangeListener implements
164: PropertyChangeListener {
165: public void propertyChange(PropertyChangeEvent evt) {
166: setTitle("Statistics History for [" + loadTest.getName()
167: + "]");
168: }
169: }
170: }
|