diff --git a/pom.xml b/pom.xml index 7862eff..2c3cb76 100644 --- a/pom.xml +++ b/pom.xml @@ -3,18 +3,18 @@ 4.0.0 com.flowingcode.vaadin.addons twincolgrid - 3.2.0-SNAPSHOT + 4.0.0-SNAPSHOT TwinColGrid add-on Dual list component based on Vaadin Grids https://www.flowingcode.com/en/open-source/ - 14.11.13 - 1.8 - 1.8 + 24.9.8 + 17 + 17 UTF-8 UTF-8 - 9.4.36.v20210114 + 11.0.26 Flowing Code @@ -128,11 +128,11 @@ test - javax.servlet - servlet-api - 2.5 - provided - + jakarta.servlet + jakarta.servlet-api + 6.0.0 + provided + junit junit @@ -142,7 +142,7 @@ com.flowingcode.vaadin.addons.demo commons-demo - 3.8.0 + 5.0.0 test @@ -156,6 +156,10 @@ apache_v2 false + + main/bundles/** + main/frontend/** + @@ -351,47 +355,6 @@ - - - v23 - - 23.3.5 - 11 - 11 - - - - - v24 - - 17 - 17 - 24.2.6 - 11.0.12 - - - - vaadin-prerelease - https://maven.vaadin.com/vaadin-prereleases - - - - - vaadin-prerelease - https://maven.vaadin.com/vaadin-prereleases - - - - - - jakarta.servlet - jakarta.servlet-api - 6.0.0 - provided - - - - release @@ -416,23 +379,11 @@ 11.0.26 - - com.flowingcode.vaadin.addons.demo - commons-demo - 5.0.0 - test - com.vaadin vaadin-dev true - - jakarta.servlet - jakarta.servlet-api - 6.0.0 - provided - diff --git a/src/main/java/com/flowingcode/vaadin/addons/twincolgrid/CharSequenceUtils.java b/src/main/java/com/flowingcode/vaadin/addons/twincolgrid/CharSequenceUtils.java new file mode 100644 index 0000000..aa24623 --- /dev/null +++ b/src/main/java/com/flowingcode/vaadin/addons/twincolgrid/CharSequenceUtils.java @@ -0,0 +1,101 @@ +/*- + * #%L + * TwinColGrid add-on + * %% + * 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. + * 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.twincolgrid; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * + * https://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. + */ + +import lombok.experimental.UtilityClass; + +@UtilityClass +class CharSequenceUtils { + + /** + * Green implementation of regionMatches. + * + * @param cs the {@link CharSequence} to be processed + * @param ignoreCase whether or not to be case-insensitive + * @param thisStart the index to start on the {@code cs} CharSequence + * @param substring the {@link CharSequence} to be looked for + * @param start the index to start on the {@code substring} CharSequence + * @param length character length of the region + * @return whether the region matched + * @see String#regionMatches(boolean, int, String, int, int) + */ + static boolean regionMatches(final CharSequence cs, final boolean ignoreCase, final int thisStart, + final CharSequence substring, final int start, final int length) { + if (cs instanceof String && substring instanceof String) { + return ((String) cs).regionMatches(ignoreCase, thisStart, (String) substring, start, length); + } + int index1 = thisStart; + int index2 = start; + int tmpLen = length; + + // Extract these first so we detect NPEs the same as the java.lang.String version + final int srcLen = cs.length() - thisStart; + final int otherLen = substring.length() - start; + + // Check for invalid parameters + if (thisStart < 0 || start < 0 || length < 0) { + return false; + } + + // Check that the regions are long enough + if (srcLen < length || otherLen < length) { + return false; + } + + while (tmpLen-- > 0) { + final char c1 = cs.charAt(index1++); + final char c2 = substring.charAt(index2++); + + if (c1 == c2) { + continue; + } + + if (!ignoreCase) { + return false; + } + + // The real same check as in String#regionMatches(boolean, int, String, int, int): + final char u1 = Character.toUpperCase(c1); + final char u2 = Character.toUpperCase(c2); + if (u1 != u2 && Character.toLowerCase(u1) != Character.toLowerCase(u2)) { + return false; + } + } + + return true; + } + +} diff --git a/src/main/java/com/flowingcode/vaadin/addons/twincolgrid/FilterableTwinColumn.java b/src/main/java/com/flowingcode/vaadin/addons/twincolgrid/FilterableTwinColumn.java index 0e002cf..79b66e5 100644 --- a/src/main/java/com/flowingcode/vaadin/addons/twincolgrid/FilterableTwinColumn.java +++ b/src/main/java/com/flowingcode/vaadin/addons/twincolgrid/FilterableTwinColumn.java @@ -1,3 +1,22 @@ +/*- + * #%L + * TwinColGrid add-on + * %% + * 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. + * 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.twincolgrid; import com.vaadin.flow.component.Component; @@ -118,9 +137,9 @@ public FilterableTwinColumn setFooter(Supplier footerComponentSupp } @Override - public FilterableTwinColumn setClassNameGenerator( - SerializableFunction classNameGenerator) { - super.setClassNameGenerator(classNameGenerator); + public FilterableTwinColumn setPartNameGenerator( + SerializableFunction partNameGenerator) { + super.setPartNameGenerator(partNameGenerator); return this; } diff --git a/src/main/java/com/flowingcode/vaadin/addons/twincolgrid/LegacyTwinColGrid.java b/src/main/java/com/flowingcode/vaadin/addons/twincolgrid/LegacyTwinColGrid.java index 2ef114f..0ced0cc 100644 --- a/src/main/java/com/flowingcode/vaadin/addons/twincolgrid/LegacyTwinColGrid.java +++ b/src/main/java/com/flowingcode/vaadin/addons/twincolgrid/LegacyTwinColGrid.java @@ -1,3 +1,22 @@ +/*- + * #%L + * TwinColGrid add-on + * %% + * 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. + * 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.twincolgrid; import com.vaadin.flow.component.ItemLabelGenerator; @@ -11,7 +30,18 @@ import java.util.function.Supplier; import lombok.NonNull; -/** Implementation of {@code TwinColGrid} with deprecated methods from version 2.9.0. */ +/** + * Implementation of {@code TwinColGrid} with deprecated methods from version 2.9.0. + *

+ * This class was introduced in version 3.0.0 to maintain backward compatibility with the API from + * the previous major version. It facilitates migration by hosting methods that were removed or + * changed in the primary implementation. + *

+ * + * @deprecated As of 3.0.0, this class exists only for migration purposes. New projects should use + * {@code TwinColGrid} directly. + * @param the type of items in the grid + */ @SuppressWarnings("serial") @Deprecated public class LegacyTwinColGrid extends TwinColGrid { @@ -71,7 +101,7 @@ public LegacyTwinColGrid(@NonNull Grid availableGrid, @NonNull Grid select * Constructs a new empty TwinColGrid with caption * * @param caption the component caption - * @deprecated Use {@link TwinColGrid#TwinColGrid()} and {{@link #setCaption(String)} + * @deprecated Use {@link TwinColGrid#TwinColGrid()} and {@link #setCaption(String)} */ @Deprecated @SuppressWarnings("unchecked") @@ -148,7 +178,7 @@ public LegacyTwinColGrid( * @param caption the caption to set, can be {@code null} * @param options the options, cannot be {@code null} * @deprecated Use {@link TwinColGrid#TwinColGrid(Collection)} and - * {{@link TwinColGrid#setCaption(String)} + * {@link TwinColGrid#setCaption(String)} */ @Deprecated @SuppressWarnings("unchecked") diff --git a/src/main/java/com/flowingcode/vaadin/addons/twincolgrid/StringUtils.java b/src/main/java/com/flowingcode/vaadin/addons/twincolgrid/StringUtils.java new file mode 100644 index 0000000..a101875 --- /dev/null +++ b/src/main/java/com/flowingcode/vaadin/addons/twincolgrid/StringUtils.java @@ -0,0 +1,57 @@ +/*- + * #%L + * TwinColGrid add-on + * %% + * 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. + * 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.twincolgrid; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * + * https://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. + */ + +import lombok.experimental.UtilityClass; + +@UtilityClass +class StringUtils { + + public static boolean containsIgnoreCase(String str, String searchStr) { + if (str == null || searchStr == null) { + return false; + } + final int len = searchStr.length(); + final int max = str.length() - len; + for (int i = 0; i <= max; i++) { + if (CharSequenceUtils.regionMatches(str, true, i, searchStr, 0, len)) { + return true; + } + } + return false; + } + +} diff --git a/src/main/java/com/flowingcode/vaadin/addons/twincolgrid/TwinColGrid.java b/src/main/java/com/flowingcode/vaadin/addons/twincolgrid/TwinColGrid.java index ac1a184..e31626f 100644 --- a/src/main/java/com/flowingcode/vaadin/addons/twincolgrid/TwinColGrid.java +++ b/src/main/java/com/flowingcode/vaadin/addons/twincolgrid/TwinColGrid.java @@ -72,7 +72,6 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import lombok.NonNull; -import org.apache.commons.lang3.StringUtils; @SuppressWarnings("serial") @JsModule(value = "./src/fc-twin-col-grid-auto-resize.js") diff --git a/src/main/java/com/flowingcode/vaadin/addons/twincolgrid/TwinColumn.java b/src/main/java/com/flowingcode/vaadin/addons/twincolgrid/TwinColumn.java index 38eba89..b358a38 100644 --- a/src/main/java/com/flowingcode/vaadin/addons/twincolgrid/TwinColumn.java +++ b/src/main/java/com/flowingcode/vaadin/addons/twincolgrid/TwinColumn.java @@ -1,6 +1,26 @@ +/*- + * #%L + * TwinColGrid add-on + * %% + * 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. + * 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.twincolgrid; import com.vaadin.flow.component.Component; +import com.vaadin.flow.component.grid.Grid; import com.vaadin.flow.component.grid.Grid.Column; import com.vaadin.flow.component.grid.SortOrderProvider; import com.vaadin.flow.data.provider.QuerySortOrder; @@ -221,17 +241,21 @@ public TwinColumn setFooter(Supplier footerComponentSupplier) { } /** - * Sets the function that is used for generating CSS class names for cells in both columns. + * Sets the function that is used for generating CSS part names for cells in both columns. + * Returning {@code null} from the generator results in no custom part name being set. Multiple + * part names can be returned from the generator as space-separated. + *

+ * If {@link Grid#setPartNameGenerator(SerializableFunction)} is used together with this method, + * resulting part names from both methods will be effective. * - * @see Column#setClassNameGenerator(SerializableFunction) - * - * @param classNameGenerator the class name generator to set, not {@code null} + * @param partNameGenerator the part name generator to set, not {@code null} * @return this instance, for method chaining - * @throws NullPointerException if {@code classNameGenerator} is {@code null} + * @throws NullPointerException if {@code partNameGenerator} is {@code null} + * @see Column#setPartNameGenerator(SerializableFunction) */ - public TwinColumn setClassNameGenerator(SerializableFunction classNameGenerator) { - availableColumn.setClassNameGenerator(classNameGenerator); - selectionColumn.setClassNameGenerator(classNameGenerator); + public TwinColumn setPartNameGenerator(SerializableFunction partNameGenerator) { + availableColumn.setPartNameGenerator(partNameGenerator); + selectionColumn.setPartNameGenerator(partNameGenerator); return this; } diff --git a/src/test/java/com/flowingcode/vaadin/addons/twincolgrid/CompatibilityExtension.java b/src/test/java/com/flowingcode/vaadin/addons/twincolgrid/CompatibilityExtension.java index 73b56fd..8e3910a 100644 --- a/src/test/java/com/flowingcode/vaadin/addons/twincolgrid/CompatibilityExtension.java +++ b/src/test/java/com/flowingcode/vaadin/addons/twincolgrid/CompatibilityExtension.java @@ -1,3 +1,22 @@ +/*- + * #%L + * TwinColGrid add-on + * %% + * 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. + * 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.twincolgrid; import com.vaadin.flow.component.select.Select; diff --git a/src/test/java/com/flowingcode/vaadin/addons/twincolgrid/TwinColGridListAdapterTest.java b/src/test/java/com/flowingcode/vaadin/addons/twincolgrid/TwinColGridListAdapterTest.java index 1c1c765..b044e42 100644 --- a/src/test/java/com/flowingcode/vaadin/addons/twincolgrid/TwinColGridListAdapterTest.java +++ b/src/test/java/com/flowingcode/vaadin/addons/twincolgrid/TwinColGridListAdapterTest.java @@ -1,3 +1,22 @@ +/*- + * #%L + * TwinColGrid add-on + * %% + * 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. + * 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.twincolgrid; import org.junit.Assert; diff --git a/src/test/java/com/flowingcode/vaadin/addons/twincolgrid/TwinColGridTest.java b/src/test/java/com/flowingcode/vaadin/addons/twincolgrid/TwinColGridTest.java index 48c4daf..9c2d4d0 100644 --- a/src/test/java/com/flowingcode/vaadin/addons/twincolgrid/TwinColGridTest.java +++ b/src/test/java/com/flowingcode/vaadin/addons/twincolgrid/TwinColGridTest.java @@ -1,3 +1,22 @@ +/*- + * #%L + * TwinColGrid add-on + * %% + * 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. + * 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.twincolgrid; import org.junit.Assert;