001    package com.sptci.rwt.webui;
002    
003    import nextapp.echo2.app.Button;
004    import nextapp.echo2.app.Column;
005    import nextapp.echo2.app.Component;
006    
007    import nextapp.echo2.app.event.ActionEvent;
008    import nextapp.echo2.app.event.ActionListener;
009    
010    import com.sptci.echo2.WindowPane;
011    
012    /**
013     * A view component used to display the {@link ExecutorView#history}
014     * information.  History is displayed as {@link nextapp.echo2.app.Button}
015     * components which will reset the {@link ExecutorView#query} component.
016     *
017     * <p>&copy; Copyright 2007 <a href='http://sptci.com/' target='_new'>Sans Pareil Technologies, Inc.</a></p>
018     * @author Rakesh Vidyadharan 2007-10-13
019     * @version $Id: HistoryView.java 4123 2008-05-25 21:49:01Z rakesh $
020     */
021    public class HistoryView extends WindowPane
022    {
023      /** The executor view to which this component is bound. */
024      private final ExecutorView view;
025      
026      /** Parent Controller. */
027      private final MainController controller;
028    
029      /**
030       * Create instance of the pane using the specified controller.
031       *
032       * @param view The {@link #view} to which this view is bound.
033       * @param controller The controller to use to interact with the rest of
034       *   the application.
035       */
036      public HistoryView( final ExecutorView view,
037          final MainController controller )
038      {
039        this.view = view;
040        this.controller = controller;
041      }
042    
043      /** Life-cycle method invoked when component is added to the UI. */
044      @Override
045      public void init()
046      {
047        removeAll();
048        final Column column = new Column();
049    
050        for ( String statement : view.getHistory().keySet() )
051        {
052          final Button button = new Button( statement );
053          button.setStyleName( "Link.Button" );
054          button.addActionListener( new HistoryViewListener() );
055          column.add( button );
056        }
057    
058        add( column );
059      }
060    
061      /**
062       * The action listener used to update the {@link ExecutorView#query}
063       * field with the previous statement.
064       */
065      protected class HistoryViewListener implements ActionListener
066      {
067        /**
068         * The action listener implementation.  Invokes {@link
069         * ExecutorView#setQuery} with the statement value.
070         *
071         * @param event The action event that was triggered.
072         */
073        public void actionPerformed( final ActionEvent event )
074        {
075          Button button = (Button) event.getSource();
076          view.setQueryFromHistory( button.getText() );
077          HistoryView.this.userClose();
078        }
079      }
080    }