001 package com.sptci.rwt.webui.model;
002
003 import nextapp.echo2.app.Column;
004 import nextapp.echo2.app.Component;
005 import nextapp.echo2.app.Grid;
006 import nextapp.echo2.app.Label;
007
008 import com.sptci.ReflectionUtility;
009 import com.sptci.echo2.Application;
010 import com.sptci.echo2.Configuration;
011 import com.sptci.echo2.Utilities;
012 import com.sptci.echo2.View;
013
014 import com.sptci.rwt.MetaData;
015 import com.sptci.rwt.webui.ConnectionDialogue;
016
017 /**
018 * An abstract base class used to represent the various view components
019 * used to represent the details in the associated {@link
020 * com.sptci.rwt.MetaData} model objects.
021 *
022 * <p>© Copyright 2007 <a href='http://sptci.com/' target='_new'>Sans Pareil Technologies, Inc.</a></p>
023 * @author Rakesh Vidyadharan 2007-10-07
024 * @version $Id: AbstractView.java 4123 2008-05-25 21:49:01Z rakesh $
025 */
026 public abstract class AbstractView extends Column implements View
027 {
028 /**
029 * Create standard {@link nextapp.echo2.app.Label} components that
030 * represent the name of the specified field and the value in the
031 * specified model.
032 *
033 * @param name The name of the field.
034 * @param metaData The model object.
035 * @param component The container component to which the labels are to
036 * be added.
037 */
038 protected void createLabels( final String name, final MetaData metaData,
039 final Component component )
040 {
041 final String method = "get" + name.substring( 0, 1 ).toUpperCase() +
042 name.substring( 1 );
043
044 try
045 {
046 component.add( Utilities.createLabel(
047 getClass().getName(), name, "Title.Label" ) );
048 component.add( new Label( String.valueOf(
049 ReflectionUtility.execute( metaData, method ) ) ) );
050 }
051 catch ( Throwable t )
052 {
053 processFatalException( method, metaData.getClass().getName(), t );
054 }
055 }
056
057 /**
058 * Display an error message indicating the cause of the reflection error.
059 *
060 * @param method The name of the method that failed.
061 * @param cls The fully qualified name of the class on which the method
062 * was attempted.
063 * @param throwable The exception that was raised.
064 */
065 protected void processFatalException( final String method,
066 final String cls, final Throwable throwable )
067 {
068 String message = Configuration.getString(
069 ConnectionDialogue.class, "methodError" );
070 message = message.replaceAll( "\\$method\\$", method );
071 message = message.replaceAll( "\\$class\\$", cls );
072 Application.getApplication().processFatalException( message, throwable );
073 }
074 }