com.buglabs.menu
Class AbstractMenuNode

java.lang.Object
  extended by com.buglabs.menu.AbstractMenuNode
All Implemented Interfaces:
IMenuNode, java.lang.Comparable
Direct Known Subclasses:
AboutMenuAdapter, AppInstallNode, AppUninstallNode, BacklightMenuNode, BugNetNode, FolderMenuNode, InstallNode, IPAddressMenuNode, LabelMenuItem, LabelValueMenuItem, Menu.LogEntryStackMenuItem, MenuAccessAdapter, MenuAdapter, MenuAdapter, MenuAdapter, MenuAdapter, RefreshNode, StackMenuItem, UninstallNode, UpdateNode, YesNoMenuItem

public abstract class AbstractMenuNode
extends java.lang.Object
implements IMenuNode, java.lang.Comparable

Implements common functionality for a menu node.


Constructor Summary
AbstractMenuNode(java.lang.String name)
           
AbstractMenuNode(java.lang.String name, IMenuNode parent)
           
 
Method Summary
 int compareTo(java.lang.Object arg0)
           
 boolean equals(java.lang.Object arg0)
           
 void execute()
          If menu node is a leaf, the user has selected this node for execution.
 java.lang.String getBusyName()
           
 java.util.List getChildren()
           
 java.util.Comparator getComparator()
           
 java.lang.String getErrorName()
           
 IMenuNode getFirstParentOfType(java.lang.String type)
          Iterate through ancestors until one of specified type is found.
 java.lang.String getName()
          Name property used in the UI.
 IMenuNode getNextSibling()
           
 IMenuNode getParent()
           
 java.lang.String getPath()
           
 IMenuNode getPreviousSibling()
           
 boolean hasChildren()
           
 boolean isBusy()
          If a node is busy, the menu system will display a spinner in the place of the node.
 boolean isError()
           
 void setName(java.lang.String name)
          Sets the name property used in the UI.
 IMenuNode setParent(IMenuNode parent)
           
 boolean sortChildren()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractMenuNode

public AbstractMenuNode(java.lang.String name)

AbstractMenuNode

public AbstractMenuNode(java.lang.String name,
                        IMenuNode parent)
Method Detail

getChildren

public java.util.List getChildren()
Specified by:
getChildren in interface IMenuNode
Returns:
All children for this node.

sortChildren

public boolean sortChildren()
Specified by:
sortChildren in interface IMenuNode
Returns:
true if the children should be sorted, and false if they should not be.

getComparator

public java.util.Comparator getComparator()
Specified by:
getComparator in interface IMenuNode
Returns:
The Comparator to sort by if sortChildren() returns true. If null is returned, and sortChildren() returns true, the natural ordering, taken from the compareTo() method, will be used.

getParent

public IMenuNode getParent()
Specified by:
getParent in interface IMenuNode

setParent

public IMenuNode setParent(IMenuNode parent)
Specified by:
setParent in interface IMenuNode

hasChildren

public boolean hasChildren()
Specified by:
hasChildren in interface IMenuNode
Returns:
true if number of children greater than 0.

isBusy

public boolean isBusy()
Description copied from interface: IMenuNode
If a node is busy, the menu system will display a spinner in the place of the node. The user will be able to go back to other nodes while the node is busy. The correct way to utilize this feature is to set the node to busy, spawn a new Thread to take care of the work, and set the node to not busy after the thread completes. This way, the menu system will not block.

Specified by:
isBusy in interface IMenuNode
Returns:
true if the node is busy and false if the node is not busy.

getBusyName

public java.lang.String getBusyName()
Specified by:
getBusyName in interface IMenuNode
Returns:
Alternate text to display when a node is busy. If null, use the node name.

getFirstParentOfType

public IMenuNode getFirstParentOfType(java.lang.String type)
Description copied from interface: IMenuNode
Iterate through ancestors until one of specified type is found. NULL if none found.

Specified by:
getFirstParentOfType in interface IMenuNode
Returns:

execute

public void execute()
             throws java.lang.Exception
Description copied from interface: IMenuNode
If menu node is a leaf, the user has selected this node for execution. Specific logic should be implemented here.

Specified by:
execute in interface IMenuNode
Throws:
java.lang.Exception

getNextSibling

public IMenuNode getNextSibling()
Specified by:
getNextSibling in interface IMenuNode
Returns:
next IMenuNode in tree that is current (list index + 1) in same level.

getPreviousSibling

public IMenuNode getPreviousSibling()
Specified by:
getPreviousSibling in interface IMenuNode
Returns:
previous IMenuNode in tree that is current (list index - 1) in same level.

getName

public java.lang.String getName()
Description copied from interface: IMenuNode
Name property used in the UI.

Specified by:
getName in interface IMenuNode
Returns:

setName

public void setName(java.lang.String name)
Description copied from interface: IMenuNode
Sets the name property used in the UI. Not unique.

Specified by:
setName in interface IMenuNode

toString

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

equals

public boolean equals(java.lang.Object arg0)
Overrides:
equals in class java.lang.Object

compareTo

public int compareTo(java.lang.Object arg0)
Specified by:
compareTo in interface java.lang.Comparable

getPath

public java.lang.String getPath()
Specified by:
getPath in interface IMenuNode
Returns:
a '.' separated path for this node.

isError

public boolean isError()
Specified by:
isError in interface IMenuNode
Returns:
true if this node should currently display an error, false otherwise.

getErrorName

public java.lang.String getErrorName()
Specified by:
getErrorName in interface IMenuNode
Returns:
The name to display if isError() returns true.