4141import org .apache .jmeter .testelement .TestElementSchema ;
4242import org .apache .jmeter .util .JMeterUtils ;
4343import org .apache .jmeter .visualizers .Printable ;
44+ import org .apache .jorphan .gui .JEditableCheckBox ;
4445import org .apache .jorphan .gui .JFactory ;
4546import org .apiguardian .api .API ;
4647import org .slf4j .Logger ;
@@ -70,9 +71,6 @@ public abstract class AbstractJMeterGuiComponent extends JPanel implements JMete
7071 /** Logging */
7172 private static final Logger log = LoggerFactory .getLogger (AbstractJMeterGuiComponent .class );
7273
73- /** Flag indicating whether this component is enabled. */
74- private boolean enabled = true ;
75-
7674 /**
7775 * A GUI panel containing the name of this component.
7876 * @deprecated use {@link #getName()} or {@link AbstractJMeterGuiComponent#createTitleLabel()} for better alignment of the fields
@@ -84,6 +82,10 @@ public abstract class AbstractJMeterGuiComponent extends JPanel implements JMete
8482
8583 private final JTextArea commentField = JFactory .tabMovesFocus (new JTextArea ());
8684
85+ private final JBooleanPropertyEditor enabled = new JBooleanPropertyEditor (
86+ TestElementSchema .INSTANCE .getEnabled (),
87+ JMeterUtils .getResString ("enable" ));
88+
8789 /**
8890 * Stores a collection of property editors, so GuiCompoenent can have default implementations that
8991 * update the UI fields based on {@link TestElement} properties and vice versa.
@@ -99,6 +101,7 @@ public abstract class AbstractJMeterGuiComponent extends JPanel implements JMete
99101 protected AbstractJMeterGuiComponent () {
100102 namePanel = new NamePanel ();
101103 init ();
104+ bindingGroup .add (enabled );
102105 }
103106
104107 /**
@@ -127,7 +130,7 @@ public void setComment(String comment) {
127130 */
128131 @ Override
129132 public boolean isEnabled () {
130- return enabled ;
133+ return enabled . getValue (). equals ( JEditableCheckBox . Value . of ( true )) ;
131134 }
132135
133136 /**
@@ -137,7 +140,7 @@ public boolean isEnabled() {
137140 @ Override
138141 public void setEnabled (boolean enabled ) {
139142 log .debug ("Setting enabled: {}" , enabled );
140- this .enabled = enabled ;
143+ this .enabled . setValue ( JEditableCheckBox . Value . of ( enabled )) ;
141144 }
142145
143146 /**
@@ -211,7 +214,6 @@ protected Component createTitleLabel() {
211214 @ Override
212215 public void configure (TestElement element ) {
213216 setName (element .getName ());
214- enabled = element .isEnabled ();
215217 commentField .setText (element .getComment ());
216218 bindingGroup .updateUi (element );
217219 }
@@ -225,7 +227,6 @@ public void configure(TestElement element) {
225227 @ Override
226228 public void clearGui () {
227229 initGui ();
228- enabled = true ;
229230 }
230231
231232 private void initGui () {
@@ -241,7 +242,7 @@ private void init() {
241242 @ API (status = EXPERIMENTAL , since = "5.6.3" )
242243 public void modifyTestElement (TestElement element ) {
243244 JMeterGUIComponent .super .modifyTestElement (element );
244- modifyTestElementEnabledAndComment (element );
245+ modifyTestElementComment (element );
245246 bindingGroup .updateElement (element );
246247 }
247248
@@ -264,22 +265,18 @@ protected void configureTestElement(TestElement mc) {
264265 TestElementSchema schema = TestElementSchema .INSTANCE ;
265266 mc .set (schema .getGuiClass (), getClass ());
266267 mc .set (schema .getTestClass (), mc .getClass ());
267- modifyTestElementEnabledAndComment (mc );
268+ modifyTestElementComment (mc );
269+ // This stores the state of the TestElement
270+ log .debug ("setting element to enabled: {}" , enabled .getValue ());
271+ enabled .updateElement (mc );
268272 }
269273
270274 /**
271275 * Assigns basic fields from UI to the test element: name, comments, gui class, and the registered editors.
272276 *
273277 * @param mc test element
274278 */
275- private void modifyTestElementEnabledAndComment (TestElement mc ) {
276- // This stores the state of the TestElement
277- log .debug ("setting element to enabled: {}" , enabled );
278- // We can skip storing "enabled" state if it's true, as it's default value.
279- // JMeter removes disabled elements early from the tree, so configuration elements
280- // with enabled=false (~HTTP Request Defaults) can't unexpectedly override the regular ones
281- // like HTTP Request.
282- mc .set (TestElementSchema .INSTANCE .getEnabled (), enabled ? null : Boolean .FALSE );
279+ private void modifyTestElementComment (TestElement mc ) {
283280 // Note: we can't use editors for "comments" as getComments() is not a final method, so plugins might
284281 // override it and provide a different implementation.
285282 mc .setComment (StringUtils .defaultIfEmpty (getComment (), null ));
@@ -305,6 +302,7 @@ protected Container makeTitlePanel() {
305302 commentField .setWrapStyleWord (true );
306303 commentField .setLineWrap (true );
307304 titlePanel .add (commentField );
305+ titlePanel .add (enabled , "span 2" );
308306
309307 // Note: VerticalPanel has a workaround for Box layout which aligns elements, so we can't
310308 // use trivial JPanel.
0 commit comments