001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.jmeter.report.gui.action;
020:
021: import java.awt.event.ActionEvent;
022: import java.util.HashSet;
023: import java.util.Set;
024:
025: import org.apache.jmeter.engine.StandardJMeterEngine;
026: import org.apache.jmeter.gui.ReportGuiPackage;
027: import org.apache.jmeter.gui.action.ActionNames;
028: import org.apache.jorphan.logging.LoggingManager;
029: import org.apache.log.Logger;
030:
031: /**
032: * @author Michael Stover Created March 1, 2001
033: * @version $Revision: 493793 $ Last updated: $Date: 2007-01-07 18:19:27 +0000 (Sun, 07 Jan 2007) $
034: */
035: public class ReportStart extends AbstractAction {
036: private static Logger log = LoggingManager.getLoggerForClass();
037:
038: private static Set commands = new HashSet();
039: static {
040: commands.add(ActionNames.ACTION_START);
041: commands.add(ActionNames.ACTION_STOP);
042: commands.add(ActionNames.ACTION_SHUTDOWN);
043: }
044:
045: private StandardJMeterEngine engine;
046:
047: /**
048: * Constructor for the Start object.
049: */
050: public ReportStart() {
051: }
052:
053: /**
054: * Gets the ActionNames attribute of the Start object.
055: *
056: * @return the ActionNames value
057: */
058: public Set getActionNames() {
059: return commands;
060: }
061:
062: public void doAction(ActionEvent e) {
063: if (e.getActionCommand().equals(ActionNames.ACTION_START)) {
064: popupShouldSave(e);
065: startEngine();
066: } else if (e.getActionCommand().equals(ActionNames.ACTION_STOP)) {
067: if (engine != null) {
068: ReportGuiPackage.getInstance().getMainFrame()
069: .showStoppingMessage("");
070: engine.stopTest();
071: engine = null;
072: }
073: } else if (e.getActionCommand().equals(
074: ActionNames.ACTION_SHUTDOWN)) {
075: if (engine != null) {
076: ReportGuiPackage.getInstance().getMainFrame()
077: .showStoppingMessage("");
078: engine.askThreadsToStop();
079: engine = null;
080: }
081: }
082: }
083:
084: protected void startEngine() {
085: /**
086: * this will need to be changed
087: ReportGuiPackage gui = ReportGuiPackage.getInstance();
088: engine = new StandardJMeterEngine();
089: HashTree testTree = gui.getTreeModel().getTestPlan();
090: convertSubTree(testTree);
091: DisabledComponentRemover remover = new DisabledComponentRemover(testTree);
092: testTree.traverse(remover);
093: testTree.add(testTree.getArray()[0], gui.getMainFrame());
094: log.debug("test plan before cloning is running version: "
095: + ((TestPlan) testTree.getArray()[0]).isRunningVersion());
096: TreeCloner cloner = new TreeCloner(false);
097: testTree.traverse(cloner);
098: engine.configure(cloner.getClonedTree());
099: try {
100: engine.runTest();
101: } catch (JMeterEngineException e) {
102: JOptionPane.showMessageDialog(gui.getMainFrame(), e.getMessage(), JMeterUtils
103: .getResString("Error Occurred"), JOptionPane.ERROR_MESSAGE);
104: }
105: log.debug("test plan after cloning and running test is running version: "
106: + ((TestPlan) testTree.getArray()[0]).isRunningVersion());
107: */
108: }
109: }
|