|
JavaGantt 2011.1 API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecteu.beesoft.gaia.swing.client.SwingClient
public abstract class SwingClient
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:
JFrame
or JDialog
) - the
best place to do it is probably a constructorgetCurrentBuilder()
methodgetCurrentWindow()
methodprocessApplicationResponse(ApplicationResponse, SwingClientAction)
method -
here you will process (your own) instructions returned from the server. Please, note, there is a
method buildForm(ApplicationResponse, SwingBuilderFactory)
prepared to help.
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 |
---|
public SwingClient()
getApplicationId()
method) and initializes the default system UI look and feel.
Method Detail |
---|
public static SwingClient getInstance()
public final java.lang.String getApplicationId()
public java.lang.String getServerUrl()
public void setServerUrl(java.lang.String serverUrl)
serverUrl
- the serverUrl to setpublic java.lang.String getCommunicationLog()
public void setCommunicationLog(java.lang.String communicationLogDirectory)
communicationLogDirectory
- the communication log directory name to setprotected abstract ComponentBuilder<?> getCurrentBuilder()
protected abstract javax.swing.RootPaneContainer getCurrentWindow()
public void actionPerformed(SwingClientAction action)
ApplicationRequest
and fills it with data from
form - via method createApplicationRequest(SwingClientAction)
talkToServer(ApplicationRequest)
to send this request to server and to
obtain a responseprocessApplicationResponse(ApplicationResponse, SwingClientAction)
methodSwingWorker
.
public void download(java.lang.String serverFileName, java.io.File clientFile, ProgressMediator mediator)
serverFileName
- - file name (and relative path) on the serverclientFile
- - local file to store file from servermediator
- - instance of mediator used to show the download progress, may be null
java.lang.RuntimeException
- if some error occurs in communication with serverpublic void invokeOnSwingThreadAndWait(java.lang.Runnable runnable)
runnable
- - instance of Runnable
to run
java.lang.RuntimeException
- if some error occursprotected ApplicationResponse talkToServer(ApplicationRequest request)
request
- - request to send
java.lang.RuntimeException
- if some error in communication occursprotected ApplicationRequest createApplicationRequest(SwingClientAction action)
ApplicationRequest
and fills it with command from given action and with
(modified) data from current form.
action
- - action to process (send to server)
protected abstract void processApplicationResponse(ApplicationResponse response, SwingClientAction action)
actionPerformed(SwingClientAction)
. It is a programmer responsibility to serve this
method. Please, note there is buildForm(ApplicationResponse, SwingBuilderFactory)
method to help.
response
- - server response to processaction
- - client action which invokes that responseprotected SwingBuilder<?> buildForm(ApplicationResponse response, SwingBuilderFactory factory)
disableComponent(SwingBuilder)
is invoked for each disabled componenthideComponent(SwingBuilder)
is invoked for each hidden componentaddAction(Action, SwingBuilder)
is invoked for each built actioninitListModel(ListModel, List)
is invoked for each list model without
class
name in the XML formpropagateValidationErrors(ValidationResult, SwingBuilder)
is invoked if
there are some validation errors in the given server response
response
- - the server response as source to build a new formfactory
- - object factory used to build form
ObjectBuilder.getObject()
from it)protected void disableComponent(SwingBuilder<?> builder)
JTextComponent
invokes setEditable (false)
method on itJDateField
invokes setEditable (false)
method on itComponent
invokes setEnabled (false)
method on
itAction
invokes setEnabled (false)
method on it
builder
- - builder which object should be disabledprotected void hideComponent(SwingBuilder<?> builder)
Component
setVisible (false)
method on
itTableColumn
in JZebraTable
method
JZebraTable.setColumnVisible(TableColumn, boolean)
Action
setEnabled (false)
method on itbuildForm(ApplicationResponse, SwingBuilderFactory)
.
builder
- - builder which object should be hiddenprotected void addAction(javax.swing.Action action, SwingBuilder<?> formBuilder)
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).
action
- - an action to addformBuilder
- - component builder to which component should be action addedprotected void initListModel(javax.swing.ListModel model, java.util.List<?> data)
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)
.
model
- - a list model to initializedata
- - data to set to list modelprotected void propagateValidationErrors(ValidationResult errors, SwingBuilder<?> formBuilder)
buildForm(ApplicationResponse, SwingBuilderFactory)
.
|
JavaGantt 2011.1 API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |