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    import nextapp.echo2.app.Grid;
007    import nextapp.echo2.app.Label;
008    
009    import echopointng.ExpandableSection;
010    
011    import com.sptci.echo2.Utilities;
012    import com.sptci.echo2.WindowPane;
013    import com.sptci.rwt.Category;
014    
015    /**
016     * The component that is used to delete saved queries.
017     *
018     * <p>&copy; Copyright 2007 <a href='http://sptci.com/' target='_new'>Sans Pareil Technologies, Inc.</a></p>
019     * @author Rakesh Vidyadharan 2007-10-14
020     * @version $Id: ManageSavedQueriesView.java 4123 2008-05-25 21:49:01Z rakesh $
021     */
022    public class ManageSavedQueriesView extends WindowPane
023    {
024      /** The controller used to interact with the application. */
025      private final MainController controller;
026    
027      /**
028       * Create a new instance using the specified controller.
029       *
030       * @param controller The {@link #controller} to use to interact with the
031       *   application.
032       */
033      public ManageSavedQueriesView( final MainController controller )
034      {
035        this.controller = controller;
036      }
037    
038      /**
039       * Life-cycle method invoked when the component is added to the component
040       * hierarchy.
041       *
042       * @see #createCategory
043       */
044      @Override
045      public void init()
046      {
047        removeAll();
048        Column column = new Column();
049    
050        for ( Category category : controller.getQueries().getCategories() )
051        {
052          column.add( createCategory( category ) );
053        }
054    
055        add( column );
056      }
057    
058      /**
059       * Create the component that displays the saved queries in a specified
060       * database category.
061       *
062       * @param category The database category for which saved queries are available.
063       */
064      private Component createCategory( final Category category )
065      {
066        ExpandableSection section = new ExpandableSection( category.getName() );
067        Grid grid = new Grid();
068    
069        for ( String name : category.getNames() )
070        {
071          Label label = new Label( name );
072          label.setStyleName( "Title.Label" );
073          grid.add( label );
074          grid.add( Utilities.createButton( getClass().getName(), "delete",
075              new DeleteSavedQueryListener(
076                category.getName(), name, controller ) ) );
077        }
078    
079        section.add( grid );
080        return section;
081      }
082    }