From adc8c0ad3573272c236040c3a76005b9e73a5737 Mon Sep 17 00:00:00 2001
From: Henri Sara
- * 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.
- *
- * The causes that do not specify error level default to
- *
- * This interface defines the combination of
- * A specialized set of identified Items. Basically the Container is a set of
- * Items, 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
- * neccessarily {@link Container.Ordered ordered}or {@link Container.Indexed
- * indexed}.
- *
- *
- * The Container interface is split to several subinterfaces so that a class can
- * implement only the ones it needs.
- *
- * 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.
- *
- * Note that Property ID and type information is preserved. This
- * functionality is optional.
- *
- * 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.
- *
- * The indexes of the item currently in the given position and all the
- * following items are incremented.
- *
- * The indexes of the item currently in the given position and all the
- * following items are incremented.
- *
- * 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.itmill.toolkit.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.
- *
- * 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
- * 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
- * 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.
- * Provides interfaces for the data layer which contains classes
-for typed data values, data collections, and handlers. A
-{@link com.itmill.toolkit.data.Property Property} is a simple typed data
-value; an {@link com.itmill.toolkit.data.Item Item} is a collection of
-Properties, each corresponding to a unique identifier; a
-{@link com.itmill.toolkit.data.Container Container} is a collection of
-identified Items with special constraints; a
-{@link com.itmill.toolkit.data.Buffered Buffered} class is able to track
-its changes and to commit or discard them later. The package contains a three-tiered structure for typed data objects and
-collections of them: In addition to these interfaces the package contains the
-{@link com.itmill.toolkit.data.Buffered Buffered} interface, which defines
-the methods to make an object buffered, that is, track the changes to an
-object and allow committing or discarding them at a later time. Provides interfaces for the validation framework. The framework
-defines two interfaces; one for classes that need to support external
-validation, and another one for the validators themselves. The most important method defined by the
-{@link com.itmill.toolkit.data.Validatable Validatable} interface is
-{@link com.itmill.toolkit.data.Validatable#isValid() isValid()}. It
-asks all registered validators to verify if the object's value is valid
-or not. Note that it depends on the validators registered for a object which
-values are valid and which are not. For example, a
-
- In addition to {@link com.itmill.toolkit.data.Validator Validator} defines the
-interface for an external validator. These validators may be added to
-any In addition to
- * Creates a new instance of
- * Note : This version only supports introspectable bean properties and
- * their getter and setter methods. Stand-alone
- * Creates a new instance of
- * Creates a new instance of
- * Note : This version only supports introspectable bean properties and
- * their getter and setter methods. Stand-alone
- * Creates a new instance of
- * Note : This version only supports introspectable bean properties and
- * their getter and setter methods. Stand-alone
- * 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
- * Bean objects act as identifiers. For this reason, they should implement
- * Object.equals(Object) and Object.hashCode().
- *
- * The item is also added in the visible part of the list if it passes the
- * filters.
- * 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.
- */
- 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.
- *
- */
- 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.
- */
- 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.
- */
- public void setReadThrough(boolean readThrough) throws SourceException;
-
- /**
- * Tests if the value stored in the object has been modified since it was
- * last updated from the data source.
- *
- * @return 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 IT Mill Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
- @SuppressWarnings("serial")
- public class SourceException extends RuntimeException implements
- ErrorMessage, 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 cause for the exception.
- * @throws MoreThanOneCauseException
- * if there is more than one cause for the exception. This
- * is possible if the commit operation triggers more than
- * one error at the same time.
- */
- @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;
- }
-
- /**
- * Gets the error level of this buffered source exception. The level of
- * the exception is maximum error level of all the contained causes.
- * ERROR
level. Also source exception without any causes
- * are of level ERROR
.
- * 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/itmill/toolkit/data/Container.java b/src/com/itmill/toolkit/data/Container.java
deleted file mode 100644
index 7b9bb31971..0000000000
--- a/src/com/itmill/toolkit/data/Container.java
+++ /dev/null
@@ -1,766 +0,0 @@
-/*
-@ITMillApache2LicenseForJavaFiles@
- */
-
-package com.itmill.toolkit.data;
-
-import java.io.Serializable;
-import java.util.Collection;
-
-/**
- *
- *
- *
- * null
values.
- *
- *
null
is returned.
- *
- * @param itemId
- * ID of the Item to retrieve
- * @return the 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 are
- * returned as a unmodifiable collection.
- *
- * @return unmodifiable collection of Property IDs
- */
- public Collection> getContainerPropertyIds();
-
- /**
- * Gets the ID's of all Items stored in the Container. The ID's are returned
- * as a unmodifiable collection.
- *
- * @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 Property,
- * null
is returned.
- *
- * @param itemId
- * ID of the 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 Items in the Container.
- *
- * @return number of Items in the Container
- */
- public int size();
-
- /**
- * Tests if the Container contains the specified Item
- *
- * @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 into the Container. The new
- * null
if the operation fails or the Container already
- * contains a Item with the given ID.
- * null
in case of a failure
- */
- 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
- */
- public Object addItem() throws UnsupportedOperationException;
-
- /**
- * Removes the Item identified by ItemId
from the Container.
- * This functionality is optional.
- *
- * @param itemId
- * ID of the Item to remove
- * @return true
if the operation succeeded, false
- * if not
- */
- 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
- */
- 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
- */
- public boolean removeContainerProperty(Object propertyId)
- throws UnsupportedOperationException;
-
- /**
- * Removes all Items from the Container.
- *
- * true
if the operation succeeded, false
- * if not
- */
- public boolean removeAllItems() throws UnsupportedOperationException;
-
- /**
- * Interface for Container classes whose Items can be traversed in order.
- */
- public interface Ordered extends Container {
-
- /**
- * Gets the ID of the Item following the Item that corresponds to
- * itemId
. If the given Item is the last or not found in
- * the Container, null
is returned.
- *
- * @param itemId
- * ID of an Item in the Container
- * @return ID of the next 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 an Item in the Container
- * @return ID of the previous Item or null
- */
- public Object prevItemId(Object itemId);
-
- /**
- * Gets the ID of the first Item in the Container.
- *
- * @return ID of the first Item in the Container
- */
- public Object firstItemId();
-
- /**
- * Gets the ID of the last Item in the Container..
- *
- * @return ID of the last 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 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 in the Container,
- * false
if not
- */
- public boolean isLastId(Object itemId);
-
- /**
- * Adds new item after the given item.
- * getSortableContainerPropertyIds
- * @param ascending
- * Array of sorting order flags corresponding to each
- * property ID used in sorting. If this array is shorter than
- * propertyId array, ascending order is assumed for items
- * where the order is not specified. Use 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 item.
- *
- * @return The sortable field ids.
- */
- Collection> getSortableContainerPropertyIds();
-
- }
-
- /** Interface for Container classes whose Items can be indexed. */
- public interface Indexed extends Ordered {
-
- /**
- * Gets the index of the Item corresponding to the itemId. The following
- * is true
for the returned index: 0 <= index < size().
- *
- * @param itemId
- * ID of an Item in the Container
- * @return index of the Item, or -1 if 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 Container
- * @return ID of the Item in the given index
- */
- public Object getIdByIndex(int index);
-
- /**
- * Adds new item at given index.
- * 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);
- }
-
- /**
- * Interface is implemented by containers that allow reducing their visible
- * contents with set of filters.
- *
- * When a set of filters are set, only items that match 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 com.itmill.toolkit.data.Ordered} or
- * {@link com.itmill.toolkit.data.Indexed} container is filtered, all
- * operations of these interfaces should only use the filtered contents and
- * the filtered indices to the container.
- *
- * Adding items (if supported) to a filtered
- * {@link com.itmill.toolkit.data.Ordered} or
- * {@link com.itmill.toolkit.data.Indexed} container should insert them
- * immediately after the indicated visible item. The unfiltered position of
- * items added at index 0, at index
- * {@link com.itmill.toolkit.data.Container#size()} or at an undefined
- * position is up to the implementation.
- *
- * @since 5.0
- */
- public interface Filterable extends Container, Serializable {
-
- /**
- * Add a filter for given property.
- *
- * Only items where given property for which toString() contains or
- * starts with given filterString are visible in the container.
- *
- * @param propertyId
- * Property for which the filter is applied to.
- * @param filterString
- * String that must match contents of the property
- * @param ignoreCase
- * Determine if the casing can be ignored when comparing
- * strings.
- * @param onlyMatchPrefix
- * Only match prefixes; no other matches are included.
- */
- public void addContainerFilter(Object propertyId, String filterString,
- boolean ignoreCase, boolean onlyMatchPrefix);
-
- /** Remove all filters from all properties. */
- public void removeAllContainerFilters();
-
- /** Remove all filters from given property. */
- public void removeContainerFilters(Object propertyId);
- }
-
- /**
- * Interface implemented by viewer classes capable of using a Container as a
- * data source.
- */
- public interface Viewer extends Serializable {
-
- /**
- * Sets the Container that serves as the data source of the viewer.
- *
- * @param newDataSource
- * The new data source Item
- */
- public void setContainerDataSource(Container newDataSource);
-
- /**
- * Gets the Container serving as the data source of the viewer.
- *
- * @return data source Container
- */
- public Container getContainerDataSource();
-
- }
-
- /**
- * Container.Editor
interface
- * does not restrict the class from editing the Container contents
- * internally.
- * Event
object specifying the Container whose Item set has
- * changed.
- */
- 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. */
- public interface ItemSetChangeListener extends Serializable {
-
- /**
- * Lets the listener know a Containers 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.
- * 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.
- */
- 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.
- */
- public interface PropertySetChangeListener extends Serializable {
-
- /**
- * Notifies this listener that the Containers contents 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 its
- * contents are 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.
- * String
in addition to the native type of the
- * Property (as given by the getType
method). If the
- * String
conversion fails or is unsupported, the method should
- * throw Property.ConversionException
. The string conversion
- * should at least understand the format returned by the
- * toString
method of the Property.
- *
- * @param newValue
- * New value of the Property. This should be assignable to the
- * type returned by getType, but also String type should be
- * supported
- *
- * @throws Property.ReadOnlyException
- * if the object is in read-only mode
- * @throws Property.ConversionException
- * if newValue can't be converted into the Property's native
- * type directly or through String
- */
- public void setValue(Object newValue) throws Property.ReadOnlyException,
- Property.ConversionException;
-
- /**
- * Returns the value of the Property in human readable textual format. The
- * return value should be assignable to the setValue
method if
- * the Property is not in read-only mode.
- *
- * @return String
representation of the value stored in the
- * Property
- */
- public String toString();
-
- /**
- * Returns the type of the Property. The methods 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> 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);
-
- /**
- * Exception
object that signals that a requested Property
- * modification failed because it's in read-only mode.
- *
- * @author IT Mill 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);
- }
- }
-
- /**
- * An exception that signals that the value passed to the
- * setValue
method couldn't be converted to the native type of
- * the Property.
- *
- * @author IT Mill Ltd
- * @version
- * @VERSION@
- * @since 3.0
- */
- @SuppressWarnings("serial")
- public class ConversionException extends RuntimeException {
-
- /**
- * Constructs a new ConversionException
without a detail
- * message.
- */
- public ConversionException() {
- }
-
- /**
- * Constructs a new ConversionException
with the specified
- * detail message.
- *
- * @param msg
- * the detail message
- */
- public ConversionException(String msg) {
- super(msg);
- }
-
- /**
- * Constructs a new ConversionException
from another
- * exception.
- *
- * @param cause
- * The cause of the the conversion failure
- */
- public ConversionException(Throwable cause) {
- super(cause.toString());
- }
- }
-
- /**
- * Interface implemented by the viewer classes capable of using a Property
- * as a data source.
- *
- * @author IT Mill 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 IT Mill 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 IT Mill 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 IT Mill 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 IT Mill 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 Collection> getValidators();
-
- /**
- * false
.
- * true
if the registered validators concur that the
- * value is valid, false
otherwise
- */
- public boolean isValid();
-
- /**
- * Validator.InvalidValueException
- * true
.
- * Validatable#isValid(Object)
iterates all registered
- * Validator
s, calling their {@link #validate(Object)} methods.
- * validate(Object)
should throw the
- * {@link Validator.InvalidValueException} if the given value is not valid by
- * its standards.
- *
- * Validators should not have side effects on other objects as they can be
- * called from Paintable.paint().
- *
- * @author IT Mill Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
-public interface Validator extends Serializable {
-
- /**
- * Checks the given value against this validator. If the value is valid this
- * method should do nothing, and if it's not valid, it should throw
- * Validator.InvalidValueException
- *
- * @param value
- * the value to check
- * @throws Validator.InvalidValueException
- * if the value is not valid
- */
- public void validate(Object value) throws Validator.InvalidValueException;
-
- /**
- * Tests if the given value is valid.
- *
- * @param value
- * the value to check
- * @return true
for valid value, otherwise false
.
- */
- public boolean isValid(Object value);
-
- /**
- * Invalid value exception can be thrown by {@link Validator} when a given
- * value is not valid.
- *
- * @author IT Mill Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
- @SuppressWarnings("serial")
- public class InvalidValueException extends RuntimeException implements
- ErrorMessage {
-
- /** Array of validation errors that are causing the problem. */
- private InvalidValueException[] causes = null;
-
- /**
- * Constructs a new InvalidValueException
with the
- * specified detail message.
- *
- * @param message
- * The detail message of the problem.
- */
- public InvalidValueException(String message) {
- this(message, new InvalidValueException[] {});
- }
-
- /**
- * Constructs a new InvalidValueException
with a set of
- * causing validation exceptions. The error message contains first the
- * given message and then a list of validation errors in the given
- * validatables.
- *
- * @param message
- * The detail message of the problem.
- * @param causes
- * Array of validatables whos invalidities are possiblity
- * causing the invalidity.
- */
- public InvalidValueException(String message,
- InvalidValueException[] causes) {
- super(message);
- if (causes == null) {
- throw new NullPointerException(
- "Possible causes array must not be null");
- }
-
- this.causes = causes;
- }
-
- /**
- * See if the error message doesn't paint anything visible.
- *
- * @return True iff the paint method does not paint anything visible.
- */
- public boolean isInvisible() {
- String msg = getMessage();
- if (msg != null && msg.length() > 0) {
- return false;
- }
- if (causes != null) {
- for (int i = 0; i < causes.length; i++) {
- if (!causes[i].isInvisible()) {
- return false;
- }
- }
- }
- return true;
- }
-
- public final int getErrorLevel() {
- return ErrorMessage.ERROR;
- }
-
- public void paint(PaintTarget target) throws PaintException {
- target.startTag("error");
- target.addAttribute("level", "error");
-
- // Error message
- final String message = getLocalizedMessage();
- if (message != null) {
- target.addText(message);
- }
-
- // Paint all the causes
- for (int i = 0; i < causes.length; i++) {
- causes[i].paint(target);
- }
-
- target.endTag("error");
- }
-
- /* Documented in super interface */
- public void addListener(RepaintRequestListener listener) {
- }
-
- /* Documented in super interface */
- public void removeListener(RepaintRequestListener listener) {
- }
-
- /* Documented in super interface */
- public void requestRepaint() {
- }
-
- /* Documented in super interface */
- public void requestRepaintRequests() {
- }
-
- public String getDebugId() {
- return null;
- }
-
- public void setDebugId(String id) {
- throw new UnsupportedOperationException(
- "Setting testing id for this Paintable is not implemented");
- }
-
- }
-
- @SuppressWarnings("serial")
- public class EmptyValueException extends Validator.InvalidValueException {
-
- public EmptyValueException(String message) {
- super(message);
- }
-
- }
-}
diff --git a/src/com/itmill/toolkit/data/doc-files/Container_full.gif b/src/com/itmill/toolkit/data/doc-files/Container_full.gif
deleted file mode 100644
index 28ee720e32..0000000000
Binary files a/src/com/itmill/toolkit/data/doc-files/Container_full.gif and /dev/null differ
diff --git a/src/com/itmill/toolkit/data/doc-files/Container_simple.gif b/src/com/itmill/toolkit/data/doc-files/Container_simple.gif
deleted file mode 100644
index 6db32581b8..0000000000
Binary files a/src/com/itmill/toolkit/data/doc-files/Container_simple.gif and /dev/null differ
diff --git a/src/com/itmill/toolkit/data/doc-files/Item.gif b/src/com/itmill/toolkit/data/doc-files/Item.gif
deleted file mode 100644
index 4cd202ceba..0000000000
Binary files a/src/com/itmill/toolkit/data/doc-files/Item.gif and /dev/null differ
diff --git a/src/com/itmill/toolkit/data/doc-files/Property.gif b/src/com/itmill/toolkit/data/doc-files/Property.gif
deleted file mode 100644
index 4aff19db1c..0000000000
Binary files a/src/com/itmill/toolkit/data/doc-files/Property.gif and /dev/null differ
diff --git a/src/com/itmill/toolkit/data/doc-files/datalayer.gif b/src/com/itmill/toolkit/data/doc-files/datalayer.gif
deleted file mode 100644
index b3d25639e0..0000000000
Binary files a/src/com/itmill/toolkit/data/doc-files/datalayer.gif and /dev/null differ
diff --git a/src/com/itmill/toolkit/data/package.html b/src/com/itmill/toolkit/data/package.html
deleted file mode 100644
index 2263ab459a..0000000000
--- a/src/com/itmill/toolkit/data/package.html
+++ /dev/null
@@ -1,86 +0,0 @@
-
-
-
-
-
-
-
-Package Specification
-
-
-
-
-Validation
-
-null
value
-can be valid value for one validator but invalid for another.isValid()
, Validatable
defines
-methods to add, remove and list validators of a validatable object.Validatable
object, and their task is to check, when
-requested, that the object which they are attached to contains a valid
-value. The actual validation logic is hidden in the
-{@link com.itmill.toolkit.data.Validator#validate(Object) validate(Object)}
-method.check(Object)
, Validator
defines
-the InvalidValueException
which is used to signal that a
-checked value is invalid, and the
-{@link com.itmill.toolkit.data.Validator.Suggestive Suggestive}
-subinterface which includes functionality to suggest a valid value for
-the validated object.BeanItem
and adds all properties
- * of a Java Bean to it. The properties are identified by their respective
- * bean names.
- * is
and
- * are
methods are not supported.
- * BeanItem
using a pre-computed set
- * of properties. The properties are identified by their respective bean
- * names.
- * BeanItem
and adds all listed
- * properties of a Java Bean to it - in specified order. The properties are
- * identified by their respective bean names.
- * is
and
- * are
methods are not supported.
- * BeanItem
and adds all listed
- * properties of a Java Bean to it - in specified order. The properties are
- * identified by their respective bean names.
- * is
and
- * are
methods are not supported.
- * is
and
- * are
methods are not supported.
- *
- * The item is also added in the visible part of the list if it passes the - * filters. - *
- * - * @param index - * Internal index to add the new item. - * @param newItemId - * Id of the new item to be added. - * @return Returns new item or null if the operation fails. - */ - private Item addItemAtInternalIndex(int index, Object newItemId) { - // Make sure that the Item is valid and has not been created yet - if (index < 0 || index > itemIds.size() || newItemId == null - || items.containsKey(newItemId)) { - return null; - } - - // Adds the Item to container - itemIds.add(index, newItemId); - Hashtable t = new Hashtable(); - items.put(newItemId, t); - addDefaultValues(t); - - if (filteredItemIds != null) { - // when the item data is set later (IndexedContainerProperty), - // filtering is updated - updateContainerFiltering(); - } else { - fireContentsChange(index); - } - - return new IndexedContainerItem(newItemId); - } - - /** - * Anevent
object specifying the list whose Property set has
- * changed.
- *
- * @author IT Mill Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
- private class PropertySetChangeEvent extends EventObject implements
- Container.PropertySetChangeEvent, Serializable {
-
- private PropertySetChangeEvent(IndexedContainer source) {
- super(source);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * com.itmill.toolkit.data.Container.PropertySetChangeEvent#getContainer
- * ()
- */
- public Container getContainer() {
- return (Container) getSource();
- }
- }
-
- /**
- * An event
object specifying the list whose Item set has
- * changed.
- *
- * @author IT Mill Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
- public class ItemSetChangeEvent extends EventObject implements
- Container.ItemSetChangeEvent, Serializable {
-
- private final int addedItemIndex;
-
- private ItemSetChangeEvent(IndexedContainer source, int addedItemIndex) {
- super(source);
- this.addedItemIndex = addedItemIndex;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * com.itmill.toolkit.data.Container.ItemSetChangeEvent#getContainer()
- */
- public Container getContainer() {
- return (Container) getSource();
- }
-
- /**
- * 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 IT Mill Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
- private class PropertyValueChangeEvent extends EventObject implements
- Property.ValueChangeEvent, Serializable {
-
- private PropertyValueChangeEvent(Property source) {
- super(source);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.itmill.toolkit.data.Property.ValueChangeEvent#getProperty()
- */
- public Property getProperty() {
- return (Property) getSource();
- }
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * com.itmill.toolkit.data.Container.PropertySetChangeNotifier#addListener
- * (com.itmill.toolkit.data.Container.PropertySetChangeListener)
- */
- public void addListener(Container.PropertySetChangeListener listener) {
- if (propertySetChangeListeners == null) {
- propertySetChangeListeners = new LinkedList();
- }
- propertySetChangeListeners.add(listener);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * com.itmill.toolkit.data.Container.PropertySetChangeNotifier#removeListener
- * (com.itmill.toolkit.data.Container.PropertySetChangeListener)
- */
- public void removeListener(Container.PropertySetChangeListener listener) {
- if (propertySetChangeListeners != null) {
- propertySetChangeListeners.remove(listener);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * com.itmill.toolkit.data.Container.ItemSetChangeNotifier#addListener(com
- * .itmill.toolkit.data.Container.ItemSetChangeListener)
- */
- public void addListener(Container.ItemSetChangeListener listener) {
- if (itemSetChangeListeners == null) {
- itemSetChangeListeners = new LinkedList();
- }
- itemSetChangeListeners.add(listener);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * com.itmill.toolkit.data.Container.ItemSetChangeNotifier#removeListener
- * (com.itmill.toolkit.data.Container.ItemSetChangeListener)
- */
- public void removeListener(Container.ItemSetChangeListener listener) {
- if (itemSetChangeListeners != null) {
- itemSetChangeListeners.remove(listener);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * com.itmill.toolkit.data.Property.ValueChangeNotifier#addListener(com.
- * itmill.toolkit.data.Property.ValueChangeListener)
- */
- public void addListener(Property.ValueChangeListener listener) {
- if (propertyValueChangeListeners == null) {
- propertyValueChangeListeners = new LinkedList();
- }
- propertyValueChangeListeners.add(listener);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * com.itmill.toolkit.data.Property.ValueChangeNotifier#removeListener(com
- * .itmill.toolkit.data.Property.ValueChangeListener)
- */
- public void removeListener(Property.ValueChangeListener listener) {
- if (propertyValueChangeListeners != null) {
- propertyValueChangeListeners.remove(listener);
- }
- }
-
- /**
- * Sends a Property value change event to all interested listeners.
- *
- * @param source
- * the IndexedContainerProperty object.
- */
- private void firePropertyValueChange(IndexedContainerProperty source) {
-
- // Sends event to listeners listening all value changes
- if (propertyValueChangeListeners != null) {
- final Object[] l = propertyValueChangeListeners.toArray();
- final Property.ValueChangeEvent event = new IndexedContainer.PropertyValueChangeEvent(
- source);
- for (int i = 0; i < l.length; i++) {
- ((Property.ValueChangeListener) l[i]).valueChange(event);
- }
- }
-
- // Sends event to single property value change listeners
- if (singlePropertyValueChangeListeners != null) {
- final Hashtable propertySetToListenerListMap = (Hashtable) singlePropertyValueChangeListeners
- .get(source.propertyId);
- if (propertySetToListenerListMap != null) {
- final LinkedList listenerList = (LinkedList) propertySetToListenerListMap
- .get(source.itemId);
- if (listenerList != null) {
- final Property.ValueChangeEvent event = new IndexedContainer.PropertyValueChangeEvent(
- source);
- Object[] listeners = listenerList.toArray();
- for (int i = 0; i < listeners.length; i++) {
- ((Property.ValueChangeListener) listeners[i])
- .valueChange(event);
- }
- }
- }
- }
-
- }
-
- /**
- * Sends a Property set change event to all interested listeners.
- */
- private void fireContainerPropertySetChange() {
- if (propertySetChangeListeners != null) {
- final Object[] l = propertySetChangeListeners.toArray();
- final Container.PropertySetChangeEvent event = new IndexedContainer.PropertySetChangeEvent(
- this);
- for (int i = 0; i < l.length; i++) {
- ((Container.PropertySetChangeListener) l[i])
- .containerPropertySetChange(event);
- }
- }
- }
-
- /**
- * Sends Item set change event to all registered interested listeners.
- *
- * @param addedItemIndex
- * index of new item if change event was an item addition
- */
- private void fireContentsChange(int addedItemIndex) {
- if (itemSetChangeListeners != null) {
- final Object[] l = itemSetChangeListeners.toArray();
- final Container.ItemSetChangeEvent event = new IndexedContainer.ItemSetChangeEvent(
- this, addedItemIndex);
- for (int i = 0; i < l.length; i++) {
- ((Container.ItemSetChangeListener) l[i])
- .containerItemSetChange(event);
- }
- }
- }
-
- /**
- * Adds new single Property change listener.
- *
- * @param propertyId
- * the ID of the Property to add.
- * @param itemId
- * the ID of the Item .
- * @param listener
- * the listener to be added.
- */
- private void addSinglePropertyChangeListener(Object propertyId,
- Object itemId, Property.ValueChangeListener listener) {
- if (listener != null) {
- if (singlePropertyValueChangeListeners == null) {
- singlePropertyValueChangeListeners = new Hashtable();
- }
- Hashtable propertySetToListenerListMap = (Hashtable) singlePropertyValueChangeListeners
- .get(propertyId);
- if (propertySetToListenerListMap == null) {
- propertySetToListenerListMap = new Hashtable();
- singlePropertyValueChangeListeners.put(propertyId,
- propertySetToListenerListMap);
- }
- LinkedList listenerList = (LinkedList) propertySetToListenerListMap
- .get(itemId);
- if (listenerList == null) {
- listenerList = new LinkedList();
- propertySetToListenerListMap.put(itemId, listenerList);
- }
- listenerList.addLast(listener);
- }
- }
-
- /**
- * Removes a previously registered single Property change listener.
- *
- * @param propertyId
- * the ID of the Property to remove.
- * @param itemId
- * the ID of the Item.
- * @param listener
- * the listener to be removed.
- */
- private void removeSinglePropertyChangeListener(Object propertyId,
- Object itemId, Property.ValueChangeListener listener) {
- if (listener != null && singlePropertyValueChangeListeners != null) {
- final Hashtable propertySetToListenerListMap = (Hashtable) singlePropertyValueChangeListeners
- .get(propertyId);
- if (propertySetToListenerListMap != null) {
- final LinkedList listenerList = (LinkedList) propertySetToListenerListMap
- .get(itemId);
- if (listenerList != null) {
- listenerList.remove(listener);
- if (listenerList.isEmpty()) {
- propertySetToListenerListMap.remove(itemId);
- }
- }
- if (propertySetToListenerListMap.isEmpty()) {
- singlePropertyValueChangeListeners.remove(propertyId);
- }
- }
- if (singlePropertyValueChangeListeners.isEmpty()) {
- singlePropertyValueChangeListeners = null;
- }
- }
- }
-
- /* Internal Item and Property implementations */
-
- /*
- * A class implementing the com.itmill.toolkit.data.Item interface to be
- * contained in the list. @author IT Mill Ltd.
- *
- * @version @VERSION@
- *
- * @since 3.0
- */
- class IndexedContainerItem implements Item {
-
- /**
- * Item ID in the host container for this Item.
- */
- private final Object itemId;
-
- /**
- * Constructs a new ListItem instance and connects it to a host
- * container.
- *
- * @param itemId
- * the Item ID of the new Item.
- */
- private IndexedContainerItem(Object itemId) {
-
- // Gets the item contents from the host
- if (itemId == null) {
- throw new NullPointerException();
- }
- this.itemId = itemId;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.itmill.toolkit.data.Item#getItemProperty(java.lang.Object)
- */
- public Property getItemProperty(Object id) {
- return new IndexedContainerProperty(itemId, id);
- }
-
- public Collection getItemPropertyIds() {
- return Collections.unmodifiableCollection(propertyIds);
- }
-
- /**
- * Gets the String
representation of the contents of the
- * Item. The format of the string is a space separated catenation of the
- * String
representations 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).toString();
- 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.itmill.toolkit.data.Item#addProperty(Object, Property)
- */
- 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.itmill.toolkit.data.Item#removeProperty(Object)
- */
- 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 IT Mill Ltd.
- *
- * @version
- * @VERSION@
- * @since 3.0
- */
- private class IndexedContainerProperty implements Property,
- Property.ValueChangeNotifier {
-
- /**
- * ID of the Item, where this property resides.
- */
- private final Object itemId;
-
- /**
- * Id of the Property.
- */
- private final Object propertyId;
-
- /**
- * Constructs a new {@link IndexedContainerProperty} object.
- *
- * @param itemId
- * the ID of the Item to connect the new Property to.
- * @param propertyId
- * the Property ID of the new Property.
- * @param host
- * the list that contains the Item to contain the new
- * Property.
- */
- private IndexedContainerProperty(Object itemId, Object propertyId) {
- if (itemId == null || propertyId == null) {
- // Null ids are not accepted
- throw new NullPointerException(
- "Container item or property ids can not be null");
- }
- this.propertyId = propertyId;
- this.itemId = itemId;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.itmill.toolkit.data.Property#getType()
- */
- public Class getType() {
- return (Class) types.get(propertyId);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.itmill.toolkit.data.Property#getValue()
- */
- public Object getValue() {
- return ((Hashtable) items.get(itemId)).get(propertyId);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.itmill.toolkit.data.Property#isReadOnly()
- */
- public boolean isReadOnly() {
- return readOnlyProperties.contains(this);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.itmill.toolkit.data.Property#setReadOnly(boolean)
- */
- public void setReadOnly(boolean newStatus) {
- if (newStatus) {
- readOnlyProperties.add(this);
- } else {
- readOnlyProperties.remove(this);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.itmill.toolkit.data.Property#setValue(java.lang.Object)
- */
- public void setValue(Object newValue)
- throws Property.ReadOnlyException, Property.ConversionException {
-
- // Gets the Property set
- final Hashtable propertySet = (Hashtable) items.get(itemId);
-
- // Support null values on all types
- if (newValue == null) {
- propertySet.remove(propertyId);
- } else if (getType().isAssignableFrom(newValue.getClass())) {
- propertySet.put(propertyId, newValue);
- } else {
- try {
-
- // Gets the string constructor
- final Constructor constr = getType().getConstructor(
- new Class[] { String.class });
-
- // Creates new object from the string
- propertySet.put(propertyId, constr
- .newInstance(new Object[] { newValue.toString() }));
-
- } catch (final java.lang.Exception e) {
- throw new Property.ConversionException(
- "Conversion for value '" + newValue + "' of class "
- + newValue.getClass().getName() + " to "
- + getType().getName() + " failed");
- }
- }
-
- // update the container filtering if this property is being filtered
- updateContainerFiltering(propertyId);
-
- firePropertyValueChange(this);
- }
-
- /**
- * Returns the value of the Property in human readable textual format.
- * The return value should be assignable to the setValue
- * method if the Property is not in read-only mode.
- *
- * @return String
representation of the value stored in the
- * Property
- */
- @Override
- public String toString() {
- final Object value = getValue();
- if (value == null) {
- return null;
- }
- return value.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.itmill.toolkit.data.Property.ValueChangeNotifier#addListener(
- * com.itmill.toolkit.data.Property.ValueChangeListener)
- */
- public void addListener(Property.ValueChangeListener listener) {
- addSinglePropertyChangeListener(propertyId, itemId, listener);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * com.itmill.toolkit.data.Property.ValueChangeNotifier#removeListener
- * (com.itmill.toolkit.data.Property.ValueChangeListener)
- */
- public void removeListener(Property.ValueChangeListener listener) {
- removeSinglePropertyChangeListener(propertyId, itemId, listener);
- }
-
- private IndexedContainer getHost() {
- return IndexedContainer.this;
- }
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.itmill.toolkit.data.Container.Sortable#sort(java.lang.Object[],
- * boolean[])
- */
- public void sort(Object[] propertyId, boolean[] ascending) {
-
- // Removes any non-sortable property ids
- final List ids = new ArrayList();
- final List- * 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 null
setter method in which case the
- * resulting MethodProperty is read-only.
- *
- * 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. - *
- * - * @author IT Mill Ltd. - * @version - * @VERSION@ - * @since 3.0 - */ -@SuppressWarnings("serial") -public class MethodProperty implements Property, Property.ValueChangeNotifier, - Property.ReadOnlyStatusChangeNotifier { - - /** - * The object that includes the property the MethodProperty is bound to. - */ - private transient Object instance; - - /** - * Argument arrays for the getter and setter methods. - */ - private transient Object[] setArgs, getArgs; - - /** - * Is the MethodProperty read-only? - */ - private boolean readOnly; - - /** - * The getter and setter methods. - */ - private transient Method setMethod, getMethod; - - /** - * Index of the new value in the argument list for the setter method. If the - * setter method requires several parameters, this index tells which one is - * the actual value to change. - */ - private int setArgumentIndex; - - /** - * Type of the property. - */ - private Class type; - - /** - * List of listeners who are interested in the read-only status changes of - * the MethodProperty - */ - private LinkedList readOnlyStatusChangeListeners = null; - - /** - * List of listeners who are interested in the value changes of the - * MethodProperty - */ - private LinkedList valueChangeListeners = null; - - /* Special serialization to handle method references */ - private void writeObject(java.io.ObjectOutputStream out) throws IOException { - out.defaultWriteObject(); - out.writeObject(instance); - out.writeObject(setArgs); - out.writeObject(getArgs); - if (setMethod != null) { - out.writeObject(setMethod.getName()); - out.writeObject(setMethod.getParameterTypes()); - } else { - out.writeObject(""); - out.writeObject(""); - } - if (getMethod != null) { - out.writeObject(getMethod.getName()); - out.writeObject(getMethod.getParameterTypes()); - } else { - out.writeObject(""); - out.writeObject(""); - } - }; - - /* Special serialization to handle method references */ - private void readObject(java.io.ObjectInputStream in) throws IOException, - ClassNotFoundException { - in.defaultReadObject(); - try { - instance = in.readObject(); - setArgs = (Object[]) in.readObject(); - getArgs = (Object[]) in.readObject(); - String name = (String) in.readObject(); - Class>[] paramTypes = (Class>[]) in.readObject(); - if (name != null && !name.equals("")) { - setMethod = instance.getClass().getMethod(name, paramTypes); - } else { - setMethod = null; - } - name = (String) in.readObject(); - paramTypes = (Class>[]) in.readObject(); - if (name != null && !name.equals("")) { - getMethod = instance.getClass().getMethod(name, paramTypes); - } else { - getMethod = null; - } - } catch (SecurityException e) { - System.err.println("Internal deserialization error"); - e.printStackTrace(); - } catch (NoSuchMethodException e) { - System.err.println("Internal deserialization error"); - e.printStackTrace(); - } - }; - - /** - *
- * Creates a new instance of 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.
- *
- * 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.
- *
- * If the setter method is unavailable, the resulting
- * MethodProperty
will be read-only, otherwise it will be
- * read-write.
- *
- * Method names are constucted from the bean property by adding - * get/is/are/set prefix and capitalising the first character in the name of - * the given bean property. - *
- * - * @param instance - * the object that includes the property. - * @param beanPropertyName - * the name of the property to bind to. - */ - public MethodProperty(Object instance, String beanPropertyName) { - - final Class beanClass = instance.getClass(); - - // Assure that the first letter is upper cased (it is a common - // mistake to write firstName, not FirstName). - if (Character.isLowerCase(beanPropertyName.charAt(0))) { - final char[] buf = beanPropertyName.toCharArray(); - buf[0] = Character.toUpperCase(buf[0]); - beanPropertyName = new String(buf); - } - - // Find the get method - getMethod = null; - try { - getMethod = beanClass.getMethod("get" + beanPropertyName, - new Class[] {}); - } catch (final java.lang.NoSuchMethodException ignored) { - try { - getMethod = beanClass.getMethod("is" + beanPropertyName, - new Class[] {}); - } catch (final java.lang.NoSuchMethodException ignoredAsWell) { - try { - getMethod = beanClass.getMethod("are" + beanPropertyName, - new Class[] {}); - } catch (final java.lang.NoSuchMethodException e) { - throw new MethodProperty.MethodException("Bean property " - + beanPropertyName + " can not be found"); - } - } - } - - // In case the get method is found, resolve the type - type = getMethod.getReturnType(); - - // Finds the set method - setMethod = null; - try { - setMethod = beanClass.getMethod("set" + beanPropertyName, - new Class[] { type }); - } catch (final java.lang.NoSuchMethodException skipped) { - } - - // Gets the return type from get method - if (type.isPrimitive()) { - if (type.equals(Boolean.TYPE)) { - type = Boolean.class; - } else if (type.equals(Integer.TYPE)) { - type = Integer.class; - } else if (type.equals(Float.TYPE)) { - type = Float.class; - } else if (type.equals(Double.TYPE)) { - type = Double.class; - } else if (type.equals(Byte.TYPE)) { - type = Byte.class; - } else if (type.equals(Character.TYPE)) { - type = Character.class; - } else if (type.equals(Short.TYPE)) { - type = Short.class; - } else if (type.equals(Long.TYPE)) { - type = Long.class; - } - } - - setArguments(new Object[] {}, new Object[] { null }, 0); - readOnly = (setMethod == null); - this.instance = instance; - } - - /** - *
- * Creates a new instance of 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.
- *
- * If the setter method is null
, the resulting
- * MethodProperty
will be read-only, otherwise it will be
- * read-write.
- *
- * Creates a new instance of 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.
- *
- * If the setter method is null
, the resulting
- * MethodProperty
will be read-only, otherwise it will be
- * read-write.
- *
- * Creates a new instance of 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.
- *
- * For example, if the 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.
- */
- public MethodProperty(Class 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 MethodProperty.MethodException(
- "Could not uniquely identify " + getMethodName
- + "-method");
- } else {
- found = true;
- getMethod = m[i];
- }
- }
- }
- if (found != true) {
- throw new MethodProperty.MethodException("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 MethodProperty.MethodException(
- "Could not identify unique " + setMethodName
- + "-method");
- } else {
- found = true;
- setMethod = m[i];
- }
- }
- }
- if (found != true) {
- throw new MethodProperty.MethodException("Could not identify "
- + setMethodName + "-method");
- }
- }
-
- // Gets the return type from get method
- if (type.isPrimitive()) {
- if (type.equals(Boolean.TYPE)) {
- type = Boolean.class;
- } else if (type.equals(Integer.TYPE)) {
- type = Integer.class;
- } else if (type.equals(Float.TYPE)) {
- type = Float.class;
- } else if (type.equals(Double.TYPE)) {
- type = Double.class;
- } else if (type.equals(Byte.TYPE)) {
- type = Byte.class;
- } else if (type.equals(Character.TYPE)) {
- type = Character.class;
- } else if (type.equals(Short.TYPE)) {
- type = Short.class;
- } else if (type.equals(Long.TYPE)) {
- type = Long.class;
- }
- }
-
- setArguments(getArgs, setArgs, setArgumentIndex);
- readOnly = (setMethod == null);
- this.instance = instance;
- }
-
- /**
- *
- * Creates a new instance of MethodProperty
from the getter and
- * setter methods, and argument lists.
- *
- * This constructor behaves exactly like - * {@link #MethodProperty(Class type, Object instance, String getMethodName, String setMethodName, Object [] getArgs, Object [] setArgs, int setArgumentIndex)} - * except that instead of names of the getter and setter methods this - * constructor is given the actual methods themselves. - *
- * - * @param type - * the type of the property. - * @param instance - * the object that includes the property. - * @param getMethod - * the getter method. - * @param setMethod - * the setter method. - * @param getArgs - * the fixed argument list to be passed to the getter method. - * @param setArgs - * the fixed argument list to be passed to the setter method. - * @param setArgumentIndex - * the index of the argument insetArgs
to be
- * replaced with newValue
when
- * {@link #setValue(Object newValue)} is called.
- */
- public MethodProperty(Class type, Object instance, Method getMethod,
- Method setMethod, Object[] getArgs, Object[] setArgs,
- int setArgumentIndex) {
-
- if (getMethod == null) {
- throw new MethodProperty.MethodException(
- "Property GET-method cannot not be null: " + type);
- }
-
- if (setMethod != null) {
- if (setArgs == null) {
- throw new IndexOutOfBoundsException(
- "The setArgs can not be null");
- }
- if (setArgumentIndex < 0 || setArgumentIndex >= setArgs.length) {
- throw new IndexOutOfBoundsException(
- "The setArgumentIndex must be >= 0 and < setArgs.length");
- }
- }
-
- // Gets the return type from get method
- if (type.isPrimitive()) {
- if (type.equals(Boolean.TYPE)) {
- type = Boolean.class;
- } else if (type.equals(Integer.TYPE)) {
- type = Integer.class;
- } else if (type.equals(Float.TYPE)) {
- type = Float.class;
- } else if (type.equals(Double.TYPE)) {
- type = Double.class;
- } else if (type.equals(Byte.TYPE)) {
- type = Byte.class;
- } else if (type.equals(Character.TYPE)) {
- type = Character.class;
- } else if (type.equals(Short.TYPE)) {
- type = Short.class;
- } else if (type.equals(Long.TYPE)) {
- type = Long.class;
- }
- }
-
- this.getMethod = getMethod;
- this.setMethod = setMethod;
- setArguments(getArgs, setArgs, setArgumentIndex);
- readOnly = (setMethod == null);
- this.instance = instance;
- this.type = type;
- }
-
- /**
- * Returns the type of the Property. The methods 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 final Class getType() {
- return type;
- }
-
- /**
- * Tests if the object is in read-only mode. In read-only mode calls to
- * setValue
will throw ReadOnlyException
and will
- * not modify the value of the Property.
- *
- * @return true
if the object is in read-only mode,
- * false
if it's not
- */
- public boolean isReadOnly() {
- return readOnly;
- }
-
- /**
- * Gets the value stored in the Property. The value is resolved by calling
- * the specified getter method with the argument specified at instantiation.
- *
- * @return the value of the Property
- */
- public Object getValue() {
- try {
- return getMethod.invoke(instance, getArgs);
- } catch (final Throwable e) {
- throw new MethodProperty.MethodException(e);
- }
- }
-
- /**
- * Returns the value of the MethodProperty
in human readable
- * textual format. The return value should be assignable to the
- * setValue
method if the Property is not in read-only mode.
- *
- * @return String representation of the value stored in the Property
- */
- @Override
- public String toString() {
- final Object value = getValue();
- if (value == null) {
- return null;
- }
- return value.toString();
- }
-
- /**
- * - * Sets the setter method and getter method argument lists. - *
- * - * @param getArgs - * the fixed argument list to be passed to the getter method. - * @param setArgs - * the fixed argument list to be passed to the setter method. - * @param setArgumentIndex - * the index of the argument insetArgs
to be
- * replaced with newValue
when
- * {@link #setValue(Object newValue)} is called.
- */
- public void setArguments(Object[] getArgs, Object[] setArgs,
- int setArgumentIndex) {
- this.getArgs = new Object[getArgs.length];
- for (int i = 0; i < getArgs.length; i++) {
- this.getArgs[i] = getArgs[i];
- }
- this.setArgs = new Object[setArgs.length];
- for (int i = 0; i < setArgs.length; i++) {
- this.setArgs[i] = setArgs[i];
- }
- this.setArgumentIndex = setArgumentIndex;
- }
-
- /**
- * Sets the value of the property. This method supports setting from
- * String
s if either String
is directly assignable
- * to property type, or the type class contains a string constructor.
- *
- * @param newValue
- * the New value of the property.
- * @throws Property.ReadOnlyException
if the object is in
- * read-only mode.
- * @throws Property.ConversionException
if
- * newValue
can't be converted into the Property's
- * native type directly or through String
.
- * @see #invokeSetMethod(Object)
- */
- public void setValue(Object newValue) throws Property.ReadOnlyException,
- Property.ConversionException {
-
- // Checks the mode
- if (isReadOnly()) {
- throw new Property.ReadOnlyException();
- }
-
- // Try to assign the compatible value directly
- if (newValue == null || type.isAssignableFrom(newValue.getClass())) {
- invokeSetMethod(newValue);
- } else {
-
- Object value;
- try {
-
- // Gets the string constructor
- final Constructor constr = getType().getConstructor(
- new Class[] { String.class });
-
- value = constr
- .newInstance(new Object[] { newValue.toString() });
-
- } catch (final java.lang.Exception e) {
- throw new Property.ConversionException(e);
- }
-
- // Creates new object from the string
- invokeSetMethod(value);
- }
- fireValueChange();
- }
-
- /**
- * Internal method to actually call the setter method of the wrapped
- * property.
- *
- * @param value
- */
- private void invokeSetMethod(Object value) {
-
- try {
- // Construct a temporary argument array only if needed
- if (setArgs.length == 1) {
- setMethod.invoke(instance, new Object[] { value });
- } else {
-
- // Sets the value to argument array
- final Object[] args = new Object[setArgs.length];
- for (int i = 0; i < setArgs.length; i++) {
- args[i] = (i == setArgumentIndex) ? value : setArgs[i];
- }
- setMethod.invoke(instance, args);
- }
- } catch (final InvocationTargetException e) {
- final Throwable targetException = e.getTargetException();
- throw new MethodProperty.MethodException(targetException);
- } catch (final Exception e) {
- throw new MethodProperty.MethodException(e);
- }
- }
-
- /**
- * Sets the Property's read-only mode to the specified status.
- *
- * @param newStatus
- * the new read-only status of the Property.
- */
- public void setReadOnly(boolean newStatus) {
- final boolean prevStatus = readOnly;
- if (newStatus) {
- readOnly = true;
- } else {
- readOnly = (setMethod == null);
- }
- if (prevStatus != readOnly) {
- fireReadOnlyStatusChange();
- }
- }
-
- /**
- * Exception
object that signals that there were problems
- * calling or finding the specified getter or setter methods of the
- * property.
- *
- * @author IT Mill Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
- public class MethodException extends RuntimeException {
-
- /**
- * Cause of the method exception
- */
- private Throwable cause;
-
- /**
- * Constructs a new MethodException
with the specified
- * detail message.
- *
- * @param msg
- * the detail message.
- */
- public MethodException(String msg) {
- super(msg);
- }
-
- /**
- * Constructs a new MethodException
from another exception.
- *
- * @param cause
- * the cause of the exception.
- */
- public MethodException(Throwable cause) {
- this.cause = cause;
- }
-
- /**
- * @see java.lang.Throwable#getCause()
- */
- @Override
- public Throwable getCause() {
- return cause;
- }
-
- /**
- * Gets the method property this exception originates from.
- */
- public MethodProperty getMethodProperty() {
- return MethodProperty.this;
- }
- }
-
- /* Events */
-
- /**
- * An Event
object specifying the Property whose read-only
- * status has been changed.
- *
- * @author IT Mill Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
- private 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(MethodProperty source) {
- super(source);
- }
-
- /**
- * Gets the Property whose read-only state has changed.
- *
- * @return source Property of the event.
- */
- 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.
- */
- public void addListener(Property.ReadOnlyStatusChangeListener listener) {
- if (readOnlyStatusChangeListeners == null) {
- readOnlyStatusChangeListeners = new LinkedList();
- }
- readOnlyStatusChangeListeners.add(listener);
- }
-
- /**
- * Removes a previously registered read-only status change listener.
- *
- * @param listener
- * the listener to be removed.
- */
- public void removeListener(Property.ReadOnlyStatusChangeListener listener) {
- if (readOnlyStatusChangeListeners != null) {
- readOnlyStatusChangeListeners.remove(listener);
- }
- }
-
- /**
- * Sends a read only status change event to all registered listeners.
- */
- private void fireReadOnlyStatusChange() {
- if (readOnlyStatusChangeListeners != null) {
- final Object[] l = readOnlyStatusChangeListeners.toArray();
- final Property.ReadOnlyStatusChangeEvent event = new MethodProperty.ReadOnlyStatusChangeEvent(
- this);
- for (int i = 0; i < l.length; i++) {
- ((Property.ReadOnlyStatusChangeListener) l[i])
- .readOnlyStatusChange(event);
- }
- }
- }
-
- /**
- * An Event
object specifying the Property whose value has been
- * changed.
- *
- * @author IT Mill Ltd.
- * @version
- * @VERSION@
- * @since 5.3
- */
- private 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(MethodProperty source) {
- super(source);
- }
-
- /**
- * Gets the Property whose value has changed.
- *
- * @return source Property of the event.
- */
- public Property getProperty() {
- return (Property) getSource();
- }
-
- }
-
- public void addListener(ValueChangeListener listener) {
- if (valueChangeListeners == null) {
- valueChangeListeners = new LinkedList();
- }
- valueChangeListeners.add(listener);
-
- }
-
- public void removeListener(ValueChangeListener listener) {
- if (valueChangeListeners != null) {
- valueChangeListeners.remove(listener);
- }
-
- }
-
- /**
- * Sends a value change event to all registered listeners.
- */
- public void fireValueChange() {
- if (valueChangeListeners != null) {
- final Object[] l = valueChangeListeners.toArray();
- final Property.ValueChangeEvent event = new MethodProperty.ValueChangeEvent(
- this);
- for (int i = 0; i < l.length; i++) {
- ((Property.ValueChangeListener) l[i]).valueChange(event);
- }
- }
- }
-
-}
diff --git a/src/com/itmill/toolkit/data/util/ObjectProperty.java b/src/com/itmill/toolkit/data/util/ObjectProperty.java
deleted file mode 100644
index dd31c89606..0000000000
--- a/src/com/itmill/toolkit/data/util/ObjectProperty.java
+++ /dev/null
@@ -1,349 +0,0 @@
-/*
-@ITMillApache2LicenseForJavaFiles@
- */
-
-package com.itmill.toolkit.data.util;
-
-import java.lang.reflect.Constructor;
-import java.util.LinkedList;
-
-import com.itmill.toolkit.data.Property;
-
-/**
- * A simple data object containing one typed value. This class is a
- * straightforward implementation of the the
- * {@link com.itmill.toolkit.data.Property} interface.
- *
- * @author IT Mill Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
-@SuppressWarnings("serial")
-public class ObjectProperty implements Property, Property.ValueChangeNotifier,
- Property.ReadOnlyStatusChangeNotifier {
-
- /**
- * A boolean value storing the Property's read-only status information.
- */
- private boolean readOnly = false;
-
- /**
- * The value contained by the Property.
- */
- private Object value;
-
- /**
- * Data type of the Property's value.
- */
- private final Class type;
-
- /**
- * Internal list of registered value change listeners.
- */
- private LinkedList valueChangeListeners = null;
-
- /**
- * Internal list of registered read-only status change listeners.
- */
- private LinkedList readOnlyStatusChangeListeners = null;
-
- /**
- * Creates a new instance of ObjectProperty with the given value. The type
- * of the property is automatically initialized to be the type of the given
- * value.
- *
- * @param value
- * the Initial value of the Property.
- */
- public ObjectProperty(Object value) {
- this(value, value.getClass());
- }
-
- /**
- * Creates a new instance of ObjectProperty with the given value and type.
- *
- * @param value
- * the Initial value of the Property.
- * @param type
- * the type of the value. The value must be assignable to given
- * type.
- */
- public ObjectProperty(Object value, Class type) {
-
- // Set the values
- this.type = type;
- setValue(value);
- }
-
- /**
- * Creates a new instance of ObjectProperty with the given value, type and
- * read-only mode status.
- *
- * @param value
- * the Initial value of the property.
- * @param type
- * the type of the value. value
must be assignable
- * to this type.
- * @param readOnly
- * Sets the read-only mode.
- */
- public ObjectProperty(Object value, Class type, boolean readOnly) {
- this(value, type);
- setReadOnly(readOnly);
- }
-
- /**
- * Returns the type of the ObjectProperty. The methods 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 final Class getType() {
- return type;
- }
-
- /**
- * Gets the value stored in the Property.
- *
- * @return the value stored in the Property
- */
- public Object getValue() {
- return value;
- }
-
- /**
- * Returns the value of the ObjectProperty in human readable textual format.
- * The return value should be assignable to the setValue
method
- * if the Property is not in read-only mode.
- *
- * @return String
representation of the value stored in the
- * ObjectProperty
- */
- @Override
- public String toString() {
- final Object value = getValue();
- if (value != null) {
- return value.toString();
- } else {
- return null;
- }
- }
-
- /**
- * Tests if the Property is in read-only mode. In read-only mode calls to
- * the method setValue
will throw
- * ReadOnlyException
s 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() {
- return readOnly;
- }
-
- /**
- * Sets the Property's read-only mode to the specified status.
- *
- * @param newStatus
- * the new read-only status of the Property.
- */
- public void setReadOnly(boolean newStatus) {
- if (newStatus != readOnly) {
- readOnly = newStatus;
- fireReadOnlyStatusChange();
- }
- }
-
- /**
- * Sets the value of the property. This method supports setting from
- * String
if either String
is directly assignable
- * to property type, or the type class contains a string constructor.
- *
- * @param newValue
- * the New value of the property.
- * @throws Property.ReadOnlyException
if the object is in
- * read-only mode
- * @throws Property.ConversionException
if the newValue can't
- * be converted into the Property's native type directly or through
- * String
- */
- public void setValue(Object newValue) throws Property.ReadOnlyException,
- Property.ConversionException {
-
- // Checks the mode
- if (isReadOnly()) {
- throw new Property.ReadOnlyException();
- }
-
- // Tries to assign the compatible value directly
- if (newValue == null || type.isAssignableFrom(newValue.getClass())) {
- value = newValue;
- } else {
- try {
-
- // Gets the string constructor
- final Constructor constr = getType().getConstructor(
- new Class[] { String.class });
-
- // Creates new object from the string
- value = constr
- .newInstance(new Object[] { newValue.toString() });
-
- } catch (final java.lang.Exception e) {
- throw new Property.ConversionException(e);
- }
- }
-
- fireValueChange();
- }
-
- /* Events */
-
- /**
- * An Event
object specifying the ObjectProperty whose value
- * has changed.
- *
- * @author IT Mill Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
- private class ValueChangeEvent extends java.util.EventObject implements
- Property.ValueChangeEvent {
-
- /**
- * Constructs a new value change event for this object.
- *
- * @param source
- * the source object of the event.
- */
- protected ValueChangeEvent(ObjectProperty source) {
- super(source);
- }
-
- /**
- * Gets the Property whose read-only state has changed.
- *
- * @return source the Property of the event.
- */
- public Property getProperty() {
- return (Property) getSource();
- }
- }
-
- /**
- * An Event
object specifying the Property whose read-only
- * status has been changed.
- *
- * @author IT Mill Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
- private 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(ObjectProperty source) {
- super(source);
- }
-
- /**
- * Gets the Property whose read-only state has changed.
- *
- * @return source Property of the event.
- */
- public Property getProperty() {
- return (Property) getSource();
- }
- }
-
- /**
- * Removes a previously registered value change listener.
- *
- * @param listener
- * the listener to be removed.
- */
- public void removeListener(Property.ValueChangeListener listener) {
- if (valueChangeListeners != null) {
- valueChangeListeners.remove(listener);
- }
- }
-
- /**
- * Registers a new value change listener for this ObjectProperty.
- *
- * @param listener
- * the new Listener to be registered
- */
- public void addListener(Property.ValueChangeListener listener) {
- if (valueChangeListeners == null) {
- valueChangeListeners = new LinkedList();
- }
- valueChangeListeners.add(listener);
- }
-
- /**
- * Registers a new read-only status change listener for this Property.
- *
- * @param listener
- * the new Listener to be registered
- */
- public void addListener(Property.ReadOnlyStatusChangeListener listener) {
- if (readOnlyStatusChangeListeners == null) {
- readOnlyStatusChangeListeners = new LinkedList();
- }
- readOnlyStatusChangeListeners.add(listener);
- }
-
- /**
- * Removes a previously registered read-only status change listener.
- *
- * @param listener
- * the listener to be removed.
- */
- public void removeListener(Property.ReadOnlyStatusChangeListener listener) {
- if (readOnlyStatusChangeListeners != null) {
- readOnlyStatusChangeListeners.remove(listener);
- }
- }
-
- /**
- * Sends a value change event to all registered listeners.
- */
- private void fireValueChange() {
- if (valueChangeListeners != null) {
- final Object[] l = valueChangeListeners.toArray();
- final Property.ValueChangeEvent event = new ObjectProperty.ValueChangeEvent(
- this);
- for (int i = 0; i < l.length; i++) {
- ((Property.ValueChangeListener) l[i]).valueChange(event);
- }
- }
- }
-
- /**
- * Sends a read only status change event to all registered listeners.
- */
- private void fireReadOnlyStatusChange() {
- if (readOnlyStatusChangeListeners != null) {
- final Object[] l = readOnlyStatusChangeListeners.toArray();
- final Property.ReadOnlyStatusChangeEvent event = new ObjectProperty.ReadOnlyStatusChangeEvent(
- this);
- for (int i = 0; i < l.length; i++) {
- ((Property.ReadOnlyStatusChangeListener) l[i])
- .readOnlyStatusChange(event);
- }
- }
- }
-}
diff --git a/src/com/itmill/toolkit/data/util/PropertyFormatter.java b/src/com/itmill/toolkit/data/util/PropertyFormatter.java
deleted file mode 100644
index 0b407bdd52..0000000000
--- a/src/com/itmill/toolkit/data/util/PropertyFormatter.java
+++ /dev/null
@@ -1,380 +0,0 @@
-package com.itmill.toolkit.data.util;
-
-import java.util.LinkedList;
-
-import com.itmill.toolkit.data.Property;
-
-/**
- * Formatting proxy for a property.
- *
- * - * This class can be used to implement formatting for any type of Property - * datasources. The idea is to connect this as proxy between UI component and - * the original datasource. - *
- * - *
- * For example
- * textfield.setPropertyDataSource(new PropertyFormatter(property) {
- public String format(Object value) {
- return ((Double) value).toString() + "000000000";
- }
-
- public Object parse(String formattedValue) throws Exception {
- return Double.parseDouble(formattedValue);
- }
-
- });
adds formatter for Double-typed property that extends standard
- * "1.0" notation with more zeroes.
- *
null
if
- * none defined.
- */
- public Property getPropertyDataSource() {
- return dataSource;
- }
-
- /**
- * Sets the specified Property as the data source for the formatter.
- *
- *
- * - * Remember that new data sources getValue() must return objects that are - * compatible with parse() and format() methods. - *
- * - * @param newDataSource - * the new data source Property. - */ - public void setPropertyDataSource(Property newDataSource) { - - boolean readOnly = false; - String prevValue = null; - - if (dataSource != null) { - if (dataSource instanceof Property.ValueChangeNotifier) { - ((Property.ValueChangeNotifier) dataSource) - .removeListener(this); - } - if (dataSource instanceof Property.ReadOnlyStatusChangeListener) { - ((Property.ReadOnlyStatusChangeNotifier) dataSource) - .removeListener(this); - } - readOnly = isReadOnly(); - prevValue = toString(); - } - - dataSource = newDataSource; - - if (dataSource != null) { - if (dataSource instanceof Property.ValueChangeNotifier) { - ((Property.ValueChangeNotifier) dataSource).addListener(this); - } - if (dataSource instanceof Property.ReadOnlyStatusChangeListener) { - ((Property.ReadOnlyStatusChangeNotifier) dataSource) - .addListener(this); - } - } - - if (isReadOnly() != readOnly) { - fireReadOnlyStatusChange(); - } - String newVal = toString(); - if ((prevValue == null && newVal != null) - || !prevValue.equals(prevValue)) { - fireValueChange(); - } - } - - /* Documented in the interface */ - public Class getType() { - return String.class; - } - - /** - * Get the formatted value. - * - * @return If the datasource returns null, this is null. Otherwise this is - * String given by format(). - */ - public Object getValue() { - return toString(); - } - - /** - * Get the formatted value. - * - * @return If the datasource returns null, this is null. Otherwise this is - * String given by format(). - */ - @Override - public String toString() { - Object value = dataSource == null ? false : dataSource.getValue(); - if (value == null) { - return null; - } - return format(value); - } - - /** Reflects the read-only status of the datasource. */ - public boolean isReadOnly() { - return dataSource == null ? false : dataSource.isReadOnly(); - } - - /** - * This method must be implemented to format the values received from - * DataSource. - * - * @param value - * Value object got from the datasource. This is guaranteed to be - * non-null and of the type compatible with getType() of the - * datasource. - * @return - */ - abstract public String format(Object value); - - /** - * Parse string and convert it to format compatible with datasource. - * - * The method is required to assure that parse(format(x)) equals x. - * - * @param formattedValue - * This is guaranteed to be non-null string. - * @return Non-null value compatible with datasource. - * @throws Exception - * Any type of exception can be thrown to indicate that the - * conversion was not succesful. - */ - abstract public Object parse(String formattedValue) throws Exception; - - /** - * Sets the Property's read-only mode to the specified status. - * - * @param newStatus - * the new read-only status of the Property. - */ - public void setReadOnly(boolean newStatus) { - if (dataSource != null) { - dataSource.setReadOnly(newStatus); - } - } - - public void setValue(Object newValue) throws ReadOnlyException, - ConversionException { - if (dataSource == null) { - return; - } - if (newValue == null) { - dataSource.setValue(null); - } - try { - dataSource.setValue(parse((String) newValue)); - if (!newValue.equals(toString())) { - fireValueChange(); - } - } catch (Exception e) { - if (e instanceof ConversionException) { - throw (ConversionException) e; - } else { - throw new ConversionException(e); - } - } - - } - - /** - * AnEvent
object specifying the ObjectProperty whose value
- * has changed.
- *
- * @author IT Mill Ltd.
- * @since 5.3.0
- */
- private class ValueChangeEvent extends java.util.EventObject implements
- Property.ValueChangeEvent {
-
- /**
- * Constructs a new value change event for this object.
- *
- * @param source
- * the source object of the event.
- */
- protected ValueChangeEvent(PropertyFormatter source) {
- super(source);
- }
-
- /**
- * Gets the Property whose read-only state has changed.
- *
- * @return source the Property of the event.
- */
- public Property getProperty() {
- return (Property) getSource();
- }
- }
-
- /**
- * An Event
object specifying the Property whose read-only
- * status has been changed.
- *
- * @author IT Mill Ltd.
- * @since 5.3.0
- */
- private 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(PropertyFormatter source) {
- super(source);
- }
-
- /**
- * Gets the Property whose read-only state has changed.
- *
- * @return source Property of the event.
- */
- public Property getProperty() {
- return (Property) getSource();
- }
- }
-
- /**
- * Removes a previously registered value change listener.
- *
- * @param listener
- * the listener to be removed.
- */
- public void removeListener(Property.ValueChangeListener listener) {
- if (valueChangeListeners != null) {
- valueChangeListeners.remove(listener);
- }
- }
-
- /**
- * Registers a new value change listener for this ObjectProperty.
- *
- * @param listener
- * the new Listener to be registered
- */
- public void addListener(Property.ValueChangeListener listener) {
- if (valueChangeListeners == null) {
- valueChangeListeners = new LinkedList();
- }
- valueChangeListeners.add(listener);
- }
-
- /**
- * Registers a new read-only status change listener for this Property.
- *
- * @param listener
- * the new Listener to be registered
- */
- public void addListener(Property.ReadOnlyStatusChangeListener listener) {
- if (readOnlyStatusChangeListeners == null) {
- readOnlyStatusChangeListeners = new LinkedList();
- }
- readOnlyStatusChangeListeners.add(listener);
- }
-
- /**
- * Removes a previously registered read-only status change listener.
- *
- * @param listener
- * the listener to be removed.
- */
- public void removeListener(Property.ReadOnlyStatusChangeListener listener) {
- if (readOnlyStatusChangeListeners != null) {
- readOnlyStatusChangeListeners.remove(listener);
- }
- }
-
- /**
- * Sends a value change event to all registered listeners.
- */
- private void fireValueChange() {
- if (valueChangeListeners != null) {
- final Object[] l = valueChangeListeners.toArray();
- final Property.ValueChangeEvent event = new ValueChangeEvent(this);
- for (int i = 0; i < l.length; i++) {
- ((Property.ValueChangeListener) l[i]).valueChange(event);
- }
- }
- }
-
- /**
- * Sends a read only status change event to all registered listeners.
- */
- private void fireReadOnlyStatusChange() {
- if (readOnlyStatusChangeListeners != null) {
- final Object[] l = readOnlyStatusChangeListeners.toArray();
- final Property.ReadOnlyStatusChangeEvent event = new ReadOnlyStatusChangeEvent(
- this);
- for (int i = 0; i < l.length; i++) {
- ((Property.ReadOnlyStatusChangeListener) l[i])
- .readOnlyStatusChange(event);
- }
- }
- }
-
- /**
- * Listens for changes in the datasource.
- *
- * This should not be called directly.
- */
- public void valueChange(
- com.itmill.toolkit.data.Property.ValueChangeEvent event) {
- fireValueChange();
- }
-
- /**
- * Listens for changes in the datasource.
- *
- * This should not be called directly.
- */
- public void readOnlyStatusChange(
- com.itmill.toolkit.data.Property.ReadOnlyStatusChangeEvent event) {
- fireReadOnlyStatusChange();
- }
-
-}
diff --git a/src/com/itmill/toolkit/data/util/PropertysetItem.java b/src/com/itmill/toolkit/data/util/PropertysetItem.java
deleted file mode 100644
index d2d2946d4e..0000000000
--- a/src/com/itmill/toolkit/data/util/PropertysetItem.java
+++ /dev/null
@@ -1,314 +0,0 @@
-/*
-@ITMillApache2LicenseForJavaFiles@
- */
-
-package com.itmill.toolkit.data.util;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.EventObject;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-
-import com.itmill.toolkit.data.Item;
-import com.itmill.toolkit.data.Property;
-
-/**
- * Class for handling a set of identified Properties. The elements contained in
- * a MapItem can be referenced using locally unique identifiers.
- * The class supports listeners who are interested in changes to the Property
- * set managed by the class.
- *
- * @author IT Mill Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
-@SuppressWarnings("serial")
-public class PropertysetItem implements Item, Item.PropertySetChangeNotifier,
- Cloneable {
-
- /* Private representation of the item */
-
- /**
- * Mapping from property id to property.
- */
- private HashMap map = new HashMap();
-
- /**
- * List of all property ids to maintain the order.
- */
- private LinkedList list = new LinkedList();
-
- /**
- * List of property set modification listeners.
- */
- private LinkedList propertySetChangeListeners = null;
-
- /* Item methods */
-
- /**
- * Gets the Property corresponding to the given Property ID stored in the
- * Item. If the Item does not contain the Property, null
is
- * returned.
- *
- * @param id
- * the identifier of the Property to get.
- * @return the Property with the given ID or null
- */
- public Property getItemProperty(Object id) {
- return (Property) map.get(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() {
- return Collections.unmodifiableCollection(list);
- }
-
- /* Item.Managed methods */
-
- /**
- * Removes the Property identified by ID from the Item. This functionality
- * is optional. If the method is not implemented, the method always returns
- * false
.
- *
- * @param id
- * the ID of the Property to be removed.
- * @return true
if the operation succeeded false
- * if not
- */
- public boolean removeItemProperty(Object id) {
-
- // Cant remove missing properties
- if (map.remove(id) == null) {
- return false;
- }
- list.remove(id);
-
- // Send change events
- fireItemPropertySetChange();
-
- return true;
- }
-
- /**
- * Tries to add a new Property into the Item.
- *
- * @param id
- * the ID of the new Property.
- * @param property
- * the Property to be added and associated with the id.
- * @return true
if the operation succeeded, false
- * if not
- */
- public boolean addItemProperty(Object id, Property property) {
-
- // Null ids are not accepted
- if (id == null) {
- throw new NullPointerException("Item property id can not be null");
- }
-
- // Cant add a property twice
- if (map.containsKey(id)) {
- return false;
- }
-
- // Put the property to map
- map.put(id, property);
- list.add(id);
-
- // Send event
- fireItemPropertySetChange();
-
- return true;
- }
-
- /**
- * Gets the String
representation of the contents of the Item.
- * The format of the string is a space separated catenation of the
- * String
representations of the Properties contained by the
- * Item.
- *
- * @return String
representation of the Item contents
- */
- @Override
- public String toString() {
- String retValue = "";
-
- for (final Iterator i = getItemPropertyIds().iterator(); i.hasNext();) {
- final Object propertyId = i.next();
- retValue += getItemProperty(propertyId).toString();
- if (i.hasNext()) {
- retValue += " ";
- }
- }
-
- return retValue;
- }
-
- /* Notifiers */
-
- /**
- * An event
object specifying an Item whose Property set has
- * changed.
- *
- * @author IT Mill Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
- private class PropertySetChangeEvent extends EventObject implements
- Item.PropertySetChangeEvent {
-
- private PropertySetChangeEvent(Item source) {
- super(source);
- }
-
- /**
- * Gets the Item whose Property set has changed.
- *
- * @return source object of the event as an Item
- */
- public Item getItem() {
- return (Item) getSource();
- }
- }
-
- /**
- * Registers a new property set change listener for this Item.
- *
- * @param listener
- * the new Listener to be registered.
- */
- public void addListener(Item.PropertySetChangeListener listener) {
- if (propertySetChangeListeners == null) {
- propertySetChangeListeners = new LinkedList();
- }
- propertySetChangeListeners.add(listener);
- }
-
- /**
- * Removes a previously registered property set change listener.
- *
- * @param listener
- * the Listener to be removed.
- */
- public void removeListener(Item.PropertySetChangeListener listener) {
- if (propertySetChangeListeners != null) {
- propertySetChangeListeners.remove(listener);
- }
- }
-
- /**
- * Sends a Property set change event to all interested listeners.
- */
- private void fireItemPropertySetChange() {
- if (propertySetChangeListeners != null) {
- final Object[] l = propertySetChangeListeners.toArray();
- final Item.PropertySetChangeEvent event = new PropertysetItem.PropertySetChangeEvent(
- this);
- for (int i = 0; i < l.length; i++) {
- ((Item.PropertySetChangeListener) l[i])
- .itemPropertySetChange(event);
- }
- }
- }
-
- /**
- * Creates and returns a copy of this object.
- *
- * The method clone
performs a shallow copy of the
- * PropertysetItem
.
- *
- * Note : All arrays are considered to implement the interface Cloneable. - * Otherwise, this method creates a new instance of the class of this object - * and initializes all its fields with exactly the contents of the - * corresponding fields of this object, as if by assignment, the contents of - * the fields are not themselves cloned. Thus, this method performs a - * "shallow copy" of this object, not a "deep copy" operation. - *
- * - * @throws CloneNotSupportedException - * if the object's class does not support the Cloneable - * interface. - * - * @see java.lang.Object#clone() - */ - @Override - public Object clone() throws CloneNotSupportedException { - - final PropertysetItem npsi = new PropertysetItem(); - - npsi.list = list != null ? (LinkedList) list.clone() : null; - npsi.propertySetChangeListeners = propertySetChangeListeners != null ? (LinkedList) propertySetChangeListeners - .clone() - : null; - npsi.map = (HashMap) map.clone(); - - return npsi; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) { - - if (obj == null || !(obj instanceof PropertysetItem)) { - return false; - } - - final PropertysetItem other = (PropertysetItem) obj; - - if (other.list != list) { - if (other.list == null) { - return false; - } - if (!other.list.equals(list)) { - return false; - } - } - if (other.map != map) { - if (other.map == null) { - return false; - } - if (!other.map.equals(map)) { - return false; - } - } - if (other.propertySetChangeListeners != propertySetChangeListeners) { - if (other.propertySetChangeListeners == null) { - return false; - } - if (!other.propertySetChangeListeners - .equals(propertySetChangeListeners)) { - return false; - } - } - - return true; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - - return (list == null ? 0 : list.hashCode()) - ^ (map == null ? 0 : map.hashCode()) - ^ (propertySetChangeListeners == null ? 0 - : propertySetChangeListeners.hashCode()); - } -} diff --git a/src/com/itmill/toolkit/data/util/QueryContainer.java b/src/com/itmill/toolkit/data/util/QueryContainer.java deleted file mode 100644 index 2139318e0c..0000000000 --- a/src/com/itmill/toolkit/data/util/QueryContainer.java +++ /dev/null @@ -1,641 +0,0 @@ -/* -@ITMillApache2LicenseForJavaFiles@ - */ - -package com.itmill.toolkit.data.util; - -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; - -import com.itmill.toolkit.data.Container; -import com.itmill.toolkit.data.Item; -import com.itmill.toolkit.data.Property; - -/** - *
- * The QueryContainer
is the specialized form of Container which is
- * Ordered and Indexed. This is used to represent the contents of relational
- * database tables accessed through the JDBC Connection in the Toolkit Table.
- * This creates Items based on the queryStatement provided to the container.
- *
- * The QueryContainer
can be visualized as a representation of a
- * relational database table.Each Item in the container represents the row
- * fetched by the query.All cells in a column have same data type and the data
- * type information is retrieved from the metadata of the resultset.
- *
- * Note : If data in the tables gets modified, Container will not get reflected - * with the updates, we have to explicity invoke QueryContainer.refresh method. - * {@link com.itmill.toolkit.data.util.QueryContainer#refresh() refresh()} - *
- * - * @see com.itmill.toolkit.data.Container - * - * @author IT Mill Ltd. - * @version - * @since 4.0 - */ - -@SuppressWarnings("serial") -public class QueryContainer implements Container, Container.Ordered, - Container.Indexed { - - // default ResultSet type - public static final int DEFAULT_RESULTSET_TYPE = ResultSet.TYPE_SCROLL_INSENSITIVE; - - // default ResultSet concurrency - public static final int DEFAULT_RESULTSET_CONCURRENCY = ResultSet.CONCUR_READ_ONLY; - - private int resultSetType = DEFAULT_RESULTSET_TYPE; - - private int resultSetConcurrency = DEFAULT_RESULTSET_CONCURRENCY; - - private final String queryStatement; - - private final Connection connection; - - private ResultSet result; - - private Collection propertyIds; - - private final HashMap propertyTypes = new HashMap(); - - private int size = -1; - - private Statement statement; - - /** - * Constructs newQueryContainer
with the specified
- * queryStatement
.
- *
- * @param queryStatement
- * Database query
- * @param connection
- * Connection object
- * @param resultSetType
- * @param resultSetConcurrency
- * @throws SQLException
- * when database operation fails
- */
- public QueryContainer(String queryStatement, Connection connection,
- int resultSetType, int resultSetConcurrency) throws SQLException {
- this.queryStatement = queryStatement;
- this.connection = connection;
- this.resultSetType = resultSetType;
- this.resultSetConcurrency = resultSetConcurrency;
- init();
- }
-
- /**
- * Constructs new QueryContainer
with the specified
- * queryStatement using the default resultset type and default resultset
- * concurrency.
- *
- * @param queryStatement
- * Database query
- * @param connection
- * Connection object
- * @see QueryContainer#DEFAULT_RESULTSET_TYPE
- * @see QueryContainer#DEFAULT_RESULTSET_CONCURRENCY
- * @throws SQLException
- * when database operation fails
- */
- public QueryContainer(String queryStatement, Connection connection)
- throws SQLException {
- this(queryStatement, connection, DEFAULT_RESULTSET_TYPE,
- DEFAULT_RESULTSET_CONCURRENCY);
- }
-
- /**
- * Fills the Container with the items and properties. Invoked by the
- * constructor.
- *
- * @throws SQLException
- * when parameter initialization fails.
- * @see QueryContainer#QueryContainer(String, Connection, int, int).
- */
- private void init() throws SQLException {
- refresh();
- ResultSetMetaData metadata;
- metadata = result.getMetaData();
- final int count = metadata.getColumnCount();
- final ArrayList list = new ArrayList(count);
- for (int i = 1; i <= count; i++) {
- final String columnName = metadata.getColumnName(i);
- list.add(columnName);
- final Property p = getContainerProperty(new Integer(1), columnName);
- propertyTypes.put(columnName, p == null ? Object.class : p
- .getType());
- }
- propertyIds = Collections.unmodifiableCollection(list);
- }
-
- /**
- * - * Restores items in the container. This method will update the latest data - * to the container. - *
- * Note: This method should be used to update the container with the latest - * items. - * - * @throws SQLException - * when database operation fails - * - */ - - public void refresh() throws SQLException { - close(); - statement = connection.createStatement(resultSetType, - resultSetConcurrency); - result = statement.executeQuery(queryStatement); - result.last(); - size = result.getRow(); - } - - /** - * Releases and nullifies thestatement
.
- *
- * @throws SQLException
- * when database operation fails
- */
-
- public void close() throws SQLException {
- if (statement != null) {
- statement.close();
- }
- statement = null;
- }
-
- /**
- * Gets the Item with the given Item ID from the Container.
- *
- * @param id
- * ID of the Item to retrieve
- * @return Item Id.
- */
-
- public Item getItem(Object id) {
- return new Row(id);
- }
-
- /**
- * Gets the collection of propertyId from the Container.
- *
- * @return Collection of Property ID.
- */
-
- public Collection getContainerPropertyIds() {
- return propertyIds;
- }
-
- /**
- * Gets an collection of all the item IDs in the container.
- *
- * @return collection of Item IDs
- */
- public Collection getItemIds() {
- final Collection c = new ArrayList(size);
- for (int i = 1; i <= size; i++) {
- c.add(new Integer(i));
- }
- return c;
- }
-
- /**
- * Gets the property identified by the given itemId and propertyId from the
- * container. If the container does not contain the property
- * null
is returned.
- *
- * @param itemId
- * ID of the Item which contains the Property
- * @param propertyId
- * ID of the Property to retrieve
- *
- * @return Property with the given ID if exists; null
- * otherwise.
- */
-
- public synchronized Property getContainerProperty(Object itemId,
- Object propertyId) {
- if (!(itemId instanceof Integer && propertyId instanceof String)) {
- return null;
- }
- Object value;
- try {
- result.absolute(((Integer) itemId).intValue());
- value = result.getObject((String) propertyId);
- } catch (final Exception e) {
- return null;
- }
-
- // Handle also null values from the database
- return new ObjectProperty(value != null ? value : new String(""));
- }
-
- /**
- * Gets the data type of all properties identified by the given type ID.
- *
- * @param id
- * ID identifying the Properties
- *
- * @return data type of the Properties
- */
-
- public Class getType(Object id) {
- return (Class) propertyTypes.get(id);
- }
-
- /**
- * Gets the number of items in the container.
- *
- * @return the number of items in the container.
- */
- public int size() {
- return size;
- }
-
- /**
- * Tests if the list contains the specified Item.
- *
- * @param id
- * ID the of Item to be tested.
- * @return true
if given id is in the container;
- * false
otherwise.
- */
- public boolean containsId(Object id) {
- if (!(id instanceof Integer)) {
- return false;
- }
- final int i = ((Integer) id).intValue();
- if (i < 1) {
- return false;
- }
- if (i > size) {
- return false;
- }
- return true;
- }
-
- /**
- * Creates new Item with the given ID into the Container.
- *
- * @param itemId
- * ID of the Item to be created.
- *
- * @return Created new Item, or null
if it fails.
- *
- * @throws UnsupportedOperationException
- * if the addItem method is not supported.
- */
- public Item addItem(Object itemId) throws UnsupportedOperationException {
- throw new UnsupportedOperationException();
- }
-
- /**
- * Creates a new Item into the Container, and assign it an ID.
- *
- * @return ID of the newly created Item, or null
if it fails.
- * @throws UnsupportedOperationException
- * if the addItem method is not supported.
- */
- public Object addItem() throws UnsupportedOperationException {
- throw new UnsupportedOperationException();
- }
-
- /**
- * Removes the Item identified by ItemId from the Container.
- *
- * @param itemId
- * ID of the Item to remove.
- * @return true
if the operation succeeded; false
- * otherwise.
- * @throws UnsupportedOperationException
- * if the removeItem method is not supported.
- */
- public boolean removeItem(Object itemId)
- throws UnsupportedOperationException {
- throw new UnsupportedOperationException();
- }
-
- /**
- * Adds new Property to all Items in the Container.
- *
- * @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
- * otherwise.
- * @throws UnsupportedOperationException
- * if the addContainerProperty method is not supported.
- */
- public boolean addContainerProperty(Object propertyId, Class type,
- Object defaultValue) throws UnsupportedOperationException {
- throw new UnsupportedOperationException();
- }
-
- /**
- * Removes a Property specified by the given Property ID from the Container.
- *
- * @param propertyId
- * ID of the Property to remove
- * @return true
if the operation succeeded; false
- * otherwise.
- * @throws UnsupportedOperationException
- * if the removeContainerProperty method is not supported.
- */
- public boolean removeContainerProperty(Object propertyId)
- throws UnsupportedOperationException {
- throw new UnsupportedOperationException();
- }
-
- /**
- * Removes all Items from the Container.
- *
- * @return true
if the operation succeeded; false
- * otherwise.
- * @throws UnsupportedOperationException
- * if the removeAllItems method is not supported.
- */
- public boolean removeAllItems() throws UnsupportedOperationException {
- throw new UnsupportedOperationException();
- }
-
- /**
- * Adds new item after the given item.
- *
- * @param previousItemId
- * Id of the previous item in ordered container.
- * @param newItemId
- * Id of the new item to be added.
- * @return Returns new item or null
if the operation fails.
- * @throws UnsupportedOperationException
- * if the addItemAfter method is not supported.
- */
- public Item addItemAfter(Object previousItemId, Object newItemId)
- throws UnsupportedOperationException {
- throw new UnsupportedOperationException();
- }
-
- /**
- * Adds new item after the given item.
- *
- * @param previousItemId
- * Id of the previous item in ordered container.
- * @return Returns item id created new item or null
if the
- * operation fails.
- * @throws UnsupportedOperationException
- * if the addItemAfter method is not supported.
- */
- public Object addItemAfter(Object previousItemId)
- throws UnsupportedOperationException {
- throw new UnsupportedOperationException();
- }
-
- /**
- * Returns id of first item in the Container.
- *
- * @return ID of the first Item in the list.
- */
- public Object firstItemId() {
- if (size < 1) {
- return null;
- }
- return new Integer(1);
- }
-
- /**
- * Returns true
if given id is first id at first index.
- *
- * @param id
- * ID of an Item in the Container.
- */
- public boolean isFirstId(Object id) {
- return size > 0 && (id instanceof Integer)
- && ((Integer) id).intValue() == 1;
- }
-
- /**
- * Returns true
if given id is last id at last index.
- *
- * @param id
- * ID of an Item in the Container
- *
- */
- public boolean isLastId(Object id) {
- return size > 0 && (id instanceof Integer)
- && ((Integer) id).intValue() == size;
- }
-
- /**
- * Returns id of last item in the Container.
- *
- * @return ID of the last Item.
- */
- public Object lastItemId() {
- if (size < 1) {
- return null;
- }
- return new Integer(size);
- }
-
- /**
- * Returns id of next item in container at next index.
- *
- * @param id
- * ID of an Item in the Container.
- * @return ID of the next Item or null.
- */
- public Object nextItemId(Object id) {
- if (size < 1 || !(id instanceof Integer)) {
- return null;
- }
- final int i = ((Integer) id).intValue();
- if (i >= size) {
- return null;
- }
- return new Integer(i + 1);
- }
-
- /**
- * Returns id of previous item in container at previous index.
- *
- * @param id
- * ID of an Item in the Container.
- * @return ID of the previous Item or null.
- */
- public Object prevItemId(Object id) {
- if (size < 1 || !(id instanceof Integer)) {
- return null;
- }
- final int i = ((Integer) id).intValue();
- if (i <= 1) {
- return null;
- }
- return new Integer(i - 1);
- }
-
- /**
- * The Row
class implements methods of Item.
- *
- * @author IT Mill Ltd.
- * @version
- * @since 4.0
- */
- class Row implements Item {
-
- Object id;
-
- private Row(Object rowId) {
- id = rowId;
- }
-
- /**
- * Adds the item property.
- *
- * @param id
- * ID of the new Property.
- * @param property
- * Property to be added and associated with ID.
- * @return true
if the operation succeeded;
- * false
otherwise.
- * @throws UnsupportedOperationException
- * if the addItemProperty method is not supported.
- */
- public boolean addItemProperty(Object id, Property property)
- throws UnsupportedOperationException {
- throw new UnsupportedOperationException();
- }
-
- /**
- * Gets the property corresponding to the given property ID stored in
- * the Item.
- *
- * @param propertyId
- * identifier of the Property to get
- * @return the Property with the given ID or null
- */
- public Property getItemProperty(Object propertyId) {
- return getContainerProperty(id, propertyId);
- }
-
- /**
- * Gets the collection of property IDs stored in the Item.
- *
- * @return unmodifiable collection containing IDs of the Properties
- * stored the Item.
- */
- public Collection getItemPropertyIds() {
- return propertyIds;
- }
-
- /**
- * Removes given item property.
- *
- * @param id
- * ID of the Property to be removed.
- * @return true
if the item property is removed;
- * false
otherwise.
- * @throws UnsupportedOperationException
- * if the removeItemProperty is not supported.
- */
- public boolean removeItemProperty(Object id)
- throws UnsupportedOperationException {
- throw new UnsupportedOperationException();
- }
-
- }
-
- /**
- * Closes the statement.
- *
- * @see #close()
- */
- @Override
- public void finalize() {
- try {
- close();
- } catch (final SQLException ignored) {
-
- }
- }
-
- /**
- * Adds the given item at the position of given index.
- *
- * @param index
- * Index to add the new item.
- * @param newItemId
- * Id of the new item to be added.
- * @return new item or null
if the operation fails.
- * @throws UnsupportedOperationException
- * if the addItemAt is not supported.
- */
- public Item addItemAt(int index, Object newItemId)
- throws UnsupportedOperationException {
- throw new UnsupportedOperationException();
- }
-
- /**
- * Adds item at the position of provided index in the container.
- *
- * @param index
- * Index to add the new item.
- * @return item id created new item or null
if the operation
- * fails.
- *
- * @throws UnsupportedOperationException
- * if the addItemAt is not supported.
- */
-
- public Object addItemAt(int index) throws UnsupportedOperationException {
- throw new UnsupportedOperationException();
- }
-
- /**
- * Gets the Index id in the container.
- *
- * @param index
- * Index Id.
- * @return ID in the given index.
- */
- public Object getIdByIndex(int index) {
- if (size < 1 || index < 0 || index >= size) {
- return null;
- }
- return new Integer(index + 1);
- }
-
- /**
- * Gets the index of the Item corresponding to id in the container.
- *
- * @param id
- * ID of an Item in the Container
- * @return index of the Item, or -1 if the Container does not include the
- * Item
- */
-
- public int indexOfId(Object id) {
- if (size < 1 || !(id instanceof Integer)) {
- return -1;
- }
- final int i = ((Integer) id).intValue();
- if (i >= size || i < 1) {
- return -1;
- }
- return i - 1;
- }
-
-}
diff --git a/src/com/itmill/toolkit/data/util/package.html b/src/com/itmill/toolkit/data/util/package.html
deleted file mode 100644
index 3148c89d4a..0000000000
--- a/src/com/itmill/toolkit/data/util/package.html
+++ /dev/null
@@ -1,37 +0,0 @@
-
-
-
-
-
-
-
-
-Provides various utility classes that implement the data layer -functionality.
- -The first {@link com.itmill.toolkit.data.Property Property} class, -{@link com.itmill.toolkit.data.util.ObjectProperty ObjectProperty}, provides -a simple class containing a typed data value. The second, -{@link com.itmill.toolkit.data.util.MethodProperty MethodProperty}, provides -a way to bind a field of an object to the Property interface using the -accessor methods for the field.
- -The next level of the data layer, the -{@link com.itmill.toolkit.data.Item Item}, is implemented by -{@link com.itmill.toolkit.data.util.BeanItem BeanItem}, though it is only a -simple wrapper to the former to provide the Item interface for any regular -Java Bean.
- -The third level, the {@link com.itmill.toolkit.data.Container Container}, -has several implementations in the {@link com.itmill.toolkit.data.util} -package.
- - - - - - - - - - diff --git a/src/com/itmill/toolkit/data/validator/AbstractStringValidator.java b/src/com/itmill/toolkit/data/validator/AbstractStringValidator.java deleted file mode 100644 index cecc63a637..0000000000 --- a/src/com/itmill/toolkit/data/validator/AbstractStringValidator.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.itmill.toolkit.data.validator; - -/** - * Validator base class for validating strings. See - * {@link com.itmill.toolkit.data.validator.AbstractValidator} for more - * information. - * - *- * If the validation fails, the exception thrown contains the error message with - * its argument 0 replaced with the string being validated. - *
- * - * @author IT Mill Ltd. - * @version - * @VERSION@ - * @since 5.4 - */ -@SuppressWarnings("serial") -public abstract class AbstractStringValidator extends AbstractValidator { - - /** - * Constructs a validator for strings. - *- * Null and empty string values are always accepted. To disallow empty - * values, set the field being validated as required. - *
- * - * @param errorMessage - * the message included in the exception (with its parameter {0} - * replaced by the string to be validated) in case the validation - * fails - */ - public AbstractStringValidator(String errorMessage) { - super(errorMessage); - } - - public boolean isValid(Object value) { - if (value == null) { - return true; - } - if (!(value instanceof String)) { - return false; - } - return isValidString((String) value); - } - - /** - * Checks if the given string is valid. - * - * @param value - * String to check. Can never be null. - * @return true if the string is valid, false otherwise - */ - protected abstract boolean isValidString(String value); -} diff --git a/src/com/itmill/toolkit/data/validator/AbstractValidator.java b/src/com/itmill/toolkit/data/validator/AbstractValidator.java deleted file mode 100644 index c12ea0d848..0000000000 --- a/src/com/itmill/toolkit/data/validator/AbstractValidator.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.itmill.toolkit.data.validator; - -import com.itmill.toolkit.data.Validator; - -/** - * Default Validator base class. See - * {@link com.itmill.toolkit.data.validator.Validator} for more information. - *- * If the validation fails, the exception thrown contains the error message with - * its argument 0 replaced with the toString() of the object being validated. - *
- * - * @author IT Mill Ltd. - * @version - * @VERSION@ - * @since 5.4 - */ -@SuppressWarnings("serial") -public abstract class AbstractValidator implements Validator { - - /** - * Error message. - */ - private String errorMessage; - - /** - * Constructs a validator with an error message. - * - * @param errorMessage - * the message included in the exception (with its parameter {0} - * replaced by toString() of the object to be validated) in case - * the validation fails - */ - public AbstractValidator(String errorMessage) { - this.errorMessage = errorMessage; - } - - public void validate(Object value) throws InvalidValueException { - if (!isValid(value)) { - String message; - if (value == null) { - message = errorMessage.replace("{0}", "null"); - } else { - message = errorMessage.replace("{0}", value.toString()); - } - throw new InvalidValueException(message); - } - } - - /** - * Gets the message to be displayed in case the value does not validate. - * - * @return the Error Message. - */ - public String getErrorMessage() { - return errorMessage; - } - - /** - * Sets the message to be displayed in case the value does not validate. - * - * @param errorMessage - * the Error Message to set. - */ - public void setErrorMessage(String errorMessage) { - this.errorMessage = errorMessage; - } -} diff --git a/src/com/itmill/toolkit/data/validator/CompositeValidator.java b/src/com/itmill/toolkit/data/validator/CompositeValidator.java deleted file mode 100644 index 13266d4ca8..0000000000 --- a/src/com/itmill/toolkit/data/validator/CompositeValidator.java +++ /dev/null @@ -1,269 +0,0 @@ -/* -@ITMillApache2LicenseForJavaFiles@ - */ - -package com.itmill.toolkit.data.validator; - -import java.util.Collection; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; - -import com.itmill.toolkit.data.Validator; - -/** - * TheCompositeValidator
allows you to chain (compose) many
- * validators to validate one field. The contained validators may be required to
- * all validate the value to validate or it may be enough that one contained
- * validator validates the value. This behaviour is controlled by the modes
- * AND
and OR
.
- *
- * @author IT Mill Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
-@SuppressWarnings("serial")
-public class CompositeValidator extends AbstractValidator {
-
- /**
- * The validators are combined with AND
clause: validity of the
- * composite implies validity of the all validators it is composed of must
- * be valid.
- */
- public static final int MODE_AND = 0;
-
- /**
- * The validators are combined with OR
clause: validity of the
- * composite implies that some of validators it is composed of must be
- * valid.
- */
- public static final int MODE_OR = 1;
-
- /**
- * The validators are combined with and clause: validity of the composite
- * implies validity of the all validators it is composed of
- */
- public static final int MODE_DEFAULT = MODE_AND;
-
- /**
- * Operation mode.
- */
- private int mode = MODE_DEFAULT;
-
- /**
- * List of contained validators.
- */
- private final ListAND
mode without error
- * message.
- */
- public CompositeValidator() {
- super("");
- }
-
- /**
- * Constructs a composite validator in given mode.
- */
- public CompositeValidator(int mode, String errorMessage) {
- super(errorMessage);
- setMode(mode);
- }
-
- /**
- * Validates the given value.
- * - * The value is valid, if: - *
MODE_AND
: All of the sub-validators are valid
- * MODE_OR
: Any of the sub-validators are valid
- * MODE_AND
: All of the sub-validators are valid
- * MODE_OR
: Any of the sub-validators are valid
- * MODE_AND
or
- * MODE_OR
.
- */
- public final int getMode() {
- return mode;
- }
-
- /**
- * Sets the mode of the validator. The valid modes are:
- * MODE_AND
(default)
- * MODE_OR
- *
- * If the component contains directly or recursively (it contains another
- * composite containing the validator) validators compatible with given type
- * they are returned. This only applies to AND
mode composite
- * validators.
- *
- * If the validator is in OR
mode or does not contain any
- * validators of given type null is returned.
- *
true
for valid value, otherwise false
.
- */
- public boolean isValid(Object value) {
- return onlyNullAllowed ? value == null : value != null;
- }
-
- /**
- * Returns true
if nulls are allowed otherwise
- * false
.
- */
- public final boolean isNullAllowed() {
- return onlyNullAllowed;
- }
-
- /**
- * Sets if nulls (and only nulls) are to be allowed.
- *
- * @param onlyNullAllowed
- * If true, only nulls are allowed. If false only non-nulls are
- * allowed. Do we allow nulls?
- */
- public void setNullAllowed(boolean onlyNullAllowed) {
- this.onlyNullAllowed = onlyNullAllowed;
- }
-
- /**
- * Gets the error message that is displayed in case the value is invalid.
- *
- * @return the Error Message.
- */
- public String getErrorMessage() {
- return errorMessage;
- }
-
- /**
- * Sets the error message to be displayed on invalid value.
- *
- * @param errorMessage
- * the Error Message to set.
- */
- public void setErrorMessage(String errorMessage) {
- this.errorMessage = errorMessage;
- }
-
-}
diff --git a/src/com/itmill/toolkit/data/validator/RegexpValidator.java b/src/com/itmill/toolkit/data/validator/RegexpValidator.java
deleted file mode 100644
index eb42a2668a..0000000000
--- a/src/com/itmill/toolkit/data/validator/RegexpValidator.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package com.itmill.toolkit.data.validator;
-
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * String validator comparing the string against a Java regular expression. Both
- * complete matches and substring matches are supported.
- *
- * - * For the Java regular expression syntax, see - * {@link java.util.regex.Pattern#sum} - *
- *- * See {@link com.itmill.toolkit.data.validator.AbstractStringValidator} for - * more information. - *
- * - * @author IT Mill Ltd. - * @version - * @VERSION@ - * @since 5.4 - */ -@SuppressWarnings("serial") -public class RegexpValidator extends AbstractStringValidator { - - private Pattern pattern; - private boolean complete; - private Matcher matcher = null; - - /** - * Creates a validator for checking that the regular expression matches the - * complete string to validate. - * - * @param regexp - * a Java regular expression - * @param errorMessage - * the message to display in case the value does not validate. - */ - public RegexpValidator(String regexp, String errorMessage) { - this(regexp, true, errorMessage); - } - - /** - * Creates a validator for checking that the regular expression matches the - * string to validate. - * - * @param regexp - * a Java regular expression - * @param complete - * true to use check for a complete match, false to look for a - * matching substring - * @param errorMessage - * the message to display in case the value does not validate. - */ - public RegexpValidator(String regexp, boolean complete, String errorMessage) { - super(errorMessage); - pattern = Pattern.compile(regexp); - this.complete = complete; - } - - @Override - protected boolean isValidString(String value) { - if (complete) { - return getMatcher(value).matches(); - } else { - return getMatcher(value).find(); - } - } - - /** - * Get a new or reused matcher for the pattern - * - * @param value - * the string to find matches in - * @return Matcher for the string - */ - private Matcher getMatcher(String value) { - if (matcher == null) { - matcher = pattern.matcher(value); - } else { - matcher.reset(value); - } - return matcher; - } - -} diff --git a/src/com/itmill/toolkit/data/validator/StringLengthValidator.java b/src/com/itmill/toolkit/data/validator/StringLengthValidator.java deleted file mode 100644 index 6105b0e746..0000000000 --- a/src/com/itmill/toolkit/data/validator/StringLengthValidator.java +++ /dev/null @@ -1,144 +0,0 @@ -/* -@ITMillApache2LicenseForJavaFiles@ - */ - -package com.itmill.toolkit.data.validator; - -/** - * ThisStringLengthValidator
is used to validate the length of
- * strings.
- *
- * @author IT Mill Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
-@SuppressWarnings("serial")
-public class StringLengthValidator extends AbstractValidator {
-
- private int minLength = -1;
-
- private int maxLength = -1;
-
- private boolean allowNull = true;
-
- /**
- * Creates a new StringLengthValidator with a given error message.
- *
- * @param errorMessage
- * the message to display in case the value does not validate.
- */
- public StringLengthValidator(String errorMessage) {
- super(errorMessage);
- }
-
- /**
- * Creates a new StringLengthValidator with a given error message,
- * permissable lengths and null-string allowance.
- *
- * @param errorMessage
- * the message to display in case the value does not validate.
- * @param minLength
- * the minimum permissible length of the string.
- * @param maxLength
- * the maximum permissible length of the string.
- * @param allowNull
- * Are null strings permissible? This can be handled better by
- * setting a field as required or not.
- */
- public StringLengthValidator(String errorMessage, int minLength,
- int maxLength, boolean allowNull) {
- this(errorMessage);
- setMinLength(minLength);
- setMaxLength(maxLength);
- setNullAllowed(allowNull);
- }
-
- /**
- * Checks if the given value is valid.
- *
- * @param value
- * the value to validate.
- * @return true
for valid value, otherwise false
.
- */
- public boolean isValid(Object value) {
- if (value == null) {
- return allowNull;
- }
- final String s = value.toString();
- if (s == null) {
- return allowNull;
- }
- final int len = s.length();
- if ((minLength >= 0 && len < minLength)
- || (maxLength >= 0 && len > maxLength)) {
- return false;
- }
- return true;
- }
-
- /**
- * Returns true
if null strings are allowed.
- *
- * @return true
if allows null string, otherwise
- * false
.
- */
- @Deprecated
- public final boolean isNullAllowed() {
- return allowNull;
- }
-
- /**
- * Gets the maximum permissible length of the string.
- *
- * @return the maximum length of the string.
- */
- public final int getMaxLength() {
- return maxLength;
- }
-
- /**
- * Gets the minimum permissible length of the string.
- *
- * @return the minimum length of the string.
- */
- public final int getMinLength() {
- return minLength;
- }
-
- /**
- * Sets whether null-strings are to be allowed. This can be better handled
- * by setting a field as required or not.
- */
- @Deprecated
- public void setNullAllowed(boolean allowNull) {
- this.allowNull = allowNull;
- }
-
- /**
- * Sets the maximum permissible length of the string.
- *
- * @param maxLength
- * the length to set.
- */
- public void setMaxLength(int maxLength) {
- if (maxLength < -1) {
- maxLength = -1;
- }
- this.maxLength = maxLength;
- }
-
- /**
- * Sets the minimum permissible length.
- *
- * @param minLength
- * the length to set.
- */
- public void setMinLength(int minLength) {
- if (minLength < -1) {
- minLength = -1;
- }
- this.minLength = minLength;
- }
-
-}
diff --git a/src/com/itmill/toolkit/data/validator/package.html b/src/com/itmill/toolkit/data/validator/package.html
deleted file mode 100644
index 8697eb6313..0000000000
--- a/src/com/itmill/toolkit/data/validator/package.html
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-Provides validators for data contained in data-bound objects..
- - - - - - - - - -- cgit v1.2.3