Skip to content

Commit 4e3a778

Browse files
committed
feat: add "use expression" button to JEditableCheckBox for better UX
1 parent c01ddbe commit 4e3a778

6 files changed

Lines changed: 71 additions & 0 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class JBooleanPropertyEditor(
4141
private fun createConfiguration(resourceLocalizer: ResourceLocalizer) =
4242
Configuration(
4343
useExpression = LocalizedString("edit_as_expression_action", resourceLocalizer),
44+
useExpressionTooltip = LocalizedString("edit_as_expression_tooltip", resourceLocalizer),
4445
trueValue = LocalizedString("editable_checkbox.true", resourceLocalizer),
4546
falseValue = LocalizedString("editable_checkbox.false", resourceLocalizer),
4647
extraValues = listOf(

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ duration_assertion_title=Duration Assertion
316316
duration_tooltip=Elapsed time of current running Test
317317
edit=Edit
318318
edit_as_expression_action=Use Expression
319+
edit_as_expression_tooltip=Switch to expression mode to use variables like ${__P(property)}
319320
editable_checkbox.true=True
320321
editable_checkbox.false=False
321322
email_results_title=Email Results

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ duration_assertion_title=Assertion Durée
311311
duration_tooltip=Temps passé depuis le début du test en cours
312312
edit=Editer
313313
edit_as_expression_action=Utiliser l'expression
314+
edit_as_expression_tooltip=Passer en mode expression pour utiliser des variables comme ${__P(property)}
314315
email_results_title=Résultat d'email
315316
en=Anglais
316317
enable=Activer

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ public open class JEditableCheckBox(
9292
public data class Configuration(
9393
/** Menu item title to "start editing" the checkbox value. */
9494
val useExpression: LocalizedString,
95+
/** Tooltip for "start editing" button. */
96+
val useExpressionTooltip: LocalizedString,
9597
/** The title to be used for "true" value in the checkbox. */
9698
val trueValue: LocalizedString,
9799
/** The title to be used for "false" value in the checkbox. */
@@ -133,6 +135,12 @@ public open class JEditableCheckBox(
133135
labelFor = comboBox
134136
}
135137

138+
private val expressionButton = JEllipsisButton().apply {
139+
// Tooltip will be set via configuration or use default
140+
toolTipText = configuration.useExpressionTooltip.toString()
141+
addActionListener(useExpressionAction)
142+
}
143+
136144
@Transient
137145
private var changeEvent: ChangeEvent? = null
138146

@@ -143,6 +151,7 @@ public open class JEditableCheckBox(
143151
Container().apply {
144152
layout = FlowLayout(FlowLayout.LEADING, 0, 0)
145153
add(checkbox)
154+
add(expressionButton)
146155
},
147156
CHECKBOX_CARD
148157
)
@@ -165,6 +174,7 @@ public open class JEditableCheckBox(
165174
super.setEnabled(enabled)
166175
checkbox.isEnabled = enabled
167176
comboBox.isEnabled = enabled
177+
expressionButton.isEnabled = enabled
168178
useExpressionAction.isEnabled = enabled
169179
}
170180

@@ -223,6 +233,7 @@ public open class JEditableCheckBox(
223233

224234
public fun makeSmall() {
225235
JFactory.small(checkbox)
236+
JFactory.small(expressionButton)
226237
// We do not make combobox small as the expression migh be hard to read
227238
}
228239
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to you under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.jorphan.gui
19+
20+
import javax.swing.plaf.nimbus.NimbusStyle
21+
22+
public class JEllipsisButton : JSquareButton("") {
23+
init {
24+
putClientProperty("JComponent.sizeVariant", NimbusStyle.SMALL_KEY)
25+
putClientProperty("JButton.square", true)
26+
putClientProperty("JButton.thin", true)
27+
}
28+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to you under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.jorphan.gui
19+
20+
import org.jetbrains.annotations.Nls
21+
import java.awt.Dimension
22+
import javax.swing.JButton
23+
24+
public open class JSquareButton(title: @Nls String) : JButton(title) {
25+
override fun getPreferredSize(): Dimension {
26+
val dimension = super.getPreferredSize()
27+
return Dimension(dimension.height + 15, dimension.height)
28+
}
29+
}

0 commit comments

Comments
 (0)