001 package com.sptci.rwt.webui.tree;
002
003 import com.sptci.echo2.Application;
004 import com.sptci.echo2.Configuration;
005
006 import com.sptci.epng.TreeNode;
007 import com.sptci.rwt.MetaData;
008
009 /**
010 * An abstract {@link echopointng.tree.TreeNode} that represents {@link
011 * com.sptci.rwt.MetaData} objects.
012 *
013 * <p>© Copyright 2007 <a href='http://sptci.com/' target='_new'>Sans Pareil Technologies, Inc.</a></p>
014 * @author Rakesh Vidyadharan 2007-09-28
015 * @version $Id: AbstractNode.java 4123 2008-05-25 21:49:01Z rakesh $
016 */
017 public abstract class AbstractNode<S extends MetaData> extends TreeNode<S>
018 {
019 /**
020 * Create a new tree node with no <code>userObject</code> specified.
021 */
022 protected AbstractNode()
023 {
024 super();
025 }
026
027 /**
028 * Create a new tree node using the specified metadata object. The
029 * object represents a object in the database.
030 *
031 * @param userObject The model object for this node.
032 */
033 public AbstractNode( final S userObject )
034 {
035 super( userObject );
036 }
037
038 /**
039 * Return the number of child nodes under this node. Lazily loaded on
040 * first request.
041 *
042 * @see #createChildren
043 * @return The number of children for this node.
044 */
045 @Override
046 public int getChildCount()
047 {
048 if ( ! initialised ) createChildren();
049 return super.getChildCount();
050 }
051
052 /**
053 * Determine whether this node holds children or not. Over-ridden
054 * to always indicate that there are children.
055 *
056 * @return Returns <code>true</code> if the receiver is a leaf. Always
057 * returns <code>false</code>.
058 */
059 @Override
060 public boolean isLeaf()
061 {
062 return false;
063 }
064
065 /**
066 * Create the child nodes for this node.
067 */
068 protected abstract void createChildren();
069
070 /**
071 * Display an error message if fetching meta data fails.
072 *
073 * @param throwable The exception that was raised.
074 */
075 protected void processFatalException( final Throwable throwable )
076 {
077 Application.getApplication().processFatalException(
078 Configuration.getString( this, "error" ), throwable );
079 }
080
081 /**
082 * Display an error message if fetching meta data fails. Over-loaded
083 * to replace a <code>$object$</code> place holder with the specified
084 * <code>name</code>.
085 *
086 * @param name The name of the database object that was being analysed.
087 * @param throwable The exception that was raised.
088 */
089 protected void processFatalException( final String name,
090 final Throwable throwable )
091 {
092 String message = Configuration.getString( this, "error" );
093 message = message.replaceAll( "\\$object\\$", name );
094 Application.getApplication().processFatalException( message, throwable );
095 }
096 }