Skip to content

Commit c01ddbe

Browse files
committed
feat: support localization in JEditableCheckBox
1 parent 46cf52b commit c01ddbe

11 files changed

Lines changed: 86 additions & 66 deletions

File tree

src/core/src/main/java/org/apache/jmeter/control/gui/TestPlanGui.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,20 @@ public class TestPlanGui extends AbstractJMeterGuiComponent {
5757
private final JBooleanPropertyEditor functionalMode =
5858
new JBooleanPropertyEditor(
5959
TestPlanSchema.INSTANCE.getFunctionalMode(),
60-
JMeterUtils.getResString("functional_mode"));
60+
"functional_mode",
61+
JMeterUtils::getResString);
6162

6263
private final JBooleanPropertyEditor serializedMode =
6364
new JBooleanPropertyEditor(
6465
TestPlanSchema.INSTANCE.getSerializeThreadgroups(),
65-
JMeterUtils.getResString("testplan.serialized"));
66+
"testplan.serialized",
67+
JMeterUtils::getResString);
6668

6769
private final JBooleanPropertyEditor tearDownOnShutdown =
6870
new JBooleanPropertyEditor(
6971
TestPlanSchema.INSTANCE.getTearDownOnShutdown(),
70-
JMeterUtils.getResString("teardown_on_shutdown"));
72+
"teardown_on_shutdown",
73+
JMeterUtils::getResString);
7174

7275
/** A panel allowing the user to define variables. */
7376
private final ArgumentsPanel argsPanel;

src/core/src/main/java/org/apache/jmeter/control/gui/TransactionControllerGui.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@ public class TransactionControllerGui extends AbstractControllerGui {
3939
private final JBooleanPropertyEditor generateParentSample =
4040
new JBooleanPropertyEditor(
4141
TransactionControllerSchema.INSTANCE.getGenearteParentSample(),
42-
JMeterUtils.getResString("transaction_controller_parent"));
42+
"transaction_controller_parent",
43+
JMeterUtils::getResString);
4344

4445
/** if selected, add duration of timers to total runtime */
4546
private final JBooleanPropertyEditor includeTimers =
4647
new JBooleanPropertyEditor(
4748
TransactionControllerSchema.INSTANCE.getIncludeTimers(),
48-
JMeterUtils.getResString("transaction_controller_include_timers"));
49+
"transaction_controller_parent",
50+
JMeterUtils::getResString);
4951

5052
/**
5153
* Create a new TransactionControllerGui instance.

src/core/src/main/java/org/apache/jmeter/threads/gui/ThreadGroupGui.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ public class ThreadGroupGui extends AbstractThreadGroupGui implements ItemListen
6565
private final JBooleanPropertyEditor scheduler =
6666
new JBooleanPropertyEditor(
6767
ThreadGroupSchema.INSTANCE.getUseScheduler(),
68-
JMeterUtils.getResString("scheduler"));
68+
"scheduler",
69+
JMeterUtils::getResString);
6970

7071
private final JTextField duration = new JTextField();
7172
private final JLabel durationLabel = labelFor(duration, "duration");
@@ -76,7 +77,8 @@ public class ThreadGroupGui extends AbstractThreadGroupGui implements ItemListen
7677
private final JBooleanPropertyEditor sameUserBox =
7778
new JBooleanPropertyEditor(
7879
AbstractThreadGroupSchema.INSTANCE.getSameUserOnNextIteration(),
79-
JMeterUtils.getResString("threadgroup_same_user"));
80+
"threadgroup_same_user",
81+
JMeterUtils::getResString);
8082

8183
public ThreadGroupGui() {
8284
this(true);
@@ -199,7 +201,8 @@ private void init() { // WARNING: called from ctor so must not be overridden (i.
199201
if (showDelayedStart) {
200202
delayedStart = new JBooleanPropertyEditor(
201203
ThreadGroupSchema.INSTANCE.getDelayedStart(),
202-
JMeterUtils.getResString("delayed_start")); // $NON-NLS-1$
204+
"delayed_start",
205+
JMeterUtils::getResString); // $NON-NLS-1$
203206
threadPropsPanel.add(delayedStart, "span 2");
204207
}
205208
scheduler.addPropertyChangeListener(

src/core/src/main/kotlin/org/apache/jmeter/gui/JBooleanPropertyEditor.kt

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ package org.apache.jmeter.gui
2020
import org.apache.jmeter.testelement.TestElement
2121
import org.apache.jmeter.testelement.property.BooleanProperty
2222
import org.apache.jmeter.testelement.schema.BooleanPropertyDescriptor
23-
import org.apache.jmeter.util.JMeterUtils
2423
import org.apache.jorphan.gui.JEditableCheckBox
24+
import org.apache.jorphan.locale.LocalizedString
25+
import org.apache.jorphan.locale.PlainValue
26+
import org.apache.jorphan.locale.ResourceLocalizer
2527
import org.apiguardian.api.API
28+
import org.jetbrains.annotations.NonNls
2629

2730
/**
2831
* Provides editor component for boolean properties that accommodate both true/false and expression string.
@@ -31,19 +34,20 @@ import org.apiguardian.api.API
3134
@API(status = API.Status.EXPERIMENTAL, since = "5.6")
3235
public class JBooleanPropertyEditor(
3336
private val propertyDescriptor: BooleanPropertyDescriptor<*>,
34-
label: String,
35-
) : JEditableCheckBox(label, DEFAULT_CONFIGURATION), Binding {
37+
label: @NonNls String,
38+
resourceLocalizer: ResourceLocalizer,
39+
) : JEditableCheckBox(label, createConfiguration(resourceLocalizer), resourceLocalizer), Binding {
3640
private companion object {
37-
@JvmField
38-
val DEFAULT_CONFIGURATION: Configuration = Configuration(
39-
startEditing = JMeterUtils.getResString("editable_checkbox.use_expression"),
40-
trueValue = "true",
41-
falseValue = "false",
42-
extraValues = listOf(
43-
"\${__P(property_name)}",
44-
"\${variable_name}",
41+
private fun createConfiguration(resourceLocalizer: ResourceLocalizer) =
42+
Configuration(
43+
useExpression = LocalizedString("edit_as_expression_action", resourceLocalizer),
44+
trueValue = LocalizedString("editable_checkbox.true", resourceLocalizer),
45+
falseValue = LocalizedString("editable_checkbox.false", resourceLocalizer),
46+
extraValues = listOf(
47+
PlainValue("\${__P(property_name)}"),
48+
PlainValue("\${variable_name}"),
49+
)
4550
)
46-
)
4751
}
4852

4953
public fun reset() {

src/core/src/main/resources/org/apache/jmeter/resources/messages.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,9 @@ duration_assertion_label=Duration in milliseconds\:
315315
duration_assertion_title=Duration Assertion
316316
duration_tooltip=Elapsed time of current running Test
317317
edit=Edit
318-
editable_checkbox.use_expression=Use Expression
318+
edit_as_expression_action=Use Expression
319+
editable_checkbox.true=True
320+
editable_checkbox.false=False
319321
email_results_title=Email Results
320322
en=English
321323
enable=Enable

src/core/src/main/resources/org/apache/jmeter/resources/messages_fr.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ duration_assertion_label=Durée en millisecondes \:
310310
duration_assertion_title=Assertion Durée
311311
duration_tooltip=Temps passé depuis le début du test en cours
312312
edit=Editer
313-
editable_checkbox.use_expression=Utiliser l'expression
313+
edit_as_expression_action=Utiliser l'expression
314314
email_results_title=Résultat d'email
315315
en=Anglais
316316
enable=Activer

src/jorphan/src/main/kotlin/org/apache/jorphan/gui/JEditableCheckBox.kt

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@
1717

1818
package org.apache.jorphan.gui
1919

20+
import org.apache.jorphan.locale.ComboBoxValue
21+
import org.apache.jorphan.locale.LocalizedString
22+
import org.apache.jorphan.locale.PlainValue
23+
import org.apache.jorphan.locale.ResourceKeyed
24+
import org.apache.jorphan.locale.ResourceLocalizer
2025
import org.apiguardian.api.API
26+
import org.jetbrains.annotations.NonNls
2127
import java.awt.Container
2228
import java.awt.FlowLayout
2329
import java.awt.event.ActionEvent
@@ -28,7 +34,6 @@ import javax.swing.JComboBox
2834
import javax.swing.JLabel
2935
import javax.swing.JPanel
3036
import javax.swing.JPopupMenu
31-
import javax.swing.SwingUtilities
3237
import javax.swing.event.ChangeEvent
3338

3439
/**
@@ -37,8 +42,9 @@ import javax.swing.event.ChangeEvent
3742
*/
3843
@API(status = API.Status.EXPERIMENTAL, since = "5.6")
3944
public open class JEditableCheckBox(
40-
label: String,
41-
private val configuration: Configuration
45+
label: @NonNls String,
46+
private val configuration: Configuration,
47+
resourceLocalizer: ResourceLocalizer,
4248
) : JPanel() {
4349
public companion object {
4450
public const val CHECKBOX_CARD: String = "checkbox"
@@ -82,28 +88,29 @@ public open class JEditableCheckBox(
8288
/**
8389
* Supplies the parameters to [JEditableCheckBox].
8490
*/
91+
@API(status = API.Status.EXPERIMENTAL, since = "5.6.0")
8592
public data class Configuration(
8693
/** Menu item title to "start editing" the checkbox value. */
87-
val startEditing: String = "Use Expression",
94+
val useExpression: LocalizedString,
8895
/** The title to be used for "true" value in the checkbox. */
89-
val trueValue: String = "true",
96+
val trueValue: LocalizedString,
9097
/** The title to be used for "false" value in the checkbox. */
91-
val falseValue: String = "false",
98+
val falseValue: LocalizedString,
9299
/** Extra values to be added for the combobox. */
93-
val extraValues: List<String> = listOf(),
100+
val extraValues: List<ComboBoxValue> = listOf(),
94101
)
95102

96103
private val cards = CardLayoutWithSizeOfCurrentVisibleElement()
97104

98-
private val useExpressionAction = object : AbstractAction(configuration.startEditing) {
105+
private val useExpressionAction = object : AbstractAction(configuration.useExpression.toString()) {
99106
override fun actionPerformed(e: ActionEvent?) {
100107
cards.next(this@JEditableCheckBox)
108+
comboBox.selectedItem = if (checkbox.isSelected) configuration.trueValue else configuration.falseValue
101109
comboBox.requestFocusInWindow()
102-
fireValueChanged()
103110
}
104111
}
105112

106-
private val checkbox: JCheckBox = JCheckBox(label).apply {
113+
private val checkbox: JCheckBox = JCheckBox(resourceLocalizer.localize(label)).apply {
107114
val cb = this
108115
componentPopupMenu = JPopupMenu().apply {
109116
add(useExpressionAction)
@@ -113,34 +120,16 @@ public open class JEditableCheckBox(
113120
}
114121
}
115122

116-
private val comboBox: JComboBox<String> = JComboBox<String>().apply {
123+
private val comboBox: JComboBox<ComboBoxValue> = JComboBox<ComboBoxValue>().apply {
117124
isEditable = true
118125
configuration.extraValues.forEach {
119126
addItem(it)
120127
}
121128
addItem(configuration.trueValue)
122129
addItem(configuration.falseValue)
123-
addActionListener {
124-
val jComboBox = it.source as JComboBox<*>
125-
SwingUtilities.invokeLater {
126-
if (jComboBox.isPopupVisible) {
127-
fireValueChanged()
128-
return@invokeLater
129-
}
130-
when (val value = jComboBox.selectedItem as String) {
131-
configuration.trueValue, configuration.falseValue -> {
132-
checkbox.isSelected = value == configuration.trueValue
133-
cards.show(this@JEditableCheckBox, CHECKBOX_CARD)
134-
checkbox.requestFocusInWindow()
135-
fireValueChanged()
136-
}
137-
}
138-
}
139-
}
140-
// TODO: trigger value changed when the text is changed
141130
}
142131

143-
private val textFieldLabel = JLabel(label).apply {
132+
private val textFieldLabel = JLabel(resourceLocalizer.localize(label)).apply {
144133
labelFor = comboBox
145134
}
146135

@@ -190,19 +179,26 @@ public open class JEditableCheckBox(
190179
public var value: Value
191180
get() = when (components.indexOfFirst { it.isVisible }) {
192181
0 -> if (checkbox.isSelected) Value.Boolean.TRUE else Value.Boolean.FALSE
193-
else -> Value.Text(comboBox.selectedItem as String)
182+
else ->
183+
when (val value = comboBox.selectedItem) {
184+
is ResourceKeyed ->
185+
when (value.resourceKey) {
186+
configuration.trueValue.resourceKey -> Value.Boolean.TRUE
187+
configuration.falseValue.resourceKey -> Value.Boolean.FALSE
188+
else -> Value.Text(value.resourceKey)
189+
}
190+
else -> Value.Text(value?.toString() ?: "")
191+
}
194192
}
195193
set(value) {
196194
when (value) {
197195
is Value.Boolean -> {
198-
comboBox.selectedItem = ""
199196
checkbox.isSelected = value.value
200197
cards.show(this, CHECKBOX_CARD)
201198
}
202199

203200
is Value.Text -> {
204-
checkbox.isSelected = false
205-
comboBox.selectedItem = value.value
201+
comboBox.selectedItem = PlainValue(value.value)
206202
cards.show(this, EDITABLE_CARD)
207203
}
208204
}

src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/config/gui/HttpDefaultsGui.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,17 @@ public class HttpDefaultsGui extends AbstractConfigGui {
6161
private UrlConfigGui urlConfigGui;
6262
private final JBooleanPropertyEditor retrieveEmbeddedResources = new JBooleanPropertyEditor(
6363
HTTPSamplerBaseSchema.INSTANCE.getRetrieveEmbeddedResources(),
64-
JMeterUtils.getResString("web_testing_retrieve_images"));
64+
"web_testing_retrieve_images",
65+
JMeterUtils::getResString);
6566
private final JBooleanPropertyEditor concurrentDwn = new JBooleanPropertyEditor(
6667
HTTPSamplerBaseSchema.INSTANCE.getConcurrentDownload(),
67-
JMeterUtils.getResString("web_testing_concurrent_download"));
68+
"web_testing_concurrent_download",
69+
JMeterUtils::getResString);
6870
private JTextField concurrentPool;
6971
private final JBooleanPropertyEditor useMD5 = new JBooleanPropertyEditor(
7072
HTTPSamplerBaseSchema.INSTANCE.getStoreAsMD5(),
71-
JMeterUtils.getResString("response_save_as_md5")); // $NON-NLS-1$
73+
"response_save_as_md5",
74+
JMeterUtils::getResString); // $NON-NLS-1$
7275
private JTextField embeddedAllowRE; // regular expression used to match against embedded resource URLs to allow
7376
private JTextField embeddedExcludeRE; // regular expression used to match against embedded resource URLs to discard
7477
private JTextField sourceIpAddr; // does not apply to Java implementation

src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/config/gui/UrlConfigGui.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,19 +380,22 @@ protected Component getPathPanel() {
380380

381381
useKeepAlive = new JBooleanPropertyEditor(
382382
HTTPSamplerBaseSchema.INSTANCE.getUseKeepalive(),
383-
JMeterUtils.getResString("use_keepalive"));
383+
"use_keepalive",
384+
JMeterUtils::getResString);
384385
JFactory.small(useKeepAlive);
385386
useKeepAlive.setVisible(getUrlConfigDefaults().isUseKeepAliveVisible());
386387

387388
useMultipart = new JBooleanPropertyEditor(
388389
HTTPSamplerBaseSchema.INSTANCE.getUseMultipartPost(),
389-
JMeterUtils.getResString("use_multipart_for_http_post")); // $NON-NLS-1$
390+
"use_multipart_for_http_post",
391+
JMeterUtils::getResString);
390392
JFactory.small(useMultipart);
391393
useMultipart.setVisible(getUrlConfigDefaults().isUseMultipartVisible());
392394

393395
useBrowserCompatibleMultipartMode = new JBooleanPropertyEditor(
394396
HTTPSamplerBaseSchema.INSTANCE.getUseBrowserCompatibleMultipart(),
395-
JMeterUtils.getResString("use_multipart_mode_browser")); // $NON-NLS-1$
397+
"use_multipart_mode_browser",
398+
JMeterUtils::getResString);
396399
JFactory.small(useBrowserCompatibleMultipartMode);
397400
useBrowserCompatibleMultipartMode.setVisible(getUrlConfigDefaults().isUseBrowserCompatibleMultipartModeVisible());
398401
}

src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/gui/HttpTestSampleGui.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,17 @@ public class HttpTestSampleGui extends AbstractSamplerGui {
6363
private UrlConfigGui urlConfigGui;
6464
private final JBooleanPropertyEditor retrieveEmbeddedResources = new JBooleanPropertyEditor(
6565
HTTPSamplerBaseSchema.INSTANCE.getRetrieveEmbeddedResources(),
66-
JMeterUtils.getResString("web_testing_retrieve_images"));
66+
"web_testing_retrieve_images",
67+
JMeterUtils::getResString);
6768
private final JBooleanPropertyEditor concurrentDwn = new JBooleanPropertyEditor(
6869
HTTPSamplerBaseSchema.INSTANCE.getConcurrentDownload(),
69-
JMeterUtils.getResString("web_testing_concurrent_download"));
70+
"web_testing_concurrent_download",
71+
JMeterUtils::getResString);
7072
private JTextField concurrentPool;
7173
private final JBooleanPropertyEditor useMD5 = new JBooleanPropertyEditor(
7274
HTTPSamplerBaseSchema.INSTANCE.getStoreAsMD5(),
73-
JMeterUtils.getResString("response_save_as_md5")); // $NON-NLS-1$
75+
"response_save_as_md5",
76+
JMeterUtils::getResString);
7477
private JTextField embeddedAllowRE; // regular expression used to match against embedded resource URLs to allow
7578
private JTextField embeddedExcludeRE; // regular expression used to match against embedded resource URLs to exclude
7679
private JTextField sourceIpAddr; // does not apply to Java implementation

0 commit comments

Comments
 (0)