com.arsdigita.bebop
Class ToggleLink

java.lang.Object
  extended bycom.arsdigita.bebop.Completable
      extended bycom.arsdigita.bebop.SimpleComponent
          extended bycom.arsdigita.bebop.TextStylable
              extended bycom.arsdigita.bebop.BaseLink
                  extended bycom.arsdigita.bebop.ControlLink
                      extended bycom.arsdigita.bebop.ToggleLink
All Implemented Interfaces:
Cloneable, Component, Lockable

public class ToggleLink
extends ControlLink

A component that is either selected or not. By default, a link is only generated when the component is not selected. When it is selected, only a label is printed.

See BaseLink for a description of all Bebop Link classes.

Version:
$Id: //core-platform/dev/src/com/arsdigita/bebop/ToggleLink.java#8 $
Author:
David Lutterkort

Field Summary
protected  String TYPE_TOGGLE
          The value for the XML type attribute for a ToggleLink
static String versionId
           
 
Fields inherited from class com.arsdigita.bebop.ControlLink
TYPE_CONTROL
 
Fields inherited from class com.arsdigita.bebop.BaseLink
m_child, m_noJavascriptURL, m_url
 
Fields inherited from class com.arsdigita.bebop.SimpleComponent
m_attr
 
Fields inherited from interface com.arsdigita.bebop.Component
BEBOP_XML_NS, CLASS, ID, ON_CLICK, STYLE
 
Constructor Summary
ToggleLink(Component child)
          Create a ToggleLink that uses child to label the link it generates when it is not selected, and that displays child by itself when it is selected.
ToggleLink(String label)
          Creates a ToggleLink that uses a Label containing label to label the link it generates when it is not selected, and that displays just the label by itself when it is selected.
 
Method Summary
 Iterator children()
          Returns the selected component if it has been set.
protected  void generateExtraXMLAttributes(PageState s, Element link)
          Adds a selected attribute to the standard XML generated by Link.
 void generateXML(PageState s, Element e)
          Generates a DOM fragment:
 Component getSelectedComponent()
          Gets the component that is displayed if the link is selected.
 boolean isSelected(PageState s)
          Returns true if the link is currently selected in the request represented by s
 void register(Page p)
          Registers the link and its state with the page.
 void respond(PageState s)
          Responds to the incoming request represented by s.
 void setControlEvent(PageState s)
          Sets the page state's control event so that generated links cause this link's selected state to be toggled when the user clicks them.
 void setSelected(PageState s, boolean v)
          Sets whether the link is selected in the context of the request described by s.
 void setSelectedComponent(Component v)
          Sets the component that is displayed if the link is selected.
 
Methods inherited from class com.arsdigita.bebop.ControlLink
addActionListener, fireActionEvent, generateURL, removeActionListener
 
Methods inherited from class com.arsdigita.bebop.BaseLink
addPrintListener, clone, firePrintEvent, getChild, getNoJavascriptTarget, getTarget, removePrintListener, setChild, setConfirmation, setNoJavascriptTarget, setOnClick, setTarget, setTypeAttr, setupNoJavascriptURL
 
Methods inherited from class com.arsdigita.bebop.TextStylable
setBackgroundColor, setColor
 
Methods inherited from class com.arsdigita.bebop.SimpleComponent
exportAttributes, getAttribute, getClassAttr, getIdAttr, getKey, getMetaDataAttribute, getStyleAttr, hasAttributes, isLocked, isVisible, lock, register, setAttribute, setClassAttr, setIdAttr, setKey, setMetaDataAttribute, setStyleAttr, setVisible
 
Methods inherited from class com.arsdigita.bebop.Completable
addCompletionListener, fireCompletionEvent
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

versionId

public static final String versionId
See Also:
Constant Field Values

TYPE_TOGGLE

protected final String TYPE_TOGGLE
The value for the XML type attribute for a ToggleLink

See Also:
Constant Field Values
Constructor Detail

ToggleLink

public ToggleLink(Component child)
Create a ToggleLink that uses child to label the link it generates when it is not selected, and that displays child by itself when it is selected. The child is selected by default.

Parameters:
child - the component used to label this link

ToggleLink

public ToggleLink(String label)
Creates a ToggleLink that uses a Label containing label to label the link it generates when it is not selected, and that displays just the label by itself when it is selected.

Parameters:
label - the string used to label this link
Method Detail

register

public void register(Page p)
Registers the link and its state with the page.

Specified by:
register in interface Component
Overrides:
register in class SimpleComponent
Parameters:
p - the page that contains this link

respond

public void respond(PageState s)
Responds to the incoming request represented by s. Changes whether the link is selected or not according to what is indicated in s. Fires an ActionEvent after updating its state.

Specified by:
respond in interface Component
Overrides:
respond in class ControlLink
Parameters:
s - represents the current request

children

public Iterator children()
Returns the selected component if it has been set.

Specified by:
children in interface Component
Overrides:
children in class SimpleComponent
Returns:
an iterator over the link's children.

isSelected

public boolean isSelected(PageState s)
Returns true if the link is currently selected in the request represented by s

Parameters:
s - describes the current request
Returns:
true if the link is selected; false otherwise.

setSelected

public void setSelected(PageState s,
                        boolean v)
Sets whether the link is selected in the context of the request described by s.

Parameters:
s - describes the current request
v - true if the link is currently selected

getSelectedComponent

public final Component getSelectedComponent()
Gets the component that is displayed if the link is selected.

Returns:
the component to display if the link is selected.

setSelectedComponent

public void setSelectedComponent(Component v)
Sets the component that is displayed if the link is selected.

Parameters:
v - the component to display if the link is selected

generateXML

public void generateXML(PageState s,
                        Element e)
Description copied from class: BaseLink

Generates a DOM fragment:

 <bebop:link href="..." type="..." %bebopAttr;/>
 
The href attribute contains the target the link should point to. The type attribute is used to give more finegrained control over which kind of link this element represents. The types are link for a Link, control for a ControlLink, and toggle for a ToggleLink. There may be additional attributes depending on what type of link this link represents.

Specified by:
generateXML in interface Component
Overrides:
generateXML in class BaseLink
See Also:
BaseLink.generateXML(com.arsdigita.bebop.PageState, com.arsdigita.xml.Element), generateXML(com.arsdigita.bebop.PageState, com.arsdigita.xml.Element)

setControlEvent

public void setControlEvent(PageState s)
Sets the page state's control event so that generated links cause this link's selected state to be toggled when the user clicks them.

Overrides:
setControlEvent in class ControlLink
Parameters:
s - the current page state

generateExtraXMLAttributes

protected void generateExtraXMLAttributes(PageState s,
                                          Element link)
Adds a selected attribute to the standard XML generated by Link. The value of the attribute is either yes or no, reflecting whether the link is selected or not.

Overrides:
generateExtraXMLAttributes in class BaseLink
Parameters:
s - a PageState value
link - an Element value


Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 20 2004:2337 UTC