Skip to content

Commit 6b8b522

Browse files
authored
Merge pull request #28 from aalmiray/extension-points
Extension points
2 parents d846829 + bace4e2 commit 6b8b522

27 files changed

+134
-134
lines changed

formsfx-core/src/main/java/com/dlsc/formsfx/model/structure/BooleanField.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class BooleanField extends DataField<BooleanProperty, Boolean, BooleanFie
4343
* The property that is used to store the latest persisted
4444
* value of the field.
4545
*/
46-
BooleanField(SimpleBooleanProperty valueProperty, SimpleBooleanProperty persistentValueProperty) {
46+
protected BooleanField(SimpleBooleanProperty valueProperty, SimpleBooleanProperty persistentValueProperty) {
4747
super(valueProperty, persistentValueProperty);
4848

4949
valueTransformer = Boolean::parseBoolean;

formsfx-core/src/main/java/com/dlsc/formsfx/model/structure/DataField.java

+13-13
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
* @author Sacha Schmid
4444
* @author Rinesch Murugathas
4545
*/
46-
public class DataField<P extends Property, V, F extends Field> extends Field<F> {
46+
public abstract class DataField<P extends Property, V, F extends Field> extends Field<F> {
4747

4848
/**
4949
* Every field tracks its value in multiple ways.
@@ -57,35 +57,35 @@ public class DataField<P extends Property, V, F extends Field> extends Field<F>
5757
* is the responsibility of the form creator to persist the field values
5858
* at the correct time.
5959
*/
60-
final P value;
61-
private final P persistentValue;
62-
final StringProperty userInput = new SimpleStringProperty("");
60+
protected final P value;
61+
protected final P persistentValue;
62+
protected final StringProperty userInput = new SimpleStringProperty("");
6363

6464
/**
6565
* Every field contains a list of validators. The validators are limited to
6666
* the ones that correspond to the field's type.
6767
*/
68-
private final List<Validator<V>> validators = new ArrayList<>();
68+
protected final List<Validator<V>> validators = new ArrayList<>();
6969

7070
/**
7171
* The value transformer is responsible for transforming the user input
7272
* string to the specific type of the field's value.
7373
*/
74-
ValueTransformer<V> valueTransformer;
74+
protected ValueTransformer<V> valueTransformer;
7575

7676
/**
7777
* The format error is displayed when the value transformation fails.
7878
*
7979
* This property is translatable if a {@link TranslationService} is set on
8080
* the containing form.
8181
*/
82-
private final StringProperty formatErrorKey = new SimpleStringProperty("");
83-
private final StringProperty formatError = new SimpleStringProperty("");
82+
protected final StringProperty formatErrorKey = new SimpleStringProperty("");
83+
protected final StringProperty formatError = new SimpleStringProperty("");
8484

8585
/**
8686
* This listener updates the field when the external binding changes.
8787
*/
88-
private final InvalidationListener externalBindingListener = (observable) -> userInput.setValue(((P) observable).getValue().toString());
88+
protected final InvalidationListener externalBindingListener = (observable) -> userInput.setValue(((P) observable).getValue().toString());
8989

9090
/**
9191
* Internal constructor for the {@code DataField} class. To create new
@@ -103,7 +103,7 @@ public class DataField<P extends Property, V, F extends Field> extends Field<F>
103103
* The property that is used to store the latest persisted
104104
* value of the field.
105105
*/
106-
DataField(P valueProperty, P persistentValueProperty) {
106+
protected DataField(P valueProperty, P persistentValueProperty) {
107107
value = valueProperty;
108108
persistentValue = persistentValueProperty;
109109

@@ -256,7 +256,7 @@ public void setBindingMode(BindingMode newValue) {
256256
* Stores the field's current value in its persistent value. This stores
257257
* the user's changes in the model.
258258
*/
259-
void persist() {
259+
public void persist() {
260260
if (!isValid()) {
261261
return;
262262
}
@@ -268,7 +268,7 @@ void persist() {
268268
* Sets the field's current value to its persistent value, thus resetting
269269
* any changes made by the user.
270270
*/
271-
void reset() {
271+
public void reset() {
272272
if (!hasChanged()) {
273273
return;
274274
}
@@ -295,7 +295,7 @@ protected boolean validateRequired(String newValue) {
295295
*
296296
* @return Returns whether the user input is a valid value or not.
297297
*/
298-
boolean validate() {
298+
public boolean validate() {
299299
String newValue = userInput.getValue();
300300

301301
if (!validateRequired(newValue)) {

formsfx-core/src/main/java/com/dlsc/formsfx/model/structure/DoubleField.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class DoubleField extends DataField<DoubleProperty, Double, DoubleField>
4343
* The property that is used to store the latest persisted
4444
* value of the field.
4545
*/
46-
DoubleField(SimpleDoubleProperty valueProperty, SimpleDoubleProperty persistentValueProperty) {
46+
protected DoubleField(SimpleDoubleProperty valueProperty, SimpleDoubleProperty persistentValueProperty) {
4747
super(valueProperty, persistentValueProperty);
4848

4949
valueTransformer = Double::parseDouble;

formsfx-core/src/main/java/com/dlsc/formsfx/model/structure/Field.java

+26-26
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ public abstract class Field<F extends Field> {
6767
* This property is translatable if a {@link TranslationService} is set on
6868
* the containing form.
6969
*/
70-
private final StringProperty label = new SimpleStringProperty("");
71-
private final StringProperty labelKey = new SimpleStringProperty("");
70+
protected final StringProperty label = new SimpleStringProperty("");
71+
protected final StringProperty labelKey = new SimpleStringProperty("");
7272

7373
/**
7474
* The tooltip is an extension of the label. It contains additional
@@ -77,8 +77,8 @@ public abstract class Field<F extends Field> {
7777
* This property is translatable if a {@link TranslationService} is set on
7878
* the containing form.
7979
*/
80-
private final StringProperty tooltip = new SimpleStringProperty("");
81-
private final StringProperty tooltipKey = new SimpleStringProperty("");
80+
protected final StringProperty tooltip = new SimpleStringProperty("");
81+
protected final StringProperty tooltipKey = new SimpleStringProperty("");
8282

8383
/**
8484
* The placeholder is only visible in an empty field. It provides a hint to
@@ -87,31 +87,31 @@ public abstract class Field<F extends Field> {
8787
* This property is translatable if a {@link TranslationService} is set on
8888
* the containing form.
8989
*/
90-
private final StringProperty placeholder = new SimpleStringProperty("");
91-
private final StringProperty placeholderKey = new SimpleStringProperty("");
90+
protected final StringProperty placeholder = new SimpleStringProperty("");
91+
protected final StringProperty placeholderKey = new SimpleStringProperty("");
9292

9393
/**
9494
* Every field can be marked as {@code required} and {@code editable}. These
9595
* properties can change the field's behaviour.
9696
*/
97-
final StringProperty requiredErrorKey = new SimpleStringProperty("");
98-
final StringProperty requiredError = new SimpleStringProperty("");
99-
private final BooleanProperty required = new SimpleBooleanProperty(false);
100-
private final BooleanProperty editable = new SimpleBooleanProperty(true);
97+
protected final StringProperty requiredErrorKey = new SimpleStringProperty("");
98+
protected final StringProperty requiredError = new SimpleStringProperty("");
99+
protected final BooleanProperty required = new SimpleBooleanProperty(false);
100+
protected final BooleanProperty editable = new SimpleBooleanProperty(true);
101101

102102
/**
103103
* The field's current state is represented by the value properties, as
104104
* well as by the {@code valid} and {@code changed} flags.
105105
*/
106-
final BooleanProperty valid = new SimpleBooleanProperty(true);
107-
final BooleanProperty changed = new SimpleBooleanProperty(false);
106+
protected final BooleanProperty valid = new SimpleBooleanProperty(true);
107+
protected final BooleanProperty changed = new SimpleBooleanProperty(false);
108108

109109
/**
110110
* Fields can be styled using CSS through ID or class hooks.
111111
*/
112-
private final StringProperty id = new SimpleStringProperty(UUID.randomUUID().toString());
113-
private final ListProperty<String> styleClass = new SimpleListProperty<>(FXCollections.observableArrayList());
114-
private final IntegerProperty span = new SimpleIntegerProperty(12);
112+
protected final StringProperty id = new SimpleStringProperty(UUID.randomUUID().toString());
113+
protected final ListProperty<String> styleClass = new SimpleListProperty<>(FXCollections.observableArrayList());
114+
protected final IntegerProperty span = new SimpleIntegerProperty(12);
115115

116116
/**
117117
* The results of the field's validation is stored in this property. After
@@ -120,8 +120,8 @@ public abstract class Field<F extends Field> {
120120
* This property is translatable if a {@link TranslationService} is set on
121121
* the containing form.
122122
*/
123-
final ListProperty<String> errorMessages = new SimpleListProperty<>(FXCollections.observableArrayList());
124-
final ListProperty<String> errorMessageKeys = new SimpleListProperty<>(FXCollections.observableArrayList());
123+
protected final ListProperty<String> errorMessages = new SimpleListProperty<>(FXCollections.observableArrayList());
124+
protected final ListProperty<String> errorMessageKeys = new SimpleListProperty<>(FXCollections.observableArrayList());
125125

126126
/**
127127
* Additional descriptions for the field's label and value are stored in these properties.
@@ -141,15 +141,15 @@ public abstract class Field<F extends Field> {
141141
* The translation service is passed down from the containing section. It
142142
* is used to translate all translatable values of the field.
143143
*/
144-
TranslationService translationService;
144+
protected TranslationService translationService;
145145

146-
SimpleControl<F> renderer;
146+
protected SimpleControl<F> renderer;
147147

148148
/**
149149
* With the continuous binding mode, values are always directly persisted
150150
* upon any changes.
151151
*/
152-
final InvalidationListener bindingModeListener = (observable) -> {
152+
protected final InvalidationListener bindingModeListener = (observable) -> {
153153
if (validate()) {
154154
persist();
155155
}
@@ -166,7 +166,7 @@ public abstract class Field<F extends Field> {
166166
* @see Field::ofMultiSelectionType
167167
* @see Field::ofSingleSelectionType
168168
*/
169-
Field() {
169+
protected Field() {
170170

171171
// Whenever one of the translatable fields' keys change, update the
172172
// displayed value based on the new translation.
@@ -669,11 +669,11 @@ public F span(ColSpan newValue) {
669669
* @param newValue
670670
* The new binding mode for the current field.
671671
*/
672-
abstract void setBindingMode(BindingMode newValue);
672+
public abstract void setBindingMode(BindingMode newValue);
673673

674-
abstract void persist();
674+
public abstract void persist();
675675

676-
abstract void reset();
676+
public abstract void reset();
677677

678678
/**
679679
* This internal method is called by the containing section when a new
@@ -710,7 +710,7 @@ public void translate(TranslationService newValue) {
710710
* @param keyProperty
711711
* The internal property that holds the translation key.
712712
*/
713-
void updateElement(StringProperty displayProperty, StringProperty keyProperty) {
713+
protected void updateElement(StringProperty displayProperty, StringProperty keyProperty) {
714714

715715
// If the key has not yet been set that means that the translation
716716
// service was added for the first time. We can simply set the key
@@ -760,7 +760,7 @@ void updateElement(Node node, StringProperty keyProperty) {
760760
*
761761
* @return Returns whether the user input is a valid value or not.
762762
*/
763-
abstract boolean validate();
763+
protected abstract boolean validate();
764764

765765
public String getPlaceholder() {
766766
return placeholder.get();

formsfx-core/src/main/java/com/dlsc/formsfx/model/structure/Form.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,23 @@
4444
*/
4545
public class Form {
4646

47-
private final List<Group> groups = new ArrayList<>();
47+
protected final List<Group> groups = new ArrayList<>();
4848

4949
/**
5050
* The title acts as a description for the form.
5151
*
5252
* This property is translatable if a {@link TranslationService} is set.
5353
*/
54-
private final StringProperty title = new SimpleStringProperty("");
55-
private final StringProperty titleKey = new SimpleStringProperty("");
54+
protected final StringProperty title = new SimpleStringProperty("");
55+
protected final StringProperty titleKey = new SimpleStringProperty("");
5656

5757
/**
5858
* The form acts as a proxy for its contained sections' {@code changed}
5959
* and {@code valid} properties.
6060
*/
61-
private final BooleanProperty valid = new SimpleBooleanProperty(true);
62-
private final BooleanProperty changed = new SimpleBooleanProperty(false);
63-
private final BooleanProperty persistable = new SimpleBooleanProperty(false);
61+
protected final BooleanProperty valid = new SimpleBooleanProperty(true);
62+
protected final BooleanProperty changed = new SimpleBooleanProperty(false);
63+
protected final BooleanProperty persistable = new SimpleBooleanProperty(false);
6464

6565
/**
6666
* A form can optionally have a translation service. This service is used to
@@ -69,8 +69,8 @@ public class Form {
6969
*
7070
* @see TranslationService
7171
*/
72-
private final ObjectProperty<TranslationService> translationService = new SimpleObjectProperty<>();
73-
private final Runnable localeChangeListener = this::translate;
72+
protected final ObjectProperty<TranslationService> translationService = new SimpleObjectProperty<>();
73+
protected final Runnable localeChangeListener = this::translate;
7474

7575
/**
7676
* Internal constructor for the {@code Form} class. To create new
@@ -184,7 +184,7 @@ public Form binding(BindingMode newValue) {
184184
*
185185
* @see Group::translate
186186
*/
187-
private void translate() {
187+
protected void translate() {
188188
TranslationService tr = translationService.get();
189189

190190
if (!isI18N()) {
@@ -230,7 +230,7 @@ public void reset() {
230230
* Sets this form's {@code changed} property based on its contained
231231
* groups' changed properties.
232232
*/
233-
private void setChangedProperty() {
233+
protected void setChangedProperty() {
234234
changed.setValue(groups.stream().anyMatch(Group::hasChanged));
235235
setPersistableProperty();
236236
}
@@ -239,7 +239,7 @@ private void setChangedProperty() {
239239
* Sets this form's {@code valid} property based on its contained groups'
240240
* changed properties.
241241
*/
242-
private void setValidProperty() {
242+
protected void setValidProperty() {
243243
valid.setValue(groups.stream().allMatch(Group::isValid));
244244
setPersistableProperty();
245245
}
@@ -248,7 +248,7 @@ private void setValidProperty() {
248248
* Sets this form's {@code persistable} property based on its contained
249249
* groups' persistable properties.
250250
*/
251-
private void setPersistableProperty() {
251+
protected void setPersistableProperty() {
252252
persistable.setValue(groups.stream().anyMatch(Group::hasChanged) && groups.stream().allMatch(Group::isValid));
253253
}
254254

formsfx-core/src/main/java/com/dlsc/formsfx/model/structure/Group.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public class Group {
4545
* The group acts as a proxy for its contained fields' {@code changed}
4646
* and {@code valid} properties.
4747
*/
48-
private final BooleanProperty valid = new SimpleBooleanProperty(true);
49-
private final BooleanProperty changed = new SimpleBooleanProperty(false);
48+
protected final BooleanProperty valid = new SimpleBooleanProperty(true);
49+
protected final BooleanProperty changed = new SimpleBooleanProperty(false);
5050

5151
/**
5252
* The translation service is passed down from the containing form. It
@@ -103,7 +103,7 @@ public static Group of(Field... fields) {
103103
* @param newValue
104104
* The new service to use for translating translatable values.
105105
*/
106-
void translate(TranslationService newValue) {
106+
protected void translate(TranslationService newValue) {
107107
translationService = newValue;
108108

109109
if (!isI18N()) {
@@ -117,7 +117,7 @@ void translate(TranslationService newValue) {
117117
* Persists the values for all contained fields.
118118
* @see Field::persist
119119
*/
120-
void persist() {
120+
public void persist() {
121121
if (!isValid()) {
122122
return;
123123
}
@@ -129,7 +129,7 @@ void persist() {
129129
* Resets the values for all contained fields.
130130
* @see Field::reset
131131
*/
132-
void reset() {
132+
public void reset() {
133133
if (!hasChanged()) {
134134
return;
135135
}
@@ -141,15 +141,15 @@ void reset() {
141141
* Sets this group's {@code changed} property based on its contained
142142
* fields' changed properties.
143143
*/
144-
private void setChangedProperty() {
144+
protected void setChangedProperty() {
145145
changed.setValue(fields.stream().anyMatch(Field::hasChanged));
146146
}
147147

148148
/**
149149
* Sets this group's {@code valid} property based on its contained fields'
150150
* changed properties.
151151
*/
152-
private void setValidProperty() {
152+
protected void setValidProperty() {
153153
valid.setValue(fields.stream().allMatch(Field::isValid));
154154
}
155155

formsfx-core/src/main/java/com/dlsc/formsfx/model/structure/IntegerField.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class IntegerField extends DataField<IntegerProperty, Integer, IntegerFie
4444
* The property that is used to store the latest persisted
4545
* value of the field.
4646
*/
47-
IntegerField(SimpleIntegerProperty valueProperty, SimpleIntegerProperty persistentValueProperty) {
47+
protected IntegerField(SimpleIntegerProperty valueProperty, SimpleIntegerProperty persistentValueProperty) {
4848
super(valueProperty, persistentValueProperty);
4949

5050
valueTransformer = Integer::parseInt;

0 commit comments

Comments
 (0)