Skip to content

Commit a2854ff

Browse files
committed
* Throwing now on clear() * Implemented getEmptyValue() and isEmpty() * Refactored some code * Improved docs
1 parent 39f6f43 commit a2854ff

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

vaadin-date-range-picker/src/main/java/software/xdev/vaadin/daterange_picker/ui/DateRangePicker.java

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ protected static synchronized int getNextID()
9191
protected boolean closeOnOutsideClick = true;
9292

9393
/*
94-
* UI-Comp
94+
* UI-Components
9595
*/
9696
protected final Button btnOverview = new Button();
9797

@@ -110,7 +110,7 @@ public DateRangePicker(final DateRangeModel<D> defaultModel, final D[] items)
110110

111111
public DateRangePicker(final DateRangeModel<D> defaultModel, final Collection<D> items)
112112
{
113-
this.model = defaultModel;
113+
this.model = Objects.requireNonNull(defaultModel);
114114
this.overlay.setItems(items);
115115

116116
this.initUI();
@@ -299,7 +299,7 @@ protected void addClickOutsideListener()
299299
" if(event.target.id == 'overlay') {\r\n" +
300300
" return;\r\n" +
301301
" }\r\n" +
302-
// Check if the click was done by this element
302+
// Check if the click was done on this element
303303
" var isClickInside = spEl.contains(event.target);\r\n" +
304304
" if (!isClickInside) {\r\n" +
305305
" spEl.$server.clickOutsideOccured()\r\n" +
@@ -500,6 +500,8 @@ public DateRangePicker<D> setDateRange(final D dateRange)
500500
@Override
501501
public void setValue(final DateRangeModel<D> value)
502502
{
503+
Objects.requireNonNull(value);
504+
503505
this.model = value;
504506
this.updateFromModel(true);
505507
}
@@ -521,6 +523,42 @@ public Registration addValueChangeListener(final ValueChangeListener<? super Dat
521523
return ComponentUtil.addListener(this, DateRangeValueChangeEvent.class, componentListener);
522524
}
523525

526+
/**
527+
* DateRangePicker always has a value<br>
528+
* However for compatibility reasons (with Vaadin) this returns {@code null}
529+
* @return {@code null}
530+
*/
531+
@Override
532+
public DateRangeModel<D> getEmptyValue()
533+
{
534+
return null;
535+
}
536+
537+
/**
538+
* DateRangePicker always has a value<br>
539+
* Therefore this always returns {@code false}
540+
*
541+
* @return {@code false}
542+
*/
543+
@Override
544+
public boolean isEmpty()
545+
{
546+
return false;
547+
}
548+
549+
/**
550+
* Do not use this method, as it throws a {@link UnsupportedOperationException}<br>
551+
* The calling of clear is not supported because DateRangePicker always has a value<br>
552+
* Use {@link DateRangePicker#setValue(DateRangeModel)} instead.
553+
*
554+
* @throws UnsupportedOperationException
555+
*/
556+
@Override
557+
public void clear()
558+
{
559+
throw new UnsupportedOperationException("The calling of clear is not supported because DateRangePicker always has a value");
560+
}
561+
524562
@Override
525563
public void setReadOnly(final boolean readOnly)
526564
{
@@ -533,12 +571,23 @@ public boolean isReadOnly()
533571
return this.getOverlay().isReadOnly();
534572
}
535573

574+
/**
575+
* The required indicator is not implemented<br>
576+
* <br>
577+
* This method doesn't have any functionallity
578+
*/
536579
@Override
537580
public void setRequiredIndicatorVisible(final boolean requiredIndicatorVisible)
538581
{
539582
// Not required/implemented
540583
}
541584

585+
/**
586+
* The required indicator is not implemented<br>
587+
* This will always return {@code false}
588+
*
589+
* @return {@code false}
590+
*/
542591
@Override
543592
public boolean isRequiredIndicatorVisible()
544593
{

vaadin-date-range-picker/src/main/java/software/xdev/vaadin/daterange_picker/ui/DateRangePickerOverlay.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import java.time.LocalDate;
2424
import java.util.Collection;
25+
import java.util.Objects;
2526
import java.util.Optional;
2627
import java.util.function.Function;
2728

@@ -78,7 +79,7 @@ public class DateRangePickerOverlay<D extends DateRange> extends Composite<Verti
7879

7980
public DateRangePickerOverlay(final DateRangePicker<D> dateRangePicker)
8081
{
81-
this.dateRangePicker = dateRangePicker;
82+
this.dateRangePicker = Objects.requireNonNull(dateRangePicker);
8283
this.currentModel = this.dateRangePicker.getValue();
8384

8485
this.initUI();
@@ -238,6 +239,8 @@ protected void fireValueChanged(final DateRangeModel<D> oldValue, final boolean
238239
@Override
239240
public void setItems(final Collection<D> items)
240241
{
242+
Objects.requireNonNull(items);
243+
241244
this.getCbDateRange().setItems(items);
242245
}
243246

0 commit comments

Comments
 (0)