Skip to content

Commit

Permalink
Merge pull request #28 from aalmiray/extension-points
Browse files Browse the repository at this point in the history
Extension points
  • Loading branch information
dlemmermann committed Aug 10, 2018
2 parents d846829 + bace4e2 commit 6b8b522
Show file tree
Hide file tree
Showing 27 changed files with 134 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class BooleanField extends DataField<BooleanProperty, Boolean, BooleanFie
* The property that is used to store the latest persisted
* value of the field.
*/
BooleanField(SimpleBooleanProperty valueProperty, SimpleBooleanProperty persistentValueProperty) {
protected BooleanField(SimpleBooleanProperty valueProperty, SimpleBooleanProperty persistentValueProperty) {
super(valueProperty, persistentValueProperty);

valueTransformer = Boolean::parseBoolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
* @author Sacha Schmid
* @author Rinesch Murugathas
*/
public class DataField<P extends Property, V, F extends Field> extends Field<F> {
public abstract class DataField<P extends Property, V, F extends Field> extends Field<F> {

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

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

/**
* The value transformer is responsible for transforming the user input
* string to the specific type of the field's value.
*/
ValueTransformer<V> valueTransformer;
protected ValueTransformer<V> valueTransformer;

/**
* The format error is displayed when the value transformation fails.
*
* This property is translatable if a {@link TranslationService} is set on
* the containing form.
*/
private final StringProperty formatErrorKey = new SimpleStringProperty("");
private final StringProperty formatError = new SimpleStringProperty("");
protected final StringProperty formatErrorKey = new SimpleStringProperty("");
protected final StringProperty formatError = new SimpleStringProperty("");

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

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

Expand Down Expand Up @@ -256,7 +256,7 @@ public void setBindingMode(BindingMode newValue) {
* Stores the field's current value in its persistent value. This stores
* the user's changes in the model.
*/
void persist() {
public void persist() {
if (!isValid()) {
return;
}
Expand All @@ -268,7 +268,7 @@ void persist() {
* Sets the field's current value to its persistent value, thus resetting
* any changes made by the user.
*/
void reset() {
public void reset() {
if (!hasChanged()) {
return;
}
Expand All @@ -295,7 +295,7 @@ protected boolean validateRequired(String newValue) {
*
* @return Returns whether the user input is a valid value or not.
*/
boolean validate() {
public boolean validate() {
String newValue = userInput.getValue();

if (!validateRequired(newValue)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class DoubleField extends DataField<DoubleProperty, Double, DoubleField>
* The property that is used to store the latest persisted
* value of the field.
*/
DoubleField(SimpleDoubleProperty valueProperty, SimpleDoubleProperty persistentValueProperty) {
protected DoubleField(SimpleDoubleProperty valueProperty, SimpleDoubleProperty persistentValueProperty) {
super(valueProperty, persistentValueProperty);

valueTransformer = Double::parseDouble;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public abstract class Field<F extends Field> {
* This property is translatable if a {@link TranslationService} is set on
* the containing form.
*/
private final StringProperty label = new SimpleStringProperty("");
private final StringProperty labelKey = new SimpleStringProperty("");
protected final StringProperty label = new SimpleStringProperty("");
protected final StringProperty labelKey = new SimpleStringProperty("");

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

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

/**
* Every field can be marked as {@code required} and {@code editable}. These
* properties can change the field's behaviour.
*/
final StringProperty requiredErrorKey = new SimpleStringProperty("");
final StringProperty requiredError = new SimpleStringProperty("");
private final BooleanProperty required = new SimpleBooleanProperty(false);
private final BooleanProperty editable = new SimpleBooleanProperty(true);
protected final StringProperty requiredErrorKey = new SimpleStringProperty("");
protected final StringProperty requiredError = new SimpleStringProperty("");
protected final BooleanProperty required = new SimpleBooleanProperty(false);
protected final BooleanProperty editable = new SimpleBooleanProperty(true);

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

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

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

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

SimpleControl<F> renderer;
protected SimpleControl<F> renderer;

/**
* With the continuous binding mode, values are always directly persisted
* upon any changes.
*/
final InvalidationListener bindingModeListener = (observable) -> {
protected final InvalidationListener bindingModeListener = (observable) -> {
if (validate()) {
persist();
}
Expand All @@ -166,7 +166,7 @@ public abstract class Field<F extends Field> {
* @see Field::ofMultiSelectionType
* @see Field::ofSingleSelectionType
*/
Field() {
protected Field() {

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

abstract void persist();
public abstract void persist();

abstract void reset();
public abstract void reset();

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

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

public String getPlaceholder() {
return placeholder.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,23 @@
*/
public class Form {

private final List<Group> groups = new ArrayList<>();
protected final List<Group> groups = new ArrayList<>();

/**
* The title acts as a description for the form.
*
* This property is translatable if a {@link TranslationService} is set.
*/
private final StringProperty title = new SimpleStringProperty("");
private final StringProperty titleKey = new SimpleStringProperty("");
protected final StringProperty title = new SimpleStringProperty("");
protected final StringProperty titleKey = new SimpleStringProperty("");

/**
* The form acts as a proxy for its contained sections' {@code changed}
* and {@code valid} properties.
*/
private final BooleanProperty valid = new SimpleBooleanProperty(true);
private final BooleanProperty changed = new SimpleBooleanProperty(false);
private final BooleanProperty persistable = new SimpleBooleanProperty(false);
protected final BooleanProperty valid = new SimpleBooleanProperty(true);
protected final BooleanProperty changed = new SimpleBooleanProperty(false);
protected final BooleanProperty persistable = new SimpleBooleanProperty(false);

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

/**
* Internal constructor for the {@code Form} class. To create new
Expand Down Expand Up @@ -184,7 +184,7 @@ public Form binding(BindingMode newValue) {
*
* @see Group::translate
*/
private void translate() {
protected void translate() {
TranslationService tr = translationService.get();

if (!isI18N()) {
Expand Down Expand Up @@ -230,7 +230,7 @@ public void reset() {
* Sets this form's {@code changed} property based on its contained
* groups' changed properties.
*/
private void setChangedProperty() {
protected void setChangedProperty() {
changed.setValue(groups.stream().anyMatch(Group::hasChanged));
setPersistableProperty();
}
Expand All @@ -239,7 +239,7 @@ private void setChangedProperty() {
* Sets this form's {@code valid} property based on its contained groups'
* changed properties.
*/
private void setValidProperty() {
protected void setValidProperty() {
valid.setValue(groups.stream().allMatch(Group::isValid));
setPersistableProperty();
}
Expand All @@ -248,7 +248,7 @@ private void setValidProperty() {
* Sets this form's {@code persistable} property based on its contained
* groups' persistable properties.
*/
private void setPersistableProperty() {
protected void setPersistableProperty() {
persistable.setValue(groups.stream().anyMatch(Group::hasChanged) && groups.stream().allMatch(Group::isValid));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public class Group {
* The group acts as a proxy for its contained fields' {@code changed}
* and {@code valid} properties.
*/
private final BooleanProperty valid = new SimpleBooleanProperty(true);
private final BooleanProperty changed = new SimpleBooleanProperty(false);
protected final BooleanProperty valid = new SimpleBooleanProperty(true);
protected final BooleanProperty changed = new SimpleBooleanProperty(false);

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

if (!isI18N()) {
Expand All @@ -117,7 +117,7 @@ void translate(TranslationService newValue) {
* Persists the values for all contained fields.
* @see Field::persist
*/
void persist() {
public void persist() {
if (!isValid()) {
return;
}
Expand All @@ -129,7 +129,7 @@ void persist() {
* Resets the values for all contained fields.
* @see Field::reset
*/
void reset() {
public void reset() {
if (!hasChanged()) {
return;
}
Expand All @@ -141,15 +141,15 @@ void reset() {
* Sets this group's {@code changed} property based on its contained
* fields' changed properties.
*/
private void setChangedProperty() {
protected void setChangedProperty() {
changed.setValue(fields.stream().anyMatch(Field::hasChanged));
}

/**
* Sets this group's {@code valid} property based on its contained fields'
* changed properties.
*/
private void setValidProperty() {
protected void setValidProperty() {
valid.setValue(fields.stream().allMatch(Field::isValid));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class IntegerField extends DataField<IntegerProperty, Integer, IntegerFie
* The property that is used to store the latest persisted
* value of the field.
*/
IntegerField(SimpleIntegerProperty valueProperty, SimpleIntegerProperty persistentValueProperty) {
protected IntegerField(SimpleIntegerProperty valueProperty, SimpleIntegerProperty persistentValueProperty) {
super(valueProperty, persistentValueProperty);

valueTransformer = Integer::parseInt;
Expand Down
Loading

0 comments on commit 6b8b522

Please sign in to comment.