diff --git a/pom.xml b/pom.xml
index f374a0d..34add2e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
com.flowingcode.vaadin.addons
badge-list-addon
- 1.0.2-SNAPSHOT
+ 1.1.0-SNAPSHOT
Badge List Add-on
Badge List Add-on for Vaadin Flow
https://www.flowingcode.com/en/open-source/
diff --git a/src/main/java/com/flowingcode/vaadin/addons/badgelist/Badge.java b/src/main/java/com/flowingcode/vaadin/addons/badgelist/Badge.java
index 8994385..a9fea38 100644
--- a/src/main/java/com/flowingcode/vaadin/addons/badgelist/Badge.java
+++ b/src/main/java/com/flowingcode/vaadin/addons/badgelist/Badge.java
@@ -2,7 +2,7 @@
* #%L
* Badge List Add-on
* %%
- * Copyright (C) 2023 Flowing Code
+ * Copyright (C) 2023 - 2024 Flowing Code
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/src/main/java/com/flowingcode/vaadin/addons/badgelist/BadgeList.java b/src/main/java/com/flowingcode/vaadin/addons/badgelist/BadgeList.java
index f64330f..eca46dc 100644
--- a/src/main/java/com/flowingcode/vaadin/addons/badgelist/BadgeList.java
+++ b/src/main/java/com/flowingcode/vaadin/addons/badgelist/BadgeList.java
@@ -2,7 +2,7 @@
* #%L
* Badge List Add-on
* %%
- * Copyright (C) 2023 Flowing Code
+ * Copyright (C) 2023 - 2024 Flowing Code
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,6 +39,11 @@
public class BadgeList extends Component implements HasTheme, HasSize {
private List badges = new ArrayList<>();
+
+ /**
+ * Creates a new instance of BadgeList.
+ */
+ public BadgeList() {}
/**
* Creates a new instance of BadgeList with the supplied list of {@link Badge badges}.
@@ -46,15 +51,31 @@ public class BadgeList extends Component implements HasTheme, HasSize {
* @param badges list of badges
*/
public BadgeList(List badges) {
+ this.setBadges(badges);
+ }
+
+ /**
+ * Sets a list of {@link Badge badges} to the BadgeList component.
+ *
+ * @param badges the list of badges to add
+ */
+ public void setBadges(List badges) {
+ this.clearBadges();
this.badges = badges;
this.addBadges();
}
private void addBadges() {
- this.badges.forEach(
- badge -> {
- badge.getElement().setAttribute("slot", "badges");
- this.getElement().appendChild(badge.getElement());
- });
+ this.badges.forEach(badge -> {
+ badge.getElement().setAttribute("slot", "badges");
+ this.getElement().appendChild(badge.getElement());
+ });
+ }
+
+ private void clearBadges() {
+ this.badges.forEach(badge -> {
+ badge.getElement().removeAttribute("slot");
+ badge.removeFromParent();
+ });
}
}
diff --git a/src/main/resources/META-INF/resources/frontend/src/fc-badge-list.ts b/src/main/resources/META-INF/resources/frontend/src/fc-badge-list.ts
index 1498b5e..928218a 100644
--- a/src/main/resources/META-INF/resources/frontend/src/fc-badge-list.ts
+++ b/src/main/resources/META-INF/resources/frontend/src/fc-badge-list.ts
@@ -2,7 +2,7 @@
* #%L
* Badge List Add-on
* %%
- * Copyright (C) 2023 Flowing Code
+ * Copyright (C) 2023 - 2024 Flowing Code
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/src/test/java/com/flowingcode/vaadin/addons/DemoLayout.java b/src/test/java/com/flowingcode/vaadin/addons/DemoLayout.java
index 2c94686..69007a9 100644
--- a/src/test/java/com/flowingcode/vaadin/addons/DemoLayout.java
+++ b/src/test/java/com/flowingcode/vaadin/addons/DemoLayout.java
@@ -2,7 +2,7 @@
* #%L
* Badge List Add-on
* %%
- * Copyright (C) 2023 Flowing Code
+ * Copyright (C) 2023 - 2024 Flowing Code
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/src/test/java/com/flowingcode/vaadin/addons/badgelist/BadgeListDemo.java b/src/test/java/com/flowingcode/vaadin/addons/badgelist/BadgeListDemo.java
index 2553510..8d6aac0 100644
--- a/src/test/java/com/flowingcode/vaadin/addons/badgelist/BadgeListDemo.java
+++ b/src/test/java/com/flowingcode/vaadin/addons/badgelist/BadgeListDemo.java
@@ -2,7 +2,7 @@
* #%L
* Badge List Add-on
* %%
- * Copyright (C) 2023 Flowing Code
+ * Copyright (C) 2023 - 2024 Flowing Code
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/src/test/java/com/flowingcode/vaadin/addons/badgelist/BadgeListDemoView.java b/src/test/java/com/flowingcode/vaadin/addons/badgelist/BadgeListDemoView.java
index ccf2be0..1560058 100644
--- a/src/test/java/com/flowingcode/vaadin/addons/badgelist/BadgeListDemoView.java
+++ b/src/test/java/com/flowingcode/vaadin/addons/badgelist/BadgeListDemoView.java
@@ -2,7 +2,7 @@
* #%L
* Badge List Add-on
* %%
- * Copyright (C) 2023 Flowing Code
+ * Copyright (C) 2023 - 2024 Flowing Code
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,6 +38,7 @@ public class BadgeListDemoView extends TabbedDemo {
public BadgeListDemoView() {
addDemo(BadgeListDemo.class);
addDemo(StyledBadgesDemo.class);
+ addDemo(ReadOnlyBinderDemo.class);
setSizeFull();
}
}
diff --git a/src/test/java/com/flowingcode/vaadin/addons/badgelist/BaseBadgeListDemo.java b/src/test/java/com/flowingcode/vaadin/addons/badgelist/BaseBadgeListDemo.java
index 6fdc0dc..941f975 100644
--- a/src/test/java/com/flowingcode/vaadin/addons/badgelist/BaseBadgeListDemo.java
+++ b/src/test/java/com/flowingcode/vaadin/addons/badgelist/BaseBadgeListDemo.java
@@ -2,7 +2,7 @@
* #%L
* Badge List Add-on
* %%
- * Copyright (C) 2023 Flowing Code
+ * Copyright (C) 2023 - 2024 Flowing Code
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/src/test/java/com/flowingcode/vaadin/addons/badgelist/DemoView.java b/src/test/java/com/flowingcode/vaadin/addons/badgelist/DemoView.java
index 1a4bdf6..c1b812d 100644
--- a/src/test/java/com/flowingcode/vaadin/addons/badgelist/DemoView.java
+++ b/src/test/java/com/flowingcode/vaadin/addons/badgelist/DemoView.java
@@ -2,7 +2,7 @@
* #%L
* Badge List Add-on
* %%
- * Copyright (C) 2023 Flowing Code
+ * Copyright (C) 2023 - 2024 Flowing Code
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/src/test/java/com/flowingcode/vaadin/addons/badgelist/Person.java b/src/test/java/com/flowingcode/vaadin/addons/badgelist/Person.java
index 298e81c..a20332f 100644
--- a/src/test/java/com/flowingcode/vaadin/addons/badgelist/Person.java
+++ b/src/test/java/com/flowingcode/vaadin/addons/badgelist/Person.java
@@ -2,7 +2,7 @@
* #%L
* Badge List Add-on
* %%
- * Copyright (C) 2023 Flowing Code
+ * Copyright (C) 2023 - 2024 Flowing Code
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,16 +20,15 @@
package com.flowingcode.vaadin.addons.badgelist;
import java.util.List;
-import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
-import lombok.experimental.FieldDefaults;
+import lombok.Setter;
@Getter
+@Setter
@AllArgsConstructor
-@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
@EqualsAndHashCode
@Builder
public class Person {
diff --git a/src/test/java/com/flowingcode/vaadin/addons/badgelist/ReadOnlyBinderDemo.java b/src/test/java/com/flowingcode/vaadin/addons/badgelist/ReadOnlyBinderDemo.java
new file mode 100644
index 0000000..8d0c4d2
--- /dev/null
+++ b/src/test/java/com/flowingcode/vaadin/addons/badgelist/ReadOnlyBinderDemo.java
@@ -0,0 +1,119 @@
+/*-
+ * #%L
+ * Badge List Add-on
+ * %%
+ * Copyright (C) 2023 - 2024 Flowing Code
+ * %%
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * #L%
+ */
+package com.flowingcode.vaadin.addons.badgelist;
+
+import com.flowingcode.vaadin.addons.demo.DemoSource;
+import com.vaadin.flow.component.button.Button;
+import com.vaadin.flow.component.combobox.MultiSelectComboBox;
+import com.vaadin.flow.component.html.Div;
+import com.vaadin.flow.component.html.Span;
+import com.vaadin.flow.component.orderedlayout.FlexComponent.JustifyContentMode;
+import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
+import com.vaadin.flow.component.orderedlayout.VerticalLayout;
+import com.vaadin.flow.component.textfield.TextField;
+import com.vaadin.flow.data.binder.Binder;
+import com.vaadin.flow.data.binder.ReadOnlyHasValue;
+import com.vaadin.flow.router.PageTitle;
+import com.vaadin.flow.router.Route;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+@DemoSource
+@PageTitle("Read Only Binder Demo")
+@SuppressWarnings("serial")
+@Route(value = "badge-list/readonly", layout = BadgeListDemoView.class)
+public class ReadOnlyBinderDemo extends BaseBadgeListDemo {
+
+ private TextField firstName = new TextField("First Name");
+ private TextField lastName = new TextField("Last Name");
+ private MultiSelectComboBox rolesComboBox =
+ new MultiSelectComboBox("Select Roles");
+ private BadgeList rolesBadgeList = new BadgeList();
+ private ReadOnlyHasValue> readonlyBadgeList;
+ private Div rolesBadgeListDiv = new Div();
+ private Button editModeButton = new Button("Edit Mode");
+ private Button readOnlyModeButton = new Button("Read Only Mode");
+ private Binder binder;
+
+ public ReadOnlyBinderDemo() {
+
+ Person person = TestData.singlePerson();
+
+ List roles =
+ IntStream.rangeClosed(1, 12).mapToObj(i -> "ROLE" + i).collect(Collectors.toList());
+ rolesComboBox.setItems(roles);
+
+ rolesBadgeList = new BadgeList();
+ readonlyBadgeList = new ReadOnlyHasValue>(rolesBadgeList::setBadges);
+
+ binder = new Binder<>();
+ binder.bind(firstName, Person::getFirstName, Person::setFirstName);
+ binder.bind(lastName, Person::getLastName, Person::setLastName);
+ readOnlyMode();
+ binder.setBean(person);
+
+ editModeButton.addClickListener(e -> editMode());
+ readOnlyModeButton.addClickListener(e -> readOnlyMode());
+
+ HorizontalLayout buttonsLayout = new HorizontalLayout();
+ buttonsLayout.add(editModeButton, readOnlyModeButton);
+ buttonsLayout.setMargin(true);
+ buttonsLayout.setJustifyContentMode(JustifyContentMode.END);
+
+ VerticalLayout layout = new VerticalLayout();
+ Span span = new Span("Roles");
+ span.addClassName("readonly-badge-list-label");
+ rolesBadgeListDiv.add(span);
+ rolesBadgeListDiv.setWidth("450px");
+ rolesBadgeListDiv.add(rolesBadgeList);
+ layout.add(firstName, lastName, rolesComboBox, rolesBadgeListDiv);
+
+ add(layout, buttonsLayout);
+ }
+
+ private void editMode() {
+ editModeButton.setEnabled(false);
+ readOnlyModeButton.setEnabled(true);
+ rolesBadgeListDiv.setVisible(false);
+ binder.removeBinding(readonlyBadgeList);
+ rolesComboBox.setVisible(true);
+ binder.bind(rolesComboBox, person -> new HashSet(person.getRoles()),
+ (person, roles) -> {
+ person.setRoles(new ArrayList(roles));
+ });
+ binder.setReadOnly(false);
+ }
+
+ private void readOnlyMode() {
+ readOnlyModeButton.setEnabled(false);
+ editModeButton.setEnabled(true);
+ rolesComboBox.setVisible(false);
+ binder.removeBinding(rolesComboBox);
+ rolesBadgeListDiv.setVisible(true);
+ binder.forField(readonlyBadgeList).bindReadOnly(person -> {
+ return person.getRoles().stream()
+ .collect(Collectors.mapping(role -> new Badge(role), Collectors.toList()));
+ });
+ binder.setReadOnly(true);
+ }
+}
diff --git a/src/test/java/com/flowingcode/vaadin/addons/badgelist/StyledBadgesDemo.java b/src/test/java/com/flowingcode/vaadin/addons/badgelist/StyledBadgesDemo.java
index ae87e13..78e9617 100644
--- a/src/test/java/com/flowingcode/vaadin/addons/badgelist/StyledBadgesDemo.java
+++ b/src/test/java/com/flowingcode/vaadin/addons/badgelist/StyledBadgesDemo.java
@@ -2,7 +2,7 @@
* #%L
* Badge List Add-on
* %%
- * Copyright (C) 2023 Flowing Code
+ * Copyright (C) 2023 - 2024 Flowing Code
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/src/test/java/com/flowingcode/vaadin/addons/badgelist/TestData.java b/src/test/java/com/flowingcode/vaadin/addons/badgelist/TestData.java
index ba61d3a..dd90c93 100644
--- a/src/test/java/com/flowingcode/vaadin/addons/badgelist/TestData.java
+++ b/src/test/java/com/flowingcode/vaadin/addons/badgelist/TestData.java
@@ -2,7 +2,7 @@
* #%L
* Badge List Add-on
* %%
- * Copyright (C) 2023 Flowing Code
+ * Copyright (C) 2023 - 2024 Flowing Code
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,6 +44,10 @@ private static synchronized Person newPerson() {
public static List initializeData() {
return Stream.generate(TestData::newPerson).limit(8).collect(Collectors.toList());
}
+
+ public static Person singlePerson() {
+ return newPerson();
+ }
private static List generateRoles() {
List roles = new ArrayList<>();
diff --git a/src/test/java/com/flowingcode/vaadin/addons/badgelist/it/AbstractViewTest.java b/src/test/java/com/flowingcode/vaadin/addons/badgelist/it/AbstractViewTest.java
index 1b393a0..ec65558 100644
--- a/src/test/java/com/flowingcode/vaadin/addons/badgelist/it/AbstractViewTest.java
+++ b/src/test/java/com/flowingcode/vaadin/addons/badgelist/it/AbstractViewTest.java
@@ -2,7 +2,7 @@
* #%L
* Badge List Add-on
* %%
- * Copyright (C) 2023 Flowing Code
+ * Copyright (C) 2023 - 2024 Flowing Code
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/src/test/java/com/flowingcode/vaadin/addons/badgelist/it/ViewIT.java b/src/test/java/com/flowingcode/vaadin/addons/badgelist/it/ViewIT.java
index f09671d..40b525b 100644
--- a/src/test/java/com/flowingcode/vaadin/addons/badgelist/it/ViewIT.java
+++ b/src/test/java/com/flowingcode/vaadin/addons/badgelist/it/ViewIT.java
@@ -2,7 +2,7 @@
* #%L
* Badge List Add-on
* %%
- * Copyright (C) 2023 Flowing Code
+ * Copyright (C) 2023 - 2024 Flowing Code
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/src/test/java/com/flowingcode/vaadin/addons/badgelist/test/SerializationTest.java b/src/test/java/com/flowingcode/vaadin/addons/badgelist/test/SerializationTest.java
index 33a0a03..9808a4d 100644
--- a/src/test/java/com/flowingcode/vaadin/addons/badgelist/test/SerializationTest.java
+++ b/src/test/java/com/flowingcode/vaadin/addons/badgelist/test/SerializationTest.java
@@ -2,7 +2,7 @@
* #%L
* Badge List Add-on
* %%
- * Copyright (C) 2023 Flowing Code
+ * Copyright (C) 2023 - 2024 Flowing Code
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/src/test/resources/META-INF/frontend/styles/badge-list-demo-styles.css b/src/test/resources/META-INF/frontend/styles/badge-list-demo-styles.css
index 710c4d2..3474075 100644
--- a/src/test/resources/META-INF/frontend/styles/badge-list-demo-styles.css
+++ b/src/test/resources/META-INF/frontend/styles/badge-list-demo-styles.css
@@ -2,7 +2,7 @@
* #%L
* Badge List Add-on
* %%
- * Copyright (C) 2023 Flowing Code
+ * Copyright (C) 2023 - 2024 Flowing Code
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,3 +36,9 @@ fc-badge-list[class="styled-badges-second-example"]::part(overflow-badge), .cust
border: 1px green dashed;
border-radius: 0;
}
+
+.readonly-badge-list-label {
+ color: var(--lumo-secondary-text-color);
+ font-weight: 500;
+ font-size: var(--lumo-font-size-s);
+}