/** * Load choices from the named property * * @param propertyName Name of the property containing the choices. Must be in the acceptable * format. If the property name is null, loads a default set of choices. */ public void loadChoices(String propertyName) { clear(); if (propertyName == null || propertyName.isEmpty()) { addChoice("All Dates", false); addChoice("Today|T|T", false); addChoice("Last Week|T|T-7", false); addChoice("Last Month|T|T-30|1", false); addChoice("Last Year|T|T-365", false); addChoice("Last Two Years|T|T-730", false); } else { for (String value : PropertyUtil.getValues(propertyName, null)) { addChoice(value, false); } } checkSelection(true); }
/** * Adds a date range item to the choice list from its string representation (see DateRange class * for format). * * @param range String representation of date range. * @param isCustom If true, range is a custom item. In this case, if another matching custom * item exists, it will not be added. * @return List item that was added (or found if duplicate custom item). */ public Listitem addChoice(String range, boolean isCustom) { return addChoice(new DateRange(range), isCustom); }
/** * onSelect event handler. * * @param event The change event. */ @EventHandler("change") private void onChange(ChangeEvent event) { /** * When the custom range item is selected, triggers the display of the date range dialog. */ if (getSelectedItem() == customItem) { event.stopPropagation(); DateRangeDialog.show((range) -> { if (range == null) { setSelectedItem(lastSelectedItem); } else { setSelectedItem(addChoice(range, true)); } checkSelection(false); }); } else { checkSelection(false); } } }