org.pm4j.core.pm.impl
Class PmCommandImpl

java.lang.Object
  extended by org.pm4j.core.pm.impl.PmObjectBase
      extended by org.pm4j.core.pm.impl.PmCommandImpl
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable<PmObject>, PmCommand, PmObject
Direct Known Subclasses:
PmCommandGroup, PmCommandNaviBack, PmCommandProxy, PmCommandSeparator, PmContentChangeCommand, PmListAddItemCommand, PmListRemoveItemCommand, PmTableColImpl.CmdSortPm, PmValueChangeCommand

public class PmCommandImpl
extends PmObjectBase
implements PmCommand, java.lang.Cloneable

Implementation for PmCommand.

Author:
olaf boede

Nested Class Summary
protected static class PmCommandImpl.MetaData
          Shared meta data for all commands of the same kind.
 
Nested classes/interfaces inherited from class org.pm4j.core.pm.impl.PmObjectBase
PmObjectBase.NameBuilder, PmObjectBase.NameBuilderAbsoluteName, PmObjectBase.NameBuilderShortName, PmObjectBase.NameBuilderTitle
 
Nested classes/interfaces inherited from interface org.pm4j.core.pm.PmCommand
PmCommand.CmdKind, PmCommand.CommandSet, PmCommand.CommandState
 
Field Summary
static java.lang.String NAVI_PARAM_NEXT_DLG_PM
          A navigation parameter that contains the PM for a dialog to start after command execution.
protected static java.lang.String PERFORMED_REDIRECT
          Internal marker object.
 
Fields inherited from class org.pm4j.core.pm.impl.PmObjectBase
pmCacheLog
 
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
PmCommandImpl(PmObject pmParent)
          Constructor for fix commands that have an associated field in the parent PM.
PmCommandImpl(PmObject pmParent, org.pm4j.navi.NaviLink naviLink)
          Constructor for fix commands that have an associated field in the parent PM.
 
Method Summary
 void accept(PmVisitor visitor)
           
protected  org.pm4j.navi.NaviLink actionReturnOnFailure(org.pm4j.navi.NaviLink suggestedNaviLink)
          The default implementation returns just the suggested framework navigation.
 void addCommandDecorator(PmCommandDecorator commandDecorator)
           
protected  org.pm4j.navi.NaviLink afterDo(boolean changeCommandHistory)
           
protected  boolean beforeDo()
          Is executed before doItImpl() gets called.
protected  PmCommandImpl clone()
           
 PmCommand doIt()
          Does the operation.
 PmCommand doIt(boolean changeCommandHistory)
          See {@link #doIt().
protected  void doItImpl()
          Subclasses may implement here their concrete logic.
 PmObject doItReturnNextDlgPm()
          Executes the command.
 java.lang.String doItReturnString()
          Interface for web frameworks like JSF.
 void doItReturnVoid()
          Command call with void return type.
 PmCommand.CmdKind getCmdKind()
           
 PmCommand.CommandState getCommandState()
          
protected  org.pm4j.navi.NaviLink getNavigateBackLink(org.pm4j.navi.NaviLink... linksToSkip)
          Provides the link to navigate to.
The default implementation calls NaviHistory#getPrevOrStartLink()
 org.pm4j.navi.NaviLink getNaviLink()
          Provides an optional link to a navigation target.
protected  org.pm4j.navi.NaviLink getNaviLinkImpl()
           
 java.util.List<PmCommand> getParentCommands()
          A command may be nested in a hierarchy of other parent commands (command groups).
 PmCommand getUndoCommand()
          Provides an instance that may undo the effect of this command.
 PmCommandDecorator getVetoCommandDecorator()
          Provides the command decorator that returned false for its call of PmCommandDecorator.beforeDo(PmCommand).
 java.util.List<PmCommand> getVisiblePmCommands(PmCommand.CommandSet commandSet)
          Commands usually don't have popups.
protected  void initMetaData(PmObjectBase.MetaData metaData)
           
protected  boolean isASubCommandEnabled()
           
protected  boolean isASubCommandVisible()
           
protected  boolean isPmEnabledImpl()
          The default implementation checks the own enabled flag and the enablement of its parent context element.
protected  boolean isPmVisibleImpl()
           
 boolean isRequiresValidValues()
           
protected  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 makeOptionalSuccessMsg()
          Is called on each successful command execution.
protected  void navigateBack(org.pm4j.navi.NaviLink... linksToSkip)
          Navigates to the page, the user came from.
protected  void navigateTo(org.pm4j.navi.NaviLink naviLink)
          Defines a target for navigation after command execution.
protected  void setNaviLink(org.pm4j.navi.NaviLink naviLink)
          Defines a target for navigation after command execution.
 void setUndoCommand(PmCommand undoCommand)
          Defines the command that may undo this one.
protected  void validate()
          Gets called before command execution.
Commands may add here specific precondition validations.
 
Methods inherited from class org.pm4j.core.pm.impl.PmObjectBase
addToPmComposite, canSetPmTitle, clearCachedPmValues, clearPmInvalidValues, compareTo, ensurePmMetaDataInitialization, findAnnotationsInPmHierarchy, getPmConversation, getPmConversationImpl, getPmIconPath, getPmMetaData, getPmMetaDataWithoutPmInitCall, getPmName, getPmParent, getPmProperty, getPmRelativeName, getPmResKey, getPmResKeyBase, getPmResLoaderCtxtClasses, getPmShortTitle, getPmStyleClasses, getPmStyleClassesImpl, getPmTitle, getPmTitleDef, getPmTitleImpl, getPmTooltip, getPmTooltipImpl, getVisiblePmCommands, isMetaDataInitialized, isPmEnabled, isPmReadonly, isPmReadonlyImpl, isPmValid, isPmVisible, onPmChildStateChange, onPmInit, onPmValueChange, readCacheStrategy, removePmChild, setPmEnabled, setPmParent, setPmProperty, setPmTitle, setPmVisible, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.pm4j.core.pm.PmObject
canSetPmTitle, compareTo, getPmConversation, getPmIconPath, getPmName, getPmParent, getPmProperty, getPmRelativeName, getPmShortTitle, getPmStyleClasses, getPmTitle, getPmTooltip, isPmEnabled, isPmReadonly, isPmValid, isPmVisible, setPmEnabled, setPmParent, setPmProperty, setPmTitle, setPmVisible
 

Field Detail

PERFORMED_REDIRECT

protected static final java.lang.String PERFORMED_REDIRECT
Internal marker object.

See Also:
Constant Field Values

NAVI_PARAM_NEXT_DLG_PM

public static final java.lang.String NAVI_PARAM_NEXT_DLG_PM
A navigation parameter that contains the PM for a dialog to start after command execution.

See Also:
Constant Field Values
Constructor Detail

PmCommandImpl

public PmCommandImpl(PmObject pmParent,
                     org.pm4j.navi.NaviLink naviLink)
Constructor for fix commands that have an associated field in the parent PM.

Parameters:
pmParent - The presentation model that command acts on.

PmCommandImpl

public PmCommandImpl(PmObject pmParent)
Constructor for fix commands that have an associated field in the parent PM.

Parameters:
pmParent - The presentation model that command acts on.
Method Detail

setUndoCommand

public void setUndoCommand(PmCommand undoCommand)
Defines the command that may undo this one.

Parameters:
undoCommand -

addCommandDecorator

public void addCommandDecorator(PmCommandDecorator commandDecorator)
Specified by:
addCommandDecorator in interface PmCommand
Parameters:
commandDecorator - The decorator to add to the command execution logic.

actionReturnOnFailure

protected org.pm4j.navi.NaviLink actionReturnOnFailure(org.pm4j.navi.NaviLink suggestedNaviLink)
The default implementation returns just the suggested framework navigation.

Subclasses may override this to provide alternate navigation rules.

Parameters:
suggestedNaviLink - The default navigation suggested by the framework.
Returns:
The intended navigation.

isPmVisibleImpl

protected boolean isPmVisibleImpl()
Overrides:
isPmVisibleImpl in class PmObjectBase

isPmEnabledImpl

protected boolean isPmEnabledImpl()
The default implementation checks the own enabled flag and the enablement of its parent context element.

If the command is child of a command (group), the enablement of the first non-command parent will be checked.

Overrides:
isPmEnabledImpl in class PmObjectBase

getVisiblePmCommands

public java.util.List<PmCommand> getVisiblePmCommands(PmCommand.CommandSet commandSet)
Commands usually don't have popups. This default implementation always provides an empty list for this command set kind.

Overrides:
getVisiblePmCommands in class PmObjectBase

accept

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

doIt

public PmCommand doIt()
Description copied from interface: PmCommand
Does the operation.

It internally clones this command instance and perfroms the operation using the cloned command.
This prototype pattern approach allows to store execution time specific values within the command (E.g. navigation links, values, an undo-command).

Returns the command instance (clone) that performed the operation.

Any error messages are reported as error messages.

Specified by:
doIt in interface PmCommand
Returns:
The command clone that performed the operation.

doItReturnNextDlgPm

public PmObject doItReturnNextDlgPm()
Description copied from interface: PmCommand
Executes the command. If the command provides a next dialog (E.g. in case of wizard page flows), the PM of the next page will be returned.

Specified by:
doItReturnNextDlgPm in interface PmCommand
Returns:
The PM of the next page to show.

doIt

public PmCommand doIt(boolean changeCommandHistory)
See {@link #doIt().

Parameters:
changeCommandHistory -
Returns:

doItReturnString

public final java.lang.String doItReturnString()
Description copied from interface: PmCommand
Interface for web frameworks like JSF.

Specified by:
doItReturnString in interface PmCommand
Returns:
Implementation dependent. Typically "myPm.cmdDoSomeWork.success" or "myPm.cmdDoSomeWork.failed".

doItReturnVoid

public final void doItReturnVoid()
Description copied from interface: PmCommand
Command call with void return type. Used to support some ui frameworks (such as a4j) that need void signatures for actions.

Specified by:
doItReturnVoid in interface PmCommand

getUndoCommand

public final PmCommand getUndoCommand()
Description copied from interface: PmCommand
Provides an instance that may undo the effect of this command.

A command is 'undo-able' when this method returns null.

Specified by:
getUndoCommand in interface PmCommand
Returns:
The command that can undo the effect of this command or null.

doItImpl

protected void doItImpl()
                 throws java.lang.Exception
Subclasses may implement here their concrete logic.

Throws:
org.pm4j.core.exception.PmUserMessageException - In case of handled failures that should be reported with a localized error message in the UI.
java.lang.Exception - In case of an unexpected failure.

navigateTo

protected final void navigateTo(org.pm4j.navi.NaviLink naviLink)
Defines a target for navigation after command execution.

Does the same as setNaviLink(NaviLink). Provides just a more intuitive 'wording' that may be used in doItImpl(). It may express, that the navigation will be performed very soon.

Parameters:
naviLink - The target to navigate to after command execution.

navigateBack

protected void navigateBack(org.pm4j.navi.NaviLink... linksToSkip)
Navigates to the page, the user came from.

ATTENTION: Works only in case of an enabled navigation history!

Parameters:
linksToSkip - An optional set of pages that should be skipped.
Example: A cancel button of a wizzard page seqence should skip the pages of the wizzard itself.

getNavigateBackLink

protected org.pm4j.navi.NaviLink getNavigateBackLink(org.pm4j.navi.NaviLink... linksToSkip)
Provides the link to navigate to.
The default implementation calls NaviHistory#getPrevOrStartLink()

Subclasses may override this method to provide alternative implementations.

Returns:
The back-link to navigate to.
null if no navigation history is available.

setNaviLink

protected void setNaviLink(org.pm4j.navi.NaviLink naviLink)
Defines a target for navigation after command execution.

Does the same as navigateTo(NaviLink). Is only more intuitive 'wording' that may be used in PmObjectBase.onPmInit(). It makes clear, that the navigation will not be executed on calling this method.

Parameters:
naviLink - The target to navigate to after command execution.

makeOptionalSuccessMsg

protected void makeOptionalSuccessMsg()
Is called on each successful command execution.

The default implementation provides a success message when a string resource with the postfix "_successInfo" is defined.

The message will only be added if the message was not already added (e.g. by the doItImpl() method).


getCmdKind

public PmCommand.CmdKind getCmdKind()
Specified by:
getCmdKind in interface PmCommand
Returns:
The PmCommand.CmdKind of this command item.

getParentCommands

public java.util.List<PmCommand> getParentCommands()
Description copied from interface: PmCommand
A command may be nested in a hierarchy of other parent commands (command groups). This method returns this set. The first list item is the root group. The last list item is the nearest parent.

Specified by:
getParentCommands in interface PmCommand
Returns:
The parent command list. In case of no parents an empty list, never null.

getNaviLink

public final org.pm4j.navi.NaviLink getNaviLink()
Description copied from interface: PmCommand
Provides an optional link to a navigation target.

Is usually provided by commands that just perform a static navigation.

Some commands calculate their navigation target when they get executed. In this case only the result of the PmCommand.doIt() call provides the correct navigation link.

Specified by:
getNaviLink in interface PmCommand
Returns:
The navigation link or null.

getNaviLinkImpl

protected org.pm4j.navi.NaviLink getNaviLinkImpl()

isRequiresValidValues

public boolean isRequiresValidValues()
Specified by:
isRequiresValidValues in interface PmCommand
Returns:
true when the command should fail when there are invalid values within the current session.

isASubCommandEnabled

protected boolean isASubCommandEnabled()
Returns:
true when at least a single child command is enabled.

isASubCommandVisible

protected boolean isASubCommandVisible()
Returns:
true when at least a single child command is visible.

clone

protected PmCommandImpl clone()
Overrides:
clone in class java.lang.Object

validate

protected void validate()
Gets called before command execution.
Commands may add here specific precondition validations.

The default implementation checks isRequiresValidValues() and triggers the validation of the parent element.


beforeDo

protected boolean beforeDo()
Is executed before doItImpl() gets called.

validate() gets called in case of commands the require valid values.
This method returns false if the validation fails. Consequently the doItImpl() method will not be called.

If the command does not required valid values, the current PM messages (error messages) get cleared and the command gets executed.
This matches the usual cancel-button logic.

Returns:
true if the doItImpl() logic should be executed.

afterDo

protected org.pm4j.navi.NaviLink afterDo(boolean changeCommandHistory)

getVetoCommandDecorator

public PmCommandDecorator getVetoCommandDecorator()
Provides the command decorator that returned false for its call of PmCommandDecorator.beforeDo(PmCommand).

In other words: The decorator that prevented the execution of the doItImpl() logic of this command.

Returns:
activeCommandDecorator

getCommandState

public PmCommand.CommandState getCommandState()

Specified by:
getCommandState in interface PmCommand
Returns:
The command (execution) state.

makeMetaData

protected PmObjectBase.MetaData makeMetaData()
Description copied from class: PmObjectBase
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.

Specified by:
makeMetaData in class PmObjectBase
Returns:
A static data container for this presentation model.

initMetaData

protected void initMetaData(PmObjectBase.MetaData metaData)
Overrides:
initMetaData in class PmObjectBase