LEONARDI Application Composer - 8.9.0.40 by W4 S.A.

leon.control
Class LyController

java.lang.Object
  extended by leon.control.LyController
All Implemented Interfaces:
LyGetSessionInterface, LyGuiListener, LyEvaluator, LyDemandListener
Direct Known Subclasses:
LyAreaController, LyFieldController, LyImportContentController, LyReportController, LyViewController

public abstract class LyController
extends java.lang.Object
implements LyGuiListener, LyDemandListener, LyEvaluator, LyGetSessionInterface

The controller class is inherited by all view controllers. It provides de basic services and accessors common to all implementations of view controllers.

A controller is usually the result of the invocation of an action. Generic actions (_create, _consult, _table, _tree ...) create a new controller instance.

A controller implements the generic processing associated to a view, the integration between the view layer (graphical components) and the data Layer.

A controllers also implements the generic response to user interactions and content (data) modifications.

Controllers enable the views to be 'dynamic', and they are usually associated to a LyBehavior class which enable the user to override.

A LyBehavior instance is usually associated to a controller : LyBehavior enables the developper of a Leonardi aplication to change or extend the generic response of the controller to create the logic of the application.

Normally, simple developments tasks should be implemented as an inheritance of the LyBehavior. Creating you own controllers or inheritance from a generic controller if of course possible, but should be considered as a more advanced task not possible to achieve in the behavior.

Main tasks of a controller :


Field Summary
static java.lang.String __VERSION
          File version
static int _nbControllers
          Number of controllers for debug purpose.
static long _nextId
          Used to compute id sequentially (in test mode).
static char CONTROLLER_ID_SEP
          Separator for controller ids.
static java.lang.String DEFAULT_IMAGE_FORMAT
          Default image extension.
static java.lang.String DEMAND_HELP
          The key of the Help demand.
static java.lang.String ID_SEP
          Separator for view ids.
 
Constructor Summary
LyController(LySession session, LyController parent)
          Constructor.
LyController(LySession session, LyController parent, java.lang.String id)
          Constructor.
 
Method Summary
 void actionDemand(LyActionDemand demand)
          Invoked when an action notification is sent to this listener.
 void activateViewDemand(LyActivateViewDemand demand)
          Invoked when an activate view notification is sent to this listener.
 void clearViewCache()
          Clears all cached data for this controller (especially the view and the component).
 void demandPerformed(LyDemand demand)
          Invoked when a notification is sent to this listener.
 void dragDropDemand(LyDragDropDemand demand)
          Invoked when a Drag & Drop occurs.
 void free()
          Free this controller.
 LyApplication getApplication()
          Accessor to the current application instance.
 LyBehaviorInterface getBehavior()
          Accessor to controller behavior A behavior is associated to a controller to let the Developer specify application logic in the behavior.
 java.lang.Class<?> getBehaviorInterface()
          Method that gives the interface that must be implemented by the behavior associated to this controller.
 LyBuilder getBuilder()
          Accessor to the internal builder.
 LyClassInfo getClassInfo(java.lang.String id)
          Shortcut to get a classInfo of the application this method is a utility shortcut to getApplication().getClassInfo(id);
 LyComponent getComponent()
          Accessor to the view component instance.
 LyEnvironment getEnvironment()
          Accessor to the current Environment instance (shortcut for getSession().getEnvironment()).
 java.lang.String getId()
          Accessor to the identifier of the controller.
 java.lang.String getImage(LyObject object)
          Get the name of the image (key or path) representing an object instance.
 java.lang.String getImage(LyObjectInfo objectInfo)
          Get the name of the image (key or path) representing an objectinfo.
 java.lang.String getImage(LyObjectInfo objectInfo, int size)
          Get the name of the image (key or path) representing an objectinfo.
 java.lang.String getImage(LyObjectInfo objectInfo, int size, boolean defaultImage)
          Get the name of the image (key or path) representing an objectinfo.
 java.lang.String getImageFromPrefix(java.lang.String prefix)
          Build an image path from a prefix.
 java.lang.String getImageFromPrefix(java.lang.String prefix, java.lang.String format, int height)
          Build an image path from a prefix, an image extension and a specified height.
 java.lang.String getImageFromPrefix(java.lang.String prefix, java.lang.String format, int width, int height)
          Build an image path from a prefix, extension, and size.
 java.lang.Object getKeyValue(java.lang.String key)
          Retrieves a value from a registered key.
 long getLastModified()
          Accessor to the last modification date of this controller.
 java.lang.String getName()
          Accessor to the name of the controller.
 LyObjectId getObjectId(java.lang.String id)
          Factory for a LyObjectId instance for the specified String identifier This is a shortcut to : new LyObjectId(getApplication(), id).
 LyController getParent()
          Accessor to the reference to the parent controller.
 LySession getSession()
          Accessor to the session instance associated to this controller.
 java.lang.Object getUserData()
          Gets user data : data stored on controller by application.
 LyView getView()
          Accessor view that contains the component (getComponent) of the controller.
abstract  LyViewController getViewController()
          Accessor to the view controller (Frame or dialog controller) which is the container of this view.
 LyViewManager getViewManager()
          Accessor to the current view manager instance (shortcut for getViewManager()).
 boolean hasViewController()
          Check the controller have a viewController.
 void helpDemand(LyHelpDemand demand)
          Invoked when an help notification is sent to this listener.
 void hideView()
          Hide the view.
 void hideView(boolean free)
          Hide the view.
 boolean isFreed()
          Internal method to check if this controller was freed.
 boolean isIdle()
          Check idle status of the table.
 void menuDemand(LyMenuDemand demand)
          Invoked when an menu item notification is sent to this listener.
 void selectionDemand(LySelectionDemand demand)
          Invoked when an selection notification is sent to this listener.
 void setBuilder(LyBuilder builder)
          Sets a builder for this controller.
 void setBuilderClass(java.lang.Class<?> builderClass)
          Sets a builder class for this controller.
 void setIdle(boolean idle)
          Sets idle status of the table.
 void setLastModified(long time)
          Accessor to set the last modification date of this controller.
 void setName(java.lang.String name)
          Accessor to the name of the controller.
 void setUserData(java.lang.Object userData)
          Sets user data : data stored on controller by application.
 void showError(LyObject object, LyError error)
          Show an error for the specified object.
 void showError(java.lang.String message)
          Show a popup message error box with the specified message.
 void showView()
          Make the view visible to the user.
 void showWarning(java.lang.String message)
          Show a popup message warning box with the specified message.
 java.lang.String toString()
          Override generic method to display the name of this controller.
 void updateViewFromValues(LyDemand demand)
          Update the view of the controller with the specified values from the demand (internal use) .
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

__VERSION

public static final java.lang.String __VERSION
File version

See Also:
Constant Field Values

DEFAULT_IMAGE_FORMAT

public static java.lang.String DEFAULT_IMAGE_FORMAT
Default image extension. The default is ".gif". Another possible value is '.jpg'


ID_SEP

public static final java.lang.String ID_SEP
Separator for view ids. The separator is used in the view ids to separate some information pieces.

See Also:
Constant Field Values

CONTROLLER_ID_SEP

public static final char CONTROLLER_ID_SEP
Separator for controller ids. This separator is used to generate constant identifiers for controllers.

See Also:
Constant Field Values

_nbControllers

public static int _nbControllers
Number of controllers for debug purpose.


_nextId

public static long _nextId
Used to compute id sequentially (in test mode).


DEMAND_HELP

public static final java.lang.String DEMAND_HELP
The key of the Help demand. When the help button is pressed in a view, the view event (demand) return this as the source object.

See Also:
LyDemand.getSource()
Constructor Detail

LyController

public LyController(LySession session,
                    LyController parent)
Constructor. The identifier of this controller is automatically generated (random id).

Parameters:
session - current session associated to the controller. The controller automatically registers on the specified session.
parent - parent controller (or null for 'root' controller). Controller hierarchy indicates a child controller (for example a dialog created from a main view)

LyController

public LyController(LySession session,
                    LyController parent,
                    java.lang.String id)
Constructor.

Parameters:
session - current session associated to the controller. The controller automatically registers on the specified session.
parent - parent controller (or null for 'root' controller). Controller hierarchy indicates a child controller (for example a dialog created from a main view)
id - identifier of the controller : can not be null. To generate the id automatically, use LyString.getRandomId() or alternate constructor.
Method Detail

showView

public void showView()
Make the view visible to the user. The effect of this command depends on the nature of the application. If the display is a fat client (windows (awt) / swing) this methods should open a window and show the view. In the case of thin client (html), this prepares the pages which will be returned and displayed in the client browser.

For any display, this method should consider that the page is ready to be shown and should be displayed.


hideView

public void hideView()
Hide the view. The effect of this command depends on the nature of the application. If the display is a fat client for example (windows (awt) / swing) this methods should close the window or hide the view.

This method should consider that the page is closed and should disappear.

The view is only HIDDEN, not cleared (see free), so it should be possible to open it again with showView and resources allocated for the view are not freed.


hideView

public void hideView(boolean free)
Hide the view. The effect of this command depends on the nature of the application. If the display is a fat client for example (windows (awt) / swing) this methods should close the window or hide the view.

This method should consider that the page is closed and should disappear.

Parameters:
free - Indicates if only HIDDEN, not FREED (true).

free

public void free()
Free this controller. This method unregister the controller from the session and stop listening from events. Additionally, the method should free all internal resources allocated by the controller. The controller instance can not be used anymore after the invocation of the free method.


getId

public java.lang.String getId()
Accessor to the identifier of the controller. The identifier of the controller is unique within a user session.

Additionally, this method is required for the LyDemandListener interface.

Specified by:
getId in interface LyDemandListener
Returns:
The identifier which is used to identify which controller is processing the demands (user events) of a view.

getName

public java.lang.String getName()
Accessor to the name of the controller.

Returns:
The name of the controller may be displayed to the user in a view.

setName

public void setName(java.lang.String name)
Accessor to the name of the controller.

Parameters:
name - The name of the controller may be displayed to the user in a view.

getParent

public LyController getParent()
Accessor to the reference to the parent controller.

Returns:
the parent controller instance or null for root controllers.

setBuilder

public void setBuilder(LyBuilder builder)
Sets a builder for this controller. This method may be used to specify a specific builder for this controller.

If no builder was specified, the controller will create a default builder using the getDefaultBuilder() method.

Parameters:
builder - the specified builder, or null to use default.

setBuilderClass

public void setBuilderClass(java.lang.Class<?> builderClass)
Sets a builder class for this controller. This method may be used to specify a specific builder class for this controller.

If no builder class was specified, the controller will create a default builder using the getDefaultBuilder() method.

Parameters:
builderClass - the specified builder class, or null to use default.

getBuilder

public LyBuilder getBuilder()
Accessor to the internal builder. If no builder is set, the method returns the reference to a default builder (invokes getDefaultBuilder).

Returns:
the builder which creates the XML description of the view. Returned value is not null and several invocation on getBuilder always return the same instance.

getBehaviorInterface

public java.lang.Class<?> getBehaviorInterface()
Method that gives the interface that must be implemented by the behavior associated to this controller.

Returns:
Class representing the behavior interface of this controller.

getBehavior

public LyBehaviorInterface getBehavior()
Accessor to controller behavior A behavior is associated to a controller to let the Developer specify application logic in the behavior.

Returns:
associated behavior

getComponent

public LyComponent getComponent()
Accessor to the view component instance. (XML description of the view) This instance is created by the builder, and multiple calls to this method always return the same instance.

Returns:
the LyComponent instance of the view package, memory representation (parsed) of the XML description of the view.

getViewController

public abstract LyViewController getViewController()
Accessor to the view controller (Frame or dialog controller) which is the container of this view. This method must be implemented in subclasses depending on the nature of the component.

Returns:
the reference to a view controller, never returns null if the controller is associated to a view.

getView

public LyView getView()
Accessor view that contains the component (getComponent) of the controller. This is a shortcut to getViewController.getView(). Returned value depends on the nature of the controller.

Returns:
the LyView instance (memory representation of the XML view) which contains the current LyComponent.

getSession

public LySession getSession()
Accessor to the session instance associated to this controller.

Specified by:
getSession in interface LyGetSessionInterface
Returns:
current session instance.

getApplication

public LyApplication getApplication()
Accessor to the current application instance. (shortcut for getSession().getApplication()).

Returns:
current application instance.

getEnvironment

public LyEnvironment getEnvironment()
Accessor to the current Environment instance (shortcut for getSession().getEnvironment()).

Returns:
current environment instance.

getViewManager

public LyViewManager getViewManager()
Accessor to the current view manager instance (shortcut for getViewManager()).

Returns:
current view manager instance.

getLastModified

public long getLastModified()
Accessor to the last modification date of this controller. The modification date is updated when anything in the view has changed. This parameter is used by view manager to decide whether the cache could be used or not.

Returns:
the last modification date (as described in java.util.Date.getTime())

setLastModified

public void setLastModified(long time)
Accessor to set the last modification date of this controller. The modification date is updated when anything in the view has changed. The value should be (new Date()).getTime()

Parameters:
time - the new modification time

toString

public java.lang.String toString()
Override generic method to display the name of this controller. Default is identical to getName

Overrides:
toString in class java.lang.Object
Returns:
the name of this controller
See Also:
getName()

isFreed

public boolean isFreed()
Internal method to check if this controller was freed.

Returns:
True if this controller was freed, false otherwise.

demandPerformed

public void demandPerformed(LyDemand demand)
Invoked when a notification is sent to this listener. Default implementation redirect the event depending on demand type :

The listener should make the interpretation of the event, and update the view description if necessary.

Specified by:
demandPerformed in interface LyDemandListener
Parameters:
demand - demand parameters sent by the view component.
See Also:
interface

updateViewFromValues

public void updateViewFromValues(LyDemand demand)
Update the view of the controller with the specified values from the demand (internal use) .

Parameters:
demand - demand parameters sent by the view component.

actionDemand

public void actionDemand(LyActionDemand demand)
Invoked when an action notification is sent to this listener.

This method is called by demandPerformed and may be overridden in subclasses.

Default implementation makes nothing.

Parameters:
demand - demand parameters sent by the view component.
See Also:
demandPerformed(leon.view.event.LyDemand)

selectionDemand

public void selectionDemand(LySelectionDemand demand)
Invoked when an selection notification is sent to this listener.

This method is called by demandPerformed and may be overriden in subclasses.

Default implementation makes nothing.

Parameters:
demand - demand parameters sent by the view component.
See Also:
demandPerformed(leon.view.event.LyDemand)

menuDemand

public void menuDemand(LyMenuDemand demand)
Invoked when an menu item notification is sent to this listener.

This method is called by demandPerformed and may be overriden in subclasses.

Default implementation makes nothing.

Parameters:
demand - demand parameters sent by the view component.
See Also:
demandPerformed(leon.view.event.LyDemand)

helpDemand

public void helpDemand(LyHelpDemand demand)
Invoked when an help notification is sent to this listener.

This method is called by demandPerformed and may be overridden in subclasses.

Default implementation makes nothing.

Parameters:
demand - demand parameters set by the view component.
See Also:
demandPerformed(leon.view.event.LyDemand)

activateViewDemand

public void activateViewDemand(LyActivateViewDemand demand)
Invoked when an activate view notification is sent to this listener.

This method is called by demandPerformed and may be overridden in subclasses.

Default implementation send a global event to the event manager.

Parameters:
demand - demand parameters set by the view component.
See Also:
demandPerformed(leon.view.event.LyDemand)

dragDropDemand

public void dragDropDemand(LyDragDropDemand demand)
Invoked when a Drag & Drop occurs. (LyDemandListener interface) This method handles: opening and closing line, moving an interval, action

Parameters:
demand - drag-drop demand

getClassInfo

public LyClassInfo getClassInfo(java.lang.String id)
Shortcut to get a classInfo of the application this method is a utility shortcut to getApplication().getClassInfo(id);

Parameters:
id - identifier of requested class.
Returns:
the requested classInfo, or null if it could not be found.

getImage

public java.lang.String getImage(LyObject object)
Get the name of the image (key or path) representing an object instance. Default implementation returns the icon associated to the classInfo.

Parameters:
object - source object for image association.
Returns:
the image path or key code.

getImage

public java.lang.String getImage(LyObjectInfo objectInfo)
Get the name of the image (key or path) representing an objectinfo. Default implementation builds an image path from a prefix specified in the objectInfo.

Parameters:
objectInfo - Info for which an image is searched.
Returns:
the image path or key code.
See Also:
getImageFromPrefix(java.lang.String)

getImage

public java.lang.String getImage(LyObjectInfo objectInfo,
                                 int size)
Get the name of the image (key or path) representing an objectinfo. Default implementation builds an image path from a prefix specified in the objectInfo.

Parameters:
objectInfo - Info for which an image is searched.
size - Requested size.
Returns:
the image path or key code.
See Also:
getImageFromPrefix(java.lang.String)

getImage

public java.lang.String getImage(LyObjectInfo objectInfo,
                                 int size,
                                 boolean defaultImage)
Get the name of the image (key or path) representing an objectinfo. Default implementation builds an image path from a prefix specified in the objectInfo.

Parameters:
objectInfo - Info for which an image is searched.
size - Requested size.
defaultImage - Produce a default image if image not found.
Returns:
the image path or key code.
See Also:
getImageFromPrefix(java.lang.String)

getImageFromPrefix

public java.lang.String getImageFromPrefix(java.lang.String prefix)
Build an image path from a prefix. (default extension, original size) (Prefix is usually specified in the data description : meta-model) It is possible to 'force' the default size of the image in the application resource LY_DEFAULT_IMAGE_HEIGHT (in resources.properties file).

Parameters:
prefix - the prefix to identify the image resource
Returns:
the image path.
See Also:
LyImages

getImageFromPrefix

public final java.lang.String getImageFromPrefix(java.lang.String prefix,
                                                 java.lang.String format,
                                                 int height)
Build an image path from a prefix, an image extension and a specified height. (Prefix is usually specified in the data description) The image is resized, preserving the original aspect ratio. (Width is automatically calculated).

Parameters:
prefix - the prefix to identify the image resource
format - the extension associated to the image, ".gif", ".jpg" or LyController.DEFAULT_IMAGE_FORMAT to use default value.
height - requested height of the image.
Returns:
the image path with image size information to force the height and the width (width is calculated with current aspect ratio from the height).
See Also:
LyImages

getImageFromPrefix

public java.lang.String getImageFromPrefix(java.lang.String prefix,
                                           java.lang.String format,
                                           int width,
                                           int height)
Build an image path from a prefix, extension, and size. (Prefix is usually specified in the data description)

Parameters:
prefix - the prefix to identify the image resource
format - the extension associated to the image, ".gif", ".jpg" or LyController.DEFAULT_IMAGE_FORMAT to use default value.
width - requested height of the image.
height - requested height of the image.
Returns:
the image path with image size information to force the size (width, height)
See Also:
LyImages

getObjectId

public LyObjectId getObjectId(java.lang.String id)
Factory for a LyObjectId instance for the specified String identifier This is a shortcut to : new LyObjectId(getApplication(), id).

Parameters:
id - object identifier.
Returns:
the objectid instance. Never returns null.

showWarning

public void showWarning(java.lang.String message)
Show a popup message warning box with the specified message. The message may be a text message, or the key to a String in the application disctionnary. (stringsXXX.properties files) This is a shortcut to getViewManager().showWarning()

Parameters:
message - the message to display
See Also:
LyViewManager, LyStrings

showError

public void showError(java.lang.String message)
Show a popup message error box with the specified message. The message may be a text message, or the key to a String in the application disctionnary. (stringsXXX.properties files) This is a shortcut to getViewManager().showError()

Parameters:
message - the message to display
See Also:
LyViewManager, LyStrings

showError

public void showError(LyObject object,
                      LyError error)
Show an error for the specified object. If object is null or if the resource LY_SHOWN_ERRORS_ON_OBJECTS is set to true, the error message is shown in a popup window else the specified error is added to the object.

Parameters:
object - The object in error
error - The error o show
See Also:
showError(String)

clearViewCache

public void clearViewCache()
Clears all cached data for this controller (especially the view and the component).

This method may be invoked for memory optimization, but the controller is still valid and may be used. (Unlike free) Further usage, needs to rebuild internal component & view which may be time consuming.


setIdle

public void setIdle(boolean idle)
Sets idle status of the table.

Parameters:
idle - a boolean indicating the idle mode

isIdle

public boolean isIdle()
Check idle status of the table.

Specified by:
isIdle in interface LyGuiListener
Returns:
boolean indicating the idle mode

hasViewController

public boolean hasViewController()
Check the controller have a viewController.

Returns:
boolean if the controller has a viewController

getKeyValue

public java.lang.Object getKeyValue(java.lang.String key)
Retrieves a value from a registered key.

Specified by:
getKeyValue in interface LyEvaluator
Parameters:
key - The key that must be used.
Returns:
The value stored with the key or null if the key is not registered.

getUserData

public final java.lang.Object getUserData()
Gets user data : data stored on controller by application.

Returns:
Object stored as user data.

setUserData

public final void setUserData(java.lang.Object userData)
Sets user data : data stored on controller by application.


(c) January 2013 - W4 S.A.

Website: W4 S.A., contact us: support@w4global.com