Search in sources :

Example 36 with GuiPackage

use of org.apache.jmeter.gui.GuiPackage in project jmeter by apache.

the class CheckDirty method doAction.

/**
     * @see Command#doAction(ActionEvent)
     */
@Override
public void doAction(ActionEvent e) {
    String action = e.getActionCommand();
    if (action.equals(ActionNames.SUB_TREE_SAVED)) {
        HashTree subTree = (HashTree) e.getSource();
        subTree.traverse(this);
    } else if (action.equals(ActionNames.SUB_TREE_LOADED)) {
        ListedHashTree addTree = (ListedHashTree) e.getSource();
        addTree.traverse(this);
    } else if (action.equals(ActionNames.ADD_ALL)) {
        previousGuiItems.clear();
        GuiPackage.getInstance().getTreeModel().getTestPlan().traverse(this);
        if (isWorkbenchSaveable()) {
            GuiPackage.getInstance().getTreeModel().getWorkBench().traverse(this);
        }
    } else if (action.equals(ActionNames.CHECK_REMOVE)) {
        GuiPackage guiPackage = GuiPackage.getInstance();
        JMeterTreeNode[] nodes = guiPackage.getTreeListener().getSelectedNodes();
        removeMode = true;
        try {
            for (int i = nodes.length - 1; i >= 0; i--) {
                guiPackage.getTreeModel().getCurrentSubTree(nodes[i]).traverse(this);
            }
        } finally {
            removeMode = false;
        }
    }
    // If we are merging in another test plan, we know the test plan is dirty now
    if (action.equals(ActionNames.SUB_TREE_MERGED)) {
        dirty = true;
    } else {
        dirty = false;
        checkMode = true;
        try {
            HashTree wholeTree = GuiPackage.getInstance().getTreeModel().getTestPlan();
            wholeTree.traverse(this);
            // check the workbench for modification
            if (!dirty) {
                // NOSONAR
                if (isWorkbenchSaveable()) {
                    HashTree workbench = GuiPackage.getInstance().getTreeModel().getWorkBench();
                    workbench.traverse(this);
                }
            }
        } finally {
            checkMode = false;
        }
    }
    GuiPackage.getInstance().setDirty(dirty);
}
Also used : ListedHashTree(org.apache.jorphan.collections.ListedHashTree) HashTree(org.apache.jorphan.collections.HashTree) ListedHashTree(org.apache.jorphan.collections.ListedHashTree) GuiPackage(org.apache.jmeter.gui.GuiPackage)

Example 37 with GuiPackage

use of org.apache.jmeter.gui.GuiPackage in project jmeter by apache.

the class Close method closeProject.

static void closeProject(ActionEvent e) {
    GuiPackage guiPackage = GuiPackage.getInstance();
    guiPackage.clearTestPlan();
    JTree tree = guiPackage.getTreeListener().getJTree();
    tree.setSelectionRow(0);
    FocusRequester.requestFocus(tree);
    ActionRouter.getInstance().actionPerformed(new ActionEvent(e.getSource(), e.getID(), ActionNames.ADD_ALL));
}
Also used : JTree(javax.swing.JTree) GuiPackage(org.apache.jmeter.gui.GuiPackage) ActionEvent(java.awt.event.ActionEvent)

Example 38 with GuiPackage

use of org.apache.jmeter.gui.GuiPackage in project jmeter by apache.

the class Close method performAction.

/**
     * Helper routine to allow action to be shared by LOAD.
     *
     * @param e event
     * @return true if Close was not cancelled
     */
static boolean performAction(ActionEvent e) {
    ActionRouter.getInstance().doActionNow(new ActionEvent(e.getSource(), e.getID(), ActionNames.CHECK_DIRTY));
    GuiPackage guiPackage = GuiPackage.getInstance();
    if (guiPackage.isDirty()) {
        int response;
        if ((response = JOptionPane.showConfirmDialog(GuiPackage.getInstance().getMainFrame(), // $NON-NLS-1$
        JMeterUtils.getResString("cancel_new_to_save"), // $NON-NLS-1$
        JMeterUtils.getResString("save?"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE)) == JOptionPane.YES_OPTION) {
            ActionRouter.getInstance().doActionNow(new ActionEvent(e.getSource(), e.getID(), ActionNames.SAVE));
            // in this case we should not close the test plan
            if (guiPackage.isDirty()) {
                return false;
            }
        }
        if (response == JOptionPane.CLOSED_OPTION || response == JOptionPane.CANCEL_OPTION) {
            // Don't clear the plan
            return false;
        }
    }
    ActionRouter.getInstance().doActionNow(new ActionEvent(e.getSource(), e.getID(), ActionNames.STOP_THREAD));
    closeProject(e);
    return true;
}
Also used : GuiPackage(org.apache.jmeter.gui.GuiPackage) ActionEvent(java.awt.event.ActionEvent)

Example 39 with GuiPackage

use of org.apache.jmeter.gui.GuiPackage in project jmeter by apache.

the class Clear method doAction.

@Override
public void doAction(ActionEvent e) {
    GuiPackage guiPackage = GuiPackage.getInstance();
    final String actionCommand = e.getActionCommand();
    if (actionCommand.equals(ActionNames.CLEAR)) {
        JMeterGUIComponent guiComp = guiPackage.getCurrentGui();
        if (guiComp instanceof Clearable) {
            ((Clearable) guiComp).clearData();
        }
    } else {
        guiPackage.getMainFrame().clearData();
        for (JMeterTreeNode node : guiPackage.getTreeModel().getNodesOfType(Clearable.class)) {
            JMeterGUIComponent guiComp = guiPackage.getGui(node.getTestElement());
            if (guiComp instanceof Clearable) {
                Clearable item = (Clearable) guiComp;
                try {
                    item.clearData();
                } catch (Exception ex) {
                    log.error("Can't clear: {} {}", node, guiComp, ex);
                }
            }
        }
    }
}
Also used : Clearable(org.apache.jmeter.samplers.Clearable) GuiPackage(org.apache.jmeter.gui.GuiPackage) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) JMeterGUIComponent(org.apache.jmeter.gui.JMeterGUIComponent)

Example 40 with GuiPackage

use of org.apache.jmeter.gui.GuiPackage in project jmeter by apache.

the class CollapseExpand method doAction.

/**
     * This method performs the actual command processing.
     *
     * @param e
     *            the generic UI action event
     */
@Override
public void doAction(ActionEvent e) {
    boolean collapse = ActionNames.COLLAPSE_ALL.equals(e.getActionCommand());
    GuiPackage guiInstance = GuiPackage.getInstance();
    JTree jTree = guiInstance.getMainFrame().getTree();
    if (collapse) {
        for (int i = jTree.getRowCount() - 1; i >= 0; i--) {
            jTree.collapseRow(i);
        }
        return;
    }
    for (int i = 0; i < jTree.getRowCount(); i++) {
        jTree.expandRow(i);
    }
}
Also used : JTree(javax.swing.JTree) GuiPackage(org.apache.jmeter.gui.GuiPackage)

Aggregations

GuiPackage (org.apache.jmeter.gui.GuiPackage)49 JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)21 ActionEvent (java.awt.event.ActionEvent)9 JTree (javax.swing.JTree)8 TreePath (javax.swing.tree.TreePath)7 JMeterTreeModel (org.apache.jmeter.gui.tree.JMeterTreeModel)6 TestElement (org.apache.jmeter.testelement.TestElement)5 HashTree (org.apache.jorphan.collections.HashTree)5 IllegalUserActionException (org.apache.jmeter.exceptions.IllegalUserActionException)4 JMeterGUIComponent (org.apache.jmeter.gui.JMeterGUIComponent)4 Controller (org.apache.jmeter.control.Controller)3 Searchable (org.apache.jmeter.gui.Searchable)3 Component (java.awt.Component)2 File (java.io.File)2 HashSet (java.util.HashSet)2 ListedHashTree (org.apache.jorphan.collections.ListedHashTree)2 ConversionException (com.thoughtworks.xstream.converters.ConversionException)1 HeadlessException (java.awt.HeadlessException)1 DataFlavor (java.awt.datatransfer.DataFlavor)1 Transferable (java.awt.datatransfer.Transferable)1