ca.sqlpower.wabit.swingui
Class WabitSwingSessionContextImpl

java.lang.Object
  extended by ca.sqlpower.wabit.swingui.WabitSwingSessionContextImpl
All Implemented Interfaces:
ca.sqlpower.sqlobject.SQLDatabaseMapping, ca.sqlpower.util.UserPrompterFactory, OlapConnectionMapping, WabitSwingSessionContext, WabitSessionContext

public class WabitSwingSessionContextImpl
extends java.lang.Object
implements WabitSwingSessionContext

This is the swing version of the WabitSessionContext. Swing specific operations for the context will be done in this implementation


Nested Class Summary
static class WabitSwingSessionContextImpl.SourceListStyle
          All the ways the source list can be present in the GUI.
 class WabitSwingSessionContextImpl.TreeTabDropTargetListener
          This is the droplistener on the tabbed pane which controls importing and exporting between workspaces
 
Nested classes/interfaces inherited from interface ca.sqlpower.util.UserPrompterFactory
ca.sqlpower.util.UserPrompterFactory.UserPromptType
 
Field Summary
static java.lang.String EXAMPLE_WORKSPACE_URL
           
static ca.sqlpower.swingui.action.ForumAction FORUM_ACTION
           
static javax.swing.ImageIcon FRAME_ICON
          This icon is at the top left of every frame.
static javax.swing.Icon NEW_ICON
           
static javax.swing.Icon OPEN_ICON
           
static javax.swing.Icon OPEN_WABIT_ICON
           
static javax.swing.Icon SAVE_ICON
           
 
Fields inherited from interface ca.sqlpower.wabit.WabitSessionContext
DISABLE_QUERY_AUTO_EXECUTE, NEW_WORKSPACE_URL, WABIT_ENTERPRISE_SERVER_MDNS_TYPE
 
Constructor Summary
WabitSwingSessionContextImpl(WabitSessionContext delegate, boolean headless)
           
WabitSwingSessionContextImpl(WabitSessionContext delegateContext, boolean headless, ca.sqlpower.util.UserPrompterFactory upf)
           
 
Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener l)
           
 void addServer(ca.sqlpower.enterprise.client.SPServerInfo serverInfo)
          Adds a new user-configured server specification to this context.
 void addServerListListener(ServerListListener l)
          This listener will be notified when server information is added or removed from the server list.
 java.sql.Connection borrowConnection(ca.sqlpower.sql.JDBCDataSource dataSource)
          Borrows a connection to the given data source from this session's connection pool.
 void close()
          This will attempt to close all of the currently opened sessions and stop the app.
 org.olap4j.OlapConnection createConnection(ca.sqlpower.sql.Olap4jDataSource dataSource)
          This method returns an OlapConnection that has been mapped to an Olap4jDataSource.
 ca.sqlpower.util.UserPrompter createDatabaseUserPrompter(java.lang.String question, java.util.List<java.lang.Class<? extends ca.sqlpower.sql.SPDataSource>> dsTypes, ca.sqlpower.util.UserPrompter.UserPromptOptions optionType, ca.sqlpower.util.UserPrompter.UserPromptResponse defaultResponseType, java.lang.Object defaultResponse, ca.sqlpower.sql.DataSourceCollection<ca.sqlpower.sql.SPDataSource> dsCollection, java.lang.String... buttonNames)
           
 ca.sqlpower.swingui.RecentMenu createRecentMenu()
          Creates a menu that keeps track of the last few opened and saved workspace files.
 javax.swing.JMenu createServerListMenu(java.awt.Component dialogOwner, java.lang.String name, ServerListMenuItemFactory itemFactory)
          Creates a menu whose items change dynamically as enterprise servers appear and disappear on the network.
 WabitSwingSession createServerSession(ca.sqlpower.enterprise.client.SPServerInfo serverInfo)
          Creates a new server-based session for the given server.
 WabitSwingSession createSession()
          Creates a new local session that belongs to this context.
 ca.sqlpower.util.UserPrompter createUserPrompter(java.lang.String question, ca.sqlpower.util.UserPrompterFactory.UserPromptType responseType, ca.sqlpower.util.UserPrompter.UserPromptOptions optionType, ca.sqlpower.util.UserPrompter.UserPromptResponse defaultResponseType, java.lang.Object defaultResponse, java.lang.String... buttonNames)
           
 void endLoading()
          The DAO can tell this context that it's no longer being configured based on a workspace file being loaded.
 WabitSession getActiveSession()
          Returns the session that the user is currently viewing or editing.
 WabitSwingSession getActiveSwingSession()
           
 ca.sqlpower.sqlobject.SQLDatabase getDatabase(ca.sqlpower.sql.JDBCDataSource ds)
           
 ca.sqlpower.sql.DataSourceCollection<ca.sqlpower.sql.SPDataSource> getDataSources()
           
 java.util.List<ca.sqlpower.enterprise.client.SPServerInfo> getEnterpriseServers(boolean includeDiscoveredServers)
          Returns the list of currently-known enterprise servers.
 javax.swing.JFrame getFrame()
          Returns the JFrame that displays the context.
 javax.jmdns.JmDNS getJmDNS()
          Returns this context's JmDNS client instance.
 ca.sqlpower.swingui.SwingWorkerRegistry getLoadingRegistry()
          Returns a SwingWorkerRegistry for the context to track workers that are involved with loading files.
 java.lang.String getName()
          Returns the name for this session context.
 java.util.prefs.Preferences getPrefs()
          Returns the preferences node used by this session context.
 int getRowLimit()
          Returns the number of rows that should be retrieved from the database for any result set.
 javax.swing.JSpinner getRowLimitSpinner()
          Returns the row limit component that affects all cached result sets.
 int getSessionCount()
          Returns the number of active sessions in the context.
 java.util.List<WabitSession> getSessions()
          Returns an unmodifiable list of the active sessions in the context.
 boolean isLoading()
          Tells whether or not this session is currently being configured by a DAO.
 boolean isMacOSX()
          returns true if the OS is Mac
static void main(java.lang.String[] args)
          Launches the Wabit application by loading the configuration and displaying the GUI.
 void putRecentFileName(java.lang.String fileName)
          Sets the most recent file to be saved or loaded into the session.
 void registerChildSession(WabitSession child)
          Registers the given child session with this context, marking the child session as not having any unsaved changes.
 void removePropertyChangeListener(java.beans.PropertyChangeListener l)
           
 void removeServer(ca.sqlpower.enterprise.client.SPServerInfo si)
          Removes a new user-configured server specification from this context.
 void removeServerListListener(ServerListListener l)
          This listener will stop being notified when server information is added or removed from the server list.
 void setActiveSession(WabitSession activeSession)
          Sets the active session that is being viewed or modified.
 boolean setEditorPanel()
          Sets the panel that allows editing of the current selection in the tree.
 void setStatusMessage(java.lang.String msg)
          sets the StatusMessage
 void startLoading()
          The DAO can tell this context that it's currently being configured based on a workspace file being loaded.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EXAMPLE_WORKSPACE_URL

public static final java.lang.String EXAMPLE_WORKSPACE_URL
See Also:
Constant Field Values

FRAME_ICON

public static final javax.swing.ImageIcon FRAME_ICON
This icon is at the top left of every frame.


OPEN_WABIT_ICON

public static final javax.swing.Icon OPEN_WABIT_ICON

FORUM_ACTION

public static final ca.sqlpower.swingui.action.ForumAction FORUM_ACTION

NEW_ICON

public static final javax.swing.Icon NEW_ICON

OPEN_ICON

public static final javax.swing.Icon OPEN_ICON

SAVE_ICON

public static final javax.swing.Icon SAVE_ICON
Constructor Detail

WabitSwingSessionContextImpl

public WabitSwingSessionContextImpl(WabitSessionContext delegate,
                                    boolean headless)
                             throws java.io.IOException,
                                    ca.sqlpower.sqlobject.SQLObjectException
Parameters:
delegateContext - The context which this swing session delegates all its core WabitSessionContext operations to. This core session will also have joint ownership of all sessions registered with this swing context. As such, the delegate context must not contain any registered child sessions of its own when passed in. If it does, an IllegalStateException will be thrown by this constructor.
headless - Set to true to not create any GUI objects when the context starts. This stops the welcome screen from being created.
Throws:
java.io.IOException
ca.sqlpower.sqlobject.SQLObjectException

WabitSwingSessionContextImpl

public WabitSwingSessionContextImpl(WabitSessionContext delegateContext,
                                    boolean headless,
                                    ca.sqlpower.util.UserPrompterFactory upf)
                             throws java.io.IOException,
                                    ca.sqlpower.sqlobject.SQLObjectException
Parameters:
delegateContext - The context which this swing session delegates all its core WabitSessionContext operations to. This core session will also have joint ownership of all sessions registered with this swing context. As such, the delegate context must not contain any registered child sessions of its own when passed in. If it does, an IllegalStateException will be thrown by this constructor.
terminateWhenLastSessionCloses - Set to true if the context should stop the app when the last session is closed. If false the app will have to be closed in a way other than closing all of the sessions.
headless - Set to true to not create any GUI objects when the context starts. This stops the welcome screen from being created.
upf - A user prompter factory that will be used to display appropriate prompts to the user. This can be set if a non-default prompt is desired for places like saving. This cannot be null.
Throws:
java.io.IOException
ca.sqlpower.sqlobject.SQLObjectException
Method Detail

createSession

public WabitSwingSession createSession()
Description copied from interface: WabitSwingSessionContext
Creates a new local session that belongs to this context.

Specified by:
createSession in interface WabitSwingSessionContext
Specified by:
createSession in interface WabitSessionContext

createServerSession

public WabitSwingSession createServerSession(ca.sqlpower.enterprise.client.SPServerInfo serverInfo)
Description copied from interface: WabitSwingSessionContext
Creates a new server-based session for the given server. The new session will belong to this context.

Specified by:
createServerSession in interface WabitSwingSessionContext
Specified by:
createServerSession in interface WabitSessionContext

createRecentMenu

public ca.sqlpower.swingui.RecentMenu createRecentMenu()
Description copied from interface: WabitSwingSessionContext
Creates a menu that keeps track of the last few opened and saved workspace files.

Specified by:
createRecentMenu in interface WabitSwingSessionContext

setEditorPanel

public boolean setEditorPanel()
Description copied from interface: WabitSwingSessionContext
Sets the panel that allows editing of the current selection in the tree. A new panel will be created based on the type of model the active session's currently editing if the user has no changes or wants to discard the current changes.

Specified by:
setEditorPanel in interface WabitSwingSessionContext
Returns:
False if the previous editor was not correctly saved and the old component needs to be displayed. True otherwise.

getFrame

public javax.swing.JFrame getFrame()
Description copied from interface: WabitSwingSessionContext
Returns the JFrame that displays the context.

Specified by:
getFrame in interface WabitSwingSessionContext

getSessions

public java.util.List<WabitSession> getSessions()
Description copied from interface: WabitSessionContext
Returns an unmodifiable list of the active sessions in the context.

Specified by:
getSessions in interface WabitSessionContext

putRecentFileName

public void putRecentFileName(java.lang.String fileName)
Description copied from interface: WabitSwingSessionContext
Sets the most recent file to be saved or loaded into the session. The session tracks recent files for uses like a recent menu and to decide if Wabit should start with loading a saved file.

Specified by:
putRecentFileName in interface WabitSwingSessionContext
Parameters:
fileName - The absolute path to the file with the file name.

close

public void close()
Description copied from interface: WabitSessionContext
This will attempt to close all of the currently opened sessions and stop the app. Each session will close independently and if any one session does not close successfully then the closing operation will stop. Once all sessions have been properly closed the app will terminate. If not all sessions are properly closed the app will not terminate.

Specified by:
close in interface WabitSessionContext

getRowLimitSpinner

public javax.swing.JSpinner getRowLimitSpinner()
Description copied from interface: WabitSwingSessionContext
Returns the row limit component that affects all cached result sets.

Specified by:
getRowLimitSpinner in interface WabitSwingSessionContext
Returns:

getRowLimit

public int getRowLimit()
Description copied from interface: WabitSessionContext
Returns the number of rows that should be retrieved from the database for any result set.

Specified by:
getRowLimit in interface WabitSessionContext

setStatusMessage

public void setStatusMessage(java.lang.String msg)
sets the StatusMessage

Specified by:
setStatusMessage in interface WabitSwingSessionContext

getDataSources

public ca.sqlpower.sql.DataSourceCollection<ca.sqlpower.sql.SPDataSource> getDataSources()
Specified by:
getDataSources in interface WabitSessionContext

getEnterpriseServers

public java.util.List<ca.sqlpower.enterprise.client.SPServerInfo> getEnterpriseServers(boolean includeDiscoveredServers)
Description copied from interface: WabitSessionContext
Returns the list of currently-known enterprise servers. This list will change over time, and may be empty for the first few seconds after startup.

Specified by:
getEnterpriseServers in interface WabitSessionContext
Parameters:
includeDiscoveredServers - if true, all known servers will be returned whether they were configured explicitly or discovered dynamically. If false, only the explicitly configured servers will be listed.
Returns:
contact information for the known enterprise servers

addServer

public void addServer(ca.sqlpower.enterprise.client.SPServerInfo serverInfo)
Description copied from interface: WabitSessionContext
Adds a new user-configured server specification to this context. The information will be added to the WabitSessionContext.getEnterpriseServers(boolean) list immediately, and also stored persistently so it will be included in the enterprise server list in future incarnations of WabitSessionContext.

Specified by:
addServer in interface WabitSessionContext
Parameters:
serverInfo - The serverInfo object to add.

removeServer

public void removeServer(ca.sqlpower.enterprise.client.SPServerInfo si)
Description copied from interface: WabitSessionContext
Removes a new user-configured server specification from this context. The information will be removed immediately in the current context, and also from persistent storage.

Specified by:
removeServer in interface WabitSessionContext

getJmDNS

public javax.jmdns.JmDNS getJmDNS()
Description copied from interface: WabitSessionContext
Returns this context's JmDNS client instance.

Specified by:
getJmDNS in interface WabitSessionContext

getSessionCount

public int getSessionCount()
Description copied from interface: WabitSessionContext
Returns the number of active sessions in the context.

Specified by:
getSessionCount in interface WabitSessionContext

isMacOSX

public boolean isMacOSX()
Description copied from interface: WabitSessionContext
returns true if the OS is Mac

Specified by:
isMacOSX in interface WabitSessionContext

registerChildSession

public void registerChildSession(WabitSession child)
Registers the given child session with this context, marking the child session as not having any unsaved changes.

Specified by:
registerChildSession in interface WabitSessionContext
Parameters:
child - The child session to register. Must be non-null. If it is not a WabitSwingSession, it will be wrapped in one before it's registered.

getPrefs

public java.util.prefs.Preferences getPrefs()
Description copied from interface: WabitSessionContext
Returns the preferences node used by this session context. This should not normally be used by client code; it is primarily intended for use by alternative session and session context implementations.

Specified by:
getPrefs in interface WabitSessionContext

createServerListMenu

public javax.swing.JMenu createServerListMenu(java.awt.Component dialogOwner,
                                              java.lang.String name,
                                              ServerListMenuItemFactory itemFactory)
Description copied from interface: WabitSwingSessionContext
Creates a menu whose items change dynamically as enterprise servers appear and disappear on the network.

Specified by:
createServerListMenu in interface WabitSwingSessionContext
Parameters:
dialogOwner - The component that should own any dialogs that pop up as the result of executing menu actions under the server list menu.

getName

public java.lang.String getName()
Description copied from interface: WabitSessionContext
Returns the name for this session context. If this is server session, then return the server's name, returns "Local" otherwise.

Specified by:
getName in interface WabitSessionContext

createDatabaseUserPrompter

public ca.sqlpower.util.UserPrompter createDatabaseUserPrompter(java.lang.String question,
                                                                java.util.List<java.lang.Class<? extends ca.sqlpower.sql.SPDataSource>> dsTypes,
                                                                ca.sqlpower.util.UserPrompter.UserPromptOptions optionType,
                                                                ca.sqlpower.util.UserPrompter.UserPromptResponse defaultResponseType,
                                                                java.lang.Object defaultResponse,
                                                                ca.sqlpower.sql.DataSourceCollection<ca.sqlpower.sql.SPDataSource> dsCollection,
                                                                java.lang.String... buttonNames)
Specified by:
createDatabaseUserPrompter in interface ca.sqlpower.util.UserPrompterFactory

getActiveSession

public WabitSession getActiveSession()
Description copied from interface: WabitSessionContext
Returns the session that the user is currently viewing or editing.

Specified by:
getActiveSession in interface WabitSessionContext

getActiveSwingSession

public WabitSwingSession getActiveSwingSession()
Specified by:
getActiveSwingSession in interface WabitSwingSessionContext

setActiveSession

public void setActiveSession(WabitSession activeSession)
Description copied from interface: WabitSessionContext
Sets the active session that is being viewed or modified. Some events that depend on a session will act on the active session.

Specified by:
setActiveSession in interface WabitSessionContext

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener l)
Specified by:
addPropertyChangeListener in interface WabitSessionContext

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener l)
Specified by:
removePropertyChangeListener in interface WabitSessionContext

borrowConnection

public java.sql.Connection borrowConnection(ca.sqlpower.sql.JDBCDataSource dataSource)
                                     throws ca.sqlpower.sqlobject.SQLObjectException
Description copied from interface: WabitSessionContext
Borrows a connection to the given data source from this session's connection pool. You must call Connection.close() on the returned object as soon as you are finished with it.

Design note: Equivalent to #getDatabase(SPDataSource) .getConnection(). Normally we discourage adding convenience methods to an interface, and this is indeed a convenience method on an interface. The reason for this method is to reinforce the idea that connections to data sources must be obtained via the SQLDatabase object held in the session.

Specified by:
borrowConnection in interface WabitSessionContext
Parameters:
dataSource - The data source this connection comes from.
Returns:
A connection to the given data source, which has been obtained from a connection pool that this session owns.
Throws:
ca.sqlpower.sqlobject.SQLObjectException - if it is not currently possible to connect to the given data source. This could be due to the remote database being unavailable, or an incorrect username or password, a missing JDBC driver, or many other things.

isLoading

public boolean isLoading()
Description copied from interface: WabitSessionContext
Tells whether or not this session is currently being configured by a DAO. It's not normally necessary to know this from outside the session, but this method had to be public because it's part of the interface.

Specified by:
isLoading in interface WabitSessionContext

startLoading

public void startLoading()
Description copied from interface: WabitSessionContext
The DAO can tell this context that it's currently being configured based on a workspace file being loaded. When this is the case, certain things (such as GUI updates) will not be performed. If you're not a DAO, it's not necessary or desirable for you to call this method!

Specified by:
startLoading in interface WabitSessionContext

endLoading

public void endLoading()
Description copied from interface: WabitSessionContext
The DAO can tell this context that it's no longer being configured based on a workspace file being loaded. When this is the case, certain things (such as GUI updates) will not be performed. If you're not a DAO, it's not necessary or desirable for you to call this method!

Specified by:
endLoading in interface WabitSessionContext

getDatabase

public ca.sqlpower.sqlobject.SQLDatabase getDatabase(ca.sqlpower.sql.JDBCDataSource ds)
Specified by:
getDatabase in interface ca.sqlpower.sqlobject.SQLDatabaseMapping

createConnection

public org.olap4j.OlapConnection createConnection(ca.sqlpower.sql.Olap4jDataSource dataSource)
                                           throws java.sql.SQLException,
                                                  java.lang.ClassNotFoundException,
                                                  javax.naming.NamingException
Description copied from interface: OlapConnectionMapping
This method returns an OlapConnection that has been mapped to an Olap4jDataSource. This connection should not be closed as other objects may be using it to access the data source.

Specified by:
createConnection in interface OlapConnectionMapping
Throws:
java.sql.SQLException
java.lang.ClassNotFoundException
javax.naming.NamingException

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Launches the Wabit application by loading the configuration and displaying the GUI.

Throws:
java.lang.Exception - if startup fails

createUserPrompter

public ca.sqlpower.util.UserPrompter createUserPrompter(java.lang.String question,
                                                        ca.sqlpower.util.UserPrompterFactory.UserPromptType responseType,
                                                        ca.sqlpower.util.UserPrompter.UserPromptOptions optionType,
                                                        ca.sqlpower.util.UserPrompter.UserPromptResponse defaultResponseType,
                                                        java.lang.Object defaultResponse,
                                                        java.lang.String... buttonNames)
Specified by:
createUserPrompter in interface ca.sqlpower.util.UserPrompterFactory

addServerListListener

public void addServerListListener(ServerListListener l)
Description copied from interface: WabitSessionContext
This listener will be notified when server information is added or removed from the server list.

Specified by:
addServerListListener in interface WabitSessionContext

removeServerListListener

public void removeServerListListener(ServerListListener l)
Description copied from interface: WabitSessionContext
This listener will stop being notified when server information is added or removed from the server list.

Specified by:
removeServerListListener in interface WabitSessionContext

getLoadingRegistry

public ca.sqlpower.swingui.SwingWorkerRegistry getLoadingRegistry()
Description copied from interface: WabitSwingSessionContext
Returns a SwingWorkerRegistry for the context to track workers that are involved with loading files. It would be useful if the OpenWorkspaceXMLDAO created the session(s) to load into before creating the thread to do the loading. Then the loading thread could register with the session and we could remove this implementation.

Specified by:
getLoadingRegistry in interface WabitSwingSessionContext


Copyright © 2009. All Rights Reserved.