Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@
package org.apache.jmeter.gui.action;

import java.awt.event.ActionEvent;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import javax.swing.tree.TreeNode;

import org.apache.jmeter.gui.GuiPackage;
import org.apache.jmeter.gui.tree.JMeterTreeNode;
import org.slf4j.Logger;
Expand Down Expand Up @@ -50,12 +54,15 @@ public void doAction(ActionEvent e) {
if (e.getActionCommand().equals(ActionNames.ENABLE)) {
log.debug("enabling currently selected gui objects");
enableComponents(nodes, true);
triggerChildrenRender(nodes);
} else if (e.getActionCommand().equals(ActionNames.DISABLE)) {
log.debug("disabling currently selected gui objects");
enableComponents(nodes, false);
triggerChildrenRender(nodes);
} else if (e.getActionCommand().equals(ActionNames.TOGGLE)) {
log.debug("toggling currently selected gui objects");
toggleComponents(nodes);
triggerChildrenRender(nodes);
}
}

Expand All @@ -76,6 +83,24 @@ private void toggleComponents(JMeterTreeNode[] nodes) {
}
}

private void triggerChildrenRender(JMeterTreeNode[] nodes) {
Set<TreeNode> visited = new HashSet<>();
ArrayDeque<TreeNode> queue = new ArrayDeque<>(Arrays.asList(nodes));
while (!queue.isEmpty()) {
final TreeNode next = queue.poll();
if (!visited.add(next)) {
continue;
}
if (next instanceof JMeterTreeNode) {
// Trigger render
((JMeterTreeNode) next).nameChanged();
}
for (int i = 0; i < next.getChildCount(); i++) {
queue.add(next.getChildAt(i));
}
}
}

/**
* @see org.apache.jmeter.gui.action.Command#getActionNames()
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import javax.swing.JTree;
import javax.swing.border.Border;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeNode;

import org.apache.commons.lang3.StringUtils;
import org.apache.jorphan.util.JOrphanUtils;
Expand Down Expand Up @@ -52,6 +53,13 @@ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean
JOrphanUtils.isBlank(node.getName()) ? BLANK : node.getName(),
sel, expanded, leaf, row, p_hasFocus);
boolean enabled = node.isEnabled();
// Even in case the node itself is not disabled, we render it as disabled if
// one of its parents is in fact disabled.
for (TreeNode parent = node.getParent(); parent != null && enabled; parent = parent.getParent()) {
if (parent instanceof JMeterTreeNode) {
enabled = ((JMeterTreeNode) parent).isEnabled();
}
}
ImageIcon ic = node.getIcon(enabled);
if (ic != null) {
if (enabled) {
Expand Down
15 changes: 13 additions & 2 deletions src/core/src/main/java/org/apache/jmeter/plugin/PluginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.net.URL;

import javax.swing.GrayFilter;
import javax.swing.ImageIcon;

import org.apache.jmeter.gui.GUIFactory;
Expand Down Expand Up @@ -57,14 +58,24 @@ private void installPlugin(JMeterPlugin plugin) {
if (resource == null) {
log.warn("Can't find icon for {} - {}", icon[0], icon[1]);
} else {
GUIFactory.registerIcon(icon[0], new ImageIcon(resource));
final ImageIcon regularIcon = new ImageIcon(resource);
GUIFactory.registerIcon(icon[0], regularIcon);
ImageIcon disabledIcon = null;
if (icon.length > 2 && icon[2] != null) {
URL resource2 = classloader.getResource(icon[2].trim());
if (resource2 == null) {
log.info("Can't find disabled icon for {} - {}", icon[0], icon[2]);
} else {
GUIFactory.registerDisabledIcon(icon[0], new ImageIcon(resource2));
disabledIcon = new ImageIcon(resource2);
}
} else {
// Second icon is not specified, create disabled one automatically
disabledIcon = new ImageIcon(
GrayFilter.createDisabledImage(regularIcon.getImage())
);
}
if (disabledIcon != null) {
GUIFactory.registerDisabledIcon(icon[0], disabledIcon);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions xdocs/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ to view the last release notes of version 5.2.1.
<ul>
<li><bug>63458</bug><pr>551</pr>Add new template "Functional Testing Test Plan [01]". Contributed by Sebastian Boga (sebastian.boga at endava.com)</li>
<li><bug>64119</bug>Use first renderer from <code>view.results.tree.renderers_order</code> property as default in View Results Tree</li>
<li><bug>64148</bug>Use gray icons for disabled elements in the tree, display subtree as gray</li>
</ul>

<ch_section>Non-functional changes</ch_section>
Expand Down