public interface NewItemHandler extends Consumer<String>, Serializable {
}
- /**
- * ItemIconProvider can be used to add custom icons to combo box items shown
- * in the popup.
- *
- * @see ComboBox#setItemIconProvider(ItemIconProvider)
- * @param <T>
- * item type in the combo box
- */
- @FunctionalInterface
- public interface ItemIconProvider<T>
- extends Function<T, Resource>, Serializable {
- }
-
/**
* Filter can be used to customize the filtering of items based on user
* input.
private ItemCaptionGenerator<T> itemCaptionGenerator = String::valueOf;
private StyleGenerator<T> itemStyleGenerator = item -> null;
- private ItemIconProvider<T> itemIconProvider = item -> null;
+ private IconGenerator<T> itemIconGenerator = item -> null;
private ItemFilter<T> filter = (filterText, item) -> {
if (filterText == null) {
if (style != null) {
jsonObject.put(ComboBoxConstants.STYLE, style);
}
- Resource icon = itemIconProvider.apply(data);
+ Resource icon = itemIconGenerator.apply(data);
if (icon != null) {
String iconUrl = ResourceReference
.create(icon, ComboBox.this, null).getURL();
}
/**
- * Sets the item icon provider that is used to produce custom icons for
- * showing items in the popup. The provider can return null for items with
+ * Sets the item icon generator that is used to produce custom icons for
+ * showing items in the popup. The generator can return null for items with
* no icon.
*
- * @param itemIconProvider
- * the item icon provider to set, not null
+ * @see IconGenerator
+ *
+ * @param itemIconGenerator
+ * the item icon generator to set, not null
+ * @throws NullPointerException
+ * if {@code itemIconGenerator} is {@code null}
*/
- public void setItemIconProvider(ItemIconProvider<T> itemIconProvider) {
- Objects.requireNonNull(itemIconProvider,
- "Item icon providers must not be null");
- this.itemIconProvider = itemIconProvider;
+ public void setItemIconGenerator(IconGenerator<T> itemIconGenerator) {
+ Objects.requireNonNull(itemIconGenerator,
+ "Item icon generator must not be null");
+ this.itemIconGenerator = itemIconGenerator;
getDataCommunicator().reset();
}
/**
- * Gets the currently used item icon provider. The default item icon
+ * Gets the currently used item icon generator. The default item icon
* provider returns null for all items, resulting in no icons being used.
*
- * @see #setItemIconProvider(ItemIconProvider)
+ * @see IconGenerator
+ * @see #setItemIconGenerator(IconGenerator)
*
- * @return the currently used item icon provider, not null
+ * @return the currently used item icon generator, not null
*/
- public ItemIconProvider<T> getItemIconProvider() {
- return itemIconProvider;
+ public IconGenerator<T> getItemIconGenerator() {
+ return itemIconGenerator;
}
/**
--- /dev/null
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * 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 com.vaadin.ui;
+
+import java.io.Serializable;
+import java.util.function.Function;
+
+import com.vaadin.server.Resource;
+
+/**
+ * A callback interface for generating icons for an item.
+ *
+ * @param <T>
+ * item type for which the icon is generated
+ */
+@FunctionalInterface
+public interface IconGenerator<T> extends Function<T, Resource>, Serializable {
+
+ /**
+ * Gets an icon resource for the {@code item}.
+ *
+ * @param item
+ * the item for which to generate an icon for
+ * @return the generated icon resource
+ */
+ @Override
+ public Resource apply(T item);
+}
\ No newline at end of file