ehsbe CommonsTM
Version 1.1.0rc3

com.ehsbe.commons.gui.wizard
Class ExecServiceAdapter

java.lang.Object
  extended by com.ehsbe.commons.gui.wizard.ExecServiceAdapter
All Implemented Interfaces:
ExecService

public class ExecServiceAdapter
extends Object
implements ExecService

General purpose wrapper for a task execution service.

Version:
$Revision: 496 $
Author:
Jens Elkner

Constructor Summary
ExecServiceAdapter()
          Creates a new service which returns always the same empty page.
ExecServiceAdapter(JComponent page)
          Creates a new service which returns always the same page.
 
Method Summary
 JComponent execute(HashMap<Task,HashMap<? extends Object,? extends Object>> settings, TaskControl control, EnumSet<NavMode> initalMode)
          Create the UI aka wizard page, which should be displayed and do the work described by the task.
 void finish(HashMap<Task,HashMap<? extends Object,? extends Object>> settings, TaskControl control, NavMode mode)
          Calculate final results for this task, cleanup resources and notify the controller, when all work has been done.
protected  JComponent getEmptyPanel(Task task)
          Just in case we have no page to display.
 boolean hasHelp()
          Check, whether this task may provide any help UI.
 void prepare(HashMap<Task,HashMap<? extends Object,? extends Object>> settings, TaskControl control)
          Prepare all data required to setup the UI aka wizard page for a task.
 void showHelp(HashMap<Task,HashMap<? extends Object,? extends Object>> settings, TaskControl control, JComponent parent)
          Show the help for this task.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExecServiceAdapter

public ExecServiceAdapter()
Creates a new service which returns always the same empty page.

See Also:
ExecServiceAdapter(JComponent)

ExecServiceAdapter

public ExecServiceAdapter(JComponent page)
Creates a new service which returns always the same page.

Parameters:
page - the page, which gets returned per default via execute(HashMap, TaskControl, EnumSet). Might be null.
Method Detail

prepare

public void prepare(HashMap<Task,HashMap<? extends Object,? extends Object>> settings,
                    TaskControl control)
Prepare all data required to setup the UI aka wizard page for a task. One should not perform any UI setup/modifications here, since it gets usually not invoked from the EDT!

The controller makes sure, that this method gets always called before ExecService.execute(HashMap, TaskControl, EnumSet).

Setting navigation modes here has usually no effect and gets ignored, since per default all navigation buttons are disabled until ExecService.execute(HashMap, TaskControl, EnumSet) returns.

Per default it does nothing.

Specified by:
prepare in interface ExecService
Parameters:
settings - all settings and collected data so far.
control - the controller, which is in charge aka manages this task and needs to be notified on completion/business

getEmptyPanel

protected JComponent getEmptyPanel(Task task)
Just in case we have no page to display.

Parameters:
task - current task in action
Returns:
a empty page

execute

public JComponent execute(HashMap<Task,HashMap<? extends Object,? extends Object>> settings,
                          TaskControl control,
                          EnumSet<NavMode> initalMode)
Create the UI aka wizard page, which should be displayed and do the work described by the task. The controller makes sure, that this method gets always called within the EDT. So it should return relatively fast to avoid, that the wizard seems to be hanging.

Before this method gets called, the controller makes sure, that ExecService.prepare(HashMap, TaskControl) has been called before. Thats why all none-UI related preparations should be made there, so that this method is able to return fast.

Implementations should create the UI required for user input here, add required listeners to it and return the UI. After that, the controller notifies appropriate listeners, what usually results into adding the returned component to the wizard dialog and thus it gets visible.

When the controller decides to change the current task in action, the ExecService.finish(HashMap, TaskControl, NavMode) method gets called.

Per default it just enables all possible modes and returns the page passed in the contructor. If it is null, an empty JPanel, whose name is set to EMPTY_PANEL will be used instead.

Specified by:
execute in interface ExecService
Parameters:
settings - all settings and collected data so far.
control - the controller, which is in charge aka manages this task and needs to be notified at least on completion/busyness.
initalMode - container, where to set initial navigation modes, when the UI for this wizard gets displayed.
Returns:
null if the task does not require an UI to be executed, the component, which is not visible, to display otherwise.
See Also:
Component.isVisible(), JComponent.setVisible(boolean), TaskControl.setBusy(Task, boolean), TaskControl.setLocale(Locale), TaskControl.setNavMode(Task, EnumSet)

finish

public void finish(HashMap<Task,HashMap<? extends Object,? extends Object>> settings,
                   TaskControl control,
                   NavMode mode)
Calculate final results for this task, cleanup resources and notify the controller, when all work has been done.

Invoked by the controller after ExecService.prepare(HashMap, TaskControl) or ExecService.execute(HashMap, TaskControl, EnumSet) to let the task cleanup its resources (e.g. populatated during the prepare and execute phase) and let it calculate its final results.

Usually this method gets invoked in a none-EDT in preparation to switch to the next or previous task or to finally finish the wizard. So if some UI modifications are done, one should invoke [and wait] appropriate work in the EDT.

The task is required to call its controller's TaskControl.finished(Task) method, to let it know, that it may [not] continue with the next step indicated by mode. To veto that the controller should not continue with the intended action, one should call its TaskControl.setNavMode(Task, EnumSet) before returning from this method to indicate, what is ok. However, the final decision about what to do next will be made by the controller.

So if this task denies the intended action, this method might be called several times.

Per default it just calls TaskControl.finished(Task).

Specified by:
finish in interface ExecService
Parameters:
settings - all settings and collected data so far.
control - the controller, which is in charge aka manages this task and needs to be notified at least on completion/busyness.
mode - what the controller intends to do next.
See Also:
EventQueue.isDispatchThread(), EventQueue.invokeAndWait(Runnable)

hasHelp

public boolean hasHelp()
Check, whether this task may provide any help UI.

Per default it returns false.

Specified by:
hasHelp in interface ExecService
Returns:
false if calling ExecService.showHelp(HashMap, TaskControl, JComponent) is useless, i.e. does nothing.

showHelp

public void showHelp(HashMap<Task,HashMap<? extends Object,? extends Object>> settings,
                     TaskControl control,
                     JComponent parent)
Show the help for this task.

This method gets usually called twice: First with parent set to null, i.e. none-UI work required for displaying help should be made. Per default, it gets called outside of the EDT.

When it gets called with a none-null parent, one may actually do all UI related work and show the help UI. The controller ensures, that this call gets made within the EDT.

Per default it does nothing.

Specified by:
showHelp in interface ExecService
Parameters:
settings - all settings and collected data so far.
control - the controller, which is in charge aka manages this task and needs to be notified at least on completion/busyness.
parent - where to anchor the help frame to show. null indicates, that none-UI preparations should be made - i.e. prepare help set, images etc.

ehsbe CommonsTM
Version 1.1.0rc3

Copyright ©2005-2009 EHSBE, Walther-Rathenau-Str. 58, 39104 Magdeburg, Sachsen-Anhalt, Germany. All Rights Reserved.