Skip to content

Commit

Permalink
Added CustomizationDegree. Extended ChipBadgeExtension with new custo…
Browse files Browse the repository at this point in the history
…mization degree property. Added the customization degree to the filter component. Adjusted demo.
  • Loading branch information
lcarrasco-xdev committed Oct 18, 2024
1 parent 0da5b5a commit 9c4a76b
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import software.xdev.vaadin.comparators.NotEqualComparator;
import software.xdev.vaadin.daterange_picker.business.DateRangeModel;
import software.xdev.vaadin.daterange_picker.business.SimpleDateRanges;
import software.xdev.vaadin.model.CustomizationDegree;
import software.xdev.vaadin.model.Department;
import software.xdev.vaadin.model.Person;
import software.xdev.vaadin.model.SimpleFilterField;
Expand Down Expand Up @@ -85,7 +86,7 @@ private void initUI()
.withDatePickerI18n(datePickerI18n)
.withDateTimePickerLocale(Locale.GERMANY)
.withFilterButtonText("Add filter")
.withUrlParameters("filter1")
// .withUrlParameters("filter1")
.withCustomDateRangeModel(
new DateRangeModel<>(LocalDate.now(), LocalDate.now().plusDays(5), SimpleDateRanges.FREE),
List.of(SimpleDateRanges.allValues()))
Expand All @@ -100,7 +101,8 @@ private void initUI()
EqualComparator.getInstance(),
"true",
false,
true
true,
CustomizationDegree.INPUT_VALUE
);

this.add(filterComponent, this.dataGrid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import software.xdev.vaadin.daterange_picker.ui.DateRangePicker;
import software.xdev.vaadin.model.ChipBadge;
import software.xdev.vaadin.model.ChipBadgeExtension;
import software.xdev.vaadin.model.CustomizationDegree;
import software.xdev.vaadin.model.FilterCondition;
import software.xdev.vaadin.model.FilterField;
import software.xdev.vaadin.model.FilterFieldEnumExtension;
Expand Down Expand Up @@ -296,9 +297,6 @@ else if(this.selOperations.getValue() != null)

private void onShowFilterInput()
{
// Needed if the previous condition was an editable initial condition
// The editable initial condition makes the cancel button invisible
this.btnCancelFilter.setVisible(true);

if(this.hlFilter.getChildren().findAny().isEmpty())
{
Expand All @@ -307,8 +305,10 @@ private void onShowFilterInput()
this.btnCancelFilter.setVisible(true);

this.selFields.setValue(null);
this.selFields.setReadOnly(false);
this.selOperations.setItems(Collections.emptyList());
this.selOperations.setEnabled(false);
this.selOperations.setReadOnly(false);
this.btnAcceptFilter.setEnabled(false);
this.txtSearchQuery.clear();
this.nmbSearchQuery.clear();
Expand All @@ -318,7 +318,6 @@ private void onShowFilterInput()
this.setInputComponentVisibility(String.class);

this.hlFilter.add(

this.selFields,
this.selOperations,
this.txtSearchQuery,
Expand All @@ -333,6 +332,30 @@ private void onShowFilterInput()
}
}

/**
* Method used to make the select field and select condition dependent on the customization degree readonly.
*
* @param usedCustomizationDegree Used to set which input field is readonly.
*/
private void setUsedCustomizationDegreeForComponents(final CustomizationDegree usedCustomizationDegree)
{
if(usedCustomizationDegree.equals(CustomizationDegree.INPUT_VALUE))
{
this.selFields.setReadOnly(true);
this.selOperations.setReadOnly(true);
}
else if(usedCustomizationDegree.equals(CustomizationDegree.CONDITION_AND_INPUT_VALUE))
{
this.selFields.setReadOnly(true);
this.selOperations.setReadOnly(false);
}
else
{
this.selFields.setReadOnly(false);
this.selOperations.setReadOnly(false);
}
}

/**
* Clicking on the accept filter button.
*/
Expand All @@ -341,6 +364,7 @@ private void onAcceptFilter()
final String userInput = this.getValueFromVisibleComponent();

final ChipBadgeExtension<FilterCondition<T, ?>> badge;
CustomizationDegree customizationDegree = CustomizationDegree.EVERYTHING;
final boolean deletable;
final boolean editable;

Expand All @@ -349,6 +373,14 @@ private void onAcceptFilter()
{
deletable = this.deletingBadgeEnabled;
editable = this.editingBadgeEnabled;

// Get customization rating from initial condition
customizationDegree = this.initialChipBadges
.stream()
.filter(e -> e.getBadgeId().equals(this.editingBadgeId))
.toList()
.get(0)
.getCustomizationRating();
}
else
{
Expand All @@ -361,7 +393,8 @@ private void onAcceptFilter()
this.selOperations.getValue(),
userInput,
deletable,
editable);
editable,
customizationDegree);

if(!this.identifier.isBlank())
{
Expand Down Expand Up @@ -390,7 +423,8 @@ private void onAcceptFilter()
final FilterComparator selOperation,
final String userInput,
final boolean deletableCondition,
final boolean editableCondition)
final boolean editableCondition,
final CustomizationDegree customizationDegree)
{
final ChipBadgeExtension<FilterCondition<T, ?>> badge = new ChipBadgeExtension<>(
new FilterCondition<>(
Expand Down Expand Up @@ -426,6 +460,9 @@ private void onAcceptFilter()
// Make the cancel button invisible
this.btnCancelFilter.setVisible(false);

// Set the customization rating for the filter select and condition select
this.setUsedCustomizationDegreeForComponents(customizationDegree);

// Just activated when the url parameters are activated
if(!this.identifier.isBlank())
{
Expand Down Expand Up @@ -841,15 +878,30 @@ private void createConditionsFromQueryParameters()
{
if(!this.queryBadgeIdList.get(i).equals(DELETED_INITIAL_CONDITION_STRING))
{
final String badgeId = this.queryBadgeIdList.get(i);
CustomizationDegree customizationDegree = CustomizationDegree.EVERYTHING;

// Check if it's an initial condition
final List<ChipBadgeExtension<FilterCondition<T, ?>>> cD = this.initialChipBadges
.stream()
.filter(e -> e.getBadgeId().equals(badgeId))
.toList();

if(!cD.isEmpty())
{
customizationDegree = cD.get(0).getCustomizationRating();
}

final ChipBadgeExtension<FilterCondition<T, ?>> chipBadgeExtension =
this.createBadgeConditionAndApplyFilter(
filterField,
comparatorOptional.get(),
this.queryInputFieldList.get(i),
Boolean.parseBoolean(this.queryBadgeDeletableList.get(i)),
Boolean.parseBoolean(this.queryBadgeEditableList.get(i)));
Boolean.parseBoolean(this.queryBadgeEditableList.get(i)),
customizationDegree);

chipBadgeExtension.setBadgeId(this.queryBadgeIdList.get(i));
chipBadgeExtension.setBadgeId(badgeId);
}
else
{
Expand Down Expand Up @@ -1349,6 +1401,7 @@ public FilterComponent<T> withInitialFilter(
final String searchQuery,
final boolean conditionDeletable,
final boolean conditionEditable,
final CustomizationDegree customizationDegree,
final String badgeId)
{
FilterField<T, ?> finalFilterField = filterField;
Expand Down Expand Up @@ -1381,11 +1434,14 @@ public FilterComponent<T> withInitialFilter(
selectedCondition,
searchQuery,
conditionDeletable,
conditionEditable);
conditionEditable,
customizationDegree);

// Just needed if the url parameters are activated
chipBadge.setBadgeId(badgeId);

chipBadge.setCustomizationRating(customizationDegree);

// Needed for resetting the conditions
this.initialChipBadges.add(chipBadge);

Expand Down Expand Up @@ -1414,6 +1470,30 @@ public FilterComponent<T> withInitialFilter(
searchQuery,
conditionDeletable,
conditionEditable,
CustomizationDegree.EVERYTHING,
String.valueOf(this.initialConditionIdCounter));

this.initialConditionIdCounter++;

return filterComponent;
}

public FilterComponent<T> withInitialFilter(
final FilterField<T, ?> filterField,
final FilterComparator selectedCondition,
final String searchQuery,
final boolean conditionDeletable,
final boolean conditionEditable,
final CustomizationDegree customizationDegree)
{
final FilterComponent<T> filterComponent =
this.withInitialFilter(
filterField,
selectedCondition,
searchQuery,
conditionDeletable,
conditionEditable,
customizationDegree,
String.valueOf(this.initialConditionIdCounter));

this.initialConditionIdCounter++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class ChipBadgeExtension<T> extends ChipBadge<T>

protected final Button btnEdit = new Button(VaadinIcon.PENCIL.create());

private CustomizationDegree customizationDegree = CustomizationDegree.EVERYTHING;

public ChipBadgeExtension(final T item)
{
super(item);
Expand Down Expand Up @@ -76,6 +78,16 @@ public boolean isBtnDeleteEnabled()
return this.btnDelete.isEnabled();
}

public CustomizationDegree getCustomizationRating()
{
return this.customizationDegree;
}

public void setCustomizationRating(final CustomizationDegree customizationDegree)
{
this.customizationDegree = customizationDegree;
}

public Registration addBtnEditClickListener(final ComponentEventListener<ClickEvent<Button>> listener)
{
return this.btnEdit.addClickListener(listener);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright © 2024 XDEV Software (https://xdev.software)
*
* 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.
*/
package software.xdev.vaadin.model;

public enum CustomizationDegree
{
EVERYTHING,
CONDITION_AND_INPUT_VALUE,
INPUT_VALUE
}

0 comments on commit 9c4a76b

Please sign in to comment.