001 package com.sptci.rwt.webui;
002
003 import nextapp.echo2.app.event.ActionEvent;
004
005 import com.sptci.echo2.Listener;
006 import com.sptci.rwt.ConnectionData;
007 import com.sptci.rwt.DatabaseType;
008
009 /**
010 * Action listener for launching a {@link ConnectionDialogue} initialised
011 * with the the parameters in a saved connection.
012 *
013 * <p>© Copyright 2007 <a href='http://sptci.com/' target='_new'>Sans Pareil Technologies, Inc.</a></p>
014 * @author Rakesh Vidyadharan 2007-10-14
015 * @version $Id: SavedConnectionListener.java 4123 2008-05-25 21:49:01Z rakesh $
016 */
017 public class SavedConnectionListener extends Listener<MainController>
018 {
019 /** The type of database to connect to. */
020 private final DatabaseType databaseType;
021
022 /** The name of the saved connection. */
023 private final String name;
024
025 /**
026 * Create a new instance of the listener using the specified query and
027 * controller.
028 *
029 * @param databaseType The {@link #databaseType} value to use.
030 * @param controller The controller to use to interact with the
031 * application.
032 */
033 public SavedConnectionListener( final DatabaseType databaseType,
034 final String name, final MainController controller )
035 {
036 super( controller );
037 this.databaseType = databaseType;
038 this.name = name;
039 }
040
041 /**
042 * The action listener implementation. Executes the query and exports
043 * the results.
044 *
045 * @see #createDialogue
046 * @param event The event that triggers the export process.
047 */
048 public void actionPerformed( ActionEvent event )
049 {
050 ConnectionDialogue dialogue = createDialogue();
051 controller.addPane( dialogue );
052 }
053
054 /**
055 * Create the {@link ConnectionDialogue} and initialise its components
056 * with the values in the saved connection.
057 *
058 * @return The properly initialised connection dialogue.
059 */
060 private ConnectionDialogue createDialogue()
061 {
062 ConnectionData data = databaseType.getConnectionData( name );
063
064 ConnectionDialogue dialogue = new ConnectionDialogue( controller );
065 dialogue.setDatabaseType( databaseType.getName() );
066 dialogue.setHost( data.getHost() );
067 dialogue.setPort( data.getPort() );
068 dialogue.setDatabase( data.getDatabase() );
069 dialogue.setUserName( data.getUserName() );
070 dialogue.setPassword( data.getPassword() );
071
072 return dialogue;
073 }
074 }