Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>com.flowingcode.vaadin.addons</groupId>
<artifactId>twincolgrid</artifactId>
<version>3.0.1-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
<name>TwinColGrid add-on</name>
<description>Dual list component based on Vaadin Grids</description>
<url>https://www.flowingcode.com/en/open-source/</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* TwinColGrid add-on
* %%
* Copyright (C) 2017 - 2022 Flowing Code
* Copyright (C) 2017 - 2025 Flowing Code
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,6 +26,7 @@
import com.vaadin.flow.component.ComponentUtil;
import com.vaadin.flow.component.HasComponents;
import com.vaadin.flow.component.HasSize;
import com.vaadin.flow.component.HasValidation;
import com.vaadin.flow.component.HasValue;
import com.vaadin.flow.component.HasValue.ValueChangeEvent;
import com.vaadin.flow.component.HasValueAndElement;
Expand Down Expand Up @@ -79,7 +80,7 @@
@CssImport(value = "./styles/twin-col-grid-button.css")
@CssImport(value = "./styles/twincol-grid.css")
public class TwinColGrid<T> extends VerticalLayout
implements HasValueAndElement<ValueChangeEvent<Set<T>>, Set<T>>, HasComponents, HasSize {
implements HasValueAndElement<ValueChangeEvent<Set<T>>, Set<T>>, HasComponents, HasSize, HasValidation {

private static final class TwinColModel<T> implements Serializable {
final Grid<T> grid;
Expand Down Expand Up @@ -142,6 +143,8 @@ public enum Orientation {

private Span fakeButtonContainerLabel = new Span();

private Span errorMessageSpan = new Span();

private Orientation orientation = Orientation.HORIZONTAL;

private boolean autoResize = false;
Expand Down Expand Up @@ -184,7 +187,10 @@ public TwinColGrid(@NonNull Grid<T> availableGrid, @NonNull Grid<T> selectionGri

available = new TwinColModel<>(availableGrid, "twincol-grid-available");
selection = new TwinColModel<>(selectionGrid, "twincol-grid-selection");


errorMessageSpan.setClassName("twincol-grid-error-message");
selection.layout.addComponentAtIndex(1, errorMessageSpan);

setClassName("twincol-grid");

setMargin(false);
Expand Down Expand Up @@ -677,6 +683,26 @@ public boolean isRequiredIndicatorVisible() {
return getElement().getAttribute("required") != null;
}

@Override
public void setErrorMessage(String errorMessage) {
errorMessageSpan.setText(errorMessage);
}

@Override
public String getErrorMessage() {
return errorMessageSpan.getText();
}

@Override
public void setInvalid(boolean invalid) {
getElement().setAttribute("invalid", invalid);
}

@Override
public boolean isInvalid() {
return getElement().getAttribute("invalid") != null;
}

@Override
public void setReadOnly(final boolean readOnly) {
getAvailableGrid().setSelectionMode(readOnly ? SelectionMode.NONE : SelectionMode.MULTI);
Expand Down Expand Up @@ -956,4 +982,5 @@ private void updateOrientationOnResize(int width, int height) {
this.withOrientation(Orientation.HORIZONTAL);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* TwinColGrid add-on
* %%
* Copyright (C) 2017 - 2022 Flowing Code
* Copyright (C) 2017 - 2025 Flowing Code
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,7 @@
*/
package com.flowingcode.vaadin.addons.twincolgrid;

import com.vaadin.flow.component.HasValidation;
import com.vaadin.flow.component.HasValue;
import com.vaadin.flow.component.HasValue.ValueChangeEvent;
import com.vaadin.flow.shared.Registration;
Expand All @@ -40,9 +41,9 @@
*/
@SuppressWarnings("serial")
@RequiredArgsConstructor
class TwinColGridListAdapter<T> implements HasValue<ValueChangeEvent<List<T>>, List<T>> {
class TwinColGridListAdapter<T> implements HasValue<ValueChangeEvent<List<T>>, List<T>>, HasValidation {

private interface IDelegate {
private interface IDelegate extends HasValidation {
boolean isEmpty();

void clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* TwinColGrid add-on
* %%
* Copyright (C) 2017 - 2022 Flowing Code
* Copyright (C) 2017 - 2025 Flowing Code
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -44,6 +44,19 @@
color: var(--lumo-error-text-color);
}

.twincol-grid .twincol-grid-selection .twincol-grid-error-message {
display: none;
}

.twincol-grid[invalid] .twincol-grid-selection .twincol-grid-error-message {
font-size: var(--vaadin-input-field-error-font-size, var(--lumo-font-size-xs));
line-height: var(--lumo-line-height-xs);
font-weight: var(--vaadin-input-field-error-font-weight, 400);
color: var(--vaadin-input-field-error-color, var(--lumo-error-text-color));
display: block;
padding-bottom: 4px;
}

.twincol-grid .fake-button-container-label {
font-size: var(--lumo-font-size-s);
margin-bottom: calc(var(--vaadin-button-margin, var(--lumo-space-xs))* -1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* TwinColGrid add-on
* %%
* Copyright (C) 2017 - 2022 Flowing Code
* Copyright (C) 2017 - 2025 Flowing Code
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -58,7 +58,9 @@ public BoundDemo() {
twinColGrid.setCaption("TwinColGrid demo with Binder and row select without checkbox");

final Binder<Library> binder = new Binder<>();
binder.forField(twinColGrid.asList()).asRequired().bind(Library::getBooks, Library::setBooks);
binder.forField(twinColGrid.asList())
.asRequired("You must add at least one book.")
.bind(Library::getBooks, Library::setBooks);
binder.setBean(library);

add(twinColGrid);
Expand Down