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();
}
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;
}
}
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);
}
}
}
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();
}
}
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;
}
Aggregations