Skip to content

Commit 25622cb

Browse files
committed
Update Javadocs and README for localized string docs
1 parent a26a325 commit 25622cb

29 files changed

Lines changed: 548 additions & 34 deletions

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
99
### Added
1010

1111
- Support sorting `LocalizedString` values by the user's current locale.
12-
- Configuration properties to disable the add-on sorting customizations.
12+
- Configuration properties to disable the add-on sorting customizations.
1313
- Bean Validation annotations for `LocalizedString` values, including locale-aware not-null validation.
1414

1515
### Changed

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# Jmix LocalizedString Datatype
66

7-
This add-on provides a custom [Datatype](https://docs.jmix.io/jmix/data-model/data-types.html) and related action for the [ValuePicker](https://docs.jmix.io/jmix/flow-ui/vc/components/valuePicker.html) component for storing and editing localized string values.
7+
This add-on provides a custom [Datatype](https://docs.jmix.io/jmix/data-model/data-types.html), sorting support, Bean Validation constraints, and a related action for the [ValuePicker](https://docs.jmix.io/jmix/flow-ui/vc/components/valuePicker.html) component for storing and editing localized string values.
88

99
The value displayed in visual components depends on the user's current locale.
1010

@@ -19,32 +19,32 @@ The following table shows which version of the add-on is compatible with which v
1919
|--------------|----------------|----------------------------------------------------------------------|
2020
| 2.3.0+ | 1.0.0 | com.glebfox.jmix.locstr:jmix-localized-string-datatype-starter:1.0.0 |
2121

22-
For manual installation, add the following dependencies to your `build.gradle`:
22+
For manual installation, add the following dependency to your `build.gradle`:
2323

2424
```groovy
2525
implementation 'com.glebfox.jmix.locstr:jmix-localized-string-datatype-starter:<addon-version>'
2626
```
2727

28-
## Using the Addon
28+
## Using the Add-on
2929

30-
The `LocalizedString` datatype is represented by three classes:
30+
The `LocalizedString` datatype is represented by three classes:
3131

32-
* [LocalizedString.java](jmix-localized-string-datatype/src/main/java/com/glebfox/jmix/locstr/datatype/LocalizedString.java) - custom Java class used as a type of entity attributes.
32+
* [LocalizedString.java](jmix-localized-string-datatype/src/main/java/com/glebfox/jmix/locstr/datatype/LocalizedString.java) - custom Java class used as a type of entity attributes.
3333
* [LocalizedStringDatatype.java](jmix-localized-string-datatype/src/main/java/com/glebfox/jmix/locstr/datatype/LocalizedStringDatatype.java) - a `Datatype` implementation class for `LocalizedString`.
3434
* [LocalizedStringConverter.java](jmix-localized-string-datatype/src/main/java/com/glebfox/jmix/locstr/datatype/LocalizedStringConverter.java) - a class that converts entity attribute state into database column representation and back again.
3535

3636
You can define an entity attribute with the `LocalizedString` datatype using Studio. For example:
3737

3838
![Attribute Datatype](/doc/img/attribute-datatype.png)
3939

40-
As a result, Studio generates the following attribute definition:
40+
As a result, Studio generates the following attribute definition:
4141

4242
```java
4343
@Column(name = "NAME", nullable = false)
4444
private LocalizedString name;
4545
```
4646

47-
To edit localized value, add action with `type="value_localizedStringEdit"` to the `ValuePicker` component. For example:
47+
To edit a localized value, add an action with `type="value_localizedStringEdit"` to the `ValuePicker` component. For example:
4848

4949
```xml
5050
<valuePicker id="nameField" property="name">
@@ -84,7 +84,7 @@ The `value_localizedStringEdit` action is represented by [LocalizedStringEditAct
8484

8585
### Properties
8686

87-
* `multiline` - sets whether to use a multi-line text input component. `TextArea` is used for multi-line text input, `TextField` otherwise. `false` by default. If an entity attribute is annotated with `@Lob`, multi-line text input is used. For example:
87+
* `multiline` - sets whether to use a multi-line text input component. `TextArea` is used for multi-line text input, `TextField` otherwise. If the property is not set explicitly and the entity attribute is annotated with `@Lob`, multi-line text input is used. For example:
8888

8989
```java
9090
@Lob
@@ -136,12 +136,12 @@ If the target `ValuePicker` of `LocalizedStringEditAction` is bound to a require
136136

137137
The add-on provides Bean Validation annotations for `LocalizedString` attributes:
138138

139-
* `@LocalizedStringSize`
140-
* `@LocalizedStringLength`
141-
* `@LocalizedStringPattern`
142-
* `@LocalizedStringNotNull`
143-
* `@LocalizedStringNotEmpty`
144-
* `@LocalizedStringNotBlank`
139+
* [`@LocalizedStringSize`](jmix-localized-string-datatype/src/main/java/com/glebfox/jmix/locstr/validation/constraints/LocalizedStringSize.java) checks that every localized value length is between `min` and `max`. A `null` `LocalizedString` is valid.
140+
* [`@LocalizedStringLength`](jmix-localized-string-datatype/src/main/java/com/glebfox/jmix/locstr/validation/constraints/LocalizedStringLength.java) checks that every localized value length is between `min` and `max`. A `null` `LocalizedString` is valid.
141+
* [`@LocalizedStringPattern`](jmix-localized-string-datatype/src/main/java/com/glebfox/jmix/locstr/validation/constraints/LocalizedStringPattern.java) checks that every localized value matches `regexp`. A `null` `LocalizedString` is valid.
142+
* [`@LocalizedStringNotNull`](jmix-localized-string-datatype/src/main/java/com/glebfox/jmix/locstr/validation/constraints/LocalizedStringNotNull.java) checks that a non-null localized value is stored for every configured application locale.
143+
* [`@LocalizedStringNotEmpty`](jmix-localized-string-datatype/src/main/java/com/glebfox/jmix/locstr/validation/constraints/LocalizedStringNotEmpty.java) checks that every localized value is not empty. A `null` `LocalizedString` and an empty set of localized values are invalid.
144+
* [`@LocalizedStringNotBlank`](jmix-localized-string-datatype/src/main/java/com/glebfox/jmix/locstr/validation/constraints/LocalizedStringNotBlank.java) checks that every localized value contains at least one non-whitespace character. A `null` `LocalizedString` and an empty set of localized values are invalid.
145145

146146
For example:
147147

@@ -152,7 +152,7 @@ For example:
152152
private LocalizedString name;
153153
```
154154

155-
Every stored localized value is validated. `@LocalizedStringNotNull` also checks that a value is stored for every configured application locale. When the edit dialog is used for an entity attribute, these constraints are applied to each locale field separately. Standard `@NotNull` can still be used for the attribute itself when only the `LocalizedString` object reference should be checked.
155+
When the edit dialog is used for an entity attribute, these constraints are applied to each locale field separately. Standard `@NotNull` can still be used for the attribute itself when only the `LocalizedString` object reference should be checked.
156156

157157
Additionally, you can add a validator that checks the value of every field in the edit dialog. For example:
158158

@@ -170,7 +170,7 @@ private void descriptionFieldValidator(final ValidationContext validationContext
170170

171171
### Field Provider
172172

173-
It's possible tio change edit fields by setting the field provider, which will return a component for a given `FieldGenerationContext`. For example:
173+
It's possible to change edit fields by setting the field provider, which will return a component for a given `FieldGenerationContext`. For example:
174174

175175
```java
176176
@Install(to = "descriptionField.localizedStringEdit", subject = "fieldProvider")

jmix-localized-string-datatype-starter/src/main/java/com/glebfox/jmix/autoconfigure/locstr/LocstrAutoConfiguration.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
import org.springframework.boot.autoconfigure.AutoConfiguration;
2121
import org.springframework.context.annotation.Import;
2222

23+
/**
24+
* Spring Boot auto-configuration that imports the LocalizedString Jmix module.
25+
*/
2326
@AutoConfiguration
2427
@Import({LocstrConfiguration.class})
2528
public class LocstrAutoConfiguration {
2629
}
27-

jmix-localized-string-datatype/src/main/java/com/glebfox/jmix/locstr/LocstrConfiguration.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,25 @@
3030

3131
import java.util.Collections;
3232

33+
/**
34+
* Spring configuration that registers the LocalizedString Jmix module.
35+
*/
3336
@Configuration
3437
@ComponentScan
3538
@ConfigurationPropertiesScan
3639
@JmixModule(dependsOn = {EclipselinkConfiguration.class, FlowuiConfiguration.class})
3740
@PropertySource(name = "com.glebfox.jmix.locstr", value = "classpath:/com/glebfox/jmix/locstr/module.properties")
3841
public class LocstrConfiguration {
3942

43+
/**
44+
* Registers action metadata for add-on UI actions.
45+
*
46+
* @param applicationContext Spring application context used by the
47+
* Jmix action scanner
48+
* @param metadataReaderFactory metadata reader factory used by the
49+
* Jmix action scanner
50+
* @return action configuration that scans the add-on action package
51+
*/
4052
@Bean("locstr_LocstrActions")
4153
public ActionsConfiguration actions(final ApplicationContext applicationContext,
4254
final AnnotationScanMetadataReaderFactory metadataReaderFactory) {

jmix-localized-string-datatype/src/main/java/com/glebfox/jmix/locstr/LocstrProperties.java

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,72 +24,144 @@
2424
@ConfigurationProperties(prefix = LocstrProperties.PREFIX)
2525
public class LocstrProperties {
2626

27+
/**
28+
* Root configuration prefix for the add-on.
29+
*/
2730
public static final String PREFIX = "jmix.locstr";
31+
32+
/**
33+
* Configuration prefix for database-level sorting settings.
34+
*/
2835
public static final String SORTING_DATABASE_PREFIX = PREFIX + ".sorting.database";
36+
37+
/**
38+
* Configuration prefix for in-memory sorting settings.
39+
*/
2940
public static final String SORTING_IN_MEMORY_PREFIX = PREFIX + ".sorting.in-memory";
3041

3142
/**
3243
* Sorting customization settings.
3344
*/
3445
private Sorting sorting = new Sorting();
3546

47+
/**
48+
* Returns sorting customization settings.
49+
*
50+
* @return sorting settings
51+
*/
3652
public Sorting getSorting() {
3753
return sorting;
3854
}
3955

56+
/**
57+
* Sets sorting customization settings.
58+
*
59+
* @param sorting sorting settings
60+
*/
4061
public void setSorting(Sorting sorting) {
4162
this.sorting = sorting;
4263
}
4364

65+
/**
66+
* Groups sorting customization settings.
67+
*/
4468
public static class Sorting {
4569

4670
private Database database = new Database();
4771
private InMemory inMemory = new InMemory();
4872

73+
/**
74+
* Returns database-level sorting settings.
75+
*
76+
* @return database-level sorting settings
77+
*/
4978
public Database getDatabase() {
5079
return database;
5180
}
5281

82+
/**
83+
* Sets database-level sorting settings.
84+
*
85+
* @param database database-level sorting settings
86+
*/
5387
public void setDatabase(Database database) {
5488
this.database = database;
5589
}
5690

91+
/**
92+
* Returns in-memory sorting settings.
93+
*
94+
* @return in-memory sorting settings
95+
*/
5796
public InMemory getInMemory() {
5897
return inMemory;
5998
}
6099

100+
/**
101+
* Sets in-memory sorting settings.
102+
*
103+
* @param inMemory in-memory sorting settings
104+
*/
61105
public void setInMemory(InMemory inMemory) {
62106
this.inMemory = inMemory;
63107
}
64108
}
65109

110+
/**
111+
* Configures database-level sorting for localized string attributes.
112+
*/
66113
public static class Database {
67114

68115
/**
69116
* Whether to register the add-on database-level sorting customization for LocalizedString attributes.
70117
*/
71118
private boolean enabled = true;
72119

120+
/**
121+
* Returns whether database-level sorting customization is enabled.
122+
*
123+
* @return {@code true} if database-level sorting customization is
124+
* enabled
125+
*/
73126
public boolean isEnabled() {
74127
return enabled;
75128
}
76129

130+
/**
131+
* Sets whether database-level sorting customization is enabled.
132+
*
133+
* @param enabled {@code true} to enable database-level sorting
134+
* customization
135+
*/
77136
public void setEnabled(boolean enabled) {
78137
this.enabled = enabled;
79138
}
80139
}
81140

141+
/**
142+
* Configures in-memory sorting for localized string attributes.
143+
*/
82144
public static class InMemory {
83145

84146
/**
85147
* Whether to register the add-on in-memory sorting customization for LocalizedString attributes.
86148
*/
87149
private boolean enabled = true;
88150

151+
/**
152+
* Returns whether in-memory sorting customization is enabled.
153+
*
154+
* @return {@code true} if in-memory sorting customization is enabled
155+
*/
89156
public boolean isEnabled() {
90157
return enabled;
91158
}
92159

160+
/**
161+
* Sets whether in-memory sorting customization is enabled.
162+
*
163+
* @param enabled {@code true} to enable in-memory sorting customization
164+
*/
93165
public void setEnabled(boolean enabled) {
94166
this.enabled = enabled;
95167
}

0 commit comments

Comments
 (0)