From e85d933b25cc3c5cc85eb7eb4b13b950fd8e1569 Mon Sep 17 00:00:00 2001
From: Artur Signell
- * Defines the interface to commit and discard changes to an object, supporting
- * read-through and write-through modes.
- *
- * Read-through mode means that the value read from the buffered object
- * is constantly up to date with the data source. Write-through mode
- * means that all changes to the object are immediately updated to the data
- * source.
- *
- * Since these modes are independent, their combinations may result in some
- * behaviour that may sound surprising.
- *
- * For example, if a
- * The only exception to this rule is that when the object is not in
- * write-through mode and it's buffer contains a modified value, the value
- * retrieved from the object will be the locally modified value in the
- * buffer which may differ from the value in the data source.
- *
- * When the object is in buffered mode, an internal buffer will be used to
- * store changes until {@link #commit()} is called. Calling
- * {@link #discard()} will revert the internal buffer to the value of the
- * data source.
- *
- * This is an easier way to use {@link #setReadThrough(boolean)} and
- * {@link #setWriteThrough(boolean)} and not as error prone. Changing
- * buffered mode will change both the read through and write through state
- * of the object.
- *
- * Mixing calls to {@link #setBuffered(boolean)}/{@link #isBuffered()} and
- * {@link #setReadThrough(boolean)}/{@link #isReadThrough()} or
- * {@link #setWriteThrough(boolean)}/{@link #isWriteThrough()} is generally
- * a bad idea.
- *
- * This method only returns true if both read and write buffering is used.
- *
- * This interface defines the combination of
- * Container of this type gets notified when a subtree is opened/closed in a
- * component displaying its content. This allows container to lazy load subtrees
- * and release memory when a sub-tree is no longer displayed.
- *
- * Methods from {@link Container.Ordered} (and from {@linkContainer.Indexed} if
- * implemented) are expected to work as in "preorder" of the currently visible
- * hierarchy. This means for example that the return value of size method
- * changes when subtree is collapsed/expanded. In other words items in collapsed
- * sub trees should be "ignored" by container when the container is accessed
- * with methods introduced in {@link Container.Ordered} or
- * {@linkContainer.Indexed}. From the accessors point of view, items in
- * collapsed subtrees don't exist.
- *
- *
- */
-public interface Collapsible extends Hierarchical, Ordered {
-
- /**
- *
- * Collapsing the {@link Item} indicated by
- * If called on a leaf {@link Item}, this method does nothing.
- *
- * Checks whether the {@link Item}, identified by
- * If an {@link Item} is "collapsed" its children are not included in
- * methods used to list Items in this container.
- *
- * A specialized set of identified Items. Basically the Container is a set of
- * {@link Item}s, but it imposes certain constraints on its contents. These
- * constraints state the following:
- *
- * The Container can be visualized as a representation of a relational database
- * table. Each Item in the Container represents a row in the table, and all
- * cells in a column (identified by a Property ID) have the same data type. Note
- * that as with the cells in a database table, no Property in a Container may be
- * empty, though they may contain
- * Note that though uniquely identified, the Items in a Container are not
- * necessarily {@link Container.Ordered ordered} or {@link Container.Indexed
- * indexed}.
- *
- * Containers can derive Item ID's from the item properties or use other,
- * container specific or user specified identifiers.
- *
- * If a container is {@link Filterable filtered} or {@link Sortable sorted},
- * most of the the methods of the container interface and its subinterfaces
- * (container size, {@link #containsId(Object)}, iteration and indices etc.)
- * relate to the filtered and sorted view, not to the full container contents.
- * See individual method javadoc for exceptions to this (adding and removing
- * items).
- *
- *
- *
- * The Container interface is split to several subinterfaces so that a class can
- * implement only the ones it needs.
- *
- * The new Item is returned, and it is ready to have its Properties
- * modified. Returns
- * This functionality is optional.
- *
- * The new ID is returned, or
- * This functionality is optional.
- *
- * Containers that support filtering should also allow removing an item that
- * is currently filtered out.
- *
- * This functionality is optional.
- *
- * Note that Property ID and type information is preserved. This
- * functionality is optional.
- *
- * If the container is filtered or sorted, the traversal applies to the
- * filtered and sorted view.
- *
- * The
- * Adding an item after null item adds the item as first item of the
- * ordered container.
- *
- * Adding an item after null item adds the item as first item of the
- * ordered container.
- *
- * When an {@link Ordered} or {@link Indexed} container is sorted, all
- * relevant operations of these interfaces should only use the filtered and
- * sorted contents and the filtered indices to the container. Indices or
- * item identifiers in the public API refer to the visible view unless
- * otherwise stated. However, the
- * How sorting is performed when a {@link Hierarchical} container implements
- * {@link Sortable} is implementation specific and should be documented in
- * the implementing class. However, the recommended approach is sorting the
- * roots and the sets of children of each item separately.
- *
- * Depending on the container type, sorting a container may permanently
- * change the internal order of items in the container.
- *
- * If the container is filtered or sorted, all indices refer to the filtered
- * and sorted view. However, the
- * The indices of the item currently in the given position and all the
- * following items are incremented.
- *
- * This method should apply filters to the added item after inserting
- * it, possibly hiding it immediately. If the container is being sorted,
- * the item may be added at the correct sorted position instead of the
- * given position. See {@link Indexed}, {@link Ordered},
- * {@link Filterable} and {@link Sortable} for more information.
- *
- * The indexes of the item currently in the given position and all the
- * following items are incremented.
- *
- * This method should apply filters to the added item after inserting
- * it, possibly hiding it immediately. If the container is being sorted,
- * the item may be added at the correct sorted position instead of the
- * given position. See {@link Indexed}, {@link Filterable} and
- * {@link Sortable} for more information.
- *
- * Interface for
- * Sets the parent of an Item. The new parent item must exist and be
- * able to have children. (
- *
- * This operation is optional.
- *
- * Sets the given Item's capability to have children. If the Item
- * identified with
- * The children must be first explicitly removed with
- * {@link #setParent(Object itemId, Object newParentId)}or
- * {@link com.vaadin.data.Container#removeItem(Object itemId)}.
- *
- * This operation is optional. If it is not implemented, the method
- * always returns
- * Tests if the Item specified with
- * Note that being a leaf does not imply whether or not an Item is
- * allowed to have children.
- *
- * Removes the Item identified by
- * Note that this does not remove any children the item might have.
- *
- * When a set of filters are set, only items that match all the filters are
- * included in the visible contents of the container. Still new items that
- * do not match filters can be added to the container. Multiple filters can
- * be added and the container remembers the state of the filters. When
- * multiple filters are added, all filters must match for an item to be
- * visible in the container.
- *
- * When an {@link Ordered} or {@link Indexed} container is filtered, all
- * operations of these interfaces should only use the filtered contents and
- * the filtered indices to the container.
- *
- * How filtering is performed when a {@link Hierarchical} container
- * implements {@link SimpleFilterable} is implementation specific and should
- * be documented in the implementing class.
- *
- * Adding items (if supported) to a filtered {@link Ordered} or
- * {@link Indexed} container should insert them immediately after the
- * indicated visible item. The unfiltered position of items added at index
- * 0, at index {@link com.vaadin.data.Container#size()} or at an undefined
- * position is up to the implementation.
- *
- * The functionality of SimpleFilterable can be implemented using the
- * {@link Filterable} API and {@link SimpleStringFilter}.
- *
- * When a set of filters are set, only items that match all the filters are
- * included in the visible contents of the container. Still new items that
- * do not match filters can be added to the container. Multiple filters can
- * be added and the container remembers the state of the filters. When
- * multiple filters are added, all filters must match for an item to be
- * visible in the container.
- *
- * When an {@link Ordered} or {@link Indexed} container is filtered, all
- * operations of these interfaces should only use the filtered and sorted
- * contents and the filtered indices to the container. Indices or item
- * identifiers in the public API refer to the visible view unless otherwise
- * stated. However, the
- * How filtering is performed when a {@link Hierarchical} container
- * implements {@link Filterable} is implementation specific and should be
- * documented in the implementing class.
- *
- * Adding items (if supported) to a filtered {@link Ordered} or
- * {@link Indexed} container should insert them immediately after the
- * indicated visible item. However, the unfiltered position of items added
- * at index 0, at index {@link com.vaadin.data.Container#size()} or at an
- * undefined position is up to the implementation.
- *
- * This API replaces the old Filterable interface, renamed to
- * {@link SimpleFilterable} in Vaadin 6.6.
- *
- * Interface implemented by the editor classes supporting editing the
- * Container. Implementing this interface means that the Container serving
- * as the data source of the editor can be modified through it.
- *
- * Note that not implementing the
- * Note: The general Java convention is not to explicitly declare that a
- * class generates events, but to directly define the
- *
- * The interface for adding and removing
- * A property set change means the addition, removal or other structural
- * changes to the properties of a container. Changes concerning the set of
- * items in the container and their property values are not property set
- * changes.
- *
- * Note that the general Java convention is not to explicitly declare that a
- * class generates events, but to directly define the
- *
- * Provides a mechanism for handling a set of Properties, each associated to a
- * locally unique non-null identifier. The interface is split into subinterfaces
- * to enable a class to implement only the functionalities it needs.
- *
- * This functionality is optional.
- *
- * This functionality is optional.
- *
- * Note : Not implementing the
- * Note: The values stored in the Properties may change without triggering
- * this event.
- *
- * Note : The general Java convention is not to explicitly declare that a
- * class generates events, but to directly define the
- *
- * The
- * The
- * The
- * The
- * Implementing this functionality is optional. If the functionality is
- * missing, one should declare the Property to be in read-only mode and
- * throw
- * If the value is set during a transaction the value must not replace
- * the original value until {@link #commit()} is called. Still,
- * {@link #getValue()} must return the current value set in the
- * transaction. Calling {@link #rollback()} while in a transaction must
- * rollback the value to what it was before the transaction started.
- *
- * {@link ValueChangeEvent}s must not be emitted for internal value
- * changes during a transaction. If the value changes as a result of
- * {@link #commit()}, a {@link ValueChangeEvent} should be emitted.
- *
- * If the value is changed as a result of this operation, a
- * {@link ValueChangeEvent} is emitted if such are supported.
- *
- * This method has no effect if there is no transaction is in progress.
- *
- * This method must never throw an exception.
- */
- public void commit();
-
- /**
- * Aborts and rolls back the transaction that is in progress.
- *
- * The value is reset to the value before the transaction started. No
- * {@link ValueChangeEvent} is emitted as a result of this.
- *
- * This method has no effect if there is no transaction is in progress.
- *
- * This method must never throw an exception.
- */
- public void rollback();
- }
-
- /**
- *
- * Implementing this interface means that the Property serving as the data
- * source of the editor can be modified through the editor. It does not
- * restrict the editor from editing the Property internally, though if the
- * Property is in a read-only mode, attempts to modify it will result in the
- *
- * Note : The general Java convention is not to explicitly declare that a
- * class generates events, but to directly define the
- *
- * Note : The general Java convention is not to explicitly declare that a
- * class generates events, but to directly define the
- *
- * Interface for validatable objects. Defines methods to verify if the object's
- * value is valid or not, and to add, remove and list registered validators of
- * the object.
- *
- * Adds a new validator for this object. The validator's
- * {@link Validator#validate(Object)} method is activated every time the
- * object's value needs to be verified, that is, when the {@link #isValid()}
- * method is called. This usually happens when the object's value changes.
- *
- * Removes a previously registered validator from the object. The specified
- * validator is removed from the object and its
- * Lists all validators currently registered for the object. If no
- * validators are registered, returns
- * Tests the current value of the object against all registered validators.
- * The registered validators are iterated and for each the
- * {@link Validator#validate(Object)} method is called. If any validator
- * throws the {@link Validator.InvalidValueException} this method returns
- *
- * Checks the validity of the validatable. If the validatable is valid this
- * method should do nothing, and if it's not valid, it should throw
- *
- * Checks the validabtable object accept invalid values.The default value is
- *
- * Should the validabtable object accept invalid values. Supporting this
- * configuration possibility is optional. By default invalid values are
- * allowed.
- *
- * Implementors of this class can be added to any
- * {@link com.vaadin.data.Validatable Validatable} implementor to verify its
- * value.
- *
- * {@link #validate(Object)} can be used to check if a value is valid. An
- * {@link InvalidValueException} with an appropriate validation error message is
- * thrown if the value is not valid.
- *
- * Validators must not have any side effects.
- *
- * Since Vaadin 7, the method isValid(Object) does not exist in the interface -
- * {@link #validate(Object)} should be used instead, and the exception caught
- * where applicable. Concrete classes implementing {@link Validator} can still
- * internally implement and use isValid(Object) for convenience or to ease
- * migration from earlier Vaadin versions.
- *
- * The default implementation of InvalidValueException does not support HTML
- * in error messages. To enable HTML support, override
- * {@link #getHtmlMessage()} and use the subclass in validators.
- *
- * The functionality of FieldGroup is similar to {@link Form} but
- * {@link FieldGroup} does not handle layouts in any way. The typical use case
- * is to create a layout outside the FieldGroup and then use FieldGroup to bind
- * the fields to a data source.
- *
- * {@link FieldGroup} is not a UI component so it cannot be added to a layout.
- * Using the buildAndBind methods {@link FieldGroup} can create fields for you
- * using a FieldGroupFieldFactory but you still have to add them to the correct
- * position in your layout.
- * Buffered
object is in read-through mode but
- * not in write-through mode, the result is an object whose value is updated
- * directly from the data source only if it's not locally modified. If the value
- * is locally modified, retrieving the value from the object would result in a
- * value that is different than the one stored in the data source, even though
- * the object is in read-through mode.
- * commit
is called.
- *
- * @throws SourceException
- * if the operation fails because of an exception is thrown by
- * the data source. The cause is included in the exception.
- * @throws InvalidValueException
- * if the operation fails because validation is enabled and the
- * values do not validate
- */
- public void commit() throws SourceException, InvalidValueException;
-
- /**
- * Discards all changes since last commit. The object updates its value from
- * the data source.
- *
- * @throws SourceException
- * if the operation fails because of an exception is thrown by
- * the data source. The cause is included in the exception.
- */
- public void discard() throws SourceException;
-
- /**
- * Tests if the object is in write-through mode. If the object is in
- * write-through mode, all modifications to it will result in
- * commit
being called after the modification.
- *
- * @return true
if the object is in write-through mode,
- * false
if it's not.
- * @deprecated Use {@link #setBuffered(boolean)} instead. Note that
- * setReadThrough(true), setWriteThrough(true) equals
- * setBuffered(false)
- */
- @Deprecated
- public boolean isWriteThrough();
-
- /**
- * Sets the object's write-through mode to the specified status. When
- * switching the write-through mode on, the commit
operation
- * will be performed.
- *
- * @param writeThrough
- * Boolean value to indicate if the object should be in
- * write-through mode after the call.
- * @throws SourceException
- * If the operation fails because of an exception is thrown by
- * the data source.
- * @throws InvalidValueException
- * If the implicit commit operation fails because of a
- * validation error.
- *
- * @deprecated Use {@link #setBuffered(boolean)} instead. Note that
- * setReadThrough(true), setWriteThrough(true) equals
- * setBuffered(false)
- */
- @Deprecated
- public void setWriteThrough(boolean writeThrough) throws SourceException,
- InvalidValueException;
-
- /**
- * Tests if the object is in read-through mode. If the object is in
- * read-through mode, retrieving its value will result in the value being
- * first updated from the data source to the object.
- * true
if the object is in read-through mode,
- * false
if it's not.
- * @deprecated Use {@link #isBuffered(boolean)} instead. Note that
- * setReadThrough(true), setWriteThrough(true) equals
- * setBuffered(false)
- */
- @Deprecated
- public boolean isReadThrough();
-
- /**
- * Sets the object's read-through mode to the specified status. When
- * switching read-through mode on, the object's value is updated from the
- * data source.
- *
- * @param readThrough
- * Boolean value to indicate if the object should be in
- * read-through mode after the call.
- *
- * @throws SourceException
- * If the operation fails because of an exception is thrown by
- * the data source. The cause is included in the exception.
- * @deprecated Use {@link #setBuffered(boolean)} instead. Note that
- * setReadThrough(true), setWriteThrough(true) equals
- * setBuffered(false)
- */
- @Deprecated
- public void setReadThrough(boolean readThrough) throws SourceException;
-
- /**
- * Sets the object's buffered mode to the specified status.
- * true
if the value in the object has been modified
- * since the last data source update, false
if not.
- */
- public boolean isModified();
-
- /**
- * An exception that signals that one or more exceptions occurred while a
- * buffered object tried to access its data source or if there is a problem
- * in processing a data source.
- *
- * @author Vaadin Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
- @SuppressWarnings("serial")
- public class SourceException extends RuntimeException implements
- Serializable {
-
- /** Source class implementing the buffered interface */
- private final Buffered source;
-
- /** Original cause of the source exception */
- private Throwable[] causes = {};
-
- /**
- * Creates a source exception that does not include a cause.
- *
- * @param source
- * the source object implementing the Buffered interface.
- */
- public SourceException(Buffered source) {
- this.source = source;
- }
-
- /**
- * Creates a source exception from a cause exception.
- *
- * @param source
- * the source object implementing the Buffered interface.
- * @param cause
- * the original cause for this exception.
- */
- public SourceException(Buffered source, Throwable cause) {
- this.source = source;
- causes = new Throwable[] { cause };
- }
-
- /**
- * Creates a source exception from multiple causes.
- *
- * @param source
- * the source object implementing the Buffered interface.
- * @param causes
- * the original causes for this exception.
- */
- public SourceException(Buffered source, Throwable[] causes) {
- this.source = source;
- this.causes = causes;
- }
-
- /**
- * Gets the cause of the exception.
- *
- * @return The (first) cause for the exception, null if no cause.
- */
- @Override
- public final Throwable getCause() {
- if (causes.length == 0) {
- return null;
- }
- return causes[0];
- }
-
- /**
- * Gets all the causes for this exception.
- *
- * @return throwables that caused this exception
- */
- public final Throwable[] getCauses() {
- return causes;
- }
-
- /**
- * Gets a source of the exception.
- *
- * @return the Buffered object which generated this exception.
- */
- public Buffered getSource() {
- return source;
- }
-
- }
-}
diff --git a/src/com/vaadin/data/BufferedValidatable.java b/src/com/vaadin/data/BufferedValidatable.java
deleted file mode 100644
index ce1d44fce6..0000000000
--- a/src/com/vaadin/data/BufferedValidatable.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
-@VaadinApache2LicenseForJavaFiles@
- */
-
-package com.vaadin.data;
-
-import java.io.Serializable;
-
-/**
- * Validatable
and
- * Buffered
interfaces. The combination of the interfaces defines
- * if the invalid data is committed to datasource.
- * false
.
- */
- public boolean isInvalidCommitted();
-
- /**
- * Sets if the invalid data should be committed to datasource. The default
- * is false
.
- */
- public void setInvalidCommitted(boolean isCommitted);
-}
diff --git a/src/com/vaadin/data/Collapsible.java b/src/com/vaadin/data/Collapsible.java
deleted file mode 100644
index 06c96b7ea7..0000000000
--- a/src/com/vaadin/data/Collapsible.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
-@VaadinApache2LicenseForJavaFiles@
- */
-package com.vaadin.data;
-
-import com.vaadin.data.Container.Hierarchical;
-import com.vaadin.data.Container.Ordered;
-
-/**
- * Container needed by large lazy loading hierarchies displayed e.g. in
- * TreeTable.
- * itemId
hides all
- * children, and their respective children, from the {@link Container}.
- * true
if you want to collapse the children below
- * this {@link Item}. false
if you want to
- * uncollapse the children.
- */
- public void setCollapsed(Object itemId, boolean collapsed);
-
- /**
- * itemId
is
- * collapsed or not.
- * true
iff the {@link Item} identified by
- * itemId
is currently collapsed, otherwise
- * false
.
- */
- public boolean isCollapsed(Object itemId);
-
-}
diff --git a/src/com/vaadin/data/Container.java b/src/com/vaadin/data/Container.java
deleted file mode 100644
index f4c0ed9794..0000000000
--- a/src/com/vaadin/data/Container.java
+++ /dev/null
@@ -1,1105 +0,0 @@
-/*
-@VaadinApache2LicenseForJavaFiles@
- */
-
-package com.vaadin.data;
-
-import java.io.Serializable;
-import java.util.Collection;
-
-import com.vaadin.data.util.filter.SimpleStringFilter;
-import com.vaadin.data.util.filter.UnsupportedFilterException;
-
-/**
- *
- *
- *
- * null
values.
- * null
is
- * returned.
- *
- * Containers should not return Items that are filtered out.
- *
- * @param itemId
- * ID of the {@link Item} to retrieve
- * @return the {@link Item} with the given ID or null
if the
- * Item is not found in the Container
- */
- public Item getItem(Object itemId);
-
- /**
- * Gets the ID's of all Properties stored in the Container. The ID's cannot
- * be modified through the returned collection.
- *
- * @return unmodifiable collection of Property IDs
- */
- public Collection> getContainerPropertyIds();
-
- /**
- * Gets the ID's of all visible (after filtering and sorting) Items stored
- * in the Container. The ID's cannot be modified through the returned
- * collection.
- *
- * If the container is {@link Ordered}, the collection returned by this
- * method should follow that order. If the container is {@link Sortable},
- * the items should be in the sorted order.
- *
- * Calling this method for large lazy containers can be an expensive
- * operation and should be avoided when practical.
- *
- * @return unmodifiable collection of Item IDs
- */
- public Collection> getItemIds();
-
- /**
- * Gets the Property identified by the given itemId and propertyId from the
- * Container. If the Container does not contain the item or it is filtered
- * out, or the Container does not have the Property, null
is
- * returned.
- *
- * @param itemId
- * ID of the visible Item which contains the Property
- * @param propertyId
- * ID of the Property to retrieve
- * @return Property with the given ID or null
- */
- public Property> getContainerProperty(Object itemId, Object propertyId);
-
- /**
- * Gets the data type of all Properties identified by the given Property ID.
- *
- * @param propertyId
- * ID identifying the Properties
- * @return data type of the Properties
- */
- public Class> getType(Object propertyId);
-
- /**
- * Gets the number of visible Items in the Container.
- *
- * Filtering can hide items so that they will not be visible through the
- * container API.
- *
- * @return number of Items in the Container
- */
- public int size();
-
- /**
- * Tests if the Container contains the specified Item.
- *
- * Filtering can hide items so that they will not be visible through the
- * container API, and this method should respect visibility of items (i.e.
- * only indicate visible items as being in the container) if feasible for
- * the container.
- *
- * @param itemId
- * ID the of Item to be tested
- * @return boolean indicating if the Container holds the specified Item
- */
- public boolean containsId(Object itemId);
-
- /**
- * Creates a new Item with the given ID in the Container.
- *
- * null
if the operation fails or the
- * Container already contains a Item with the given ID.
- * null
in case of a failure
- * @throws UnsupportedOperationException
- * if adding an item with an explicit item ID is not supported
- * by the container
- */
- public Item addItem(Object itemId) throws UnsupportedOperationException;
-
- /**
- * Creates a new Item into the Container, and assign it an automatic ID.
- *
- * null
if the operation fails.
- * After a successful call you can use the {@link #getItem(Object ItemId)
- * getItem
}method to fetch the Item.
- * null
in case of a
- * failure
- * @throws UnsupportedOperationException
- * if adding an item without an explicit item ID is not
- * supported by the container
- */
- public Object addItem() throws UnsupportedOperationException;
-
- /**
- * Removes the Item identified by ItemId
from the Container.
- *
- * true
if the operation succeeded, false
- * if not
- * @throws UnsupportedOperationException
- * if the container does not support removing individual items
- */
- public boolean removeItem(Object itemId)
- throws UnsupportedOperationException;
-
- /**
- * Adds a new Property to all Items in the Container. The Property ID, data
- * type and default value of the new Property are given as parameters.
- *
- * This functionality is optional.
- *
- * @param propertyId
- * ID of the Property
- * @param type
- * Data type of the new Property
- * @param defaultValue
- * The value all created Properties are initialized to
- * @return true
if the operation succeeded, false
- * if not
- * @throws UnsupportedOperationException
- * if the container does not support explicitly adding container
- * properties
- */
- public boolean addContainerProperty(Object propertyId, Class> type,
- Object defaultValue) throws UnsupportedOperationException;
-
- /**
- * Removes a Property specified by the given Property ID from the Container.
- * Note that the Property will be removed from all Items in the Container.
- *
- * This functionality is optional.
- *
- * @param propertyId
- * ID of the Property to remove
- * @return true
if the operation succeeded, false
- * if not
- * @throws UnsupportedOperationException
- * if the container does not support removing container
- * properties
- */
- public boolean removeContainerProperty(Object propertyId)
- throws UnsupportedOperationException;
-
- /**
- * Removes all Items from the Container.
- *
- * true
if the operation succeeded, false
- * if not
- * @throws UnsupportedOperationException
- * if the container does not support removing all items
- */
- public boolean removeAllItems() throws UnsupportedOperationException;
-
- /**
- * Interface for Container classes whose {@link Item}s can be traversed in
- * order.
- *
- * addItemAfter()
methods should apply filters to the added
- * item after inserting it, possibly hiding it immediately. If the container
- * is being sorted, they may add items at the correct sorted position
- * instead of the given position. See also {@link Filterable} and
- * {@link Sortable} for more information.
- * itemId
. If the given Item is the last or not found in
- * the Container, null
is returned.
- *
- * @param itemId
- * ID of a visible Item in the Container
- * @return ID of the next visible Item or null
- */
- public Object nextItemId(Object itemId);
-
- /**
- * Gets the ID of the Item preceding the Item that corresponds to
- * itemId
. If the given Item is the first or not found in
- * the Container, null
is returned.
- *
- * @param itemId
- * ID of a visible Item in the Container
- * @return ID of the previous visible Item or null
- */
- public Object prevItemId(Object itemId);
-
- /**
- * Gets the ID of the first Item in the Container.
- *
- * @return ID of the first visible Item in the Container
- */
- public Object firstItemId();
-
- /**
- * Gets the ID of the last Item in the Container..
- *
- * @return ID of the last visible Item in the Container
- */
- public Object lastItemId();
-
- /**
- * Tests if the Item corresponding to the given Item ID is the first
- * Item in the Container.
- *
- * @param itemId
- * ID of an Item in the Container
- * @return true
if the Item is first visible item in the
- * Container, false
if not
- */
- public boolean isFirstId(Object itemId);
-
- /**
- * Tests if the Item corresponding to the given Item ID is the last Item
- * in the Container.
- *
- * @return true
if the Item is last visible item in the
- * Container, false
if not
- */
- public boolean isLastId(Object itemId);
-
- /**
- * Adds a new item after the given item.
- * addItem*()
methods may add
- * items that will be filtered out after addition or moved to another
- * position based on sorting.
- * true
to
- * sort in ascending order, false
to use
- * descending order.
- */
- void sort(Object[] propertyId, boolean[] ascending);
-
- /**
- * Gets the container property IDs which can be used to sort the items.
- *
- * @return the IDs of the properties that can be used for sorting the
- * container
- */
- Collection> getSortableContainerPropertyIds();
-
- }
-
- /**
- * Interface for Container classes whose {@link Item}s can be accessed by
- * their position in the container.
- * addItemAt()
methods may add
- * items that will be filtered out after addition or moved to another
- * position based on sorting.
- * true
for the returned index: 0 <= index < size(), or
- * index = -1 if there is no visible item with that id in the container.
- *
- * @param itemId
- * ID of an Item in the Container
- * @return index of the Item, or -1 if (the filtered and sorted view of)
- * the Container does not include the Item
- */
- public int indexOfId(Object itemId);
-
- /**
- * Gets the ID of an Item by an index number.
- *
- * @param index
- * Index of the requested id in (the filtered and sorted view
- * of) the Container
- * @return ID of the Item in the given index
- */
- public Object getIdByIndex(int index);
-
- /**
- * Adds a new item at given index (in the filtered view).
- * Container
classes whose Items can be arranged
- * hierarchically. This means that the Items in the container belong in a
- * tree-like structure, with the following quirks:
- *
- *
- */
- public interface Hierarchical extends Container {
-
- /**
- * Gets the IDs of all Items that are children of the specified Item.
- * The returned collection is unmodifiable.
- *
- * @param itemId
- * ID of the Item whose children the caller is interested in
- * @return An unmodifiable {@link java.util.Collection collection}
- * containing the IDs of all other Items that are children in
- * the container hierarchy
- */
- public Collection> getChildren(Object itemId);
-
- /**
- * Gets the ID of the parent Item of the specified Item.
- *
- * @param itemId
- * ID of the Item whose parent the caller wishes to find out.
- * @return the ID of the parent Item. Will be null
if the
- * specified Item is a root element.
- */
- public Object getParent(Object itemId);
-
- /**
- * Gets the IDs of all Items in the container that don't have a parent.
- * Such items are called root
Items. The returned
- * collection is unmodifiable.
- *
- * @return An unmodifiable {@link java.util.Collection collection}
- * containing IDs of all root elements of the container
- */
- public Collection> rootItemIds();
-
- /**
- * {@link #areChildrenAllowed(Object)} == true
). It is
- * also possible to detach a node from the hierarchy (and thus make it
- * root) by setting the parent null
.
- * newParentId
- * @param newParentId
- * ID of the Item that's to be the new parent of the Item
- * identified with itemId
- * @return true
if the operation succeeded,
- * false
if not
- */
- public boolean setParent(Object itemId, Object newParentId)
- throws UnsupportedOperationException;
-
- /**
- * Tests if the Item with given ID can have children.
- *
- * @param itemId
- * ID of the Item in the container whose child capability is
- * to be tested
- * @return true
if the specified Item exists in the
- * Container and it can have children, false
if
- * it's not found from the container or it can't have children.
- */
- public boolean areChildrenAllowed(Object itemId);
-
- /**
- * itemId
already has children and
- * {@link #areChildrenAllowed(Object)}
is false this method
- * fails and false
is returned.
- * false
.
- * true
if the operation succeeded,
- * false
if not
- */
- public boolean setChildrenAllowed(Object itemId,
- boolean areChildrenAllowed)
- throws UnsupportedOperationException;
-
- /**
- * Tests if the Item specified with itemId
is a root Item.
- * The hierarchical container can have more than one root and must have
- * at least one unless it is empty. The {@link #getParent(Object itemId)}
- * method always returns null
for root Items.
- *
- * @param itemId
- * ID of the Item whose root status is to be tested
- * @return true
if the specified Item is a root,
- * false
if not
- */
- public boolean isRoot(Object itemId);
-
- /**
- * itemId
has child Items
- * or if it is a leaf. The {@link #getChildren(Object itemId)} method
- * always returns null
for leaf Items.
- * true
if the specified Item has children,
- * false
if not (is a leaf)
- */
- public boolean hasChildren(Object itemId);
-
- /**
- * ItemId
from the
- * Container.
- * true
if the operation succeeded,
- * false
if not
- */
- @Override
- public boolean removeItem(Object itemId)
- throws UnsupportedOperationException;
- }
-
- /**
- * Interface that is implemented by containers which allow reducing their
- * visible contents based on a set of filters. This interface has been
- * renamed from {@link Filterable}, and implementing the new
- * {@link Filterable} instead of or in addition to {@link SimpleFilterable}
- * is recommended. This interface might be removed in future Vaadin
- * versions.
- * addItem*()
methods may add items that
- * will be filtered out after addition or moved to another position based on
- * sorting.
- * Container.Editor
interface
- * does not restrict the class from editing the Container contents
- * internally.
- * Event
object specifying the Container whose Item set has
- * changed (items added, removed or reordered).
- *
- * A simple property value change is not an item set change.
- */
- public interface ItemSetChangeEvent extends Serializable {
-
- /**
- * Gets the Property where the event occurred.
- *
- * @return source of the event
- */
- public Container getContainer();
- }
-
- /**
- * Container Item set change listener interface.
- *
- * An item set change refers to addition, removal or reordering of items in
- * the container. A simple property value change is not an item set change.
- */
- public interface ItemSetChangeListener extends Serializable {
-
- /**
- * Lets the listener know a Containers visible (filtered and/or sorted,
- * if applicable) Item set has changed.
- *
- * @param event
- * change event text
- */
- public void containerItemSetChange(Container.ItemSetChangeEvent event);
- }
-
- /**
- * The interface for adding and removing ItemSetChangeEvent
- * listeners. By implementing this interface a class explicitly announces
- * that it will generate a ItemSetChangeEvent
when its contents
- * are modified.
- *
- * An item set change refers to addition, removal or reordering of items in
- * the container. A simple property value change is not an item set change.
- *
- * addListener
and removeListener
methods. That
- * way the caller of these methods has no real way of finding out if the
- * class really will send the events, or if it just defines the methods to
- * be able to implement an interface.
- * Event
object specifying the Container whose Property set
- * has changed.
- *
- * A property set change means the addition, removal or other structural
- * changes to the properties of a container. Changes concerning the set of
- * items in the container and their property values are not property set
- * changes.
- */
- public interface PropertySetChangeEvent extends Serializable {
-
- /**
- * Retrieves the Container whose contents have been modified.
- *
- * @return Source Container of the event.
- */
- public Container getContainer();
- }
-
- /**
- * The listener interface for receiving PropertySetChangeEvent
- * objects.
- *
- * A property set change means the addition, removal or other structural
- * change of the properties (supported property IDs) of a container. Changes
- * concerning the set of items in the container and their property values
- * are not property set changes.
- */
- public interface PropertySetChangeListener extends Serializable {
-
- /**
- * Notifies this listener that the set of property IDs supported by the
- * Container has changed.
- *
- * @param event
- * Change event.
- */
- public void containerPropertySetChange(
- Container.PropertySetChangeEvent event);
- }
-
- /**
- * PropertySetChangeEvent
- * listeners. By implementing this interface a class explicitly announces
- * that it will generate a PropertySetChangeEvent
when the set
- * of property IDs supported by the container is modified.
- * addListener
and removeListener
methods. That
- * way the caller of these methods has no real way of finding out if the
- * class really will send the events, or if it just defines the methods to
- * be able to implement an interface.
- * null
is
- * returned.
- *
- * @param id
- * identifier of the Property to get
- * @return the Property with the given ID or null
- */
- public Property> getItemProperty(Object id);
-
- /**
- * Gets the collection of IDs of all Properties stored in the Item.
- *
- * @return unmodifiable collection containing IDs of the Properties stored
- * the Item
- */
- public Collection> getItemPropertyIds();
-
- /**
- * Tries to add a new Property into the Item.
- *
- * true
if the operation succeeded, false
- * if not
- * @throws UnsupportedOperationException
- * if the operation is not supported.
- */
- public boolean addItemProperty(Object id, Property property)
- throws UnsupportedOperationException;
-
- /**
- * Removes the Property identified by ID from the Item.
- *
- * true
if the operation succeeded
- * @throws UnsupportedOperationException
- * if the operation is not supported. false
if not
- */
- public boolean removeItemProperty(Object id)
- throws UnsupportedOperationException;
-
- /**
- * Interface implemented by viewer classes capable of using an Item as a
- * data source.
- */
- public interface Viewer extends Serializable {
-
- /**
- * Sets the Item that serves as the data source of the viewer.
- *
- * @param newDataSource
- * The new data source Item
- */
- public void setItemDataSource(Item newDataSource);
-
- /**
- * Gets the Item serving as the data source of the viewer.
- *
- * @return data source Item
- */
- public Item getItemDataSource();
- }
-
- /**
- * Interface implemented by the Editor
classes capable of
- * editing the Item. Implementing this interface means that the Item serving
- * as the data source of the editor can be modified through it.
- * Item.Editor
interface does not
- * restrict the class from editing the contents of an internally.
- * Event
object specifying the Item whose contents has been
- * changed through the Property
interface.
- * PropertySetChangeEvent
- * objects.
- */
- public interface PropertySetChangeListener extends Serializable {
-
- /**
- * Notifies this listener that the Item's property set has changed.
- *
- * @param event
- * Property set change event object
- */
- public void itemPropertySetChange(Item.PropertySetChangeEvent event);
- }
-
- /**
- * The interface for adding and removing PropertySetChangeEvent
- * listeners. By implementing this interface a class explicitly announces
- * that it will generate a PropertySetChangeEvent
when its
- * Property set is modified.
- * addListener
and removeListener
methods. That
- * way the caller of these methods has no real way of finding out if the
- * class really will send the events, or if it just defines the methods to
- * be able to implement an interface.
- * Property
is a simple data object that contains one typed
- * value. This interface contains methods to inspect and modify the stored value
- * and its type, and the object's read-only state.
- * Property
also defines the events
- * ReadOnlyStatusChangeEvent
and ValueChangeEvent
, and
- * the associated listener
and notifier
interfaces.
- * Property.Viewer
interface should be used to attach the
- * Property to an external data source. This way the value in the data source
- * can be inspected using the Property
interface.
- * Property.editor
interface should be implemented if the value
- * needs to be changed through the implementing class.
- * Property.ReadOnlyException
in this function.
- * getValue
and
- * setValue
must be compatible with this type: one must be able
- * to safely cast the value returned from getValue
to the given
- * type and pass any variable assignable to this type as an argument to
- * setValue
.
- *
- * @return type of the Property
- */
- public Class extends T> getType();
-
- /**
- * Tests if the Property is in read-only mode. In read-only mode calls to
- * the method setValue
will throw
- * ReadOnlyException
and will not modify the value of the
- * Property.
- *
- * @return true
if the Property is in read-only mode,
- * false
if it's not
- */
- public boolean isReadOnly();
-
- /**
- * Sets the Property's read-only mode to the specified status.
- *
- * This functionality is optional, but all properties must implement the
- * isReadOnly
mode query correctly.
- *
- * @param newStatus
- * new read-only status of the Property
- */
- public void setReadOnly(boolean newStatus);
-
- /**
- * A Property that is capable of handle a transaction that can end in commit
- * or rollback.
- *
- * Note that this does not refer to e.g. database transactions but rather
- * two-phase commit that allows resetting old field values on a form etc. if
- * the commit of one of the properties fails after others have already been
- * committed. If
- *
- * @param Exception
object that signals that a requested Property
- * modification failed because it's in read-only mode.
- *
- * @author Vaadin Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
- @SuppressWarnings("serial")
- public class ReadOnlyException extends RuntimeException {
-
- /**
- * Constructs a new ReadOnlyException
without a detail
- * message.
- */
- public ReadOnlyException() {
- }
-
- /**
- * Constructs a new ReadOnlyException
with the specified
- * detail message.
- *
- * @param msg
- * the detail message
- */
- public ReadOnlyException(String msg) {
- super(msg);
- }
- }
-
- /**
- * Interface implemented by the viewer classes capable of using a Property
- * as a data source.
- *
- * @author Vaadin Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
- public interface Viewer extends Serializable {
-
- /**
- * Sets the Property that serves as the data source of the viewer.
- *
- * @param newDataSource
- * the new data source Property
- */
- public void setPropertyDataSource(Property newDataSource);
-
- /**
- * Gets the Property serving as the data source of the viewer.
- *
- * @return the Property serving as the viewers data source
- */
- public Property getPropertyDataSource();
- }
-
- /**
- * Interface implemented by the editor classes capable of editing the
- * Property.
- * ReadOnlyException
being thrown.
- * Event
object specifying the Property whose value has been
- * changed.
- *
- * @author Vaadin Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
- public interface ValueChangeEvent extends Serializable {
-
- /**
- * Retrieves the Property that has been modified.
- *
- * @return source Property of the event
- */
- public Property getProperty();
- }
-
- /**
- * The listener
interface for receiving
- * ValueChangeEvent
objects.
- *
- * @author Vaadin Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
- public interface ValueChangeListener extends Serializable {
-
- /**
- * Notifies this listener that the Property's value has changed.
- *
- * @param event
- * value change event object
- */
- public void valueChange(Property.ValueChangeEvent event);
- }
-
- /**
- * The interface for adding and removing ValueChangeEvent
- * listeners. If a Property wishes to allow other objects to receive
- * ValueChangeEvent
generated by it, it must implement this
- * interface.
- * addListener
and removeListener
methods. That
- * way the caller of these methods has no real way of finding out if the
- * class really will send the events, or if it just defines the methods to
- * be able to implement an interface.
- * Event
object specifying the Property whose read-only
- * status has been changed.
- *
- * @author Vaadin Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
- public interface ReadOnlyStatusChangeEvent extends Serializable {
-
- /**
- * Property whose read-only state has changed.
- *
- * @return source Property of the event.
- */
- public Property getProperty();
- }
-
- /**
- * The listener interface for receiving
- * ReadOnlyStatusChangeEvent
objects.
- *
- * @author Vaadin Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
- public interface ReadOnlyStatusChangeListener extends Serializable {
-
- /**
- * Notifies this listener that a Property's read-only status has
- * changed.
- *
- * @param event
- * Read-only status change event object
- */
- public void readOnlyStatusChange(
- Property.ReadOnlyStatusChangeEvent event);
- }
-
- /**
- * The interface for adding and removing
- * ReadOnlyStatusChangeEvent
listeners. If a Property wishes to
- * allow other objects to receive ReadOnlyStatusChangeEvent
- * generated by it, it must implement this interface.
- * addListener
and removeListener
methods. That
- * way the caller of these methods has no real way of finding out if the
- * class really will send the events, or if it just defines the methods to
- * be able to implement an interface.
- * validate
method
- * is no longer called in {@link #isValid()}.
- * null
.
- * null
- */
- public Collectionfalse
.
- * true
if the registered validators concur that the
- * value is valid, false
otherwise
- */
- public boolean isValid();
-
- /**
- * Validator.InvalidValueException
- * true
.
- *
- * This binds the firstName TextField to a "firstName" property in the item, - * lastName TextField to a "last" property and builds an age TextField using - * the field factory and then binds it to the "age" property. - *
- * - * @param objectWithMemberFields - * The object that contains (Java) member fields to build and - * bind - * @throws BindException - * If there is a problem binding or building a field - */ - public void buildAndBindMemberFields(Object objectWithMemberFields) - throws BindException { - buildAndBindMemberFields(objectWithMemberFields, true); - } - - /** - * Binds member fields found in the given object and optionally builds - * member fields that have not been initialized. - *- * This method processes all (Java) member fields whose type extends - * {@link Field} and that can be mapped to a property id. Property id - * mapping is done based on the field name or on a @{@link PropertyId} - * annotation on the field. Fields that are not initialized (null) are built - * using the field factory is buildFields is true. All non-null fields for - * which a property id can be determined are bound to the property id. - *
- * - * @param objectWithMemberFields - * The object that contains (Java) member fields to build and - * bind - * @throws BindException - * If there is a problem binding or building a field - */ - protected void buildAndBindMemberFields(Object objectWithMemberFields, - boolean buildFields) throws BindException { - Class> objectClass = objectWithMemberFields.getClass(); - - for (java.lang.reflect.Field memberField : objectClass - .getDeclaredFields()) { - - if (!Field.class.isAssignableFrom(memberField.getType())) { - // Process next field - continue; - } - - PropertyId propertyIdAnnotation = memberField - .getAnnotation(PropertyId.class); - - Class extends Field> fieldType = (Class extends Field>) memberField - .getType(); - - Object propertyId = null; - if (propertyIdAnnotation != null) { - // @PropertyId(propertyId) always overrides property id - propertyId = propertyIdAnnotation.value(); - } else { - propertyId = memberField.getName(); - } - - // Ensure that the property id exists - Class> propertyType; - - try { - propertyType = getPropertyType(propertyId); - } catch (BindException e) { - // Property id was not found, skip this field - continue; - } - - Field> field; - try { - // Get the field from the object - field = (Field>) ReflectTools.getJavaFieldValue( - objectWithMemberFields, memberField); - } catch (Exception e) { - // If we cannot determine the value, just skip the field and try - // the next one - continue; - } - - if (field == null && buildFields) { - Caption captionAnnotation = memberField - .getAnnotation(Caption.class); - String caption; - if (captionAnnotation != null) { - caption = captionAnnotation.value(); - } else { - caption = DefaultFieldFactory - .createCaptionByPropertyId(propertyId); - } - - // Create the component (Field) - field = build(caption, propertyType, fieldType); - - // Store it in the field - try { - ReflectTools.setJavaFieldValue(objectWithMemberFields, - memberField, field); - } catch (IllegalArgumentException e) { - throw new BindException("Could not assign value to field '" - + memberField.getName() + "'", e); - } catch (IllegalAccessException e) { - throw new BindException("Could not assign value to field '" - + memberField.getName() + "'", e); - } catch (InvocationTargetException e) { - throw new BindException("Could not assign value to field '" - + memberField.getName() + "'", e); - } - } - - if (field != null) { - // Bind it to the property id - bind(field, propertyId); - } - } - } - - public static class CommitException extends Exception { - - public CommitException() { - super(); - // TODO Auto-generated constructor stub - } - - public CommitException(String message, Throwable cause) { - super(message, cause); - // TODO Auto-generated constructor stub - } - - public CommitException(String message) { - super(message); - // TODO Auto-generated constructor stub - } - - public CommitException(Throwable cause) { - super(cause); - // TODO Auto-generated constructor stub - } - - } - - public static class BindException extends RuntimeException { - - public BindException(String message) { - super(message); - } - - public BindException(String message, Throwable t) { - super(message, t); - } - - } - - /** - * Builds a field and binds it to the given property id using the field - * binder. - * - * @param propertyId - * The property id to bind to. Must be present in the field - * finder. - * @throws BindException - * If there is a problem while building or binding - * @return The created and bound field - */ - public Field> buildAndBind(Object propertyId) throws BindException { - String caption = DefaultFieldFactory - .createCaptionByPropertyId(propertyId); - return buildAndBind(caption, propertyId); - } - - /** - * Builds a field using the given caption and binds it to the given property - * id using the field binder. - * - * @param caption - * The caption for the field - * @param propertyId - * The property id to bind to. Must be present in the field - * finder. - * @throws BindException - * If there is a problem while building or binding - * @return The created and bound field. Can be any type of {@link Field}. - */ - public Field> buildAndBind(String caption, Object propertyId) - throws BindException { - Class> type = getPropertyType(propertyId); - return buildAndBind(caption, propertyId, Field.class); - - } - - /** - * Builds a field using the given caption and binds it to the given property - * id using the field binder. Ensures the new field is of the given type. - * - * @param caption - * The caption for the field - * @param propertyId - * The property id to bind to. Must be present in the field - * finder. - * @throws BindException - * If the field could not be created - * @return The created and bound field. Can be any type of {@link Field}. - */ - - public- * The data type is the type that we want to edit using the field. The field - * type is the type of field we want to create, can be {@link Field} if any - * Field is good. - *
- * - * @param caption - * The caption for the new field - * @param dataType - * The data model type that we want to edit using the field - * @param fieldType - * The type of field that we want to create - * @return A Field capable of editing the given type - * @throws BindException - * If the field could not be created - */ - protectedContains interfaces for the data layer, mainly for binding typed -data and data collections to components, and for validating data.
- -The package contains a three-tiered structure for typed data -objects and collections of them:
- -For more information on the data model, see the Data model -chapter in Book of Vaadin.
- -A {@link com.vaadin.data.Buffered Buffered} implementor is able -to track and buffer changes and commit or discard them later.
- -{@link com.vaadin.data.Validator Validator} implementations are -used to validate data, typically the value of a {@link -com.vaadin.ui.Field Field}. One or more {@link com.vaadin.data.Validator -Validators} can be added to a {@link com.vaadin.data.Validatable -Validatable} implementor and then used to validate the value of the -Validatable.
- - - - diff --git a/src/com/vaadin/data/util/AbstractBeanContainer.java b/src/com/vaadin/data/util/AbstractBeanContainer.java deleted file mode 100644 index 2f428d2cb6..0000000000 --- a/src/com/vaadin/data/util/AbstractBeanContainer.java +++ /dev/null @@ -1,856 +0,0 @@ -/* -@VaadinApache2LicenseForJavaFiles@ - */ -package com.vaadin.data.util; - -import java.io.Serializable; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import com.vaadin.data.Container; -import com.vaadin.data.Container.Filterable; -import com.vaadin.data.Container.PropertySetChangeNotifier; -import com.vaadin.data.Container.SimpleFilterable; -import com.vaadin.data.Container.Sortable; -import com.vaadin.data.Item; -import com.vaadin.data.Property; -import com.vaadin.data.Property.ValueChangeEvent; -import com.vaadin.data.Property.ValueChangeListener; -import com.vaadin.data.Property.ValueChangeNotifier; -import com.vaadin.data.util.MethodProperty.MethodException; -import com.vaadin.data.util.filter.SimpleStringFilter; -import com.vaadin.data.util.filter.UnsupportedFilterException; - -/** - * An abstract base class for in-memory containers for JavaBeans. - * - *- * The properties of the container are determined automatically by introspecting - * the used JavaBean class and explicitly adding or removing properties is not - * supported. Only beans of the same type can be added to the container. - *
- * - *- * Subclasses should implement any public methods adding items to the container, - * typically calling the protected methods {@link #addItem(Object, Object)}, - * {@link #addItemAfter(Object, Object, Object)} and - * {@link #addItemAt(int, Object, Object)}. - *
- * - * @paramevent
object specifying the container whose Property set
- * has changed.
- *
- * This class does not provide information about which properties were
- * concerned by the change, but subclasses can provide additional
- * information about the changes.
- */
- protected static class BasePropertySetChangeEvent extends EventObject
- implements Container.PropertySetChangeEvent, Serializable {
-
- protected BasePropertySetChangeEvent(Container source) {
- super(source);
- }
-
- @Override
- public Container getContainer() {
- return (Container) getSource();
- }
- }
-
- /**
- * An event
object specifying the container whose Item set has
- * changed.
- *
- * This class does not provide information about the exact changes
- * performed, but subclasses can add provide additional information about
- * the changes.
- */
- protected static class BaseItemSetChangeEvent extends EventObject implements
- Container.ItemSetChangeEvent, Serializable {
-
- protected BaseItemSetChangeEvent(Container source) {
- super(source);
- }
-
- @Override
- public Container getContainer() {
- return (Container) getSource();
- }
- }
-
- // PropertySetChangeNotifier
-
- /**
- * Implementation of the corresponding method in
- * {@link PropertySetChangeNotifier}, override with the corresponding public
- * method and implement the interface to use this.
- *
- * @see PropertySetChangeNotifier#addListener(com.vaadin.data.Container.PropertySetChangeListener)
- */
- protected void addListener(Container.PropertySetChangeListener listener) {
- if (getPropertySetChangeListeners() == null) {
- setPropertySetChangeListeners(new LinkedListsort(Object[], boolean[])
.
- *
- * To implement {@link Filterable}, subclasses need to implement the methods
- * {@link Filterable#addContainerFilter(com.vaadin.data.Container.Filter)}
- * (calling {@link #addFilter(Filter)}),
- * {@link Filterable#removeAllContainerFilters()} (calling
- * {@link #removeAllFilters()}) and
- * {@link Filterable#removeContainerFilter(com.vaadin.data.Container.Filter)}
- * (calling {@link #removeFilter(com.vaadin.data.Container.Filter)}).
- *
- * To implement {@link SimpleFilterable}, subclasses also need to implement the
- * methods
- * {@link SimpleFilterable#addContainerFilter(Object, String, boolean, boolean)}
- * and {@link SimpleFilterable#removeContainerFilters(Object)} calling
- * {@link #addFilter(com.vaadin.data.Container.Filter)} and
- * {@link #removeFilters(Object)} respectively.
- *
- * @param itemSorter
has been prepared for the sort
- * operation. Typically this method calls
- * Collections.sort(aCollection, getItemSorter())
on all arrays
- * (containing item ids) that need to be sorted.
- *
- */
- protected void doSort() {
- Collections.sort(getAllItemIds(), getItemSorter());
- }
-
- /**
- * Returns the sortable property identifiers for the container. Can be used
- * to implement {@link Sortable#getSortableContainerPropertyIds()}.
- */
- protected Collection> getSortablePropertyIds() {
- LinkedList- * Caller should initiate filtering after calling this method. - *
- * - * For internal use only - subclasses should use - * {@link #internalAddItemAtEnd(Object, Item, boolean)}, - * {@link #internalAddItemAt(int, Object, Item, boolean)} and - * {@link #internalAddItemAfter(Object, Object, Item, boolean)} instead. - * - * @param position - * The position at which the item should be inserted in the - * unfiltered collection of items - * @param itemId - * The item identifier for the item to insert - * @param item - * The item to insert - * - * @return ITEMCLASS if the item was added successfully, null otherwise - */ - private ITEMCLASS internalAddAt(int position, ITEMIDTYPE itemId, - ITEMCLASS item) { - if (position < 0 || position > getAllItemIds().size() || itemId == null - || item == null) { - return null; - } - // Make sure that the item has not been added previously - if (getAllItemIds().contains(itemId)) { - return null; - } - - // "filteredList" will be updated in filterAll() which should be invoked - // by the caller after calling this method. - getAllItemIds().add(position, itemId); - registerNewItem(position, itemId, item); - - return item; - } - - /** - * Add an item at the end of the container, and perform filtering if - * necessary. An event is fired if the filtered view changes. - * - * @param newItemId - * @param item - * new item to add - * @param filter - * true to perform filtering and send event after adding the - * item, false to skip these operations for batch inserts - if - * false, caller needs to make sure these operations are - * performed at the end of the batch - * @return item added or null if no item was added - */ - protected ITEMCLASS internalAddItemAtEnd(ITEMIDTYPE newItemId, - ITEMCLASS item, boolean filter) { - ITEMCLASS newItem = internalAddAt(getAllItemIds().size(), newItemId, - item); - if (newItem != null && filter) { - // TODO filter only this item, use fireItemAdded() - filterAll(); - if (!isFiltered()) { - // TODO hack: does not detect change in filterAll() in this case - fireItemAdded(indexOfId(newItemId), newItemId, item); - } - } - return newItem; - } - - /** - * Add an item after a given (visible) item, and perform filtering. An event - * is fired if the filtered view changes. - * - * The new item is added at the beginning if previousItemId is null. - * - * @param previousItemId - * item id of a visible item after which to add the new item, or - * null to add at the beginning - * @param newItemId - * @param item - * new item to add - * @param filter - * true to perform filtering and send event after adding the - * item, false to skip these operations for batch inserts - if - * false, caller needs to make sure these operations are - * performed at the end of the batch - * @return item added or null if no item was added - */ - protected ITEMCLASS internalAddItemAfter(ITEMIDTYPE previousItemId, - ITEMIDTYPE newItemId, ITEMCLASS item, boolean filter) { - // only add if the previous item is visible - ITEMCLASS newItem = null; - if (previousItemId == null) { - newItem = internalAddAt(0, newItemId, item); - } else if (containsId(previousItemId)) { - newItem = internalAddAt( - getAllItemIds().indexOf(previousItemId) + 1, newItemId, - item); - } - if (newItem != null && filter) { - // TODO filter only this item, use fireItemAdded() - filterAll(); - if (!isFiltered()) { - // TODO hack: does not detect change in filterAll() in this case - fireItemAdded(indexOfId(newItemId), newItemId, item); - } - } - return newItem; - } - - /** - * Add an item at a given (visible after filtering) item index, and perform - * filtering. An event is fired if the filtered view changes. - * - * @param index - * position where to add the item (visible/view index) - * @param newItemId - * @param item - * new item to add - * @param filter - * true to perform filtering and send event after adding the - * item, false to skip these operations for batch inserts - if - * false, caller needs to make sure these operations are - * performed at the end of the batch - * @return item added or null if no item was added - */ - protected ITEMCLASS internalAddItemAt(int index, ITEMIDTYPE newItemId, - ITEMCLASS item, boolean filter) { - if (index < 0 || index > size()) { - return null; - } else if (index == 0) { - // add before any item, visible or not - return internalAddItemAfter(null, newItemId, item, filter); - } else { - // if index==size(), adds immediately after last visible item - return internalAddItemAfter(getIdByIndex(index - 1), newItemId, - item, filter); - } - } - - /** - * Registers a new item as having been added to the container. This can - * involve storing the item or any relevant information about it in internal - * container-specific collections if necessary, as well as registering - * listeners etc. - * - * The full identifier list in {@link AbstractInMemoryContainer} has already - * been updated to reflect the new item when this method is called. - * - * @param position - * @param itemId - * @param item - */ - protected void registerNewItem(int position, ITEMIDTYPE itemId, - ITEMCLASS item) { - } - - // item set change notifications - - /** - * Notify item set change listeners that an item has been added to the - * container. - * - * Unless subclasses specify otherwise, the default notification indicates a - * full refresh. - * - * @param postion - * position of the added item in the view (if visible) - * @param itemId - * id of the added item - * @param item - * the added item - */ - protected void fireItemAdded(int position, ITEMIDTYPE itemId, ITEMCLASS item) { - fireItemSetChange(); - } - - /** - * Notify item set change listeners that an item has been removed from the - * container. - * - * Unless subclasses specify otherwise, the default notification indicates a - * full refresh. - * - * @param postion - * position of the removed item in the view prior to removal (if - * was visible) - * @param itemId - * id of the removed item, of type {@link Object} to satisfy - * {@link Container#removeItem(Object)} API - */ - protected void fireItemRemoved(int position, Object itemId) { - fireItemSetChange(); - } - - // visible and filtered item identifier lists - - /** - * Returns the internal list of visible item identifiers after filtering. - * - * For internal use only. - */ - protected Listremove*Filter*
(which also re-filter the container) instead
- * when possible.
- *
- * @param filters
- */
- protected void setFilters(SetProperty
in human readable textual
- * format.
- *
- * @return String representation of the value stored in the Property
- * @deprecated use {@link #getValue()} instead and possibly toString on that
- */
- @Deprecated
- @Override
- public String toString() {
- throw new UnsupportedOperationException(
- "Use Property.getValue() instead of " + getClass()
- + ".toString()");
- }
-
- /* Events */
-
- /**
- * An Event
object specifying the Property whose read-only
- * status has been changed.
- */
- protected static class ReadOnlyStatusChangeEvent extends
- java.util.EventObject implements Property.ReadOnlyStatusChangeEvent {
-
- /**
- * Constructs a new read-only status change event for this object.
- *
- * @param source
- * source object of the event.
- */
- protected ReadOnlyStatusChangeEvent(Property source) {
- super(source);
- }
-
- /**
- * Gets the Property whose read-only state has changed.
- *
- * @return source Property of the event.
- */
- @Override
- public Property getProperty() {
- return (Property) getSource();
- }
-
- }
-
- /**
- * Registers a new read-only status change listener for this Property.
- *
- * @param listener
- * the new Listener to be registered.
- */
- @Override
- public void addListener(Property.ReadOnlyStatusChangeListener listener) {
- if (readOnlyStatusChangeListeners == null) {
- readOnlyStatusChangeListeners = new LinkedListEvent
object specifying the Property whose value has been
- * changed.
- */
- private static class ValueChangeEvent extends java.util.EventObject
- implements Property.ValueChangeEvent {
-
- /**
- * Constructs a new value change event for this object.
- *
- * @param source
- * source object of the event.
- */
- protected ValueChangeEvent(Property source) {
- super(source);
- }
-
- /**
- * Gets the Property whose value has changed.
- *
- * @return source Property of the event.
- */
- @Override
- public Property getProperty() {
- return (Property) getSource();
- }
-
- }
-
- @Override
- public void addListener(ValueChangeListener listener) {
- if (valueChangeListeners == null) {
- valueChangeListeners = new LinkedList- * The properties of the container are determined automatically by introspecting - * the used JavaBean class. Only beans of the same type can be added to the - * container. - *
- * - *- * In BeanContainer (unlike {@link BeanItemContainer}), the item IDs do not have - * to be the beans themselves. The container can be used either with explicit - * item IDs or the item IDs can be generated when adding beans. - *
- * - *- * To use explicit item IDs, use the methods {@link #addItem(Object, Object)}, - * {@link #addItemAfter(Object, Object, Object)} and - * {@link #addItemAt(int, Object, Object)}. - *
- * - *- * If a bean id resolver is set using - * {@link #setBeanIdResolver(com.vaadin.data.util.AbstractBeanContainer.BeanIdResolver)} - * or {@link #setBeanIdProperty(Object)}, the methods {@link #addBean(Object)}, - * {@link #addBeanAfter(Object, Object)}, {@link #addBeanAt(int, Object)} and - * {@link #addAll(java.util.Collection)} can be used to add items to the - * container. If one of these methods is called, the resolver is used to - * generate an identifier for the item (must not return null). - *
- * - *- * Note that explicit item identifiers can also be used when a resolver has been - * set by calling the addItem*() methods - the resolver is only used when adding - * beans using the addBean*() or {@link #addAll(Collection)} methods. - *
- * - *- * It is not possible to add additional properties to the container and nested - * bean properties are not supported. - *
- * - * @param
- * Creates a new instance of BeanItem
and adds all properties
- * of a Java Bean to it. The properties are identified by their respective
- * bean names.
- *
- * Note : This version only supports introspectable bean properties and
- * their getter and setter methods. Stand-alone is
and
- * are
methods are not supported.
- *
- * Creates a new instance of BeanItem
using a pre-computed set
- * of properties. The properties are identified by their respective bean
- * names.
- *
- * Creates a new instance of BeanItem
and adds all listed
- * properties of a Java Bean to it - in specified order. The properties are
- * identified by their respective bean names.
- *
- * Note : This version only supports introspectable bean properties and
- * their getter and setter methods. Stand-alone is
and
- * are
methods are not supported.
- *
- * Creates a new instance of BeanItem
and adds all listed
- * properties of a Java Bean to it - in specified order. The properties are
- * identified by their respective bean names.
- *
- * Note : This version only supports introspectable bean properties and
- * their getter and setter methods. Stand-alone is
and
- * are
methods are not supported.
- *
- * Perform introspection on a Java Bean class to find its properties. - *
- * - *
- * Note : This version only supports introspectable bean properties and
- * their getter and setter methods. Stand-alone is
and
- * are
methods are not supported.
- *
- * The properties of the container are determined automatically by introspecting - * the used JavaBean class. Only beans of the same type can be added to the - * container. - *
- * - *- * BeanItemContainer uses the beans themselves as identifiers. The - * {@link Object#hashCode()} of a bean is used when storing and looking up beans - * so it must not change during the lifetime of the bean (it should not depend - * on any part of the bean that can be modified). Typically this restricts the - * implementation of {@link Object#equals(Object)} as well in order for it to - * fulfill the contract between {@code equals()} and {@code hashCode()}. - *
- * - *- * To add items to the container, use the methods {@link #addBean(Object)}, - * {@link #addBeanAfter(Object, Object)} and {@link #addBeanAt(int, Object)}. - * Also {@link #addItem(Object)}, {@link #addItemAfter(Object, Object)} and - * {@link #addItemAt(int, Object)} can be used as synonyms for them. - *
- * - *- * It is not possible to add additional properties to the container and nested - * bean properties are not supported. - *
- * - * @param- * A wrapper class for adding external hierarchy to containers not implementing - * the {@link com.vaadin.data.Container.Hierarchical} interface. - *
- * - *- * If the wrapped container is changed directly (that is, not through the - * wrapper), and does not implement Container.ItemSetChangeNotifier and/or - * Container.PropertySetChangeNotifier the hierarchy information must be updated - * with the {@link #updateHierarchicalWrapper()} method. - *
- * - * @author Vaadin Ltd. - * @version - * @VERSION@ - * @since 3.0 - */ -@SuppressWarnings("serial") -public class ContainerHierarchicalWrapper implements Container.Hierarchical, - Container.ItemSetChangeNotifier, Container.PropertySetChangeNotifier { - - /** The wrapped container */ - private final Container container; - - /** Set of IDs of those contained Items that can't have children. */ - private HashSetContainer.Hierarchical
interface.
- *
- * @param toBeWrapped
- * the container that needs to be accessed hierarchically
- * @see #updateHierarchicalWrapper()
- */
- public ContainerHierarchicalWrapper(Container toBeWrapped) {
-
- container = toBeWrapped;
- hierarchical = container instanceof Container.Hierarchical;
-
- // Check arguments
- if (container == null) {
- throw new NullPointerException("Null can not be wrapped");
- }
-
- // Create initial order if needed
- if (!hierarchical) {
- noChildrenAllowed = new HashSet- * Note : The Item is not removed from the underlying Container. - *
- * - * @param itemId - * the ID of the item to remove from the hierarchy. - */ - private void removeFromHierarchyWrapper(Object itemId) { - - LinkedList
- * Sets the given Item's capability to have children. If the Item identified
- * with the itemId already has children and the areChildrenAllowed is false
- * this method fails and false
is returned; the children must
- * be first explicitly removed with
- * {@link #setParent(Object itemId, Object newParentId)} or
- * {@link com.vaadin.data.Container#removeItem(Object itemId)}.
- *
true
if the operation succeeded, false
- * if not
- */
- @Override
- public boolean setChildrenAllowed(Object itemId, boolean childrenAllowed) {
-
- // If the wrapped container implements the method directly, use it
- if (hierarchical) {
- return ((Container.Hierarchical) container).setChildrenAllowed(
- itemId, childrenAllowed);
- }
-
- // Check that the item is in the container
- if (!containsId(itemId)) {
- return false;
- }
-
- // Update status
- if (childrenAllowed) {
- noChildrenAllowed.remove(itemId);
- } else {
- noChildrenAllowed.add(itemId);
- }
-
- return true;
- }
-
- /**
- *
- * Sets the parent of an Item. The new parent item must exist and be able to
- * have children. (canHaveChildren(newParentId) == true
). It is
- * also possible to detach a node from the hierarchy (and thus make it root)
- * by setting the parent null
.
- *
true
if the operation succeeded, false
- * if not
- */
- @Override
- public boolean setParent(Object itemId, Object newParentId) {
-
- // If the wrapped container implements the method directly, use it
- if (hierarchical) {
- return ((Container.Hierarchical) container).setParent(itemId,
- newParentId);
- }
-
- // Check that the item is in the container
- if (!containsId(itemId)) {
- return false;
- }
-
- // Get the old parent
- final Object oldParentId = parent.get(itemId);
-
- // Check if no change is necessary
- if ((newParentId == null && oldParentId == null)
- || (newParentId != null && newParentId.equals(oldParentId))) {
- return true;
- }
-
- // Making root
- if (newParentId == null) {
-
- // Remove from old parents children list
- final LinkedListnull
if the
- * operation failed
- * @throws UnsupportedOperationException
- * if the addItem is not supported.
- */
- @Override
- public Object addItem() throws UnsupportedOperationException {
-
- final Object id = container.addItem();
- if (!hierarchical && id != null) {
- addToHierarchyWrapper(id);
- }
- return id;
- }
-
- /**
- * Adds a new Item by its ID to the underlying container and to the
- * hierarchy.
- *
- * @param itemId
- * the ID of the Item to be created.
- * @return the added Item or null
if the operation failed.
- * @throws UnsupportedOperationException
- * if the addItem is not supported.
- */
- @Override
- public Item addItem(Object itemId) throws UnsupportedOperationException {
-
- // Null ids are not accepted
- if (itemId == null) {
- throw new NullPointerException("Container item id can not be null");
- }
-
- final Item item = container.addItem(itemId);
- if (!hierarchical && item != null) {
- addToHierarchyWrapper(itemId);
- }
- return item;
- }
-
- /**
- * Removes all items from the underlying container and from the hierarcy.
- *
- * @return true
if the operation succeeded, false
- * if not
- * @throws UnsupportedOperationException
- * if the removeAllItems is not supported.
- */
- @Override
- public boolean removeAllItems() throws UnsupportedOperationException {
-
- final boolean success = container.removeAllItems();
-
- if (!hierarchical && success) {
- roots.clear();
- parent.clear();
- children.clear();
- noChildrenAllowed.clear();
- }
- return success;
- }
-
- /**
- * Removes an Item specified by the itemId from the underlying container and
- * from the hierarchy.
- *
- * @param itemId
- * the ID of the Item to be removed.
- * @return true
if the operation succeeded, false
- * if not
- * @throws UnsupportedOperationException
- * if the removeItem is not supported.
- */
- @Override
- public boolean removeItem(Object itemId)
- throws UnsupportedOperationException {
-
- final boolean success = container.removeItem(itemId);
-
- if (!hierarchical && success) {
- removeFromHierarchyWrapper(itemId);
- }
-
- return success;
- }
-
- /**
- * Removes the Item identified by given itemId and all its children.
- *
- * @see #removeItem(Object)
- * @param itemId
- * the identifier of the Item to be removed
- * @return true if the operation succeeded
- */
- public boolean removeItemRecursively(Object itemId) {
- return HierarchicalContainer.removeItemRecursively(this, itemId);
- }
-
- /**
- * Adds a new Property to all Items in the Container.
- *
- * @param propertyId
- * the ID of the new Property.
- * @param type
- * the Data type of the new Property.
- * @param defaultValue
- * the value all created Properties are initialized to.
- * @return true
if the operation succeeded, false
- * if not
- * @throws UnsupportedOperationException
- * if the addContainerProperty is not supported.
- */
- @Override
- public boolean addContainerProperty(Object propertyId, Class> type,
- Object defaultValue) throws UnsupportedOperationException {
-
- return container.addContainerProperty(propertyId, type, defaultValue);
- }
-
- /**
- * Removes the specified Property from the underlying container and from the
- * hierarchy.
- * - * Note : The Property will be removed from all Items in the Container. - *
- * - * @param propertyId - * the ID of the Property to remove. - * @returntrue
if the operation succeeded, false
- * if not
- * @throws UnsupportedOperationException
- * if the removeContainerProperty is not supported.
- */
- @Override
- public boolean removeContainerProperty(Object propertyId)
- throws UnsupportedOperationException {
- return container.removeContainerProperty(propertyId);
- }
-
- /*
- * Does the container contain the specified Item? Don't add a JavaDoc
- * comment here, we use the default documentation from implemented
- * interface.
- */
- @Override
- public boolean containsId(Object itemId) {
- return container.containsId(itemId);
- }
-
- /*
- * Gets the specified Item from the container. Don't add a JavaDoc comment
- * here, we use the default documentation from implemented interface.
- */
- @Override
- public Item getItem(Object itemId) {
- return container.getItem(itemId);
- }
-
- /*
- * Gets the ID's of all Items stored in the Container Don't add a JavaDoc
- * comment here, we use the default documentation from implemented
- * interface.
- */
- @Override
- public Collection> getItemIds() {
- return container.getItemIds();
- }
-
- /*
- * Gets the Property identified by the given itemId and propertyId from the
- * Container Don't add a JavaDoc comment here, we use the default
- * documentation from implemented interface.
- */
- @Override
- public Property> getContainerProperty(Object itemId, Object propertyId) {
- return container.getContainerProperty(itemId, propertyId);
- }
-
- /*
- * Gets the ID's of all Properties stored in the Container Don't add a
- * JavaDoc comment here, we use the default documentation from implemented
- * interface.
- */
- @Override
- public Collection> getContainerPropertyIds() {
- return container.getContainerPropertyIds();
- }
-
- /*
- * Gets the data type of all Properties identified by the given Property ID.
- * Don't add a JavaDoc comment here, we use the default documentation from
- * implemented interface.
- */
- @Override
- public Class> getType(Object propertyId) {
- return container.getType(propertyId);
- }
-
- /*
- * Gets the number of Items in the Container. Don't add a JavaDoc comment
- * here, we use the default documentation from implemented interface.
- */
- @Override
- public int size() {
- return container.size();
- }
-
- /*
- * Registers a new Item set change listener for this Container. Don't add a
- * JavaDoc comment here, we use the default documentation from implemented
- * interface.
- */
- @Override
- public void addListener(Container.ItemSetChangeListener listener) {
- if (container instanceof Container.ItemSetChangeNotifier) {
- ((Container.ItemSetChangeNotifier) container)
- .addListener(new PiggybackListener(listener));
- }
- }
-
- /*
- * Removes a Item set change listener from the object. Don't add a JavaDoc
- * comment here, we use the default documentation from implemented
- * interface.
- */
- @Override
- public void removeListener(Container.ItemSetChangeListener listener) {
- if (container instanceof Container.ItemSetChangeNotifier) {
- ((Container.ItemSetChangeNotifier) container)
- .removeListener(new PiggybackListener(listener));
- }
- }
-
- /*
- * Registers a new Property set change listener for this Container. Don't
- * add a JavaDoc comment here, we use the default documentation from
- * implemented interface.
- */
- @Override
- public void addListener(Container.PropertySetChangeListener listener) {
- if (container instanceof Container.PropertySetChangeNotifier) {
- ((Container.PropertySetChangeNotifier) container)
- .addListener(new PiggybackListener(listener));
- }
- }
-
- /*
- * Removes a Property set change listener from the object. Don't add a
- * JavaDoc comment here, we use the default documentation from implemented
- * interface.
- */
- @Override
- public void removeListener(Container.PropertySetChangeListener listener) {
- if (container instanceof Container.PropertySetChangeNotifier) {
- ((Container.PropertySetChangeNotifier) container)
- .removeListener(new PiggybackListener(listener));
- }
- }
-
- /**
- * This listener 'piggybacks' on the real listener in order to update the
- * wrapper when needed. It proxies equals() and hashCode() to the real
- * listener so that the correct listener gets removed.
- *
- */
- private class PiggybackListener implements
- Container.PropertySetChangeListener,
- Container.ItemSetChangeListener {
-
- Object listener;
-
- public PiggybackListener(Object realListener) {
- listener = realListener;
- }
-
- @Override
- public void containerItemSetChange(ItemSetChangeEvent event) {
- updateHierarchicalWrapper();
- ((Container.ItemSetChangeListener) listener)
- .containerItemSetChange(event);
-
- }
-
- @Override
- public void containerPropertySetChange(PropertySetChangeEvent event) {
- updateHierarchicalWrapper();
- ((Container.PropertySetChangeListener) listener)
- .containerPropertySetChange(event);
-
- }
-
- @Override
- public boolean equals(Object obj) {
- return obj == listener || (obj != null && obj.equals(listener));
- }
-
- @Override
- public int hashCode() {
- return listener.hashCode();
- }
-
- }
-}
diff --git a/src/com/vaadin/data/util/ContainerOrderedWrapper.java b/src/com/vaadin/data/util/ContainerOrderedWrapper.java
deleted file mode 100644
index d3d6f88d3e..0000000000
--- a/src/com/vaadin/data/util/ContainerOrderedWrapper.java
+++ /dev/null
@@ -1,644 +0,0 @@
-/*
-@VaadinApache2LicenseForJavaFiles@
- */
-
-package com.vaadin.data.util;
-
-import java.util.Collection;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.LinkedList;
-
-import com.vaadin.data.Container;
-import com.vaadin.data.Item;
-import com.vaadin.data.Property;
-
-/**
- * - * A wrapper class for adding external ordering to containers not implementing - * the {@link com.vaadin.data.Container.Ordered} interface. - *
- * - *- * If the wrapped container is changed directly (that is, not through the - * wrapper), and does not implement Container.ItemSetChangeNotifier and/or - * Container.PropertySetChangeNotifier the hierarchy information must be updated - * with the {@link #updateOrderWrapper()} method. - *
- * - * @author Vaadin Ltd. - * @version - * @VERSION@ - * @since 3.0 - */ -@SuppressWarnings("serial") -public class ContainerOrderedWrapper implements Container.Ordered, - Container.ItemSetChangeNotifier, Container.PropertySetChangeNotifier { - - /** - * The wrapped container - */ - private final Container container; - - /** - * Ordering information, ie. the mapping from Item ID to the next item ID - */ - private Hashtable- * Note : The Item is not removed from the underlying Container. - *
- * - * @param id - * the ID of the Item to be removed from the ordering. - */ - private void removeFromOrderWrapper(Object id) { - if (id != null) { - final Object pid = prev.get(id); - final Object nid = next.get(id); - if (first.equals(id)) { - first = nid; - } - if (last.equals(id)) { - first = pid; - } - if (nid != null) { - prev.put(nid, pid); - } - if (pid != null) { - next.put(pid, nid); - } - next.remove(id); - prev.remove(id); - } - } - - /** - * Registers the specified Item to the last position in the wrapper's - * internal ordering. The underlying container is not modified. - * - * @param id - * the ID of the Item to be added to the ordering. - */ - private void addToOrderWrapper(Object id) { - - // Adds the if to tail - if (last != null) { - next.put(last, id); - prev.put(id, last); - last = id; - } else { - first = last = id; - } - } - - /** - * Registers the specified Item after the specified itemId in the wrapper's - * internal ordering. The underlying container is not modified. Given item - * id must be in the container, or must be null. - * - * @param id - * the ID of the Item to be added to the ordering. - * @param previousItemId - * the Id of the previous item. - */ - private void addToOrderWrapper(Object id, Object previousItemId) { - - if (last == previousItemId || last == null) { - addToOrderWrapper(id); - } else { - if (previousItemId == null) { - next.put(id, first); - prev.put(first, id); - first = id; - } else { - prev.put(id, previousItemId); - next.put(id, next.get(previousItemId)); - prev.put(next.get(previousItemId), id); - next.put(previousItemId, id); - } - } - } - - /** - * Updates the wrapper's internal ordering information to include all Items - * in the underlying container. - *- * Note : If the contents of the wrapped container change without the - * wrapper's knowledge, this method needs to be called to update the - * ordering information of the Items. - *
- */ - public void updateOrderWrapper() { - - if (!ordered) { - - final Collection> ids = container.getItemIds(); - - // Recreates ordering if some parts of it are missing - if (next == null || first == null || last == null || prev != null) { - first = null; - last = null; - next = new Hashtabletrue
if the operation succeeded, false
- * if not
- */
- @Override
- public boolean addContainerProperty(Object propertyId, Class> type,
- Object defaultValue) throws UnsupportedOperationException {
-
- return container.addContainerProperty(propertyId, type, defaultValue);
- }
-
- /**
- * Creates a new Item into the Container, assigns it an automatic ID, and
- * adds it to the ordering.
- *
- * @return the autogenerated ID of the new Item or null
if the
- * operation failed
- * @throws UnsupportedOperationException
- * if the addItem is not supported.
- */
- @Override
- public Object addItem() throws UnsupportedOperationException {
-
- final Object id = container.addItem();
- if (!ordered && id != null) {
- addToOrderWrapper(id);
- }
- return id;
- }
-
- /**
- * Registers a new Item by its ID to the underlying container and to the
- * ordering.
- *
- * @param itemId
- * the ID of the Item to be created.
- * @return the added Item or null
if the operation failed
- * @throws UnsupportedOperationException
- * if the addItem is not supported.
- */
- @Override
- public Item addItem(Object itemId) throws UnsupportedOperationException {
- final Item item = container.addItem(itemId);
- if (!ordered && item != null) {
- addToOrderWrapper(itemId);
- }
- return item;
- }
-
- /**
- * Removes all items from the underlying container and from the ordering.
- *
- * @return true
if the operation succeeded, otherwise
- * false
- * @throws UnsupportedOperationException
- * if the removeAllItems is not supported.
- */
- @Override
- public boolean removeAllItems() throws UnsupportedOperationException {
- final boolean success = container.removeAllItems();
- if (!ordered && success) {
- first = last = null;
- next.clear();
- prev.clear();
- }
- return success;
- }
-
- /**
- * Removes an Item specified by the itemId from the underlying container and
- * from the ordering.
- *
- * @param itemId
- * the ID of the Item to be removed.
- * @return true
if the operation succeeded, false
- * if not
- * @throws UnsupportedOperationException
- * if the removeItem is not supported.
- */
- @Override
- public boolean removeItem(Object itemId)
- throws UnsupportedOperationException {
-
- final boolean success = container.removeItem(itemId);
- if (!ordered && success) {
- removeFromOrderWrapper(itemId);
- }
- return success;
- }
-
- /**
- * Removes the specified Property from the underlying container and from the
- * ordering.
- * - * Note : The Property will be removed from all the Items in the Container. - *
- * - * @param propertyId - * the ID of the Property to remove. - * @returntrue
if the operation succeeded, false
- * if not
- * @throws UnsupportedOperationException
- * if the removeContainerProperty is not supported.
- */
- @Override
- public boolean removeContainerProperty(Object propertyId)
- throws UnsupportedOperationException {
- return container.removeContainerProperty(propertyId);
- }
-
- /*
- * Does the container contain the specified Item? Don't add a JavaDoc
- * comment here, we use the default documentation from implemented
- * interface.
- */
- @Override
- public boolean containsId(Object itemId) {
- return container.containsId(itemId);
- }
-
- /*
- * Gets the specified Item from the container. Don't add a JavaDoc comment
- * here, we use the default documentation from implemented interface.
- */
- @Override
- public Item getItem(Object itemId) {
- return container.getItem(itemId);
- }
-
- /*
- * Gets the ID's of all Items stored in the Container Don't add a JavaDoc
- * comment here, we use the default documentation from implemented
- * interface.
- */
- @Override
- public Collection> getItemIds() {
- return container.getItemIds();
- }
-
- /*
- * Gets the Property identified by the given itemId and propertyId from the
- * Container Don't add a JavaDoc comment here, we use the default
- * documentation from implemented interface.
- */
- @Override
- public Property> getContainerProperty(Object itemId, Object propertyId) {
- return container.getContainerProperty(itemId, propertyId);
- }
-
- /*
- * Gets the ID's of all Properties stored in the Container Don't add a
- * JavaDoc comment here, we use the default documentation from implemented
- * interface.
- */
- @Override
- public Collection> getContainerPropertyIds() {
- return container.getContainerPropertyIds();
- }
-
- /*
- * Gets the data type of all Properties identified by the given Property ID.
- * Don't add a JavaDoc comment here, we use the default documentation from
- * implemented interface.
- */
- @Override
- public Class> getType(Object propertyId) {
- return container.getType(propertyId);
- }
-
- /*
- * Gets the number of Items in the Container. Don't add a JavaDoc comment
- * here, we use the default documentation from implemented interface.
- */
- @Override
- public int size() {
- int newSize = container.size();
- if (lastKnownSize != -1 && newSize != lastKnownSize
- && !(container instanceof Container.ItemSetChangeNotifier)) {
- // Update the internal cache when the size of the container changes
- // and the container is incapable of sending ItemSetChangeEvents
- updateOrderWrapper();
- }
- lastKnownSize = newSize;
- return newSize;
- }
-
- /*
- * Registers a new Item set change listener for this Container. Don't add a
- * JavaDoc comment here, we use the default documentation from implemented
- * interface.
- */
- @Override
- public void addListener(Container.ItemSetChangeListener listener) {
- if (container instanceof Container.ItemSetChangeNotifier) {
- ((Container.ItemSetChangeNotifier) container)
- .addListener(new PiggybackListener(listener));
- }
- }
-
- /*
- * Removes a Item set change listener from the object. Don't add a JavaDoc
- * comment here, we use the default documentation from implemented
- * interface.
- */
- @Override
- public void removeListener(Container.ItemSetChangeListener listener) {
- if (container instanceof Container.ItemSetChangeNotifier) {
- ((Container.ItemSetChangeNotifier) container)
- .removeListener(new PiggybackListener(listener));
- }
- }
-
- /*
- * Registers a new Property set change listener for this Container. Don't
- * add a JavaDoc comment here, we use the default documentation from
- * implemented interface.
- */
- @Override
- public void addListener(Container.PropertySetChangeListener listener) {
- if (container instanceof Container.PropertySetChangeNotifier) {
- ((Container.PropertySetChangeNotifier) container)
- .addListener(new PiggybackListener(listener));
- }
- }
-
- /*
- * Removes a Property set change listener from the object. Don't add a
- * JavaDoc comment here, we use the default documentation from implemented
- * interface.
- */
- @Override
- public void removeListener(Container.PropertySetChangeListener listener) {
- if (container instanceof Container.PropertySetChangeNotifier) {
- ((Container.PropertySetChangeNotifier) container)
- .removeListener(new PiggybackListener(listener));
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.vaadin.data.Container.Ordered#addItemAfter(java.lang.Object,
- * java.lang.Object)
- */
- @Override
- public Item addItemAfter(Object previousItemId, Object newItemId)
- throws UnsupportedOperationException {
-
- // If the previous item is not in the container, fail
- if (previousItemId != null && !containsId(previousItemId)) {
- return null;
- }
-
- // Adds the item to container
- final Item item = container.addItem(newItemId);
-
- // Puts the new item to its correct place
- if (!ordered && item != null) {
- addToOrderWrapper(newItemId, previousItemId);
- }
-
- return item;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.vaadin.data.Container.Ordered#addItemAfter(java.lang.Object)
- */
- @Override
- public Object addItemAfter(Object previousItemId)
- throws UnsupportedOperationException {
-
- // If the previous item is not in the container, fail
- if (previousItemId != null && !containsId(previousItemId)) {
- return null;
- }
-
- // Adds the item to container
- final Object id = container.addItem();
-
- // Puts the new item to its correct place
- if (!ordered && id != null) {
- addToOrderWrapper(id, previousItemId);
- }
-
- return id;
- }
-
- /**
- * This listener 'piggybacks' on the real listener in order to update the
- * wrapper when needed. It proxies equals() and hashCode() to the real
- * listener so that the correct listener gets removed.
- *
- */
- private class PiggybackListener implements
- Container.PropertySetChangeListener,
- Container.ItemSetChangeListener {
-
- Object listener;
-
- public PiggybackListener(Object realListener) {
- listener = realListener;
- }
-
- @Override
- public void containerItemSetChange(ItemSetChangeEvent event) {
- updateOrderWrapper();
- ((Container.ItemSetChangeListener) listener)
- .containerItemSetChange(event);
-
- }
-
- @Override
- public void containerPropertySetChange(PropertySetChangeEvent event) {
- updateOrderWrapper();
- ((Container.PropertySetChangeListener) listener)
- .containerPropertySetChange(event);
-
- }
-
- @Override
- public boolean equals(Object obj) {
- return obj == listener || (obj != null && obj.equals(listener));
- }
-
- @Override
- public int hashCode() {
- return listener.hashCode();
- }
-
- }
-
-}
diff --git a/src/com/vaadin/data/util/DefaultItemSorter.java b/src/com/vaadin/data/util/DefaultItemSorter.java
deleted file mode 100644
index 81b15ebd4f..0000000000
--- a/src/com/vaadin/data/util/DefaultItemSorter.java
+++ /dev/null
@@ -1,210 +0,0 @@
-/*
-@VaadinApache2LicenseForJavaFiles@
- */
-package com.vaadin.data.util;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.List;
-
-import com.vaadin.data.Container;
-import com.vaadin.data.Container.Sortable;
-import com.vaadin.data.Item;
-import com.vaadin.data.Property;
-
-/**
- * Provides a default implementation of an ItemSorter. The
- * DefaultItemSorter
adheres to the
- * {@link Sortable#sort(Object[], boolean[])} rules and sorts the container
- * according to the properties given using
- * {@link #setSortProperties(Sortable, Object[], boolean[])}.
- *
- * A Comparator is used for comparing the individual
- * The comparator set for this
- * Note : This is meaningful only if the root really is a directory.
- *
- * Sets the given Item's capability to have children. If the Item identified
- * with the itemId already has children and the areChildrenAllowed is false
- * this method fails and
- * Sets the parent of an Item. The new parent item must exist and be able to
- * have children. (
- * The parameters for the
- * Proxy class for creating Properties from pairs of getter and setter methods
- * of a Bean property. An instance of this class can be thought as having been
- * attached to a field of an object. Accessing the object through the Property
- * interface directly manipulates the underlying field.
- *
- * It's assumed that the return value returned by the getter method is
- * assignable to the type of the property, and the setter method parameter is
- * assignable to that value.
- *
- * A valid getter method must always be available, but instance of this class
- * can be constructed with a
- * MethodProperty implements Property.ValueChangeNotifier, but does not
- * automatically know whether or not the getter method will actually return a
- * new value - value change listeners are always notified when setValue is
- * called, without verifying what the getter returns.
- *
- * Creates a new instance of
- * The getter method of a
- * If the setter method is unavailable, the resulting
- *
- * Method names are constructed from the bean property by adding
- * get/is/are/set prefix and capitalising the first character in the name of
- * the given bean property.
- *
- * Creates a new instance of
- * If the setter method is
- * Creates a new instance of
- * If the setter method is
- * Creates a new instance of
- * For example, if the
- * Creates a new instance of Property
- * values. The comparator can be set using the constructor. If no comparator is
- * provided a default comparator is used.
- *
- */
-public class DefaultItemSorter implements ItemSorter {
-
- private java.lang.Object[] sortPropertyIds;
- private boolean[] sortDirections;
- private Container container;
- private ComparatorComparator
- * for comparing Property
values.
- *
- */
- public DefaultItemSorter() {
- this(new DefaultPropertyValueComparator());
- }
-
- /**
- * Constructs a DefaultItemSorter which uses the Comparator
- * indicated by the propertyValueComparator
parameter for
- * comparing Property
values.
- *
- * @param propertyValueComparator
- * The comparator to use when comparing individual
- * Property
values
- */
- public DefaultItemSorter(ComparatorpropertyId
in the items
- * indicated by item1
and item2
for order. Returns
- * a negative integer, zero, or a positive integer as the property value in
- * the first item is less than, equal to, or greater than the property value
- * in the second item. If the sortDirection
is false the
- * returned value is negated.
- * DefaultItemSorter
is used for
- * comparing the two property values.
- *
- * @param propertyId
- * The property id for the property that is used for comparison.
- * @param sortDirection
- * The direction of the sort. A false value negates the result.
- * @param item1
- * The first item to compare.
- * @param item2
- * The second item to compare.
- * @return a negative, zero, or positive integer if the property value in
- * the first item is less than, equal to, or greater than the
- * property value in the second item. Negated if
- * {@code sortDirection} is false.
- */
- protected int compareProperty(Object propertyId, boolean sortDirection,
- Item item1, Item item2) {
-
- // Get the properties to compare
- final Property> property1 = item1.getItemProperty(propertyId);
- final Property> property2 = item2.getItemProperty(propertyId);
-
- // Get the values to compare
- final Object value1 = (property1 == null) ? null : property1.getValue();
- final Object value2 = (property2 == null) ? null : property2.getValue();
-
- // Result of the comparison
- int r = 0;
- if (sortDirection) {
- r = propertyValueComparator.compare(value1, value2);
- } else {
- r = propertyValueComparator.compare(value2, value1);
- }
-
- return r;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * com.vaadin.data.util.ItemSorter#setSortProperties(com.vaadin.data.Container
- * .Sortable, java.lang.Object[], boolean[])
- */
- @Override
- public void setSortProperties(Container.Sortable container,
- Object[] propertyId, boolean[] ascending) {
- this.container = container;
-
- // Removes any non-sortable property ids
- final ListDefaultPropertyValueComparator
assumes all objects it
- * compares can be cast to Comparable.
- *
- */
- public static class DefaultPropertyValueComparator implements
- ComparatorFileSystemContainer
with the specified file
- * as the root of the filesystem. The files are included recursively.
- *
- * @param root
- * the root file for the new file-system container. Null values
- * are ignored.
- */
- public FilesystemContainer(File root) {
- if (root != null) {
- roots = new File[] { root };
- }
- }
-
- /**
- * Constructs a new FileSystemContainer
with the specified file
- * as the root of the filesystem. The files are included recursively.
- *
- * @param root
- * the root file for the new file-system container.
- * @param recursive
- * should the container recursively contain subdirectories.
- */
- public FilesystemContainer(File root, boolean recursive) {
- this(root);
- setRecursive(recursive);
- }
-
- /**
- * Constructs a new FileSystemContainer
with the specified file
- * as the root of the filesystem.
- *
- * @param root
- * the root file for the new file-system container.
- * @param extension
- * the Filename extension (w/o separator) to limit the files in
- * container.
- * @param recursive
- * should the container recursively contain subdirectories.
- */
- public FilesystemContainer(File root, String extension, boolean recursive) {
- this(root);
- this.setFilter(extension);
- setRecursive(recursive);
- }
-
- /**
- * Constructs a new FileSystemContainer
with the specified root
- * and recursivity status.
- *
- * @param root
- * the root file for the new file-system container.
- * @param filter
- * the Filename filter to limit the files in container.
- * @param recursive
- * should the container recursively contain subdirectories.
- */
- public FilesystemContainer(File root, FilenameFilter filter,
- boolean recursive) {
- this(root);
- this.setFilter(filter);
- setRecursive(recursive);
- }
-
- /**
- * Adds new root file directory. Adds a file to be included as root file
- * directory in the FilesystemContainer
.
- *
- * @param root
- * the File to be added as root directory. Null values are
- * ignored.
- */
- public void addRoot(File root) {
- if (root != null) {
- final File[] newRoots = new File[roots.length + 1];
- for (int i = 0; i < roots.length; i++) {
- newRoots[i] = roots[i];
- }
- newRoots[roots.length] = root;
- roots = newRoots;
- }
- }
-
- /**
- * Tests if the specified Item in the container may have children. Since a
- * FileSystemContainer
contains files and directories, this
- * method returns true
for directory Items only.
- *
- * @param itemId
- * the id of the item.
- * @return true
if the specified Item is a directory,
- * false
otherwise.
- */
- @Override
- public boolean areChildrenAllowed(Object itemId) {
- return itemId instanceof File && ((File) itemId).canRead()
- && ((File) itemId).isDirectory();
- }
-
- /*
- * Gets the ID's of all Items who are children of the specified Item. Don't
- * add a JavaDoc comment here, we use the default documentation from
- * implemented interface.
- */
- @Override
- public Collectionfalse
when conversion from files to directories is
- * not supported.
- *
- * @param itemId
- * the ID of the item.
- * @param areChildrenAllowed
- * the boolean value specifying if the Item can have children or
- * not.
- * @return true
if the operaton is successful otherwise
- * false
.
- * @throws UnsupportedOperationException
- * if the setChildrenAllowed is not supported.
- */
- @Override
- public boolean setChildrenAllowed(Object itemId, boolean areChildrenAllowed)
- throws UnsupportedOperationException {
-
- throw new UnsupportedOperationException(
- "Conversion file to/from directory is not supported");
- }
-
- /**
- * Returns false
when moving files around in the filesystem is
- * not supported.
- *
- * @param itemId
- * the ID of the item.
- * @param newParentId
- * the ID of the Item that's to be the new parent of the Item
- * identified with itemId.
- * @return true
if the operation is successful otherwise
- * false
.
- * @throws UnsupportedOperationException
- * if the setParent is not supported.
- */
- @Override
- public boolean setParent(Object itemId, Object newParentId)
- throws UnsupportedOperationException {
-
- throw new UnsupportedOperationException("File moving is not supported");
- }
-
- /*
- * Tests if the filesystem contains the specified Item. Don't add a JavaDoc
- * comment here, we use the default documentation from implemented
- * interface.
- */
- @Override
- public boolean containsId(Object itemId) {
-
- if (!(itemId instanceof File)) {
- return false;
- }
- boolean val = false;
-
- // Try to match all roots
- for (int i = 0; i < roots.length; i++) {
- try {
- val |= ((File) itemId).getCanonicalPath().startsWith(
- roots[i].getCanonicalPath());
- } catch (final IOException e) {
- // Exception ignored
- }
-
- }
- if (val && filter != null) {
- val &= filter.accept(((File) itemId).getParentFile(),
- ((File) itemId).getName());
- }
- return val;
- }
-
- /*
- * Gets the specified Item from the filesystem. Don't add a JavaDoc comment
- * here, we use the default documentation from implemented interface.
- */
- @Override
- public Item getItem(Object itemId) {
-
- if (!(itemId instanceof File)) {
- return null;
- }
- return new FileItem((File) itemId);
- }
-
- /**
- * Internal recursive method to add the files under the specified directory
- * to the collection.
- *
- * @param col
- * the collection where the found items are added
- * @param f
- * the root file where to start adding files
- */
- private void addItemIds(Collectionnull
is returned.
- *
- * @param itemId
- * the ID of the file whose property is requested.
- * @param propertyId
- * the property's ID.
- * @return the requested property's value, or null
- */
- @Override
- public Property> getContainerProperty(Object itemId, Object propertyId) {
-
- if (!(itemId instanceof File)) {
- return null;
- }
-
- if (propertyId.equals(PROPERTY_NAME)) {
- return new MethodPropertyString
,
- * "Size" is a Long
, "Last Modified" is a Date
. If
- * propertyId is not one of those, null
is returned.
- *
- * @param propertyId
- * the ID of the property whose type is requested.
- * @return data type of the requested property, or null
- */
- @Override
- public Class> getType(Object propertyId) {
-
- if (propertyId.equals(PROPERTY_NAME)) {
- return String.class;
- }
- if (propertyId.equals(PROPERTY_ICON)) {
- return Resource.class;
- }
- if (propertyId.equals(PROPERTY_SIZE)) {
- return Long.class;
- }
- if (propertyId.equals(PROPERTY_LASTMODIFIED)) {
- return Date.class;
- }
- return null;
- }
-
- /**
- * Internal method to recursively calculate the number of files under a root
- * directory.
- *
- * @param f
- * the root to start counting from.
- */
- private int getFileCounts(File f) {
- File[] l;
- if (filter != null) {
- l = f.listFiles(filter);
- } else {
- l = f.listFiles();
- }
-
- if (l == null) {
- return 0;
- }
- int ret = l.length;
- for (int i = 0; i < l.length; i++) {
- if (l[i].isDirectory()) {
- ret += getFileCounts(l[i]);
- }
- }
- return ret;
- }
-
- /**
- * Gets the number of Items in the container. In effect, this is the
- * combined amount of files and directories.
- *
- * @return Number of Items in the container.
- */
- @Override
- public int size() {
-
- if (recursive) {
- int counts = 0;
- for (int i = 0; i < roots.length; i++) {
- counts += getFileCounts(roots[i]);
- }
- return counts;
- } else {
- File[] f;
- if (roots.length == 1) {
- if (filter != null) {
- f = roots[0].listFiles(filter);
- } else {
- f = roots[0].listFiles();
- }
- } else {
- f = roots;
- }
-
- if (f == null) {
- return 0;
- }
- return f.length;
- }
- }
-
- /**
- * A Item wrapper for files in a filesystem.
- *
- * @author Vaadin Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
- public class FileItem implements Item {
-
- /**
- * The wrapped file.
- */
- private final File file;
-
- /**
- * Constructs a FileItem from a existing file.
- */
- private FileItem(File file) {
- this.file = file;
- }
-
- /*
- * Gets the specified property of this file. Don't add a JavaDoc comment
- * here, we use the default documentation from implemented interface.
- */
- @Override
- public Property> getItemProperty(Object id) {
- return getContainerProperty(file, id);
- }
-
- /*
- * Gets the IDs of all properties available for this item Don't add a
- * JavaDoc comment here, we use the default documentation from
- * implemented interface.
- */
- @Override
- public Collectiontrue
if the given object is the same as this
- * object, false
if not
- */
- @Override
- public boolean equals(Object obj) {
- if (obj == null || !(obj instanceof FileItem)) {
- return false;
- }
- final FileItem fi = (FileItem) obj;
- return fi.getHost() == getHost() && fi.file.equals(file);
- }
-
- /**
- * Gets the host of this file.
- */
- private FilesystemContainer getHost() {
- return FilesystemContainer.this;
- }
-
- /**
- * Gets the last modified date of this file.
- *
- * @return Date
- */
- public Date lastModified() {
- return new Date(file.lastModified());
- }
-
- /**
- * Gets the name of this file.
- *
- * @return file name of this file.
- */
- public String getName() {
- return file.getName();
- }
-
- /**
- * Gets the icon of this file.
- *
- * @return the icon of this file.
- */
- public Resource getIcon() {
- return FileTypeResolver.getIcon(file);
- }
-
- /**
- * Gets the size of this file.
- *
- * @return size
- */
- public long getSize() {
- if (file.isDirectory()) {
- return 0;
- }
- return file.length();
- }
-
- /**
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- if ("".equals(file.getName())) {
- return file.getAbsolutePath();
- }
- return file.getName();
- }
-
- /**
- * Filesystem container does not support adding new properties.
- *
- * @see com.vaadin.data.Item#addItemProperty(Object, Property)
- */
- @Override
- public boolean addItemProperty(Object id, Property property)
- throws UnsupportedOperationException {
- throw new UnsupportedOperationException("Filesystem container "
- + "does not support adding new properties");
- }
-
- /**
- * Filesystem container does not support removing properties.
- *
- * @see com.vaadin.data.Item#removeItemProperty(Object)
- */
- @Override
- public boolean removeItemProperty(Object id)
- throws UnsupportedOperationException {
- throw new UnsupportedOperationException(
- "Filesystem container does not support property removal");
- }
-
- }
-
- /**
- * Generic file extension filter for displaying only files having certain
- * extension.
- *
- * @author Vaadin Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
- public class FileExtensionFilter implements FilenameFilter, Serializable {
-
- private final String filter;
-
- /**
- * Constructs a new FileExtensionFilter using given extension.
- *
- * @param fileExtension
- * the File extension without the separator (dot).
- */
- public FileExtensionFilter(String fileExtension) {
- filter = "." + fileExtension;
- }
-
- /**
- * Allows only files with the extension and directories.
- *
- * @see java.io.FilenameFilter#accept(File, String)
- */
- @Override
- public boolean accept(File dir, String name) {
- if (name.endsWith(filter)) {
- return true;
- }
- return new File(dir, name).isDirectory();
- }
-
- }
-
- /**
- * Returns the file filter used to limit the files in this container.
- *
- * @return Used filter instance or null if no filter is assigned.
- */
- public FilenameFilter getFilter() {
- return filter;
- }
-
- /**
- * Sets the file filter used to limit the files in this container.
- *
- * @param filter
- * The filter to set. null
disables filtering.
- */
- public void setFilter(FilenameFilter filter) {
- this.filter = filter;
- }
-
- /**
- * Sets the file filter used to limit the files in this container.
- *
- * @param extension
- * the Filename extension (w/o separator) to limit the files in
- * container.
- */
- public void setFilter(String extension) {
- filter = new FileExtensionFilter(extension);
- }
-
- /**
- * Is this container recursive filesystem.
- *
- * @return true
if container is recursive, false
- * otherwise.
- */
- public boolean isRecursive() {
- return recursive;
- }
-
- /**
- * Sets the container recursive property. Set this to false to limit the
- * files directly under the root file.
- * false
is returned; the children must
- * be first explicitly removed with
- * {@link #setParent(Object itemId, Object newParentId)} or
- * {@link com.vaadin.data.Container#removeItem(Object itemId)}.
- * true
if the operation succeeded, false
- * if not
- */
- @Override
- public boolean setChildrenAllowed(Object itemId, boolean childrenAllowed) {
-
- // Checks that the item is in the container
- if (!containsId(itemId)) {
- return false;
- }
-
- // Updates status
- if (childrenAllowed) {
- noChildrenAllowed.remove(itemId);
- } else {
- noChildrenAllowed.add(itemId);
- }
-
- return true;
- }
-
- /**
- * canHaveChildren(newParentId) == true
). It is
- * also possible to detach a node from the hierarchy (and thus make it root)
- * by setting the parent null
.
- * true
if the operation succeeded, false
- * if not
- */
- @Override
- public boolean setParent(Object itemId, Object newParentId) {
-
- // Checks that the item is in the container
- if (!containsId(itemId)) {
- return false;
- }
-
- // Gets the old parent
- final Object oldParentId = parent.get(itemId);
-
- // Checks if no change is necessary
- if ((newParentId == null && oldParentId == null)
- || ((newParentId != null) && newParentId.equals(oldParentId))) {
- return true;
- }
-
- // Making root?
- if (newParentId == null) {
- // The itemId should become a root so we need to
- // - Remove it from the old parent's children list
- // - Add it as a root
- // - Remove it from the item -> parent list (parent is null for
- // roots)
-
- // Removes from old parents children list
- final LinkedList{@link Container.Indexed}
interface
- * with all important features.
- *
- *
- * @see com.vaadin.data.Container
- *
- * @author Vaadin Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
-
-@SuppressWarnings("serial")
-// item type is really IndexedContainerItem, but using Item not to show it in
-// public API
-public class IndexedContainer extends
- AbstractInMemoryContainerevent
object specifying the list whose Item set has
- * changed.
- *
- * @author Vaadin Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
- public static class ItemSetChangeEvent extends BaseItemSetChangeEvent {
-
- private final int addedItemIndex;
-
- private ItemSetChangeEvent(IndexedContainer source, int addedItemIndex) {
- super(source);
- this.addedItemIndex = addedItemIndex;
- }
-
- /**
- * Iff one item is added, gives its index.
- *
- * @return -1 if either multiple items are changed or some other change
- * than add is done.
- */
- public int getAddedItemIndex() {
- return addedItemIndex;
- }
-
- }
-
- /**
- * An event
object specifying the Property in a list whose
- * value has changed.
- *
- * @author Vaadin Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
- private static class PropertyValueChangeEvent extends EventObject implements
- Property.ValueChangeEvent, Serializable {
-
- private PropertyValueChangeEvent(Property source) {
- super(source);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.vaadin.data.Property.ValueChangeEvent#getProperty()
- */
- @Override
- public Property getProperty() {
- return (Property) getSource();
- }
-
- }
-
- @Override
- public void addListener(Container.PropertySetChangeListener listener) {
- super.addListener(listener);
- }
-
- @Override
- public void removeListener(Container.PropertySetChangeListener listener) {
- super.removeListener(listener);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.vaadin.data.Property.ValueChangeNotifier#addListener(com.
- * vaadin.data.Property.ValueChangeListener)
- */
- @Override
- public void addListener(Property.ValueChangeListener listener) {
- if (propertyValueChangeListeners == null) {
- propertyValueChangeListeners = new LinkedListString
representation of the contents of the
- * Item. The format of the string is a space separated catenation of the
- * String
representations of the values of the Properties
- * contained by the Item.
- *
- * @return String
representation of the Item contents
- */
- @Override
- public String toString() {
- String retValue = "";
-
- for (final Iterator> i = propertyIds.iterator(); i.hasNext();) {
- final Object propertyId = i.next();
- retValue += getItemProperty(propertyId).getValue();
- if (i.hasNext()) {
- retValue += " ";
- }
- }
-
- return retValue;
- }
-
- /**
- * Calculates a integer hash-code for the Item that's unique inside the
- * list. Two Items inside the same list have always different
- * hash-codes, though Items in different lists may have identical
- * hash-codes.
- *
- * @return A locally unique hash-code as integer
- */
- @Override
- public int hashCode() {
- return itemId.hashCode();
- }
-
- /**
- * Tests if the given object is the same as the this object. Two Items
- * got from a list container with the same ID are equal.
- *
- * @param obj
- * an object to compare with this object
- * @return true
if the given object is the same as this
- * object, false
if not
- */
- @Override
- public boolean equals(Object obj) {
- if (obj == null
- || !obj.getClass().equals(IndexedContainerItem.class)) {
- return false;
- }
- final IndexedContainerItem li = (IndexedContainerItem) obj;
- return getHost() == li.getHost() && itemId.equals(li.itemId);
- }
-
- private IndexedContainer getHost() {
- return IndexedContainer.this;
- }
-
- /**
- * IndexedContainerItem does not support adding new properties. Add
- * properties at container level. See
- * {@link IndexedContainer#addContainerProperty(Object, Class, Object)}
- *
- * @see com.vaadin.data.Item#addProperty(Object, Property)
- */
- @Override
- public boolean addItemProperty(Object id, Property property)
- throws UnsupportedOperationException {
- throw new UnsupportedOperationException("Indexed container item "
- + "does not support adding new properties");
- }
-
- /**
- * Indexed container does not support removing properties. Remove
- * properties at container level. See
- * {@link IndexedContainer#removeContainerProperty(Object)}
- *
- * @see com.vaadin.data.Item#removeProperty(Object)
- */
- @Override
- public boolean removeItemProperty(Object id)
- throws UnsupportedOperationException {
- throw new UnsupportedOperationException(
- "Indexed container item does not support property removal");
- }
-
- }
-
- /**
- * A class implementing the {@link Property} interface to be contained in
- * the {@link IndexedContainerItem} contained in the
- * {@link IndexedContainer}.
- *
- * @author Vaadin Ltd.
- *
- * @version
- * @VERSION@
- * @since 3.0
- */
- private class IndexedContainerProperty implements PropertysetValue
- * method if the Property is not in read-only mode.
- *
- * @return String
representation of the value stored in the
- * Property
- * @deprecated use {@link #getValue()} instead and possibly toString on
- * that
- */
- @Deprecated
- @Override
- public String toString() {
- throw new UnsupportedOperationException(
- "Use Property.getValue() instead of IndexedContainerProperty.toString()");
- }
-
- /**
- * Calculates a integer hash-code for the Property that's unique inside
- * the Item containing the Property. Two different Properties inside the
- * same Item contained in the same list always have different
- * hash-codes, though Properties in different Items may have identical
- * hash-codes.
- *
- * @return A locally unique hash-code as integer
- */
- @Override
- public int hashCode() {
- return itemId.hashCode() ^ propertyId.hashCode();
- }
-
- /**
- * Tests if the given object is the same as the this object. Two
- * Properties got from an Item with the same ID are equal.
- *
- * @param obj
- * an object to compare with this object
- * @return true
if the given object is the same as this
- * object, false
if not
- */
- @Override
- public boolean equals(Object obj) {
- if (obj == null
- || !obj.getClass().equals(IndexedContainerProperty.class)) {
- return false;
- }
- final IndexedContainerProperty lp = (IndexedContainerProperty) obj;
- return lp.getHost() == getHost()
- && lp.propertyId.equals(propertyId)
- && lp.itemId.equals(itemId);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.vaadin.data.Property.ValueChangeNotifier#addListener(
- * com.vaadin.data.Property.ValueChangeListener)
- */
- @Override
- public void addListener(Property.ValueChangeListener listener) {
- addSinglePropertyChangeListener(propertyId, itemId, listener);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.vaadin.data.Property.ValueChangeNotifier#removeListener
- * (com.vaadin.data.Property.ValueChangeListener)
- */
- @Override
- public void removeListener(Property.ValueChangeListener listener) {
- removeSinglePropertyChangeListener(propertyId, itemId, listener);
- }
-
- private IndexedContainer getHost() {
- return IndexedContainer.this;
- }
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.vaadin.data.Container.Sortable#sort(java.lang.Object[],
- * boolean[])
- */
- @Override
- public void sort(Object[] propertyId, boolean[] ascending) {
- sortContainer(propertyId, ascending);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.vaadin.data.Container.Sortable#getSortableContainerPropertyIds
- * ()
- */
- @Override
- public Collection> getSortableContainerPropertyIds() {
- return getSortablePropertyIds();
- }
-
- @Override
- public ItemSorter getItemSorter() {
- return super.getItemSorter();
- }
-
- @Override
- public void setItemSorter(ItemSorter itemSorter) {
- super.setItemSorter(itemSorter);
- }
-
- /**
- * Supports cloning of the IndexedContainer cleanly.
- *
- * @throws CloneNotSupportedException
- * if an object cannot be cloned. .
- *
- * @deprecated cloning support might be removed from IndexedContainer in the
- * future
- */
- @Deprecated
- @Override
- public Object clone() throws CloneNotSupportedException {
-
- // Creates the clone
- final IndexedContainer nc = new IndexedContainer();
-
- // Clone the shallow properties
- nc.setAllItemIds(getAllItemIds() != null ? (ListSetItemSorter
interface can be used in Sortable
- * implementations to provide a custom sorting method.
- */
-public interface ItemSorter extends ComparatorItemSorter
- * sorts the container.
- *
- * @param container
- * The container that will be sorted. The container must contain
- * the propertyIds given in the propertyId
- * parameter.
- * @param propertyId
- * The property ids used for sorting. The property ids must exist
- * in the container and should only be used if they are also
- * sortable, i.e include in the collection returned by
- * container.getSortableContainerPropertyIds()
. See
- * {@link Sortable#sort(Object[], boolean[])} for more
- * information.
- * @param ascending
- * Sorting order flags for each property id. See
- * {@link Sortable#sort(Object[], boolean[])} for more
- * information.
- */
- void setSortProperties(Container.Sortable container, Object[] propertyId,
- boolean[] ascending);
-
- /**
- * Compares its two arguments for order. Returns a negative integer, zero,
- * or a positive integer as the first argument is less than, equal to, or
- * greater than the second.
- * ItemSorter
compare()
- * method must always be item ids which exist in the container set using
- * {@link #setSortProperties(Sortable, Object[], boolean[])}.
- *
- * @see Comparator#compare(Object, Object)
- */
- @Override
- int compare(Object itemId1, Object itemId2);
-
-}
diff --git a/src/com/vaadin/data/util/ListSet.java b/src/com/vaadin/data/util/ListSet.java
deleted file mode 100644
index b71cc46898..0000000000
--- a/src/com/vaadin/data/util/ListSet.java
+++ /dev/null
@@ -1,264 +0,0 @@
-/*
-@VaadinApache2LicenseForJavaFiles@
- */
-package com.vaadin.data.util;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-
-/**
- * ListSet is an internal Vaadin class which implements a combination of a List
- * and a Set. The main purpose of this class is to provide a list with a fast
- * {@link #contains(Object)} method. Each inserted object must by unique (as
- * specified by {@link #equals(Object)}). The {@link #set(int, Object)} method
- * allows duplicates because of the way {@link Collections#sort(java.util.List)}
- * works.
- *
- * This class is subject to change and should not be used outside Vaadin core.
- */
-public class ListSetnull
setter method in which case the
- * resulting MethodProperty is read-only.
- * MethodProperty
from a named bean
- * property. This constructor takes an object and the name of a bean
- * property and initializes itself with the accessor methods for the
- * property.
- * MethodProperty
instantiated with this
- * constructor will be called with no arguments, and the setter method with
- * only the new value as the sole argument.
- * MethodProperty
will be read-only, otherwise it will be
- * read-write.
- * MethodProperty
from named getter
- * and setter methods. The getter method of a MethodProperty
- * instantiated with this constructor will be called with no arguments, and
- * the setter method with only the new value as the sole argument.
- * null
, the resulting
- * MethodProperty
will be read-only, otherwise it will be
- * read-write.
- * MethodProperty
with the getter and
- * setter methods. The getter method of a MethodProperty
- * instantiated with this constructor will be called with no arguments, and
- * the setter method with only the new value as the sole argument.
- * null
, the resulting
- * MethodProperty
will be read-only, otherwise it will be
- * read-write.
- * MethodProperty
from named getter
- * and setter methods and argument lists. The getter method of a
- * MethodProperty
instantiated with this constructor will be
- * called with the getArgs as arguments. The setArgs will be used as the
- * arguments for the setter method, though the argument indexed by the
- * setArgumentIndex will be replaced with the argument passed to the
- * {@link #setValue(Object newValue)} method.
- * setArgs
contains A
,
- * B
and C
, and setArgumentIndex =
- * 1
, the call methodProperty.setValue(X)
would result
- * in the setter method to be called with the parameter set of
- * {A, X, C}
- * setArgs
to be
- * replaced with newValue
when
- * {@link #setValue(Object newValue)} is called.
- */
- @SuppressWarnings("unchecked")
- public MethodProperty(Class extends T> type, Object instance,
- String getMethodName, String setMethodName, Object[] getArgs,
- Object[] setArgs, int setArgumentIndex) {
-
- // Check the setargs and setargs index
- if (setMethodName != null && setArgs == null) {
- throw new IndexOutOfBoundsException("The setArgs can not be null");
- }
- if (setMethodName != null
- && (setArgumentIndex < 0 || setArgumentIndex >= setArgs.length)) {
- throw new IndexOutOfBoundsException(
- "The setArgumentIndex must be >= 0 and < setArgs.length");
- }
-
- // Set type
- this.type = type;
-
- // Find set and get -methods
- final Method[] m = instance.getClass().getMethods();
-
- // Finds get method
- boolean found = false;
- for (int i = 0; i < m.length; i++) {
-
- // Tests the name of the get Method
- if (!m[i].getName().equals(getMethodName)) {
-
- // name does not match, try next method
- continue;
- }
-
- // Tests return type
- if (!type.equals(m[i].getReturnType())) {
- continue;
- }
-
- // Tests the parameter types
- final Class>[] c = m[i].getParameterTypes();
- if (c.length != getArgs.length) {
-
- // not the right amount of parameters, try next method
- continue;
- }
- int j = 0;
- while (j < c.length) {
- if (getArgs[j] != null
- && !c[j].isAssignableFrom(getArgs[j].getClass())) {
-
- // parameter type does not match, try next method
- break;
- }
- j++;
- }
- if (j == c.length) {
-
- // all paramteters matched
- if (found == true) {
- throw new MethodException(this,
- "Could not uniquely identify " + getMethodName
- + "-method");
- } else {
- found = true;
- getMethod = m[i];
- }
- }
- }
- if (found != true) {
- throw new MethodException(this, "Could not find " + getMethodName
- + "-method");
- }
-
- // Finds set method
- if (setMethodName != null) {
-
- // Finds setMethod
- found = false;
- for (int i = 0; i < m.length; i++) {
-
- // Checks name
- if (!m[i].getName().equals(setMethodName)) {
-
- // name does not match, try next method
- continue;
- }
-
- // Checks parameter compatibility
- final Class>[] c = m[i].getParameterTypes();
- if (c.length != setArgs.length) {
-
- // not the right amount of parameters, try next method
- continue;
- }
- int j = 0;
- while (j < c.length) {
- if (setArgs[j] != null
- && !c[j].isAssignableFrom(setArgs[j].getClass())) {
-
- // parameter type does not match, try next method
- break;
- } else if (j == setArgumentIndex && !c[j].equals(type)) {
-
- // Property type is not the same as setArg type
- break;
- }
- j++;
- }
- if (j == c.length) {
-
- // all parameters match
- if (found == true) {
- throw new MethodException(this,
- "Could not identify unique " + setMethodName
- + "-method");
- } else {
- found = true;
- setMethod = m[i];
- }
- }
- }
- if (found != true) {
- throw new MethodException(this, "Could not identify "
- + setMethodName + "-method");
- }
- }
-
- // Gets the return type from get method
- this.type = (Class