net.pandoragames.far.ui
Class UIBean

java.lang.Object
  extended by net.pandoragames.far.ui.UIBean
All Implemented Interfaces:
Resetable, UIFace

public class UIBean
extends java.lang.Object
implements UIFace

GUI neutral bridge between backend and frontend. Since searches can take quite a lot of time, the findFiles(), rename() and replace() methods execute the respective commands in a Thread on their own.

Author:
Olivier Wehner at 26.02.2008

Constructor Summary
UIBean(MessageBox sink, Localizer localizer)
          Constructor requires a sink for (error) messages
 
Method Summary
 void abort()
          Aborts a currently running operation (find, replace, ...).
 void addProgressListener(ProgressListener prol)
          Adds a ProgressListener that will reveive notifications about find and replace operations (but not about renaming operations).
 java.util.List<TargetFile> findFiles(FindForm criteriaForm)
          Uses the "criteria" parameter to configure a FileSelector and returns the list of found files.
 void removeProgressListener(ProgressListener prol)
          Removes a previously set ProgressListener
 java.util.List<TargetFile> rename(java.util.List<TargetFile> fileList, OverwriteFileCallback callback)
          Cycles through the file list and renames each file to the name specified in the "newName" property, unless the file is not selected or "newName" is empty.
 void replace(ReplaceForm criteriaForm, java.util.List<TargetFile> fileList)
          Uses the "criteria" parameter to configure a FileMatcher and applies the defined relacement algorithm to all files in the list that are marked as "selected" (the default).
 void reset()
          Aborts any currently running search and clears the history.
 void setLocalizer(Localizer localizer)
          Sets the Localizer instance to be used for translations.
 void undoLastReplace()
          Undo command for the last replace operation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UIBean

public UIBean(MessageBox sink,
              Localizer localizer)
Constructor requires a sink for (error) messages

Parameters:
sink - for (error) messages
Method Detail

findFiles

public java.util.List<TargetFile> findFiles(FindForm criteriaForm)
Uses the "criteria" parameter to configure a FileSelector and returns the list of found files.

Specified by:
findFiles in interface UIFace
Parameters:
criteriaForm - search criteria
Returns:
result list, possibly empty, never null

replace

public void replace(ReplaceForm criteriaForm,
                    java.util.List<TargetFile> fileList)
Uses the "criteria" parameter to configure a FileMatcher and applies the defined relacement algorithm to all files in the list that are marked as "selected" (the default).

Specified by:
replace in interface UIFace
Parameters:
criteriaForm - defining a regular expression and a replacement pattern
fileList - list of files to operate ons

undoLastReplace

public void undoLastReplace()
Undo command for the last replace operation. Copies the backup back to its place if one was made. Writes an error message in the sink if no backup was made or if no previous replace operation has been recorded.

Specified by:
undoLastReplace in interface UIFace

rename

public java.util.List<TargetFile> rename(java.util.List<TargetFile> fileList,
                                         OverwriteFileCallback callback)
Cycles through the file list and renames each file to the name specified in the "newName" property, unless the file is not selected or "newName" is empty. This operation will only change the file name, not the files path. If a file with the desired new name exists, the callback will be used to request user feedback. If the renaming operation fails for some reason, an error will be written to the respective TargetFile opject. Returns the transformed list of files.

Specified by:
rename in interface UIFace
Parameters:
fileList - files to be renamed
callback - for user feedback
Returns:
transformed list of files

abort

public void abort()
Aborts a currently running operation (find, replace, ...).

Specified by:
abort in interface UIFace

reset

public void reset()
Aborts any currently running search and clears the history. Does not remove any ProgressListener, but resets all internal informations about previous searches.

Specified by:
reset in interface Resetable
Specified by:
reset in interface UIFace

setLocalizer

public void setLocalizer(Localizer localizer)
Sets the Localizer instance to be used for translations.

Parameters:
localizer - for translations

addProgressListener

public void addProgressListener(ProgressListener prol)
Adds a ProgressListener that will reveive notifications about find and replace operations (but not about renaming operations).

Specified by:
addProgressListener in interface UIFace
Parameters:
prol - ProgressListener to be added.

removeProgressListener

public void removeProgressListener(ProgressListener prol)
Removes a previously set ProgressListener

Specified by:
removeProgressListener in interface UIFace
Parameters:
prol - ProgressListener to be removed