diff --git a/.github/ISSUE_TEMPLATE/bug-report.yml b/.github/ISSUE_TEMPLATE/bug-report.yml
index f804cc1..858f327 100644
--- a/.github/ISSUE_TEMPLATE/bug-report.yml
+++ b/.github/ISSUE_TEMPLATE/bug-report.yml
@@ -1,5 +1,5 @@
name: Bug Report
-description: Please report issues related to TEMPLATE_ADDON here.
+description: Please report issues related to LocaleComboBox add-on here.
body:
- type: textarea
id: problem-description
diff --git a/.github/ISSUE_TEMPLATE/feature-request.yml b/.github/ISSUE_TEMPLATE/feature-request.yml
index 4d37c3b..8019ae9 100644
--- a/.github/ISSUE_TEMPLATE/feature-request.yml
+++ b/.github/ISSUE_TEMPLATE/feature-request.yml
@@ -1,5 +1,5 @@
name: Feature Request
-description: Please add feature suggestions related to TEMPLATE_ADDON here.
+description: Please add feature suggestions related to LocaleComboBox add-on here.
body:
- type: textarea
id: feature-proposal
diff --git a/LICENSE b/LICENSE
index 5756052..7f8889b 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,7 +1,3 @@
-All parts are licensed under Apache License v2.0. See the license text below.
-
------------------------------------------------------------------------------
-
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
diff --git a/README.md b/README.md
index 44743af..013b602 100644
--- a/README.md
+++ b/README.md
@@ -1,23 +1,25 @@
-[](https://vaadin.com/directory/component/template-addon)
-[](https://vaadin.com/directory/component/template-addon)
-[](https://jenkins.flowingcode.com/job/template-addon)
-[](https://mvnrepository.com/artifact/com.flowingcode.vaadin.addons/template-addon)
+[](https://vaadin.com/directory/component/locale-combo-box-add-on)
+[](https://vaadin.com/directory/component/locale-combo-box-add-on)
+[](https://jenkins.flowingcode.com/job/LocaleComboBox-addon)
+[](https://mvnrepository.com/artifact/com.flowingcode.vaadin.addons/locale-combo-box-addon)
-# Template Add-on
+# LocaleComboBox Add-on
-This is a template project for building new Vaadin 24 add-ons
+[Vaadin ComboBox](https://vaadin.com/docs/latest/components/combo-box) extension that allows to choose between multiple locales.
## Features
-* List the features of your add-on in here
+* Displays the locale name alongside its corresponding country flag
+* Allows to specify which locales are available for selection
+* Provides an option to change the current session locale
## Online demo
-[Online demo here](http://addonsv24.flowingcode.com/template)
+[Online demo here](http://addonsv24.flowingcode.com/locale-combo-box)
## Download release
-[Available in Vaadin Directory](https://vaadin.com/directory/component/template-addon)
+[Available in Vaadin Directory](https://vaadin.com/directory/component/locale-combo-box-add-on)
### Maven install
@@ -26,20 +28,12 @@ Add the following dependencies in your pom.xml file:
```xml
com.flowingcode.vaadin.addons
- template-addon
+ locale-combo-box-addon
X.Y.Z
```
-
-```xml
-
- vaadin-addons
- https://maven.vaadin.com/vaadin-addons
-
-```
-
-For SNAPSHOT versions see [here](https://maven.flowingcode.com/snapshots/).
+Release versions are available from Maven Central repository. For SNAPSHOT versions see [here](https://maven.flowingcode.com/snapshots/).
## Building and running demo
@@ -50,7 +44,7 @@ To see the demo, navigate to http://localhost:8080/
## Release notes
-See [here](https://github.com/FlowingCode/TemplateAddon/releases)
+See [here](https://github.com/FlowingCode/LocaleComboBox/releases)
## Issue tracking
@@ -75,20 +69,18 @@ Then, follow these steps for creating a contribution:
This add-on is distributed under Apache License 2.0. For license terms, see LICENSE.txt.
-TEMPLATE_ADDON is written by Flowing Code S.A.
+LocaleComboBox Add-on is written by Flowing Code S.A.
# Developer Guide
-## Getting started
-
-Add your code samples in this section
+
## Special configuration when using Spring
-By default, Vaadin Flow only includes ```com/vaadin/flow/component``` to be always scanned for UI components and views. For this reason, the add-on might need to be whitelisted in order to display correctly.
+By default, Vaadin Flow only includes ```com/vaadin/flow/component``` to be always scanned for UI components and views. For this reason, the add-on might need to be allowed in order to display correctly.
-To do so, just add ```com.flowingcode``` to the ```vaadin.whitelisted-packages``` property in ```src/main/resources/application.properties```, like:
+To do so, just add ```com.flowingcode``` to the ```vaadin.allowed-packages``` property in ```src/main/resources/application.properties```, like:
-```vaadin.whitelisted-packages = com.vaadin,org.vaadin,dev.hilla,com.flowingcode```
+```vaadin.allowed-packages = com.vaadin,org.vaadin,dev.hilla,com.flowingcode```
-More information on Spring whitelisted configuration [here](https://vaadin.com/docs/latest/integrations/spring/configuration/#configure-the-scanning-of-packages).
+More information on Spring scanning configuration [here](https://vaadin.com/docs/latest/integrations/spring/configuration/#configure-the-scanning-of-packages).
diff --git a/pom.xml b/pom.xml
index 431cb5a..eb5a802 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,10 +5,10 @@
4.0.0
com.flowingcode.vaadin.addons
- template-addon
+ locale-combo-box-addon
1.0.0-SNAPSHOT
- Template Add-on
- Template Add-on for Vaadin Flow
+ LocaleComboBox
+ LocaleComboBox Add-on for Vaadin Flow
https://www.flowingcode.com/en/open-source/
@@ -39,9 +39,9 @@
- https://github.com/FlowingCode/AddonStarter24
- scm:git:git://github.com/FlowingCode/AddonStarter24.git
- scm:git:ssh://git@github.com:/FlowingCode/AddonStarter24.git
+ https://github.com/FlowingCode/LocaleComboBox
+ scm:git:git://github.com/FlowingCode/LocaleComboBox.git
+ scm:git:ssh://git@github.com:/FlowingCode/LocaleComboBox.git
master
@@ -260,7 +260,6 @@
src/test/resources/META-INF/resources
- src/main/resources/META-INF/resources
diff --git a/src/main/java/com/flowingcode/vaadin/addons/localecombobox/LocaleComboBox.java b/src/main/java/com/flowingcode/vaadin/addons/localecombobox/LocaleComboBox.java
new file mode 100644
index 0000000..014fd97
--- /dev/null
+++ b/src/main/java/com/flowingcode/vaadin/addons/localecombobox/LocaleComboBox.java
@@ -0,0 +1,83 @@
+/*-
+ * #%L
+ * LocaleComboBox Add-on
+ * %%
+ * Copyright (C) 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.localecombobox;
+
+import com.vaadin.flow.component.combobox.ComboBox;
+import com.vaadin.flow.component.dependency.CssImport;
+import com.vaadin.flow.component.dependency.NpmPackage;
+import com.vaadin.flow.component.html.Span;
+import com.vaadin.flow.data.renderer.LitRenderer;
+import java.util.Arrays;
+import java.util.Locale;
+
+/**
+ * Vaadin ComboBox extension that allows to choose between multiple locales.
+ *
+ * @author Tomas Peiretti / Flowing Code
+ */
+@SuppressWarnings("serial")
+@NpmPackage(value = "flag-icons", version = "7.2.3")
+@CssImport("flag-icons/css/flag-icons.min.css")
+@CssImport("styles/locale-combo-box.css")
+public class LocaleComboBox extends ComboBox {
+
+ private static final String ITEM_LAYOUT_CLASS_NAME = "fc-locale-combo-box-item-layout";
+ private static final String ITEM_FLAG_CLASS_NAME = "fc-locale-combo-box-item-flag";
+
+ /**
+ * Creates a new instance of LocaleComboBox with all the installed locales.
+ */
+ public LocaleComboBox() {
+ setItemLabelGenerator(Locale::getDisplayName);
+ setRenderer(getLocaleRenderer());
+ addValueChangeListener(this::onValueChange);
+ setItems(
+ Arrays.stream(Locale.getAvailableLocales()).filter(loc -> loc.getCountry().length() == 2)
+ .sorted((l1, l2) -> l1.getDisplayName().compareTo(l2.getDisplayName())).toList());
+ }
+
+ private LitRenderer getLocaleRenderer() {
+ return LitRenderer
+ .of(
+ """
+
+
+ ${item.displayName}
+ """)
+ .withProperty("layoutClass", loc -> ITEM_LAYOUT_CLASS_NAME)
+ .withProperty("flagClass", loc -> ITEM_FLAG_CLASS_NAME)
+ .withProperty("countryCode", loc -> loc.getCountry().toLowerCase())
+ .withProperty("countryName", loc -> loc.getDisplayCountry())
+ .withProperty("displayName", loc -> loc.getDisplayName());
+ }
+
+ private void onValueChange(ComponentValueChangeEvent, Locale> event) {
+ Locale newValue = event.getValue();
+ if (newValue == null) {
+ setPrefixComponent(null);
+ return;
+ }
+ Span flagIcon = new Span();
+ flagIcon.addClassNames("fi", "fi-" + newValue.getCountry().toLowerCase());
+ setPrefixComponent(flagIcon);
+ }
+
+}
diff --git a/src/main/resources/META-INF/frontend/styles/locale-combo-box.css b/src/main/resources/META-INF/frontend/styles/locale-combo-box.css
new file mode 100644
index 0000000..18be333
--- /dev/null
+++ b/src/main/resources/META-INF/frontend/styles/locale-combo-box.css
@@ -0,0 +1,28 @@
+/*-
+ * #%L
+ * LocaleComboBox Add-on
+ * %%
+ * Copyright (C) 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%
+ */
+vaadin-horizontal-layout.fc-locale-combo-box-item-layout {
+ align-items: center;
+ justify-content: start;
+ gap: 0.5em;
+}
+
+span.fc-locale-combo-box-item-flag {
+ flex-shrink: 0;
+}
\ No newline at end of file
diff --git a/src/main/resources/META-INF/frontend/styles/static_addon_styles b/src/main/resources/META-INF/frontend/styles/static_addon_styles
deleted file mode 100644
index c2a6ed1..0000000
--- a/src/main/resources/META-INF/frontend/styles/static_addon_styles
+++ /dev/null
@@ -1 +0,0 @@
-Place add-on shareable styles in this folder
\ No newline at end of file
diff --git a/src/main/resources/META-INF/resources/static_addon_resources b/src/main/resources/META-INF/resources/static_addon_resources
deleted file mode 100644
index 70832cc..0000000
--- a/src/main/resources/META-INF/resources/static_addon_resources
+++ /dev/null
@@ -1 +0,0 @@
-Place static add-on resources in this folder
\ No newline at end of file
diff --git a/src/test/java/com/flowingcode/vaadin/addons/DemoLayout.java b/src/test/java/com/flowingcode/vaadin/addons/DemoLayout.java
index b84172e..7cde676 100644
--- a/src/test/java/com/flowingcode/vaadin/addons/DemoLayout.java
+++ b/src/test/java/com/flowingcode/vaadin/addons/DemoLayout.java
@@ -1,6 +1,6 @@
/*-
* #%L
- * Template Add-on
+ * LocaleComboBox Add-on
* %%
* Copyright (C) 2024 Flowing Code
* %%
diff --git a/src/test/java/com/flowingcode/vaadin/addons/template/DemoView.java b/src/test/java/com/flowingcode/vaadin/addons/localecombobox/DemoView.java
similarity index 88%
rename from src/test/java/com/flowingcode/vaadin/addons/template/DemoView.java
rename to src/test/java/com/flowingcode/vaadin/addons/localecombobox/DemoView.java
index a600c9d..0aec225 100644
--- a/src/test/java/com/flowingcode/vaadin/addons/template/DemoView.java
+++ b/src/test/java/com/flowingcode/vaadin/addons/localecombobox/DemoView.java
@@ -1,6 +1,6 @@
/*-
* #%L
- * Template Add-on
+ * LocaleComboBox Add-on
* %%
* Copyright (C) 2024 Flowing Code
* %%
@@ -18,7 +18,7 @@
* #L%
*/
-package com.flowingcode.vaadin.addons.template;
+package com.flowingcode.vaadin.addons.localecombobox;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.router.BeforeEnterEvent;
@@ -31,6 +31,6 @@ public class DemoView extends VerticalLayout implements BeforeEnterObserver {
@Override
public void beforeEnter(BeforeEnterEvent event) {
- event.forwardTo(TemplateDemoView.class);
+ event.forwardTo(LocaleComboBoxDemoView.class);
}
}
diff --git a/src/main/java/com/flowingcode/vaadin/addons/template/TemplateAddon.java b/src/test/java/com/flowingcode/vaadin/addons/localecombobox/LocaleComboBoxDemo.java
similarity index 61%
rename from src/main/java/com/flowingcode/vaadin/addons/template/TemplateAddon.java
rename to src/test/java/com/flowingcode/vaadin/addons/localecombobox/LocaleComboBoxDemo.java
index c9ec694..a0c67d4 100644
--- a/src/main/java/com/flowingcode/vaadin/addons/template/TemplateAddon.java
+++ b/src/test/java/com/flowingcode/vaadin/addons/localecombobox/LocaleComboBoxDemo.java
@@ -1,6 +1,6 @@
/*-
* #%L
- * Template Add-on
+ * LocaleComboBox Add-on
* %%
* Copyright (C) 2024 Flowing Code
* %%
@@ -18,15 +18,20 @@
* #L%
*/
-package com.flowingcode.vaadin.addons.template;
+package com.flowingcode.vaadin.addons.localecombobox;
-import com.vaadin.flow.component.Tag;
-import com.vaadin.flow.component.dependency.JsModule;
-import com.vaadin.flow.component.dependency.NpmPackage;
+import com.flowingcode.vaadin.addons.demo.DemoSource;
import com.vaadin.flow.component.html.Div;
+import com.vaadin.flow.router.PageTitle;
+import com.vaadin.flow.router.Route;
+@DemoSource
+@PageTitle("LocaleComboBox Add-on Demo")
@SuppressWarnings("serial")
-@NpmPackage(value = "@polymer/paper-input", version = "3.2.1")
-@JsModule("@polymer/paper-input/paper-input.js")
-@Tag("paper-input")
-public class TemplateAddon extends Div {}
+@Route(value = "demo", layout = LocaleComboBoxDemoView.class)
+public class LocaleComboBoxDemo extends Div {
+
+ public LocaleComboBoxDemo() {
+ add(new LocaleComboBox());
+ }
+}
diff --git a/src/test/java/com/flowingcode/vaadin/addons/template/TemplateDemoView.java b/src/test/java/com/flowingcode/vaadin/addons/localecombobox/LocaleComboBoxDemoView.java
similarity index 75%
rename from src/test/java/com/flowingcode/vaadin/addons/template/TemplateDemoView.java
rename to src/test/java/com/flowingcode/vaadin/addons/localecombobox/LocaleComboBoxDemoView.java
index 1954535..c27cd70 100644
--- a/src/test/java/com/flowingcode/vaadin/addons/template/TemplateDemoView.java
+++ b/src/test/java/com/flowingcode/vaadin/addons/localecombobox/LocaleComboBoxDemoView.java
@@ -1,6 +1,6 @@
/*-
* #%L
- * Template Add-on
+ * LocaleComboBox Add-on
* %%
* Copyright (C) 2024 Flowing Code
* %%
@@ -17,7 +17,7 @@
* limitations under the License.
* #L%
*/
-package com.flowingcode.vaadin.addons.template;
+package com.flowingcode.vaadin.addons.localecombobox;
import com.flowingcode.vaadin.addons.DemoLayout;
import com.flowingcode.vaadin.addons.GithubLink;
@@ -27,12 +27,12 @@
@SuppressWarnings("serial")
@ParentLayout(DemoLayout.class)
-@Route("template")
-@GithubLink("https://github.com/FlowingCode/AddonStarter24")
-public class TemplateDemoView extends TabbedDemo {
+@Route("locale-combo-box")
+@GithubLink("https://github.com/FlowingCode/LocaleComboBox")
+public class LocaleComboBoxDemoView extends TabbedDemo {
- public TemplateDemoView() {
- addDemo(TemplateDemo.class);
+ public LocaleComboBoxDemoView() {
+ addDemo(LocaleComboBoxDemo.class);
setSizeFull();
}
}
diff --git a/src/test/java/com/flowingcode/vaadin/addons/template/it/AbstractViewTest.java b/src/test/java/com/flowingcode/vaadin/addons/localecombobox/it/AbstractViewTest.java
similarity index 97%
rename from src/test/java/com/flowingcode/vaadin/addons/template/it/AbstractViewTest.java
rename to src/test/java/com/flowingcode/vaadin/addons/localecombobox/it/AbstractViewTest.java
index 1f7749b..42b0483 100644
--- a/src/test/java/com/flowingcode/vaadin/addons/template/it/AbstractViewTest.java
+++ b/src/test/java/com/flowingcode/vaadin/addons/localecombobox/it/AbstractViewTest.java
@@ -1,6 +1,6 @@
/*-
* #%L
- * Template Add-on
+ * LocaleComboBox Add-on
* %%
* Copyright (C) 2024 Flowing Code
* %%
@@ -18,7 +18,7 @@
* #L%
*/
-package com.flowingcode.vaadin.addons.template.it;
+package com.flowingcode.vaadin.addons.localecombobox.it;
import com.vaadin.testbench.ScreenshotOnFailureRule;
import com.vaadin.testbench.TestBench;
diff --git a/src/test/java/com/flowingcode/vaadin/addons/template/it/ViewIT.java b/src/test/java/com/flowingcode/vaadin/addons/localecombobox/it/ViewIT.java
similarity index 96%
rename from src/test/java/com/flowingcode/vaadin/addons/template/it/ViewIT.java
rename to src/test/java/com/flowingcode/vaadin/addons/localecombobox/it/ViewIT.java
index 0e5f164..e8f1aba 100644
--- a/src/test/java/com/flowingcode/vaadin/addons/template/it/ViewIT.java
+++ b/src/test/java/com/flowingcode/vaadin/addons/localecombobox/it/ViewIT.java
@@ -1,6 +1,6 @@
/*-
* #%L
- * Template Add-on
+ * LocaleComboBox Add-on
* %%
* Copyright (C) 2024 Flowing Code
* %%
@@ -18,7 +18,7 @@
* #L%
*/
-package com.flowingcode.vaadin.addons.template.it;
+package com.flowingcode.vaadin.addons.localecombobox.it;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
diff --git a/src/test/java/com/flowingcode/vaadin/addons/template/test/SerializationTest.java b/src/test/java/com/flowingcode/vaadin/addons/localecombobox/test/SerializationTest.java
similarity index 88%
rename from src/test/java/com/flowingcode/vaadin/addons/template/test/SerializationTest.java
rename to src/test/java/com/flowingcode/vaadin/addons/localecombobox/test/SerializationTest.java
index 1ee78c3..13d1a0b 100644
--- a/src/test/java/com/flowingcode/vaadin/addons/template/test/SerializationTest.java
+++ b/src/test/java/com/flowingcode/vaadin/addons/localecombobox/test/SerializationTest.java
@@ -1,6 +1,6 @@
/*-
* #%L
- * Template Add-on
+ * LocaleComboBox Add-on
* %%
* Copyright (C) 2024 Flowing Code
* %%
@@ -17,9 +17,9 @@
* limitations under the License.
* #L%
*/
-package com.flowingcode.vaadin.addons.template.test;
+package com.flowingcode.vaadin.addons.localecombobox.test;
-import com.flowingcode.vaadin.addons.template.TemplateAddon;
+import com.flowingcode.vaadin.addons.localecombobox.LocaleComboBox;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -44,7 +44,7 @@ private void testSerializationOf(Object obj) throws IOException, ClassNotFoundEx
@Test
public void testSerialization() throws ClassNotFoundException, IOException {
try {
- testSerializationOf(new TemplateAddon());
+ testSerializationOf(new LocaleComboBox());
} catch (Exception e) {
Assert.fail("Problem while testing serialization: " + e.getMessage());
}
diff --git a/src/test/java/com/flowingcode/vaadin/addons/template/TemplateDemo.java b/src/test/java/com/flowingcode/vaadin/addons/template/TemplateDemo.java
deleted file mode 100644
index 5f6e6ee..0000000
--- a/src/test/java/com/flowingcode/vaadin/addons/template/TemplateDemo.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.flowingcode.vaadin.addons.template;
-
-import com.flowingcode.vaadin.addons.demo.DemoSource;
-import com.vaadin.flow.component.html.Div;
-import com.vaadin.flow.router.PageTitle;
-import com.vaadin.flow.router.Route;
-
-@DemoSource
-@PageTitle("Template Add-on Demo")
-@SuppressWarnings("serial")
-@Route(value = "demo", layout = TemplateDemoView.class)
-public class TemplateDemo extends Div {
-
- public TemplateDemo() {
- add(new TemplateAddon());
- }
-}