objectivehtml.htmlwidget
Class HtmlContainerWidget

java.lang.Object
  |
  +--objectivehtml.oms.OMSObject
        |
        +--objectivehtml.htmlwidget.HtmlElement
              |
              +--objectivehtml.htmlwidget.HtmlWidget
                    |
                    +--objectivehtml.htmlwidget.HtmlContainerWidget
Direct Known Subclasses:
HtmlTable, HtmlTableCell, HtmlTableRow, HtmlUnrestrictedContainerWidget

public abstract class HtmlContainerWidget
extends HtmlWidget

This is the base class of all container widgets. Container widgets are widgets that contain other children widgets inside them. Only container widgets can have children widgets.

All container widget can run in text-mode. Text-mode occurs automatically when a container widget has no children and the text component has been set. When the html for the widget is written out, it will contain the text inside its start and end tag. If auto-escape is turned on (default) then the text data will be escaped before being written by the printHtml(output) methods. Special html characters are escaped using the HtmlUtils.htmlSpecialChars(String) method. If the container becomes a parent then text-mode is off.

The destroy() method of a HtmlContainerWidget object will also destroy all its children objects as well.

See Also:
HtmlUtils.htmlSpecialChars(String), setAutoEscape(boolean), HtmlElement.printHtml(JspWriter), HtmlElement.printHtml(PrintWriter)

Field Summary
protected  java.util.ArrayList m_alChildrenWidgets
          Internal list of children objects
protected  boolean m_bAutoEscape
          Indicates whether auto-escape is enabled or not
protected  java.lang.String m_sText
          The text for this container in text-mode
 
Fields inherited from class objectivehtml.htmlwidget.HtmlWidget
m_bDestroyed, m_bVisible, m_objHtmlForm, m_objParentWidget
 
Fields inherited from class objectivehtml.htmlwidget.HtmlElement
m_hmAttributes, m_sEndTag, m_sQuoteType, m_sStartTag
 
Constructor Summary
HtmlContainerWidget()
          Constructs an instance of the HtmlContainerWidget object with no parent.
HtmlContainerWidget(HtmlContainerWidget objParent)
          Constructs an instance of HtmlContainerWidget object with objParent as its parent.
 
Method Summary
protected  void addHtmlWidget(HtmlWidget objHtmlWidget)
          Adds a child widget to the internal list of this container.
protected  void appendChild(HtmlWidget objHtmlWidget)
          Adds a child widget to this container.
protected  void destroy()
          Deletes itself and calls destroy() and all children widgets.
protected  void generateUpdateOrder(java.util.TreeMap objUpdateOrderTree)
          Generates the update order for this form.
 int getChildrenCount()
          Returns the number of first-level children widgets in this container widget.
 java.util.ArrayList getChildrenWidgets()
          Returns a shallow copy of the list of children widgets in this container.
 HtmlWidget getChildWidget(int nIndex)
          This will return the child widget at the specified index.
 java.lang.String getText()
          Returns the text of this container.
 int indexOfChildWidget(HtmlWidget objHtmlWidget)
          This will find the index of a child widget.
protected  void insertChild(HtmlWidget objHtmlWidget, int nPosition)
          Inserts a child widget into this container.
protected  void insertHtmlWidget(HtmlWidget objHtmlWidget, int nPosition)
          Inserts a child widget into the internal list of this container.
 boolean isAutoEscape()
          Returns whether the auto-escape feature is on or not.
 boolean isChildWidget(HtmlWidget objHtmlWidget)
          Indicates whether the specified HtmlWidget object is a child of this widget
protected  void isValidChildWidget(HtmlWidget objHtmlWidget)
          Indicates whether the specified child widget is allowed in this container.
 void printHtml(javax.servlet.jsp.JspWriter objWriter, int nOutputType)
          Prints the html that represents this object to the output stream.
 void printHtml(java.io.PrintWriter objWriter, int nOutputType)
          Prints the html that represents this object to the output stream.
protected  void removeHtmlWidget(HtmlWidget objHtmlWidget)
          Removes a child widget from the internal list of this container.
 void setAttribute(java.lang.String sName, java.lang.String sValue, boolean bApplyToChildren)
          Sets an attribute of this object and also the same attribute for all of its children.
 void setAutoEscape(boolean bAutoEscape)
          Sets the auto-escape feature to be either on (default) or off.
 void setBooleanAttribute(java.lang.String sName, boolean bIsOn, boolean bApplyToChildren)
          Sets a boolean-attribute of this object and also the same attribute for all of its children.
 void setText(java.lang.String sText)
          Sets the text of this container.
protected  void setVisible(boolean bVisible)
          Sets the visibility of this object and all its children.
 void swapHtmlWidgets(int nFirstPosition, int nSecondPosition)
          Swaps the position of 2 children widgets.
 
Methods inherited from class objectivehtml.htmlwidget.HtmlWidget
changeParent, changeParent, getClassAttribute, getHtmlForm, getID, getOnClick, getOnDblClick, getOnKeyDown, getOnKeyPress, getOnKeyUp, getOnMouseDown, getOnMouseMove, getOnMouseOut, getOnMouseOver, getOnMouseUp, getParent, getStyle, isDestroyed, isVisible, setClassAttribute, setID, setOnClick, setOnDblClick, setOnKeyDown, setOnKeyPress, setOnKeyUp, setOnMouseDown, setOnMouseMove, setOnMouseOut, setOnMouseOver, setOnMouseUp, setStyle
 
Methods inherited from class objectivehtml.htmlwidget.HtmlElement
genEndTag, genStartTag, genStartTag, getAttribute, getAttributes, getBooleanAttribute, getQuoteType, printHtml, printHtml, printHtml, printHtml, printHtml, printHtml, setAttribute, setBooleanAttribute, setQuoteType, toString, toString
 
Methods inherited from class objectivehtml.oms.OMSObject
compareClasses, connect, disconnect, emit, isAlive, setAlive, signal, slot, slot
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_alChildrenWidgets

protected java.util.ArrayList m_alChildrenWidgets
Internal list of children objects

m_bAutoEscape

protected boolean m_bAutoEscape
Indicates whether auto-escape is enabled or not

m_sText

protected java.lang.String m_sText
The text for this container in text-mode
Constructor Detail

HtmlContainerWidget

public HtmlContainerWidget(HtmlContainerWidget objParent)
                    throws InvalidParentWidgetException,
                           InvalidChildWidgetException
Constructs an instance of HtmlContainerWidget object with objParent as its parent.
Parameters:
objParent - the parent of this widget
Throws:
InvalidParentWidgetException - if the specified parent widget is not valid
InvalidChildWidgetException - if the parent widget does not accept this widget as a child

HtmlContainerWidget

public HtmlContainerWidget()
Constructs an instance of the HtmlContainerWidget object with no parent. This constructor is used by the HtmlForm class.
See Also:
HtmlForm
Method Detail

setAutoEscape

public void setAutoEscape(boolean bAutoEscape)
Sets the auto-escape feature to be either on (default) or off. If auto-escape is set as true then when in text-mode the text will have any html entity characters escaped with the HtmlUtils.htmlSpecialChars(String) method.
Parameters:
bAutoEscape - true if you want auto-escape on (default), false otherwise
See Also:
HtmlUtils.htmlSpecialChars(String), isAutoEscape()

isAutoEscape

public boolean isAutoEscape()
Returns whether the auto-escape feature is on or not.
Returns:
true if auto-escape is on, false otherwise
See Also:
setAutoEscape(boolean)

getText

public java.lang.String getText()
Returns the text of this container.
Returns:
the text
See Also:
setText(String)

setText

public void setText(java.lang.String sText)
Sets the text of this container.
Parameters:
sText - the text
See Also:
getText()

setVisible

protected void setVisible(boolean bVisible)

Sets the visibility of this object and all its children. This version overrides the version provided by HtmlWidget so that the method updates not only the visibility of itself but also the visibility of all its children.

By default this method should only be accessed by other classes of this library. If users are allowed to explicity show/hide this html widget then it needs to be made public.

Overrides:
setVisible in class HtmlWidget
Parameters:
bVisible - true indicates the object and all of its children should be visible, false indicates that the object and all of its children should not visible
See Also:
HtmlWidget.setVisible(boolean)

setAttribute

public void setAttribute(java.lang.String sName,
                         java.lang.String sValue,
                         boolean bApplyToChildren)
                  throws InvalidAttributeException

Sets an attribute of this object and also the same attribute for all of its children.

This overloaded version takes in an extra parameter bApplyToChildren. If this is true then this attribute is also set on all children widgets. Be careful to only set attributes that all html widgets have. e.g. class, style.

Parameters:
sName - the name of the attribute (case-insensitive)
sValue - the value of the attribute, if null is specified then the attribute will be cleared
bApplyToChildren - true if you want to apply this attribute to all of its children

setBooleanAttribute

public void setBooleanAttribute(java.lang.String sName,
                                boolean bIsOn,
                                boolean bApplyToChildren)
                         throws InvalidAttributeException

Sets a boolean-attribute of this object and also the same attribute for all of its children.

This overloaded version takes in an extra parameter bApplyToChildren. If this is true then this attribute is also set on all children widgets. Be careful to only set attributes that all html widgets have. e.g. class, style.

Parameters:
sName - the name of the attribute (case-insensitive)
bIsOn - true if the attribute should exist, false otherwise
bApplyToChildren - true if you want to apply this boolean-attribute to all of its children

getChildrenCount

public int getChildrenCount()
Returns the number of first-level children widgets in this container widget. Secondary-level children widgets are not included in this count.
Returns:
the number of first-level children in this container widget

getChildrenWidgets

public java.util.ArrayList getChildrenWidgets()
Returns a shallow copy of the list of children widgets in this container.
Returns:
a shallow copy of the list of children widgets

indexOfChildWidget

public int indexOfChildWidget(HtmlWidget objHtmlWidget)
This will find the index of a child widget. The indexing starts at 0 for the first child widget. The method will return -1 if the child widget does not exist in this container.
Returns:
the index position of this child widget

getChildWidget

public HtmlWidget getChildWidget(int nIndex)
This will return the child widget at the specified index.
Returns:
the child widget at the index position nIndex

swapHtmlWidgets

public void swapHtmlWidgets(int nFirstPosition,
                            int nSecondPosition)
Swaps the position of 2 children widgets. Moves the child widget at position nFirstPosition to nSecondPosition and moves the child widget at position nSecondPosition to nFirstPosition.
Parameters:
nFirstPosition - the position of the first child widget
nSecondPosition - the position of the second child widget

isChildWidget

public boolean isChildWidget(HtmlWidget objHtmlWidget)
Indicates whether the specified HtmlWidget object is a child of this widget
Returns:
true if objHtmlWidget is a child, false otherwise

appendChild

protected void appendChild(HtmlWidget objHtmlWidget)
                    throws NotEqualsHtmlFormException,
                           InvalidChildWidgetException

Adds a child widget to this container. If the widget is already a child of this container then the operation will move the widget to end of the child list for this container. If the widget is not a child of this container then the widget will be reparented resulting in this container being its new parent and will be appended to the end of the child list for this container.

By default this method should only be accessed by other classes of this library. If users are allowed to explicity add html widgets then it needs to be made public.

Parameters:
objHtmlWidget - the widget that is to be appended
Throws:
NotEqualsHtmlFormException - if the widget is not in the same form
InvalidChildWidgetException - if this widget does not accept objHtmlWidget as a child
See Also:
insertChild(HtmlWidget, int), HtmlWidget.changeParent(HtmlContainerWidget)

insertChild

protected void insertChild(HtmlWidget objHtmlWidget,
                           int nPosition)
                    throws NotEqualsHtmlFormException,
                           InvalidChildWidgetException

Inserts a child widget into this container. If the widget is already a child of this container then the operation will move the widget to the new nPosition position, which is calculated after the child is removed from its parent container. If the widget is not a child of this container then the widget will be reparented resulting in this container being its new parent and will be inserted into the the child list for this container.

By default this method should only be accessed by other classes of this library. If users are allowed to explicity insert html widgets then it needs to be made public.

Parameters:
objHtmlWidget - the widget that is to be appended
nPosition - the position the new child is to inserted (starts from 0)
Throws:
NotEqualsHtmlFormException - if the widget is not in the same form
InvalidChildWidgetException - if this widget does not accept objHtmlWidget as a child
See Also:
appendChild(HtmlWidget), HtmlWidget.changeParent(HtmlContainerWidget)

addHtmlWidget

protected void addHtmlWidget(HtmlWidget objHtmlWidget)
                      throws InvalidChildWidgetException
Adds a child widget to the internal list of this container. The method is for internal use only, it should never need to be called by normal users.
Parameters:
objHtmlWidget - the child widget to add
Throws:
InvalidChildWidgetException - if this widget does not accept objHtmlWidget as a child

insertHtmlWidget

protected void insertHtmlWidget(HtmlWidget objHtmlWidget,
                                int nPosition)
                         throws InvalidChildWidgetException

Inserts a child widget into the internal list of this container.

The method is for internal use only, it should never need to be called by normal users.

Parameters:
objHtmlWidget - the child widget to insert
nPosition - the position that the widget should be inserted into
Throws:
InvalidChildWidgetException - if this widget does not accept objHtmlWidget as a child

isValidChildWidget

protected void isValidChildWidget(HtmlWidget objHtmlWidget)
                           throws InvalidChildWidgetException

Indicates whether the specified child widget is allowed in this container. The default implementation allows any HtmlWidget to be a child widget.

All subclasses of this class should override this method if they have restrictions on suitable child widgets. If a child is not accepted then the InvalidChildWidgetException should be thrown.

Throws:
InvalidChildWidgetException - if objHtmlWidget is not accepted by this widget as a child

removeHtmlWidget

protected void removeHtmlWidget(HtmlWidget objHtmlWidget)

Removes a child widget from the internal list of this container.

The method is for internal use only, it should never need to be called by normal users.

Parameters:
objHtmlWidget - the child widget to remove

generateUpdateOrder

protected void generateUpdateOrder(java.util.TreeMap objUpdateOrderTree)
Generates the update order for this form.
Parameters:
objUpdateOrderTree - the list of control widgets to update
See Also:
HtmlForm.updateData(HttpServletRequest)

destroy

protected void destroy()
Deletes itself and calls destroy() and all children widgets.
Overrides:
destroy in class HtmlWidget
Following copied from class: objectivehtml.htmlwidget.HtmlWidget
See Also:
HtmlWidget.isDestroyed()

printHtml

public void printHtml(java.io.PrintWriter objWriter,
                      int nOutputType)
               throws java.io.IOException
Prints the html that represents this object to the output stream.
Overrides:
printHtml in class HtmlElement
Parameters:
objWriter - the output stream for a Servlet object
nOutputType - the output type
Throws:
java.io.IOException - if it cannot write the output
See Also:
HtmlElement.printHtml(PrintWriter)

printHtml

public void printHtml(javax.servlet.jsp.JspWriter objWriter,
                      int nOutputType)
               throws java.io.IOException
Prints the html that represents this object to the output stream.
Overrides:
printHtml in class HtmlElement
Parameters:
objWriter - the output stream for a Jsp page
nOutputType - the output type
Throws:
java.io.IOException - if it cannot write the output
See Also:
HtmlElement.printHtml(JspWriter)