All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.dellroad.stuff.vaadin7.SimpleContainer Maven / Gradle / Ivy

There is a newer version: 2.6.1
Show newest version

/*
 * Copyright (C) 2011 Archie L. Cobbs. All rights reserved.
 */

package org.dellroad.stuff.vaadin7;

import java.util.ArrayList;
import java.util.Collection;

/**
 * An {@link AbstractSimpleContainer} with {@link Integer} item IDs.
 *
 * 

* Use {@link #load} to (re)load the container. * * @param the type of the Java objects that back each {@link com.vaadin.data.Item} in the container * @see AbstractSimpleContainer */ @SuppressWarnings("serial") public class SimpleContainer extends AbstractSimpleContainer { private ArrayList items = new ArrayList<>(0); /** * Constructor. * *

* After using this constructor, subsequent invocations of {@link #setPropertyExtractor setPropertyExtractor()} * and {@link #setProperties setProperties()} are required to define the properties of this container * and how to extract them. */ public SimpleContainer() { } /** * Constructor. * *

* After using this constructor, a subsequent invocation of {@link #setProperties setProperties()} is required * to define the properties of this container. * * @param propertyExtractor used to extract properties from the underlying Java objects; * may be null but then container is not usable until one is configured via * {@link #setPropertyExtractor setPropertyExtractor()} */ public SimpleContainer(PropertyExtractor propertyExtractor) { this(propertyExtractor, null); } /** * Constructor. * *

* After using this constructor, a subsequent invocation of {@link #setPropertyExtractor setPropertyExtractor()} is required * to define how to extract the properties of this container; alternately, subclasses can override * {@link #getPropertyValue getPropertyValue()}. * * @param propertyDefs container property definitions; null is treated like the empty set */ protected SimpleContainer(Collection> propertyDefs) { this(null, propertyDefs); } /** * Constructor. * * @param propertyExtractor used to extract properties from the underlying Java objects; * may be null but then container is not usable until one is configured via * {@link #setPropertyExtractor setPropertyExtractor()} * @param propertyDefs container property definitions; null is treated like the empty set */ public SimpleContainer(PropertyExtractor propertyExtractor, Collection> propertyDefs) { super(propertyExtractor, propertyDefs); } /** * Constructor. * *

* Properties will be determined by the {@link ProvidesProperty @ProvidesProperty} and * {@link ProvidesPropertySort @ProvidesPropertySort} annotated methods in the given class. * * @param type class to introspect for annotated methods * @throws IllegalArgumentException if {@code type} is null * @throws IllegalArgumentException if {@code type} has two {@link ProvidesProperty @ProvidesProperty} * or {@link ProvidesPropertySort @ProvidesPropertySort} annotated methods for the same property * @throws IllegalArgumentException if a {@link ProvidesProperty @ProvidesProperty}-annotated method with no * {@linkplain ProvidesProperty#value property name specified} has a name which cannot be interpreted as a bean * property "getter" method * @see ProvidesProperty * @see ProvidesPropertySort * @see ProvidesPropertyScanner */ public SimpleContainer(Class type) { super(type); } @Override public T getJavaObject(Object itemId) { if (!(itemId instanceof Integer)) return null; int index = ((Integer)itemId).intValue(); if (index < 0 || index >= this.items.size()) return null; return this.items.get(index); } @Override protected void resetItemIds() { this.items = new ArrayList<>(); } @Override protected Integer generateItemId(T obj) { int itemId = this.items.size(); this.items.add(obj); return itemId; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy