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.Iterator;
023: import java.util.LinkedList;
024: import java.util.Set;
025:
026: import javax.swing.JOptionPane;
027:
028: import org.apache.jmeter.control.ReplaceableController;
029: import org.apache.jmeter.gui.action.Command;
030: import org.apache.jmeter.gui.ReportGuiPackage;
031: import org.apache.jmeter.report.gui.tree.ReportTreeNode;
032: import org.apache.jmeter.testelement.TestElement;
033: import org.apache.jmeter.util.JMeterUtils;
034: import org.apache.jorphan.collections.HashTree;
035: import org.apache.jorphan.logging.LoggingManager;
036: import org.apache.log.Logger;
037:
038: /**
039: * @author mstover
040: * @version $Revision: 493793 $
041: */
042: public abstract class AbstractAction implements Command {
043: private static final Logger log = LoggingManager
044: .getLoggerForClass();
045:
046: /**
047: * @see Command#doAction(ActionEvent)
048: */
049: public void doAction(ActionEvent e) {
050: }
051:
052: /**
053: * @see Command#getActionNames()
054: */
055: abstract public Set getActionNames();
056:
057: protected void convertSubTree(HashTree tree) {
058: Iterator iter = new LinkedList(tree.list()).iterator();
059: while (iter.hasNext()) {
060: Object o = iter.next();
061: if (o instanceof TestElement)
062: continue; //hey, no need to convert
063: ReportTreeNode item = (ReportTreeNode) o;
064: if (item.isEnabled()) {
065: if (item.getUserObject() instanceof ReplaceableController) {
066: ReplaceableController rc = (ReplaceableController) item
067: .getTestElement();
068: HashTree subTree = tree.getTree(item);
069:
070: if (subTree != null) {
071: HashTree replacementTree = rc
072: .getReplacementSubTree();
073: convertSubTree(replacementTree);
074: tree.replace(item, rc);
075: tree.set(rc, replacementTree);
076: }
077: } else {
078: convertSubTree(tree.getTree(item));
079: TestElement testElement = item.getTestElement();
080: tree.replace(item, testElement);
081: }
082: } else {
083: tree.remove(item);
084: }
085:
086: }
087: }
088:
089: /**
090: * @param e
091: */
092: protected void popupShouldSave(ActionEvent e) {
093: log.debug("popupShouldSave");
094: if (ReportGuiPackage.getInstance().getReportPlanFile() == null) {
095: if (JOptionPane.showConfirmDialog(ReportGuiPackage
096: .getInstance().getMainFrame(), JMeterUtils
097: .getResString("should_save"), JMeterUtils
098: .getResString("warning"),
099: JOptionPane.YES_NO_OPTION,
100: JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
101: ReportActionRouter.getInstance().doActionNow(
102: new ActionEvent(e.getSource(), e.getID(),
103: ReportSave.SAVE));
104: }
105: }
106: }
107: }
|