Skip to content

Commit

Permalink
Release 0.9.2 ready (#249)
Browse files Browse the repository at this point in the history
fixed #241 #243 and #245
  • Loading branch information
vaadin-miki authored Nov 20, 2020
1 parent e345bae commit e9c283c
Show file tree
Hide file tree
Showing 52 changed files with 1,420 additions and 383 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ This is the relevant dependency:
<dependency>
<groupId>org.vaadin.miki</groupId>
<artifactId>superfields</artifactId>
<version>0.9.1</version>
<version>0.9.2</version>
</dependency>
```

Expand Down Expand Up @@ -58,7 +58,9 @@ The author of the majority of the code is Miki, but this project would not be po
* Gerald Koch
* Sebastian Kühnau
* Jean-François Lamy
* Erik Lumme
* Simon Martinelli
* Dmitry Nazukin
* Stefan Penndorf
* Stuart Robinson
* Kaspar Scherrer
Expand All @@ -68,3 +70,5 @@ The author of the majority of the code is Miki, but this project would not be po
## Small print

All components are provided "as is", with no warranty or liability. See license for details.

This library is not officially supported or endorsed by Vaadin and is not part of the Vaadin Platform.
12 changes: 8 additions & 4 deletions demo-v14/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.9.1</version>
<version>0.9.2</version>
</parent>

<artifactId>superfields-demo-v14</artifactId>
<version>0.9.1</version>
<version>0.9.2</version>
<name>V14 demo app for SuperFields</name>
<description>Showcase application for V14 and SuperFields.</description>
<packaging>war</packaging>
Expand All @@ -23,7 +23,7 @@
<dependency>
<groupId>org.vaadin.miki</groupId>
<artifactId>superfields</artifactId>
<version>0.9.1</version>
<version>0.9.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
Expand All @@ -38,7 +38,11 @@
<artifactId>slf4j-simple</artifactId>
<version>1.7.30</version>
</dependency>

<dependency>
<groupId>org.atteo.classindex</groupId>
<artifactId>classindex</artifactId>
<version>3.10</version>
</dependency>

<dependency>
<groupId>com.vaadin</groupId>
Expand Down
421 changes: 65 additions & 356 deletions demo-v14/src/main/java/org/vaadin/miki/DemoComponentFactory.java

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion demo-v14/src/main/java/org/vaadin/miki/MainLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public MainLayout() {
public void afterNavigation(AfterNavigationEvent event) {
if(event.getLocation().getPath().isEmpty())
this.navigationTabs.setSelectedIndex(0);
else
else if(!event.getLocation().getPath().equals("binder"))
this.navigationTabs.setSelectedTab(this.tabs.get(event.getLocation().getSegments().get(1)));
}
}
21 changes: 21 additions & 0 deletions demo-v14/src/main/java/org/vaadin/miki/SampleModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.vaadin.miki;

/**
* A generic model to use in validation.
* @param <T> Type of the object to hold.
* @author miki
* @since 2020-11-14
*/
public class SampleModel<T> {

private T value;

public T getValue() {
return value;
}

public void setValue(T value) {
this.value = value;
}

}
23 changes: 23 additions & 0 deletions demo-v14/src/main/java/org/vaadin/miki/demo/ComponentProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.vaadin.miki.demo;

import com.vaadin.flow.component.Component;
import org.atteo.classindex.IndexSubclasses;

/**
* Marker interface for objects that provide an instance of a Vaadin {@link Component}.
* It is assumed that implementations of this interface provide a public, no-arg constructor.
* @param <T> Type of the component to be created.
* @author miki
* @since 2020-11-17
*/
@FunctionalInterface
@IndexSubclasses
public interface ComponentProvider<T extends Component> {

/**
* Builds a fresh instance of a component.
* @return A non-null instance of an object.
*/
T getComponent();

}
26 changes: 26 additions & 0 deletions demo-v14/src/main/java/org/vaadin/miki/demo/ContentBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.vaadin.miki.demo;

import com.vaadin.flow.component.Component;
import org.atteo.classindex.IndexSubclasses;

import java.util.function.Consumer;

/**
* Marker interface for objects that build content for components.
* Implementations of this interface must have a public no-arg constructor.
* @param <T> Type of the object to build content for.
* @author miki
* @since 2020-11-18
*/
@IndexSubclasses
@FunctionalInterface
public interface ContentBuilder<T> {

/**
* Builds content.
* @param component {@link Component} to build content for. Already cast to {@code T} for easier use.
* @param callback Callback to call when content is built.
*/
void buildContent(T component, Consumer<Component[]> callback);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.vaadin.miki.demo;

/**
* Marker interface for an object that needs access to {@link ValidatorStorage}.
* @author miki
* @since 2020-11-18
*/
@FunctionalInterface
public interface NeedsValidatorStorage {

/**
* Sets the {@link ValidatorStorage} associated with this object.
* @param storage Storage. Must not be {@code null}.
*/
void setValidatorStorage(ValidatorStorage storage);

}
19 changes: 19 additions & 0 deletions demo-v14/src/main/java/org/vaadin/miki/demo/Order.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.vaadin.miki.demo;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Defines order in which classes will be sorted.
* @author miki
* @since 2020-11-20
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Order {

int value() default Integer.MAX_VALUE;

}
38 changes: 38 additions & 0 deletions demo-v14/src/main/java/org/vaadin/miki/demo/ValidatorStorage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.vaadin.miki.demo;

import com.vaadin.flow.component.HasValue;
import com.vaadin.flow.data.binder.Validator;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;

/**
* Stores component-specific {@link Validator}s.
* @author miki
* @since 2020-11-18
*/
public class ValidatorStorage {

private final Map<HasValue<?, ?>, Validator<?>> validators = new HashMap<>();

public <V, C extends HasValue<?, V>> void registerValidator(C instance, Validator<V> validator) {
this.validators.put(instance, validator);
}

public <V, C extends HasValue<?, V>> Consumer<Validator<V>> registerValidator(final C instance) {
return validator -> this.validators.put(instance, validator);
}

public boolean isValidatorPresent(HasValue<?, ?> component) {
return this.validators.containsKey(component);
}

@SuppressWarnings("unchecked")
public <V, C extends HasValue<?, V>> Validator<V> getValidator(C instance) {
if(this.isValidatorPresent(instance))
return (Validator<V>)this.validators.get(instance);
else return null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.vaadin.miki.demo.builders;

import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.checkbox.Checkbox;
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.component.textfield.TextFieldVariant;
import org.vaadin.miki.demo.ContentBuilder;
import org.vaadin.miki.demo.Order;
import org.vaadin.miki.superfields.numbers.AbstractSuperNumberField;

import java.util.function.Consumer;

/**
* Builds content for {@link AbstractSuperNumberField}.
* @author miki
* @since 2020-11-19
*/
@Order(30)
@SuppressWarnings("squid:S5411") // no way around boxed values
public class AbstractSuperNumberFieldBuilder implements ContentBuilder<AbstractSuperNumberField<?, ?>> {

@Override
public void buildContent(AbstractSuperNumberField<?, ?> component, Consumer<Component[]> callback) {
final Checkbox autoselect = new Checkbox("Select automatically on focus?");
autoselect.addValueChangeListener(event -> component.setAutoselect(event.getValue()));

final Checkbox separatorHidden = new Checkbox("Hide grouping separator on focus?");
separatorHidden.addValueChangeListener(event -> component.setGroupingSeparatorHiddenOnFocus(event.getValue()));

final Checkbox prefix = new Checkbox("Show prefix component?");
prefix.addValueChangeListener(event -> component.setPrefixComponent(
event.getValue() ? new Span(">") : null
));

final Checkbox suffix = new Checkbox("Show suffix component?");
suffix.addValueChangeListener(event -> component.setSuffixComponent(
event.getValue() ? new Span("€") : null
));

final Checkbox alignRight = new Checkbox("Align text to the right?");
alignRight.addValueChangeListener(event -> {
if(event.getValue())
component.addThemeVariants(TextFieldVariant.LUMO_ALIGN_RIGHT);
else
component.removeThemeVariants(TextFieldVariant.LUMO_ALIGN_RIGHT);
}
);
callback.accept(new Component[]{autoselect, separatorHidden, prefix, suffix, alignRight});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.vaadin.miki.demo.builders;

import com.vaadin.flow.component.BlurNotifier;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.component.notification.Notification;
import org.vaadin.miki.demo.ContentBuilder;
import org.vaadin.miki.demo.Order;

import java.util.function.Consumer;

/**
* Builds content for {@link BlurNotifier}.
* @author miki
* @since 2020-11-19
*/
@Order(130)
public class BlurNotifierBuilder implements ContentBuilder<BlurNotifier<?>> {

@Override
public void buildContent(BlurNotifier<?> component, Consumer<Component[]> callback) {
component.addBlurListener(event ->
Notification.show(String.format(NotificationConstants.BLUR_MESSAGE, component.getClass().getSimpleName()), NotificationConstants.NOTIFICATION_TIME, Notification.Position.BOTTOM_END)
);
callback.accept(new Component[]{new Span("Leave the demo component to see a notification.")});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.vaadin.miki.demo.builders;

import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.checkbox.Checkbox;
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.component.icon.Icon;
import com.vaadin.flow.component.icon.VaadinIcon;
import com.vaadin.flow.component.orderedlayout.FlexComponent;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import org.vaadin.miki.demo.ContentBuilder;
import org.vaadin.miki.demo.Order;
import org.vaadin.miki.events.text.TextSelectionNotifier;
import org.vaadin.miki.markers.CanReceiveSelectionEventsFromClient;
import org.vaadin.miki.markers.CanSelectText;

import java.util.function.Consumer;

/**
* Builds content for {@link CanSelectText}.
* @author miki
* @since 2020-11-18
*/
@Order(10)
public class CanSelectTextBuilder implements ContentBuilder<CanSelectText> {

@Override
public void buildContent(CanSelectText component, Consumer<Component[]> callback) {
final Button selectAll = new Button("Select all", event -> component.selectAll());
final Button selectNone = new Button("Select none", event -> component.selectNone());
final HorizontalLayout layout = new HorizontalLayout(new Span("Type something in the field, then click one of the buttons:"), selectAll, selectNone);
layout.setAlignItems(FlexComponent.Alignment.CENTER);
callback.accept(new Component[]{
layout
});
if(component instanceof CanReceiveSelectionEventsFromClient) {
final Checkbox receiveFromClient = new Checkbox("Allow selection events initiated by keyboard or mouse?",
event -> ((CanReceiveSelectionEventsFromClient) component).setReceivingSelectionEventsFromClient(event.getValue()));
callback.accept(new Component[] {receiveFromClient});
}
if(component instanceof TextSelectionNotifier<?>) {
final Span selection = new Span();
((TextSelectionNotifier<?>) component).addTextSelectionListener(event -> selection.setText(event.getSelectedText()));
Icon icon = VaadinIcon.INFO_CIRCLE.create();
icon.setColor("green");
icon.getElement().setAttribute("title", "When the component does not receive events from the browser, selection events will only be called for server-side initiated actions.");
callback.accept(new Component[]{
new HorizontalLayout(new Span("Most recently selected text: <"), selection, new Span(">"), icon)
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.vaadin.miki.demo.builders;

import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.component.notification.Notification;
import org.vaadin.miki.demo.ContentBuilder;
import org.vaadin.miki.demo.Order;
import org.vaadin.miki.superfields.lazyload.ComponentObserver;

import java.util.function.Consumer;

/**
* Builds content for {@link ComponentObserver}.
* @author miki
* @since 2020-11-19
*/
@Order(100)
public class ComponentObserverBuilder implements ContentBuilder<ComponentObserver> {

@Override
public void buildContent(ComponentObserver component, Consumer<Component[]> callback) {
for(String s: new String[]{"span-one", "span-two", "span-three"}) {
Span span = new Span("This text is observed by the intersection observer. Resize the window to make it disappear and see what happens. It has id of "+s+". ");
span.setId(s);
component.observe(span);
callback.accept(new Component[]{span});
}
component.addComponentObservationListener(event -> {
if(event.isFullyVisible()) {
Notification.show("Component with id " + event.getObservedComponent().getId().orElse("(no id)") + " is now fully visible.");
if(event.getObservedComponent().getId().orElse("").equals("span-two")) {
event.getSource().unobserve(event.getObservedComponent());
Notification.show("Component with id span-two has been unobserved.");
}
}
else if(event.isNotVisible())
Notification.show("Component with id "+event.getObservedComponent().getId().orElse("(no id)")+" is now not visible.");
});
}
}
Loading

0 comments on commit e9c283c

Please sign in to comment.