public abstract class BasePresenter extends java.lang.Object implements NamedExtension
This class the base class for a result presenter. It automatically registers to a model and should present the result
presented by the ResultModel
in some way.
There are multiple callback-methods which subclasses can override to react on the event or to present the result.
The presenter must react on errors which occur while reading or comparing the files, see
onError(ExceptionData, boolean, ERROR_SOURCE)
. Exceptions are not thrown by the PDFComparer
.
DataGeneratorListener
to the actual AbstractComparator
Modifier and Type | Class and Description |
---|---|
static class |
BasePresenter.ERROR_SOURCE
Names the thread / task where the error occurred
|
Modifier and Type | Field and Description |
---|---|
static com.inet.logging.Logger |
LOGGER
Default Logger for presenter
|
static int |
MAX_FILENAME_LENGTH
The maximum length the filename of an exported file is allowed to have without extension.
|
Constructor and Description |
---|
BasePresenter() |
Modifier and Type | Method and Description |
---|---|
protected boolean |
canInformUserOnErrors()
Returns whether the presenter is able to handle errors in a way to notify the user.
|
BasePresenter |
configure(IProfile configuration)
Deprecated.
As of i-net PDFC 5.0, use instead
PDFComparer.setSettings(Settings) or ResultModel.getSettings() |
java.lang.String |
createExportFilename(java.lang.String presenterType,
java.lang.String n1,
java.lang.String n2)
Construct the default Export file name used for exports.
|
void |
detachFromModel()
Detaches this presenter from a model.
|
void |
executeImmediately(ResultModel model)
Forces an execution of the presenter no matter the current model state.
|
protected java.lang.String |
getDefaultExportName(java.lang.String presenterType)
Returns the default export file name of the current comparison.
|
PresenterExceptionData |
getLastPresenterException()
Return the last exception for this presenter.
|
protected ResultModel |
getModel()
Returns the model this presenter is registered to
|
protected BasePresenter |
getParent()
Returns the parent presenter.
|
java.util.List<PresenterExceptionData> |
getPresenterExceptions()
Return all exceptions for a this presenter.
|
protected void |
onClear()
Called upon comparison startup.
|
protected abstract void |
onComparisonDone()
Called to indicate that a comparison has finished.
|
protected void |
onDataUpdate()
Called whenever the referred model receives a data chunk.
|
protected void |
onError(ExceptionData error,
boolean interrupted,
BasePresenter.ERROR_SOURCE source)
Called in case of an error that occurred either in one of the parser threads or in the compare thread.
|
protected void |
onFilterChange()
Called whenever the filter conditions of the referenced model have changed.
|
protected void |
onFinish()
OPTIONAL: Called in case of batch comparison at the end of all comparisons of the batch run.
|
protected void |
onInit()
Called at the time the document informations have been set.
|
protected void |
onProgressUpdate(float progress)
Called whenever the comparison sends a progress state.
|
void |
setModel(ResultModel newModel)
Registers this presenter to a model.
|
protected void |
setParent(BasePresenter parent)
Sets the parent presenter for spawned presenters.
|
BasePresenter |
spawn(boolean spawnWithParent)
Creates another presenter of the the same type as the current one.
|
getExtensionName
public static final int MAX_FILENAME_LENGTH
public static final com.inet.logging.Logger LOGGER
@Deprecated public BasePresenter configure(IProfile configuration)
PDFComparer.setSettings(Settings)
or ResultModel.getSettings()
PDFCProperty.MAX_ERRORS_PER_FILE
from the configuration.configuration
- the configuration to read from, must not be null
protected void onClear() throws java.lang.Exception
java.lang.Exception
- thrown in case the processing of the clear step failsprotected void onInit() throws java.lang.Exception
java.lang.Exception
- thrown in case the processing of the init step failsprotected void onDataUpdate() throws java.lang.Exception
java.lang.Exception
- thrown in case the processing of the update step failsprotected abstract void onComparisonDone() throws java.lang.Exception
java.lang.Exception
- thrown in case the processing of the finish step failsprotected void onFinish()
PDFComparer.batchCompare(java.io.File, java.io.File)
method.protected void onError(ExceptionData error, boolean interrupted, BasePresenter.ERROR_SOURCE source)
ResultModel
.error
- the exceptioninterrupted
- indicates whether the comparison was interrupted due to this exception. If true
there will be no further calls (e.g. onComparisonDone)source
- the source module of the exception.protected void onFilterChange() throws java.lang.Exception
java.lang.Exception
- thrown in case the processing of the filter update failsprotected void onProgressUpdate(float progress)
progress
- the progress in percent, a value between 0 and 100, bounds included.public void executeImmediately(ResultModel model) throws java.lang.Exception
model
- the model to be presented, if null
the currently set model will be presented.
This model will not be set persistently to the presenter, it will be detached at the end of this methodjava.lang.IllegalStateException
- in case the no model has been set yetjava.lang.Exception
- thrown in case the processing of fails; this exception is published to the caller
to allow a feedback to the userpublic void setModel(ResultModel newModel)
newModel
- the newprotected ResultModel getModel()
public void detachFromModel()
protected java.lang.String getDefaultExportName(java.lang.String presenterType)
MAX_FILENAME_LENGTH
characters by truncating both compared file's names again.createExportFilename(String, String, String)
which is called by the implementation of this method in
BasePresenter
.presenterType
- the identifier of the calling presenter, will be part of the export name, should not be
null
null
if the comparison was not started yetcreateExportFilename(String, String, String)
public java.lang.String createExportFilename(java.lang.String presenterType, java.lang.String n1, java.lang.String n2)
getDefaultExportName(String)
in BasePresenter
with dummy parameters to
determine how much characters will be added by this method. That is required to truncate the compared files names
in order to return a filename which does not exceed a limit of MAX_FILENAME_LENGTH
characters.presenterType
- the Sting passed to getDefaultExportName(String)
which describes the presentern1
- the possibly truncated name of the first file, or an empty string for the check for how many characters
this methods addsn2
- the possibly truncated name of the second file, or an empty string for the check for how many
characters this methods addscreateExportFilename(String, String, String)
public PresenterExceptionData getLastPresenterException()
public java.util.List<PresenterExceptionData> getPresenterExceptions()
public BasePresenter spawn(boolean spawnWithParent)
spawnWithParent
- if true, the presenter is allowed to keep a reference to it's parent to create a summary on onFinish()java.lang.IllegalStateException
- in case the spawn was not successfulprotected void setParent(BasePresenter parent)
parent
- the parent presenter.protected BasePresenter getParent()
null
protected boolean canInformUserOnErrors()
true
of onError(ExceptionData, boolean, ERROR_SOURCE)
will
directly inform the user.Copyright © 2010-2022 by i-net software GmbH