Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
* Format
* Remove self explaining comments
* Remove logging - not needed on UI
* Fix typos
* Remove java serialization support
  • Loading branch information
AB-xdev committed Sep 23, 2024
1 parent 54e66c9 commit 7884306
Show file tree
Hide file tree
Showing 23 changed files with 625 additions and 894 deletions.
5 changes: 5 additions & 0 deletions vaadin-grid-filter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@
<groupId>com.vaadin</groupId>
<artifactId>vaadin-core</artifactId>
</dependency>
<dependency>
<groupId>software.xdev</groupId>
<artifactId>vaadin-date-range-picker</artifactId>
<version>4.1.1</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@
import java.util.stream.IntStream;
import java.util.stream.Stream;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.vaadin.flow.component.Composite;
import com.vaadin.flow.component.ItemLabelGenerator;
import com.vaadin.flow.component.Key;
Expand Down Expand Up @@ -91,8 +88,6 @@
*/
public class FilterComponent<T> extends Composite<VerticalLayout> implements BeforeEnterObserver
{
private static final Logger LOGGER = LogManager.getLogger(FilterComponent.class);

public static final String CHIP_BADGE_FILTER_COMPONENT = "chipFilterComponent";
public static final String BTN_ACCEPT_FILTER_FILTER_COMPONENT = "btnAcceptFilterFilterComponent";
public static final String TXT_SEARCH_QUERY_FILTER_COMPONENT = "txtSearchQueryFilterComponent";
Expand Down Expand Up @@ -227,8 +222,6 @@ private void onOperatorChanged()
{
this.selSearchQuery.setVisible(false);
this.txtSearchQuery.setVisible(true);

LOGGER.debug("Switched to input field to text field.");
}
else if(!isSelSearchQueryVisible)
{
Expand All @@ -245,7 +238,6 @@ else if(this.selFields.getValue() != null && this.selFields.getValue().getType()
this.dateRangePickerQuery.setVisible(true);
this.dateSearchQuery.setVisible(false);

LOGGER.debug("Switched input field to date range picker.");
// Validating if the accept filter button should be activated because the date range picker
// has already a value by default
this.btnAcceptFilter.setEnabled(this.shouldTheAcceptButtonBeEnabled());
Expand All @@ -257,8 +249,6 @@ else if(this.selOperations.getValue() != null)
}
}
}

LOGGER.debug("Operator changed.");
}

private void onShowFilterInput()
Expand Down Expand Up @@ -293,8 +283,6 @@ private void onShowFilterInput()
this.btnCancelFilter,
this.btnAcceptFilter
);

LOGGER.debug("Showing available filters.");
}
}

Expand All @@ -303,7 +291,6 @@ private void onShowFilterInput()
*/
private void onAcceptFilter()
{
LOGGER.debug("Filter accepted.");
final String userInput = this.getValueFromVisibleComponent();

final ChipBadgeExtension<FilterCondition<T, ?>> badge;
Expand Down Expand Up @@ -400,7 +387,6 @@ private void onAcceptFilter()

// Remove filter, update grid
this.removeChipBadgeCondition(badge);
LOGGER.debug("Editing filter now...");
}
});
}
Expand Down Expand Up @@ -439,8 +425,6 @@ private void deactivateDeleteButtonFromChipComponents(
badge.setBadgeId(DELETED_INITIAL_CONDITION_STRING);
this.addQueryParameter(badge);
}

LOGGER.debug("Filter removed.");
});
}
}
Expand All @@ -467,7 +451,6 @@ private void formatLocalDateChipBadgeText(final ChipBadge<FilterCondition<T, ?>>
}
catch(final DateTimeParseException e)
{
LOGGER.error("Error parsing local date range into chipBadge component text.", e);
startDate = LocalDate.MIN;
endDate = LocalDate.MAX;
}
Expand All @@ -488,8 +471,6 @@ private void formatLocalDateChipBadgeText(final ChipBadge<FilterCondition<T, ?>>
dateString = startDate + " and " + endDate;
}

LOGGER.debug("Formatted date range query string to {}.", dateString);

return createChipComponentString(tFilterCondition, dateString);
});
}
Expand All @@ -505,7 +486,6 @@ else if(this.dateSearchQuery.isVisible())
}
catch(final DateTimeParseException e)
{
LOGGER.error("Error parsing local date into chipBadge component text.", e);
localDate = LocalDate.MIN;
}

Expand All @@ -521,8 +501,6 @@ else if(this.dateSearchQuery.isVisible())
dateString = localDate.toString();
}

LOGGER.debug("Formatted date query string to {}.", dateString);

return createChipComponentString(tFilterCondition, dateString);
});
}
Expand All @@ -540,7 +518,6 @@ else if(this.dateTimeSearchQuery.isVisible())
}
catch(final DateTimeParseException e)
{
LOGGER.error("Error parsing local date or local date time into chipBadge component text.", e);
localDateTime = LocalDateTime.MIN;
localDate = LocalDate.MIN;
}
Expand All @@ -565,8 +542,6 @@ else if(this.dateTimeSearchQuery.isVisible())

dateString += " " + localDateTime.toLocalTime();

LOGGER.debug("Formatted date time search query string to {}.", dateString);

return createChipComponentString(tFilterCondition, dateString);
}
);
Expand All @@ -589,8 +564,6 @@ private static <T> String createChipComponentString(
*/
private String getValueFromVisibleComponent()
{
LOGGER.debug("Getting value from visible component.");

if(this.nmbSearchQuery.isVisible())
{
return this.nmbSearchQuery.getValue().toString();
Expand Down Expand Up @@ -707,22 +680,12 @@ private void onFieldChange(final FilterField<T, ?> filterField)
if(filterField instanceof FilterFieldEnumExtension)
{
this.setEnumSelectValues(this.selFields.getValue());

LOGGER.debug("Set the values for the enum selection.");
}
else if(filterField.getType() == Boolean.class)
{
this.selSearchQuery.setItems(new ArrayList<>(Arrays.asList("true", "false")));

LOGGER.debug("Set the values for the boolean selection.");
}
else
{
LOGGER.debug("Filter field is not an instance of FilterFieldTypeExtension or a type of boolean.");
}
}

LOGGER.debug("Field changed.");
}

private void setInputComponentVisibility(final Class<?> type)
Expand Down Expand Up @@ -754,14 +717,10 @@ else if(type.isAssignableFrom(Enum.class) || type.isAssignableFrom(Boolean.class
{
this.txtSearchQuery.setVisible(true);
}

LOGGER.debug("The visibility for the input component was set.");
}

private void updateGridFilter()
{
LOGGER.debug("Updating grid filter.");

if(this.chipBadges.isEmpty())
{
this.dataGrid.getListDataView().removeFilters();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,138 +15,81 @@
*/
package software.xdev.vaadin.builder;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Objects;

import com.vaadin.flow.function.ValueProvider;

import software.xdev.vaadin.model.FilterField;
import software.xdev.vaadin.model.FilterFieldEnumExtension;
import software.xdev.vaadin.model.FilterProvider;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Objects;

/**
* Used to create a customizable FilterField.
*
* @see FilterField
*/
public final class CustomizableFilterBuilder
public class CustomizableFilterBuilder
{
private CustomizableFilterBuilder()
{
}

public static CustomizableFilterBuilder builder()
{
return new CustomizableFilterBuilder();
}


/**
* Is used to create a new field for filtering.
*
* @param provider The field of the bean with type String.
* @param description Is used to set the description of the selectable field.
* @param <T> Type of the field.
* @return Returns a field for filtering.
*/
public <T> FilterField<T, String> withValueProvider(final FilterProvider.StringProvider<T> provider,
final String description)
{
return this.withValueProvider(provider, description, String.class);
}

/**
* Is used to create a new field for filtering.
*
* @param provider The field of the bean with type Number.
* @param description Is used to set the description of the selectable field.
* @param <T> Type of the field.
* @return Returns a field for filtering.
*/
public <T> FilterField<T, Number> withValueProvider(final FilterProvider.NumberProvider<T> provider,
final String description)
{
return this.withValueProvider(provider, description, Number.class);
}

/**
* Is used to create a new field for filtering.
*
* @param provider The field of the bean with type LocalDate.
* @param description Is used to set the description of the selectable field.
* @param <T> Type of the field.
* @return Returns a field for filtering.
*/
public <T> FilterField<T, LocalDate> withValueProvider(
final FilterProvider.LocalDateProvider<T> provider,
final String description)
{
return this.withValueProvider(provider, description, LocalDate.class);
}

/**
* Is used to create a new field for filtering.
*
* @param provider The field of the bean with type LocalDateTime.
* @param description Is used to set the description of the selectable field.
* @param <T> Type of the field.
* @return Returns a field for filtering.
*/
public <T> FilterField<T, LocalDateTime> withValueProvider(
final FilterProvider.LocalDateTimeProvider<T> provider,
final String description)
{
return this.withValueProvider(provider, description, LocalDateTime.class);
}

/**
* Is used to create a new field for filtering.
*
* @param provider The field of the bean with type Boolean.
* @param description Is used to set the description of the selectable field.
* @param <T> Type of the field.
* @return Returns a field for filtering.
*/
public <T> FilterField<T, Boolean> withValueProvider(
final FilterProvider.BooleanProvider<T> provider,
final String description)
{
return this.withValueProvider(provider, description, Boolean.class);
}

/**
* Is used to create a new field for filtering.
*
* @param provider The field of the bean with type Enum.
* @param description Is used to set the description of the selectable field.
* @param <T> Type of the field.
* @return Returns a field for filtering.
*/
public <T> FilterField<T, Enum> withValueProvider(final FilterProvider.EnumProvider<T> provider,
final String description,
final Enum<?>[] enumValues)
{
return new FilterFieldEnumExtension<>(provider, description, Enum.class, new ArrayList<>(), enumValues);
}

/**
* Is used to create a new field for filtering.
*
* @param provider The field of the bean.
* @param description The name of the selectable field.
* @param type The class of the field.
* @param <T> The bean.
* @param <X> The type of the field.
* @return Returns a new filterField.
*/
public <T, X> FilterField<T, X> withValueProvider(final ValueProvider<T, X> provider,
final String description,
final Class<X> type)
{
Objects.requireNonNull(provider);
Objects.requireNonNull(description);

return new FilterField<>(provider, description, type, new ArrayList<>());
}
public static CustomizableFilterBuilder builder()
{
return new CustomizableFilterBuilder();
}

public <T> FilterField<T, String> withValueProvider(
final FilterProvider.StringProvider<T> provider,
final String description)
{
return this.withValueProvider(provider, description, String.class);
}

public <T> FilterField<T, Number> withValueProvider(
final FilterProvider.NumberProvider<T> provider,
final String description)
{
return this.withValueProvider(provider, description, Number.class);
}

public <T> FilterField<T, LocalDate> withValueProvider(
final FilterProvider.LocalDateProvider<T> provider,
final String description)
{
return this.withValueProvider(provider, description, LocalDate.class);
}

public <T> FilterField<T, LocalDateTime> withValueProvider(
final FilterProvider.LocalDateTimeProvider<T> provider,
final String description)
{
return this.withValueProvider(provider, description, LocalDateTime.class);
}

public <T> FilterField<T, Boolean> withValueProvider(
final FilterProvider.BooleanProvider<T> provider,
final String description)
{
return this.withValueProvider(provider, description, Boolean.class);
}

public <T> FilterField<T, Enum> withValueProvider(
final FilterProvider.EnumProvider<T> provider,
final String description,
final Enum<?>[] enumValues)
{
return new FilterFieldEnumExtension<>(provider, description, Enum.class, new ArrayList<>(), enumValues);
}

public <T, X> FilterField<T, X> withValueProvider(
final ValueProvider<T, X> provider,
final String description,
final Class<X> type)
{
Objects.requireNonNull(provider);
Objects.requireNonNull(description);

return new FilterField<>(provider, description, type, new ArrayList<>());
}
}
Loading

0 comments on commit 7884306

Please sign in to comment.