JavaGantt 2011.1 API

eu.beesoft.gaia.swing.client
Class SwingClient

java.lang.Object
  extended by eu.beesoft.gaia.swing.client.SwingClient

public abstract class SwingClient
extends java.lang.Object

An abstract implementation of the swing client for Gaia application (there is the ApplicationServer on the server side). This class has as high level of abstraction as possible: it processes the communication with a server, but has no limits on processing of the incoming instructions.

With this class you get an instrument to build your own client, with your own instruction set and your own Swing presentation.

In the simplest implementation of your subclass you have to:


Constructor Summary
SwingClient()
          Constructor builds an unique client and server application identifier (you can get it with getApplicationId() method) and initializes the default system UI look and feel.
 
Method Summary
 void actionPerformed(SwingClientAction action)
          Processes client request and server response in these steps: freezes current window to disable any user action while is communicating with server transforms the given action to ApplicationRequest and fills it with data from form - via method createApplicationRequest(SwingClientAction) invokes talkToServer(ApplicationRequest) to send this request to server and to obtain a response returned response is processed by processApplicationResponse(ApplicationResponse, SwingClientAction) method unfreezes current window to enable user actions These steps are internally executed in different threads with support of SwingWorker.
protected  void addAction(javax.swing.Action action, SwingBuilder<?> formBuilder)
          Adds given action to component created by given formBuilder.
protected  SwingBuilder<?> buildForm(ApplicationResponse response, SwingBuilderFactory factory)
          Builds a new Swing form (component) from given server response and builder factory.These steps are performed: the form id is obtained from given response (form id is a name of the resource in class path or file system) resource bundle is set to given factory (the name of resource bundle is derived from form id by replacing of the form file extension by ".properties") the Swing form is built with support of given factory method disableComponent(SwingBuilder) is invoked for each disabled component method hideComponent(SwingBuilder) is invoked for each hidden component method addAction(Action, SwingBuilder) is invoked for each built action method initListModel(ListModel, List) is invoked for each list model without class name in the XML form method propagateValidationErrors(ValidationResult, SwingBuilder) is invoked if there are some validation errors in the given server response data are set from server response to created Swing form
protected  ApplicationRequest createApplicationRequest(SwingClientAction action)
          Creates a new ApplicationRequest and fills it with command from given action and with (modified) data from current form.
protected  void disableComponent(SwingBuilder<?> builder)
          Disables a swing component created by given builder.
 void download(java.lang.String serverFileName, java.io.File clientFile, ProgressMediator mediator)
          Downloads a file from server.
 java.lang.String getApplicationId()
          Returns an unique identifier of this client instance and the application on the server.
 java.lang.String getCommunicationLog()
          Returns the name of the directory to store logs from communication between this client and server.
protected abstract  ComponentBuilder<?> getCurrentBuilder()
          Returns the builder used to build current form.
protected abstract  javax.swing.RootPaneContainer getCurrentWindow()
          Returns instance of JFrame or JDialog or other root pane container which is client's focused window.
static SwingClient getInstance()
          Returns current instance of SwingClient or null, if no client exists.
 java.lang.String getServerUrl()
          Returns the server URL.
protected  void hideComponent(SwingBuilder<?> builder)
          Hides a swing component created by given builder.
protected  void initListModel(javax.swing.ListModel model, java.util.List<?> data)
          Initializes given list model with given data.
 void invokeOnSwingThreadAndWait(java.lang.Runnable runnable)
          Helper method to invoke given runnable instance on Swing (AWT event) thread and wait for response.
protected abstract  void processApplicationResponse(ApplicationResponse response, SwingClientAction action)
          Processes obtained application response.
protected  void propagateValidationErrors(ValidationResult errors, SwingBuilder<?> formBuilder)
          Displays erros from the form validation on the server.
 void setCommunicationLog(java.lang.String communicationLogDirectory)
          Sets the name of the directory to store logs from communication between this client and server.
 void setServerUrl(java.lang.String serverUrl)
          Sets the serverl URL.
protected  ApplicationResponse talkToServer(ApplicationRequest request)
          Sends given request to the server and returns obtained response.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SwingClient

public SwingClient()
Constructor builds an unique client and server application identifier (you can get it with getApplicationId() method) and initializes the default system UI look and feel.

Method Detail

getInstance

public static SwingClient getInstance()
Returns current instance of SwingClient or null, if no client exists.


getApplicationId

public final java.lang.String getApplicationId()
Returns an unique identifier of this client instance and the application on the server.

Returns:
an identifier of this client and application

getServerUrl

public java.lang.String getServerUrl()
Returns the server URL.

Returns:
the serverUrl

setServerUrl

public void setServerUrl(java.lang.String serverUrl)
Sets the serverl URL.

Parameters:
serverUrl - the serverUrl to set

getCommunicationLog

public java.lang.String getCommunicationLog()
Returns the name of the directory to store logs from communication between this client and server.

Returns:
the communication log directory name or null

setCommunicationLog

public void setCommunicationLog(java.lang.String communicationLogDirectory)
Sets the name of the directory to store logs from communication between this client and server. When set to null, client will not log this communication.

Parameters:
communicationLogDirectory - the communication log directory name to set

getCurrentBuilder

protected abstract ComponentBuilder<?> getCurrentBuilder()
Returns the builder used to build current form.

Returns:
current form builder

getCurrentWindow

protected abstract javax.swing.RootPaneContainer getCurrentWindow()
Returns instance of JFrame or JDialog or other root pane container which is client's focused window. This method is invoked by SwingClient to get glass pane and to freeze window while it is communicating with server.

Returns:
current window

actionPerformed

public void actionPerformed(SwingClientAction action)
Processes client request and server response in these steps:
  1. freezes current window to disable any user action while is communicating with server
  2. transforms the given action to ApplicationRequest and fills it with data from form - via method createApplicationRequest(SwingClientAction)
  3. invokes talkToServer(ApplicationRequest) to send this request to server and to obtain a response
  4. returned response is processed by processApplicationResponse(ApplicationResponse, SwingClientAction) method
  5. unfreezes current window to enable user actions
These steps are internally executed in different threads with support of SwingWorker.


download

public void download(java.lang.String serverFileName,
                     java.io.File clientFile,
                     ProgressMediator mediator)
Downloads a file from server.

Parameters:
serverFileName - - file name (and relative path) on the server
clientFile - - local file to store file from server
mediator - - instance of mediator used to show the download progress, may be null
Throws:
java.lang.RuntimeException - if some error occurs in communication with server

invokeOnSwingThreadAndWait

public void invokeOnSwingThreadAndWait(java.lang.Runnable runnable)
Helper method to invoke given runnable instance on Swing (AWT event) thread and wait for response.

Parameters:
runnable - - instance of Runnable to run
Throws:
java.lang.RuntimeException - if some error occurs

talkToServer

protected ApplicationResponse talkToServer(ApplicationRequest request)
Sends given request to the server and returns obtained response.

Parameters:
request - - request to send
Returns:
response from server
Throws:
java.lang.RuntimeException - if some error in communication occurs

createApplicationRequest

protected ApplicationRequest createApplicationRequest(SwingClientAction action)
Creates a new ApplicationRequest and fills it with command from given action and with (modified) data from current form.

Parameters:
action - - action to process (send to server)
Returns:
a newly created request

processApplicationResponse

protected abstract void processApplicationResponse(ApplicationResponse response,
                                                   SwingClientAction action)
Processes obtained application response. This method is invoked from actionPerformed(SwingClientAction). It is a programmer responsibility to serve this method. Please, note there is buildForm(ApplicationResponse, SwingBuilderFactory) method to help.

Parameters:
response - - server response to process
action - - client action which invokes that response

buildForm

protected SwingBuilder<?> buildForm(ApplicationResponse response,
                                    SwingBuilderFactory factory)
Builds a new Swing form (component) from given server response and builder factory.These steps are performed:
  1. the form id is obtained from given response (form id is a name of the resource in class path or file system)
  2. resource bundle is set to given factory (the name of resource bundle is derived from form id by replacing of the form file extension by ".properties")
  3. the Swing form is built with support of given factory
  4. method disableComponent(SwingBuilder) is invoked for each disabled component
  5. method hideComponent(SwingBuilder) is invoked for each hidden component
  6. method addAction(Action, SwingBuilder) is invoked for each built action
  7. method initListModel(ListModel, List) is invoked for each list model without class name in the XML form
  8. method propagateValidationErrors(ValidationResult, SwingBuilder) is invoked if there are some validation errors in the given server response
  9. data are set from server response to created Swing form

Parameters:
response - - the server response as source to build a new form
factory - - object factory used to build form
Returns:
root builder of the factory (you can get a form top component with method ObjectBuilder.getObject() from it)

disableComponent

protected void disableComponent(SwingBuilder<?> builder)
Disables a swing component created by given builder. It:

Parameters:
builder - - builder which object should be disabled

hideComponent

protected void hideComponent(SwingBuilder<?> builder)
Hides a swing component created by given builder. It: This method is invoked from buildForm(ApplicationResponse, SwingBuilderFactory) .

Parameters:
builder - - builder which object should be hidden

addAction

protected void addAction(javax.swing.Action action,
                         SwingBuilder<?> formBuilder)
Adds given action to component created by given formBuilder. It is invoked from buildForm(ApplicationResponse, SwingBuilderFactory) . In this implementation does nothing. Override it to process action. Usually it is bound to button which is outside of component of formBuilder (some application button panel or so).

Parameters:
action - - an action to add
formBuilder - - component builder to which component should be action added

initListModel

protected void initListModel(javax.swing.ListModel model,
                             java.util.List<?> data)
Initializes given list model with given data. This implementation supports DefaultListModel and DefaultComboBoxModel classes as list models. Null item in data is in list models interpreted as an empty item. This method is invoked from buildForm(ApplicationResponse, SwingBuilderFactory).

Parameters:
model - - a list model to initialize
data - - data to set to list model

propagateValidationErrors

protected void propagateValidationErrors(ValidationResult errors,
                                         SwingBuilder<?> formBuilder)
Displays erros from the form validation on the server. In this implementation does nothing. It is invoked from buildForm(ApplicationResponse, SwingBuilderFactory).


JavaGantt 2011.1 API