Skip to content

Commit

Permalink
Release 0.14.1 ready (#411)
Browse files Browse the repository at this point in the history
* #400 #406 #408 #402 #403 #404 done (#405)

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: vaadin-miki <vaadin-miki@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Sep 15, 2022
1 parent 45464dd commit 2922a06
Show file tree
Hide file tree
Showing 20 changed files with 430 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This is the relevant dependency:
<dependency>
<groupId>org.vaadin.miki</groupId>
<artifactId>superfields</artifactId>
<version>0.14.0</version>
<version>0.14.1</version>
</dependency>
```

Expand Down
6 changes: 3 additions & 3 deletions demo-v23/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<parent>
<artifactId>superfields-parent</artifactId>
<groupId>org.vaadin.miki</groupId>
<version>0.14.0</version>
<version>0.14.1</version>
</parent>

<artifactId>superfields-demo-v23</artifactId>
<version>0.14.0</version>
<version>0.14.1</version>
<name>V23+ demo app for SuperFields</name>
<description>Showcase application for V23+ and SuperFields.</description>
<packaging>war</packaging>
Expand All @@ -23,7 +23,7 @@
<dependency>
<groupId>org.vaadin.miki</groupId>
<artifactId>superfields</artifactId>
<version>0.14.0</version>
<version>0.14.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.vaadin.miki.demo.ContentBuilder;
import org.vaadin.miki.demo.Order;
import org.vaadin.miki.demo.data.Book;
import org.vaadin.miki.demo.data.Format;
import org.vaadin.miki.demo.data.Person;
import org.vaadin.miki.superfields.object.ObjectField;

Expand All @@ -16,9 +17,9 @@ public class ObjectFieldBuilder implements ContentBuilder<ObjectField<Book>> {
@Override
public void buildContent(ObjectField<Book> component, Consumer<Component[]> callback) {
final ComboBox<Book> values = new ComboBox<>("Select a value: ",
Book.of("1984", 1948, "English", Person.of("George Orwell", LocalDate.of(1903, 6, 25), false)),
Book.of("The God Delusion", 2006, "English", Person.of("Richard Dawkins", LocalDate.of(1941, 3, 26), false)),
Book.of("Dolina Issy", 1955, "polski", Person.of("Czesław Miłosz", LocalDate.of(1911, 6, 30), true))
Book.of("1984", 1948, "English", Format.SOFT_COVER, Person.of("George Orwell", LocalDate.of(1903, 6, 25), false)),
Book.of("The God Delusion", 2006, "English", Format.HARD_COVER, Person.of("Richard Dawkins", LocalDate.of(1941, 3, 26), false)),
Book.of("Dolina Issy", 1955, "polski", null, Person.of("Czesław Miłosz", LocalDate.of(1911, 6, 30), true))
);
values.addValueChangeListener(event -> component.setValue(event.getValue()));
values.setAllowCustomValue(false);
Expand Down
20 changes: 17 additions & 3 deletions demo-v23/src/main/java/org/vaadin/miki/demo/data/Book.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
*/
public class Book {

public static Book of(String title, int firstPublished, String language, Person... authors) {
public static Book of(String title, int firstPublished, String language, Format ownedFormat, Person... authors) {
final Book result = new Book();
result.setAuthors(Arrays.asList(authors));
result.setTitle(title);
result.setFirstPublished(firstPublished);
result.setLanguage(language);
result.setOwnedFormat(ownedFormat);
return result;
}

Expand All @@ -40,6 +41,10 @@ public static Book of(String title, int firstPublished, String language, Person.
@FieldCaption("Original language")
private String language;

@FieldOrder(6)
@FieldGroup("publication")
private Format ownedFormat;

@BigField
@FieldOrder(5)
private String summary = "";
Expand Down Expand Up @@ -84,17 +89,25 @@ public void setSummary(String summary) {
this.summary = summary;
}

public Format getOwnedFormat() {
return ownedFormat;
}

public void setOwnedFormat(Format ownedFormat) {
this.ownedFormat = ownedFormat;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Book book = (Book) o;
return getFirstPublished() == book.getFirstPublished() && Objects.equals(getTitle(), book.getTitle()) && Objects.equals(getAuthors(), book.getAuthors()) && Objects.equals(getLanguage(), book.getLanguage()) && Objects.equals(getSummary(), book.getSummary());
return getFirstPublished() == book.getFirstPublished() && Objects.equals(getTitle(), book.getTitle()) && Objects.equals(getAuthors(), book.getAuthors()) && Objects.equals(getLanguage(), book.getLanguage()) && getOwnedFormat() == book.getOwnedFormat() && Objects.equals(getSummary(), book.getSummary());
}

@Override
public int hashCode() {
return Objects.hash(getTitle(), getAuthors(), getFirstPublished(), getLanguage(), getSummary());
return Objects.hash(getTitle(), getAuthors(), getFirstPublished(), getLanguage(), getOwnedFormat(), getSummary());
}

@Override
Expand All @@ -104,6 +117,7 @@ public String toString() {
", authors=" + authors +
", firstPublished=" + firstPublished +
", language='" + language + '\'' +
", ownedFormat=" + ownedFormat +
", summary='" + summary + '\'' +
'}';
}
Expand Down
7 changes: 7 additions & 0 deletions demo-v23/src/main/java/org/vaadin/miki/demo/data/Format.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.vaadin.miki.demo.data;

public enum Format {

HARD_COVER, SOFT_COVER, AUDIO_BOOK

}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.vaadin.miki</groupId>
<artifactId>superfields-parent</artifactId>
<version>0.14.0</version>
<version>0.14.1</version>
<modules>
<module>superfields</module>
<module>demo-v23</module>
Expand Down
6 changes: 5 additions & 1 deletion superfields/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ A `CustomField<Object>`. It checks the type of the value passed to it and attemp

A `CustomField<T>` capable of building components and matching them with object's properties. Once configured it is basically an automated form generator. This component is highly configurable and details on how to use it are present in [the project's wiki](https://github.com/vaadin-miki/super-fields/wiki).

In most common cases one would use `ObjectFieldFactory` to create and configure `ObjectField`, and then annotate data model class with the additional information. Please consult the demo application or the tests (`ObjectFieldTest` and `NestedObjectFieldTest`) for details.
In most common cases one would use `ObjectFieldFactory` to create and configure `ObjectField`, and then annotate data model class with the additional information. Please consult the demo application or the tests (`ObjectFieldTest`, `NestedObjectFieldTest` and `EnumObjectTest`) for details. Also please note that [`ObjectFieldFactory` will become a separate library](https://github.com/vaadin-miki/super-fields/issues/401) at some point in the future.

### `SuperCheckbox`

It is known that [`Checkbox` does not support read-only mode](https://github.com/vaadin/web-components/issues/688). This component exists as a workaround and binds `enabled` and `readOnly` as one: setting the checkbox to read-only will disable it.

## Select fields

Expand Down
2 changes: 1 addition & 1 deletion superfields/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<artifactId>superfields</artifactId>
<name>SuperFields</name>
<description>Code for various V14+ fields and other components.</description>
<version>0.14.0</version>
<version>0.14.1</version>

<properties>
<maven.compiler.source>11</maven.compiler.source>
Expand Down
10 changes: 10 additions & 0 deletions superfields/release-notes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# 0.14.1 - SuperCheckbox and bugfixes
## New features and enhancements
* \#400 - [ObjectField should support enums and other values presentable with ComboBox](https://github.com/vaadin-miki/super-fields/issues/400)
* \#404 - [Checkbox that actually can be made read-only](https://github.com/vaadin-miki/super-fields/issues/404)
## Changes to API
* \#406 - [ObjectFieldFactory should return interface types](https://github.com/vaadin-miki/super-fields/issues/406)
## Bug fixes
* \#402 - [HasReadOnly disables layouts](https://github.com/vaadin-miki/super-fields/issues/402)
* \#403 - [Component added to read-only layout is not read-only](https://github.com/vaadin-miki/super-fields/issues/403)
* \#406 - [ObjectFieldFactory should return interface types](https://github.com/vaadin-miki/super-fields/issues/406)
# 0.14.0 - ObjectField
## New features and enhancements
* \#380 - [ObjectField](https://github.com/vaadin-miki/super-fields/issues/380)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.vaadin.miki.markers;

import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.HasComponents;
import com.vaadin.flow.component.HasEnabled;
import com.vaadin.flow.component.HasValue;

Expand Down Expand Up @@ -29,15 +30,15 @@ public interface HasReadOnly {
* @param readOnly New state.
* @param component Component.
* If it implements {@link HasReadOnly} or {@link HasValue}, the state will be updated.
* If it implements {@link HasEnabled}, read-only means disabled.
* If it implements {@link HasEnabled} and does not implement {@link HasComponents}, read-only means disabled.
* Otherwise, nothing happens.
*/
static void setReadOnly(boolean readOnly, Component component) {
if(component instanceof HasReadOnly)
((HasReadOnly) component).setReadOnly(readOnly);
else if(component instanceof HasValue)
((HasValue<?, ?>) component).setReadOnly(readOnly);
else if(component instanceof HasEnabled)
else if(component instanceof HasEnabled && !(component instanceof HasComponents)) // HasComponents implements HasEnabled, that caused #402
((HasEnabled) component).setEnabled(!readOnly);
// delegate to children
component.getChildren().forEach(child -> setReadOnly(readOnly, child));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.vaadin.miki.superfields.checkbox;

import com.vaadin.flow.component.checkbox.Checkbox;

/**
* A regular {@link Checkbox} that has its read-only state synchronised with enabledness.
* This exists purely as a workaround for <a href="https://github.com/vaadin/web-components/issues/688">a known issue of Vaadin</a>.
*
* @author miki
* @since 2022-09-14
*/
@SuppressWarnings("squid:S110") // no way around big number of parent classes
public class SuperCheckbox extends Checkbox {

@Override
public void setReadOnly(boolean readOnly) {
super.setReadOnly(readOnly);
super.setEnabled(!readOnly);
}

@Override
public void setEnabled(boolean enabled) {
super.setReadOnly(!enabled);
super.setEnabled(enabled);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
/**
* A wrapper for a typical header-body-footer layout that exposes header and footer, and delegates all
* methods from {@link HasComponents} to the body. In other words, it allows using predefined layouts.
*
* This component is {@link Iterable} over the {@link Component}s contained in the body.
* Similarly, {@link #getComponents()} ()} returns {@link Component}s things put in the body.
*
Expand Down Expand Up @@ -64,13 +63,21 @@ protected R initContent() {
return this.root;
}

private void ensureReadOnly(Component... components) {
if(this.isReadOnly())
for (Component component : components)
HasReadOnly.setReadOnly(true, component);
}

@Override
public void add(Component... components) {
this.ensureReadOnly(components);
this.body.add(components);
}

@Override
public void addComponentAtIndex(int index, Component component) {
this.ensureReadOnly(component);
this.body.addComponentAtIndex(index, component);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class MetadataProperties {
public static final String COMPONENT_BUILDER_METADATA_PROPERTY = "build-with";
public static final String COMPONENT_STYLE_METADATA_PROPERTY = "component-style-name";
public static final String COMPONENT_ID_METADATA_PROPERTY = "component-id";
public static final String AVAILABLE_ITEMS_METADATA_PROPERTY = "available-items";

private MetadataProperties() {
// no instances allowed
Expand Down
Loading

0 comments on commit 2922a06

Please sign in to comment.