public class JObjectContainer extends SimpleKeyedContainer<ObjId,JObject>
Container backed by JSimpleDB Java model objects.
Automatically creates container properties for object ID, database type, schema version, and all fields, as well as any custom
properties defined by @ProvidesProperty-annotated methods in
Java model classes. The properties of each Item in the container are derived from a corresponding
JObject which is usually stored in an in-memory SnapshotJTransaction (which may contain other
related objects, allowing an Item's properties to be derived from those related objects as well).
Instances are configured with a type, which can be any Java type. The container will then be restricted to database objects that are instances of the configured type. The type may be null, in which case there is no restriction.
Instances are loaded by invoking load() with an iteration of backing JObjects.
Normally these JObjects are contained in a SnapshotJTransaction.
Instances implement Connectable and therefore must be connect()'ed
prior to use and disconnect()'ed after use (usually done in the associated widget's
attach() and detach() methods).
Container Properties
Instances have the following container properties:
OBJECT_ID_PROPERTY: Object ObjIdTYPE_PROPERTY: Object type name (JSimpleDB type name, not Java type name, though the former
is by default the simple Java type name)VERSION_PROPERTY: Object schema versionREFERENCE_LABEL_PROPERTY: Object reference label, which is a short description identifying the
object. Reference labels are used to provide "names" for objects that are more meaningful than object ID's
and are used as such in other JSimpleDB GUI classes, for example when displaying the object in a list.
To customize the reference label for a Java model class,
annotate a method with @ProvidesProperty(REFERENCE_LABEL_PROPERTY);
otherwise, the value of this property will be the same as OBJECT_ID_PROPERTY. Note that objects with
customized reference labels will need to be included in the snapshot transaction also if they are referenced
by an object actually in the container.
JSimpleDB field that is common to all object types that sub-type
this containers's configured type. The property's ID is the field name; its value is as follows:
REFERENCE_LABEL_PROPERTY of the referred-to object, or "Null"
if the reference is null@ProvidesProperty-annotated method
in the specified type. These properties will add to (or override) the properties listed above.
| Modifier and Type | Class and Description |
|---|---|
class |
JObjectContainer.ObjFieldPropertyDef
Implements a property reflecting the value of a
JSimpleDB field. |
static class |
JObjectContainer.ObjIdPropertyDef
Implements the
OBJECT_ID_PROPERTY property. |
static class |
JObjectContainer.ObjPropertyDef<T>
Support superclass for
PropertyDef implementations that derive the property value from a JObject. |
static class |
JObjectContainer.ObjTypePropertyDef
Implements the
TYPE_PROPERTY property. |
static class |
JObjectContainer.ObjVersionPropertyDef
Implements the
VERSION_PROPERTY property. |
static class |
JObjectContainer.RefLabelPropertyDef
Implements the
REFERENCE_LABEL_PROPERTY property. |
AbstractInMemoryContainer.BaseItemAddEvent, AbstractInMemoryContainer.BaseItemRemoveEventAbstractContainer.BaseItemSetChangeEvent, AbstractContainer.BasePropertySetChangeEventContainer.Editor, Container.Filter, Container.Filterable, Container.Hierarchical, Container.Indexed, Container.ItemSetChangeEvent, Container.ItemSetChangeListener, Container.ItemSetChangeNotifier, Container.Ordered, Container.PropertySetChangeEvent, Container.PropertySetChangeListener, Container.PropertySetChangeNotifier, Container.SimpleFilterable, Container.Sortable, Container.ViewerContainer.Indexed.ItemAddEvent, Container.Indexed.ItemRemoveEvent| Modifier and Type | Field and Description |
|---|---|
protected JSimpleDB |
jdb
The associated
JSimpleDB. |
protected Logger |
log |
static String |
OBJECT_ID_PROPERTY
Container property name for the object ID property.
|
static String |
REFERENCE_LABEL_PROPERTY
Container property name for the reference label property, which has type
Component. |
static String |
TYPE_PROPERTY
Container property name for the object type property.
|
static String |
VERSION_PROPERTY
Container property name for the object schema version property.
|
| Modifier | Constructor and Description |
|---|---|
protected |
JObjectContainer(JSimpleDB jdb,
Class<?> type)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
doInTransaction(Runnable action)
Perform the given action within a new
JTransaction. |
ObjId |
getKeyFor(JObject jobj) |
List<String> |
getOrderedPropertyNames()
Get the properties of this container in preferred order.
|
<V> V |
getPropertyValue(JObject jobj,
PropertyDef<V> propertyDef) |
Class<?> |
getType()
Get the type restriction associated with this instance.
|
void |
load(Iterable<? extends JObject> jobjs)
Load this container using the supplied backing
JObjects. |
void |
load(Iterator<? extends JObject> jobjs)
Load this container using the supplied backing
JObjects. |
<T> void |
setType(Class<T> type)
Change the type restriction associated with this instance.
|
void |
updateItem(JObject jobj)
Update a single item in this container by updating its backing object.
|
generateItemId, getItemIdFor, getItemIdForSame, getJavaObject, resetItemIdsaddContainerFilter, addContainerFilter, afterReload, connect, createBackedItem, disconnect, getContainerFilters, getContainerProperty, getContainerPropertyIds, getItemIds, getPropertyExtractor, getSortableContainerPropertyIds, getType, getUnfilteredItem, internalRemoveAllItems, removeAllContainerFilters, removeContainerFilter, removeContainerFilters, setProperties, setProperty, setPropertyExtractor, sortaddContainerProperty, addFilter, addItem, addItem, addItemAfter, addItemAfter, addItemAt, addItemAt, addItemSetChangeListener, addListener, containsId, doFilterContainer, doSort, filterAll, fireItemAdded, fireItemRemoved, fireItemsAdded, fireItemsRemoved, firstItemId, getAllItemIds, getFilteredItemIds, getFilters, getFirstVisibleItem, getIdByIndex, getItem, getItemIds, getItemSorter, getSortablePropertyIds, getVisibleItemIds, hasContainerFilters, indexOfId, internalAddItemAfter, internalAddItemAt, internalAddItemAtEnd, internalRemoveItem, isFiltered, isFirstId, isLastId, isPropertyFiltered, lastItemId, nextItemId, passesFilters, prevItemId, registerNewItem, removeAllFilters, removeAllItems, removeContainerProperty, removeFilter, removeFilters, removeItem, removeItemSetChangeListener, removeListener, setAllItemIds, setFilteredItemIds, setFilters, setItemSorter, size, sortContaineraddListener, addPropertySetChangeListener, fireContainerPropertySetChange, fireContainerPropertySetChange, fireItemSetChange, fireItemSetChange, getItemSetChangeListeners, getListeners, getPropertySetChangeListeners, removeListener, removePropertySetChangeListener, setItemSetChangeListeners, setPropertySetChangeListenersclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddItemAfter, addItemAfter, firstItemId, isFirstId, isLastId, lastItemId, nextItemId, prevItemIdaddContainerProperty, addItem, addItem, containsId, getItem, removeAllItems, removeContainerProperty, removeItem, sizepublic static final String REFERENCE_LABEL_PROPERTY
Component.public static final String OBJECT_ID_PROPERTY
public static final String TYPE_PROPERTY
public static final String VERSION_PROPERTY
protected final Logger log
protected JObjectContainer(JSimpleDB jdb, Class<?> type)
jdb - JSimpleDB databasetype - type restriction, or null for no restrictionIllegalArgumentException - if jdb is nullpublic Class<?> getType()
public <T> void setType(Class<T> type)
Container.PropertySetChangeEvent and typically requires a reload.T - Java typetype - Java type restriction, or null for nonepublic List<String> getOrderedPropertyNames()
public ObjId getKeyFor(JObject jobj)
getKeyFor in class SimpleKeyedContainer<ObjId,JObject>public void load(Iterable<? extends JObject> jobjs)
JObjects.
A container Item will be created wrapping each iterated JObject;
Item properties are accessible only while the containing transaction remains open.
load in class AbstractSimpleContainer<ObjId,JObject>jobjs - backing JObjectspublic void load(Iterator<? extends JObject> jobjs)
JObjects.
A container Item will be created wrapping each iterated JObject;
Item properties are accessible only while the containing transaction remains open.
load in class AbstractSimpleContainer<ObjId,JObject>jobjs - backing JObjectspublic void updateItem(JObject jobj)
This updates the backing object with the same object ID as jobj, if any, and then fires
Property.ValueChangeEvents for all properties of the corresponding
Item.
jobj - updated database objectprotected void doInTransaction(Runnable action)
JTransaction.
The implementation in JObjectContainer performs action within a new read-only transaction.
action - the action to performpublic <V> V getPropertyValue(JObject jobj, PropertyDef<V> propertyDef)
getPropertyValue in interface PropertyExtractor<JObject>getPropertyValue in class AbstractSimpleContainer<ObjId,JObject>Copyright © 2016. All rights reserved.