-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e345bae
commit e9c283c
Showing
52 changed files
with
1,420 additions
and
383 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
421 changes: 65 additions & 356 deletions
421
demo-v14/src/main/java/org/vaadin/miki/DemoComponentFactory.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
23
demo-v14/src/main/java/org/vaadin/miki/demo/ComponentProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
26
demo-v14/src/main/java/org/vaadin/miki/demo/ContentBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
demo-v14/src/main/java/org/vaadin/miki/demo/NeedsValidatorStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
38
demo-v14/src/main/java/org/vaadin/miki/demo/ValidatorStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
demo-v14/src/main/java/org/vaadin/miki/demo/builders/AbstractSuperNumberFieldBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
demo-v14/src/main/java/org/vaadin/miki/demo/builders/BlurNotifierBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.")}); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
demo-v14/src/main/java/org/vaadin/miki/demo/builders/CanSelectTextBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}); | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
demo-v14/src/main/java/org/vaadin/miki/demo/builders/ComponentObserverBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | ||
}); | ||
} | ||
} |
Oops, something went wrong.