Search in sources :

Example 26 with GuiPackage

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

the class SearchTreeDialog method doReplaceAll.

/**
     * Replace all occurrences in nodes that contain {@link Replaceable} Test Elements
     * @param e {@link ActionEvent}
     */
private void doReplaceAll(ActionEvent e) {
    String wordToSearch = searchTF.getText();
    String wordToReplace = replaceTF.getText();
    if (StringUtils.isEmpty(wordToReplace)) {
        return;
    }
    // Save any change to current node
    GuiPackage.getInstance().updateCurrentNode();
    // reset previous result
    ActionRouter.getInstance().doActionNow(new ActionEvent(e.getSource(), e.getID(), ActionNames.SEARCH_RESET));
    Searcher searcher;
    String regex;
    if (isRegexpCB.isSelected()) {
        regex = wordToSearch;
        searcher = new RegexpSearcher(isCaseSensitiveCB.isSelected(), wordToSearch);
    } else {
        regex = Pattern.quote(wordToSearch);
        searcher = new RawTextSearcher(isCaseSensitiveCB.isSelected(), wordToSearch);
    }
    GuiPackage guiPackage = GuiPackage.getInstance();
    JMeterTreeModel jMeterTreeModel = guiPackage.getTreeModel();
    Set<JMeterTreeNode> nodes = new HashSet<>();
    boolean caseSensitiveReplacement = isCaseSensitiveCB.isSelected();
    int totalReplaced = 0;
    for (JMeterTreeNode jMeterTreeNode : jMeterTreeModel.getNodesOfType(Searchable.class)) {
        try {
            Searchable searchable = (Searchable) jMeterTreeNode.getUserObject();
            List<String> searchableTokens = searchable.getSearchableTokens();
            boolean result = searcher.search(searchableTokens);
            if (result && jMeterTreeNode.getUserObject() instanceof Replaceable) {
                Replaceable replaceable = (Replaceable) jMeterTreeNode.getUserObject();
                int numberOfReplacements = replaceable.replace(regex, wordToReplace, caseSensitiveReplacement);
                if (logger.isInfoEnabled()) {
                    logger.info("Replaced " + numberOfReplacements + " in element:" + ((TestElement) jMeterTreeNode.getUserObject()).getName());
                }
                totalReplaced += numberOfReplacements;
                if (numberOfReplacements > 0) {
                    List<JMeterTreeNode> matchingNodes = jMeterTreeNode.getPathToThreadGroup();
                    nodes.addAll(matchingNodes);
                }
            }
        } catch (Exception ex) {
            logger.error("Error occurred replacing data in node:" + jMeterTreeNode.getName(), ex);
        }
    }
    statusLabel.setText(MessageFormat.format("Replaced {0} occurrences", new Object[] { totalReplaced }));
    GuiPackage guiInstance = GuiPackage.getInstance();
    JTree jTree = guiInstance.getMainFrame().getTree();
    for (JMeterTreeNode jMeterTreeNode : nodes) {
        jMeterTreeNode.setMarkedBySearch(true);
        jTree.expandPath(new TreePath(jMeterTreeNode.getPath()));
    }
    // Update GUI as current node may be concerned by changes
    if (totalReplaced > 0) {
        GuiPackage.getInstance().refreshCurrentGui();
    }
    GuiPackage.getInstance().getMainFrame().repaint();
    searchTF.requestFocusInWindow();
}
Also used : ActionEvent(java.awt.event.ActionEvent) TestElement(org.apache.jmeter.testelement.TestElement) JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) GuiPackage(org.apache.jmeter.gui.GuiPackage) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) Searchable(org.apache.jmeter.gui.Searchable) Replaceable(org.apache.jmeter.gui.Replaceable) HashSet(java.util.HashSet)

Example 27 with GuiPackage

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

the class JMeterTreeTransferHandler method exportDone.

@Override
protected void exportDone(JComponent source, Transferable data, int action) {
    if (this.nodesForRemoval != null && ((action & MOVE) == MOVE)) {
        GuiPackage guiInstance = GuiPackage.getInstance();
        for (JMeterTreeNode jMeterTreeNode : nodesForRemoval) {
            guiInstance.getTreeModel().removeNodeFromParent(jMeterTreeNode);
        }
        nodesForRemoval = null;
    }
}
Also used : GuiPackage(org.apache.jmeter.gui.GuiPackage)

Example 28 with GuiPackage

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

the class RevertProject method doActionAfterCheck.

@Override
public void doActionAfterCheck(ActionEvent e) {
    // Get the file name of the current project
    String projectFile = GuiPackage.getInstance().getTestPlanFile();
    // Check if the user has loaded any file
    if (projectFile == null) {
        return;
    }
    // Check if the user wants to drop any changes
    ActionRouter.getInstance().doActionNow(new ActionEvent(e.getSource(), e.getID(), ActionNames.CHECK_DIRTY));
    GuiPackage guiPackage = GuiPackage.getInstance();
    if (guiPackage.isDirty()) {
        // Check if the user wants to revert
        int response = JOptionPane.showConfirmDialog(GuiPackage.getInstance().getMainFrame(), // $NON-NLS-1$
        JMeterUtils.getResString("cancel_revert_project"), // $NON-NLS-1$
        JMeterUtils.getResString("revert_project?"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        if (response == JOptionPane.YES_OPTION) {
            // Close the current project
            Close.closeProject(e);
            // Reload the project
            Load.loadProjectFile(e, new File(projectFile), false);
        }
    }
}
Also used : GuiPackage(org.apache.jmeter.gui.GuiPackage) ActionEvent(java.awt.event.ActionEvent) File(java.io.File)

Example 29 with GuiPackage

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

the class Load method loadProjectFile.

/**
     * Loads or merges a file into the current GUI, reporting any errors to the user.
     * If the file is a complete test plan, sets the GUI test plan file name
     *
     * @param e the event that triggered the action
     * @param f the file to load
     * @param merging if true, then try to merge the file into the current GUI.
     * @param setDetails if true, then set the file details (if not merging)
     */
static void loadProjectFile(final ActionEvent e, final File f, final boolean merging, final boolean setDetails) {
    ActionRouter.getInstance().doActionNow(new ActionEvent(e.getSource(), e.getID(), ActionNames.STOP_THREAD));
    final GuiPackage guiPackage = GuiPackage.getInstance();
    if (f != null) {
        try {
            if (merging) {
                log.info("Merging file: {}", f);
            } else {
                log.info("Loading file: {}", f);
                // and what if load fails?
                if (setDetails) {
                    FileServer.getFileServer().setBaseForScript(f);
                }
            }
            final HashTree tree = SaveService.loadTree(f);
            final boolean isTestPlan = insertLoadedTree(e.getID(), tree, merging);
            // don't change name if merging
            if (!merging && isTestPlan && setDetails) {
                // TODO should setBaseForScript be called here rather than
                // above?
                guiPackage.setTestPlanFile(f.getAbsolutePath());
            }
        } catch (NoClassDefFoundError ex) {
            // Allow for missing optional jars
            reportError("Missing jar file. {}", ex, true);
        } catch (ConversionException ex) {
            if (log.isWarnEnabled()) {
                log.warn("Could not convert file. {}", ex.toString());
            }
            JMeterUtils.reportErrorToUser(SaveService.CEtoString(ex));
        } catch (IOException ex) {
            reportError("Error reading file. {}", ex, false);
        } catch (Exception ex) {
            reportError("Unexpected error. {}", ex, true);
        }
        FileDialoger.setLastJFCDirectory(f.getParentFile().getAbsolutePath());
        guiPackage.updateCurrentGui();
        guiPackage.getMainFrame().repaint();
    }
}
Also used : ConversionException(com.thoughtworks.xstream.converters.ConversionException) HashTree(org.apache.jorphan.collections.HashTree) GuiPackage(org.apache.jmeter.gui.GuiPackage) ActionEvent(java.awt.event.ActionEvent) IOException(java.io.IOException) IOException(java.io.IOException) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException) ConversionException(com.thoughtworks.xstream.converters.ConversionException)

Example 30 with GuiPackage

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

the class RemoteStart method getTestTree.

private HashTree getTestTree() {
    GuiPackage gui = GuiPackage.getInstance();
    HashTree testTree = gui.getTreeModel().getTestPlan();
    JMeter.convertSubTree(testTree);
    testTree.add(testTree.getArray()[0], gui.getMainFrame());
    // Used for remote notification of threads start/stop,see BUG 54152
    testTree.add(testTree.getArray()[0], new RemoteThreadsListenerTestElement());
    return testTree;
}
Also used : HashTree(org.apache.jorphan.collections.HashTree) GuiPackage(org.apache.jmeter.gui.GuiPackage) RemoteThreadsListenerTestElement(org.apache.jmeter.threads.RemoteThreadsListenerTestElement)

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