org.pm4j.core.pm.impl
Class PmObjectBase

java.lang.Object
  extended by org.pm4j.core.pm.impl.PmObjectBase
All Implemented Interfaces:
java.lang.Comparable<PmObject>, PmObject
Direct Known Subclasses:
PmAttrBase, PmCommandImpl, PmDataInputBase, PmLabelImpl, PmTableColImpl

public abstract class PmObjectBase
extends java.lang.Object
implements PmObject

Provides base functionality if presentation model classes.

Author:
olaf boede

Nested Class Summary
protected static class PmObjectBase.MetaData
          Shared PM meta data for all attributes of the same kind.
static interface PmObjectBase.NameBuilder
           
static class PmObjectBase.NameBuilderAbsoluteName
           
static class PmObjectBase.NameBuilderShortName
           
static class PmObjectBase.NameBuilderTitle
           
 
Field Summary
protected static PmCacheLog pmCacheLog
          Logger for cache usage statistics.
 
Fields inherited from interface org.pm4j.core.pm.PmObject
STYLE_CLASS_DISABLED, STYLE_CLASS_ERROR, STYLE_CLASS_INFO, STYLE_CLASS_REQUIRED, STYLE_CLASS_WARN
 
Constructor Summary
PmObjectBase()
          Constructor.
PmObjectBase(PmObject pmParent)
           
 
Method Summary
 void accept(PmVisitor visitor)
           
protected  void addToPmComposite(java.lang.String name, PmObject pm)
          Adds the given PM as a named member of this PM composite.
 boolean canSetPmTitle()
          Indicates if it is allowed to call the #setPmTitle(Object, String) method for the given item.
protected  void clearCachedPmValues(java.util.Set<PmCacheApi.CacheKind> cacheSet)
          Clears cached content (if there was something cached).
Causes a reload of the content with the next request.
 void clearPmInvalidValues()
          Clears not yet validated values within the scope of this PM.
 int compareTo(PmObject otherPm)
          The default implementation always returns zero.
protected  void ensurePmMetaDataInitialization()
          Ensures that all static definitions of this model are initialized.
protected
<T extends java.lang.annotation.Annotation>
void
findAnnotationsInPmHierarchy(java.lang.Class<T> annotationClass, java.util.Collection<T> foundAnnotations)
          Searches an annotation within the attribute-element-session hierarchy.
 PmConversation getPmConversation()
           
protected  PmConversationImpl getPmConversationImpl()
           
 java.lang.String getPmIconPath()
           
protected  PmObjectBase.MetaData getPmMetaData()
          Provides the PM meta data.
protected  PmObjectBase.MetaData getPmMetaDataWithoutPmInitCall()
           
 java.lang.String getPmName()
          A unique short name of this item within its parent scope.
 PmObject getPmParent()
           
 java.lang.Object getPmProperty(java.lang.String propName)
          Returns a application specific property that may have been defined using PmObject.setPmProperty(String, Object).
 java.lang.String getPmRelativeName()
          The unique relative name of the pm within its PM-composite.
 java.lang.String getPmResKey()
           
 java.lang.String getPmResKeyBase()
           
 java.util.List<java.lang.Class<?>> getPmResLoaderCtxtClasses()
          Fix resources are usually located in a package and archive context of a domain class.
 java.lang.String getPmShortTitle()
          Some applications decorate titles for specific items with some extra characters.
 java.util.Set<java.lang.String> getPmStyleClasses()
          A PM may provide CSS style classes to provide layout hints.
protected  void getPmStyleClassesImpl(java.util.Set<java.lang.String> styleClassSet)
          Provides subclass specific style class definitions.
 java.lang.String getPmTitle()
           
protected
<T extends PmObject>
PmTitleProvider<T>
getPmTitleDef()
          Provides a default title provider that may be overridden by concrete classes.
protected  java.lang.String getPmTitleImpl()
           
 java.lang.String getPmTooltip()
           
protected  java.lang.String getPmTooltipImpl()
           
protected  java.util.List<PmCommand> getVisiblePmCommands()
           
protected  java.util.List<PmCommand> getVisiblePmCommands(PmCommand.CommandSet commandSet)
           
protected  void initMetaData(PmObjectBase.MetaData metaData)
           
protected  boolean isMetaDataInitialized()
           
 boolean isPmEnabled()
           
protected  boolean isPmEnabledImpl()
           
 boolean isPmReadonly()
          Please override isPmReadonlyImpl() to provide your specific logic.
protected  boolean isPmReadonlyImpl()
          Sub classes may implement their specific read-only definition here.
 boolean isPmValid()
          Checks if there is an error message related to this PM.
 boolean isPmVisible()
           
protected  boolean isPmVisibleImpl()
           
protected abstract  PmObjectBase.MetaData makeMetaData()
          Gets called when the meta data instance for this presentation model is not yet available (first call within the VM live time).
protected  void onPmChildStateChange(PmObject child, PmEvent event)
          Gets called whenever the state of a child was changed.
protected  void onPmInit()
          Gets called when the meta data part of this PM is initialized and assigned to this instance.
protected  void onPmValueChange(PmEvent event)
          Is called whenever an event with the flag PmEvent.VALUE_CHANGE was fired for this PM.
protected  PmCacheStrategy readCacheStrategy(java.lang.String cacheCfgAttrName, java.util.List<PmCacheCfg> cacheAnnotations, java.util.Map<PmCacheCfg.CacheMode,PmCacheStrategy> modeToStrategyMap)
           
protected  void removePmChild(PmObject pm)
           
 void setPmEnabled(java.lang.Boolean enabled)
           
 void setPmParent(PmObject pmParent)
          Setter for dependency injection framework support.
 void setPmProperty(java.lang.String propName, java.lang.Object value)
          TODO
 void setPmTitle(java.lang.String titleString)
          An interface for 'in place editing' of node titles.
 void setPmVisible(java.lang.Boolean visible)
          The visibility state is usually defined by some UI logic code of the implementing class.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

pmCacheLog

protected static final PmCacheLog pmCacheLog
Logger for cache usage statistics.

Constructor Detail

PmObjectBase

public PmObjectBase()
Constructor.


PmObjectBase

public PmObjectBase(PmObject pmParent)
Parameters:
pmParent - The context, this PM was created in. E.g. a session, a command, a list field.
Method Detail

canSetPmTitle

public boolean canSetPmTitle()
Description copied from interface: PmObject
Indicates if it is allowed to call the #setPmTitle(Object, String) method for the given item.

Specified by:
canSetPmTitle in interface PmObject
Returns:
true when it is allowed to call #setTitle(Object, Object, String).

getPmTitleImpl

protected java.lang.String getPmTitleImpl()

getPmShortTitle

public java.lang.String getPmShortTitle()
Description copied from interface: PmObject
Some applications decorate titles for specific items with some extra characters.

Example: A required field or a modified item may be decorated with an asterisk. So that the attribute 'name' appears with the title 'Name *' in an data entry form.

That decorated title is provided by PmObject.getPmTitle(). This method provides the undecorated title that may be used for generation of messages such as: 'Please enter a value for field Name.'.

In addition the simple title may be specified separately in the resource file with the postfix '.shortTitle'.

Example resource definition for explicit short title definition:

    myPm.oriSelection=Specify the Original
    myPm.oriSelection.shortTitle=Original
  

Specified by:
getPmShortTitle in interface PmObject
Returns:
The undecorated title string for this item.

getPmTooltip

public final java.lang.String getPmTooltip()
Specified by:
getPmTooltip in interface PmObject
Returns:
The tool tip string of this item or null when there is no tool tip.

getPmTooltipImpl

protected java.lang.String getPmTooltipImpl()

getPmIconPath

public java.lang.String getPmIconPath()
Specified by:
getPmIconPath in interface PmObject
Returns:
Resource path of the icon to show for this PM or null if no icon should be displayed.

setPmTitle

public void setPmTitle(java.lang.String titleString)
Description copied from interface: PmObject
An interface for 'in place editing' of node titles.

That might be a useful feature for title string editors of tree views where a user can simply click on a title and change it.

Specified by:
setPmTitle in interface PmObject

getPmConversation

public PmConversation getPmConversation()
Specified by:
getPmConversation in interface PmObject
Returns:
The conversation context of this model element. Never null.

getPmParent

public final PmObject getPmParent()
Specified by:
getPmParent in interface PmObject
Returns:
The parent object of this PM.
Is null for the root session only.

setPmParent

public void setPmParent(PmObject pmParent)
Description copied from interface: PmObject
Setter for dependency injection framework support.

Should only be used if the instance has not yet an assigned pmParent.

Specified by:
setPmParent in interface PmObject
Parameters:
pmParent - The context, this PM was created in.

isPmVisible

public final boolean isPmVisible()
Specified by:
isPmVisible in interface PmObject
Returns:
true when the element may be displayed.

isPmVisibleImpl

protected boolean isPmVisibleImpl()

setPmVisible

public void setPmVisible(java.lang.Boolean visible)
Description copied from interface: PmObject
The visibility state is usually defined by some UI logic code of the implementing class.

In some cases it is useful to control the visibility of an UI element by calling this setter.

Specified by:
setPmVisible in interface PmObject
Parameters:
visible - The new local visibility state. If set to null, the visibility provided by isPmVisibleImpl() will be applied.

isPmEnabled

public final boolean isPmEnabled()
Specified by:
isPmEnabled in interface PmObject
Returns:
true when the element should be rendered as enabled UI element.

isPmEnabledImpl

protected boolean isPmEnabledImpl()

setPmEnabled

public void setPmEnabled(java.lang.Boolean enabled)
Specified by:
setPmEnabled in interface PmObject
Parameters:
enabled - The new local enabled state.

isPmValid

public boolean isPmValid()
Description copied from interface: PmObject
Checks if there is an error message related to this PM.

Is often used to check if the UI should show a not valid attribute with a special style.

Specified by:
isPmValid in interface PmObject
Returns:
true if there is an error (may be a validation error) related this PM.

isPmReadonly

public final boolean isPmReadonly()
Please override isPmReadonlyImpl() to provide your specific logic.

Specified by:
isPmReadonly in interface PmObject
Returns:
true when the values of this PM may not be changed.

isPmReadonlyImpl

protected boolean isPmReadonlyImpl()
Sub classes may implement their specific read-only definition here.

Returns:
true if the PM is in read-only state.

getPmResKey

public java.lang.String getPmResKey()
Returns:
The key for language specific resources.

getPmResKeyBase

public java.lang.String getPmResKeyBase()

getPmTitle

public final java.lang.String getPmTitle()
Specified by:
getPmTitle in interface PmObject
Returns:
A title string for this item.

onPmValueChange

protected void onPmValueChange(PmEvent event)
Is called whenever an event with the flag PmEvent.VALUE_CHANGE was fired for this PM.

Parameters:
event - The fired event.

onPmChildStateChange

protected void onPmChildStateChange(PmObject child,
                                    PmEvent event)
Gets called whenever the state of a child was changed.

This method can be used to observe changes within a part of the PM tree.

Parameters:
child - The affected child of this PM. This PM must not be the changed one. The change may be related to a sub-PM of this child. Please check PmEvent.pm to get the changed PM.
event - The change event that caused this call.

clearCachedPmValues

protected void clearCachedPmValues(java.util.Set<PmCacheApi.CacheKind> cacheSet)
Clears cached content (if there was something cached).
Causes a reload of the content with the next request.

Parameters:
cacheKinds - The set of caches to be cleared. If no cacheKind is specified, all cache kinds will be cleared.

getPmTitleDef

protected <T extends PmObject> PmTitleProvider<T> getPmTitleDef()
Provides a default title provider that may be overridden by concrete classes.

Returns:
The concrete title provider that implements the specific title logic.

getPmResLoaderCtxtClasses

public java.util.List<java.lang.Class<?>> getPmResLoaderCtxtClasses()
Fix resources are usually located in a package and archive context of a domain class. E.g. the string resources are may be located in the same package or a parent package of the class that uses it.

If you write a domain specific presentation model class then the resource loader context class is just this domain class.
If you only use instances of classes (e.g. standard attributes) then the domain specific resources will not be found in relation to that class.
The standard class has to provide a way to get a domain context class. In case of standard attributes that is done by providing the parent element class.

Returns:
The class that can be used to find resources (string resources icons...).

getVisiblePmCommands

protected java.util.List<PmCommand> getVisiblePmCommands()

getVisiblePmCommands

protected java.util.List<PmCommand> getVisiblePmCommands(PmCommand.CommandSet commandSet)

getPmName

public final java.lang.String getPmName()
Description copied from interface: PmObject
A unique short name of this item within its parent scope.

Specified by:
getPmName in interface PmObject
Returns:
The attribute/command/session name.
Is null for models that are created dynamically (e.g. elements of a list).

getPmRelativeName

public final java.lang.String getPmRelativeName()
Description copied from interface: PmObject
The unique relative name of the pm within its PM-composite. This kind of name may be used in html forms to identify the fields to enter.

Specified by:
getPmRelativeName in interface PmObject
Returns:
The unique name within the PM-composite.
An empty string for non-PM-composite children. FIXME: Derzeit nicht!

getPmConversationImpl

protected PmConversationImpl getPmConversationImpl()
Returns:
The conversation implementation interface. It allows to use the internal feature set (not declared in the PmConversation interface).

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getPmMetaData

protected final PmObjectBase.MetaData getPmMetaData()
Provides the PM meta data.

Ensures that the PM is competely initialized.

Returns:
The meta data for this PM.

getPmMetaDataWithoutPmInitCall

protected final PmObjectBase.MetaData getPmMetaDataWithoutPmInitCall()

isMetaDataInitialized

protected final boolean isMetaDataInitialized()

ensurePmMetaDataInitialization

protected void ensurePmMetaDataInitialization()
Ensures that all static definitions of this model are initialized.


onPmInit

protected void onPmInit()
Gets called when the meta data part of this PM is initialized and assigned to this instance.


makeMetaData

protected abstract PmObjectBase.MetaData makeMetaData()
Gets called when the meta data instance for this presentation model is not yet available (first call within the VM live time).

Subclasses that provide more specific meta data should override this method to provide their meta data information container.

Returns:
A static data container for this presentation model.

initMetaData

protected void initMetaData(PmObjectBase.MetaData metaData)

findAnnotationsInPmHierarchy

protected <T extends java.lang.annotation.Annotation> void findAnnotationsInPmHierarchy(java.lang.Class<T> annotationClass,
                                                                                        java.util.Collection<T> foundAnnotations)
Searches an annotation within the attribute-element-session hierarchy. Adds all found annotations to the given collection. Adds nothing when no annotation was found in the hierarchy.

Parameters:
annotationClass - The annotation to find.
foundAnnotations - The set to add the found annotations to. The lowest level annotation (e.g. bound to an attribute) is at the first position. The highest level annotation (e.g. bound to the root session) is at the last position.

accept

public void accept(PmVisitor visitor)
Specified by:
accept in interface PmObject
Parameters:
visitor - A visitor to call back.

compareTo

public int compareTo(PmObject otherPm)
The default implementation always returns zero.

Specified by:
compareTo in interface java.lang.Comparable<PmObject>
Specified by:
compareTo in interface PmObject
Parameters:
otherPm - The PM to compare.
Returns:
The usual Comparable result: a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

clearPmInvalidValues

public void clearPmInvalidValues()
Clears not yet validated values within the scope of this PM.


getPmStyleClasses

public java.util.Set<java.lang.String> getPmStyleClasses()
Description copied from interface: PmObject
A PM may provide CSS style classes to provide layout hints.

The set of style classes may change whenever the state of the PM changes. It usually contains an 'error' class if there is an error message related to this PM.

Specified by:
getPmStyleClasses in interface PmObject
Returns:
The set of CSS style classes for this PM.

getPmStyleClassesImpl

protected void getPmStyleClassesImpl(java.util.Set<java.lang.String> styleClassSet)
Provides subclass specific style class definitions.

Parameters:
styleClassSet - The container to add the style classes to.

getPmProperty

public java.lang.Object getPmProperty(java.lang.String propName)
Description copied from interface: PmObject
Returns a application specific property that may have been defined using PmObject.setPmProperty(String, Object).

Specified by:
getPmProperty in interface PmObject
Returns:
The property value or null if the property is not defined.

setPmProperty

public void setPmProperty(java.lang.String propName,
                          java.lang.Object value)
Description copied from interface: PmObject
TODO

Specified by:
setPmProperty in interface PmObject

readCacheStrategy

protected PmCacheStrategy readCacheStrategy(java.lang.String cacheCfgAttrName,
                                            java.util.List<PmCacheCfg> cacheAnnotations,
                                            java.util.Map<PmCacheCfg.CacheMode,PmCacheStrategy> modeToStrategyMap)

addToPmComposite

protected void addToPmComposite(java.lang.String name,
                                PmObject pm)
Adds the given PM as a named member of this PM composite.

Has the same effect as declaring a composite PM in a public final field of its parent.


removePmChild

protected void removePmChild(PmObject pm)