📄 tableprocessor.java
字号:
while (hasNext == true);
state.setProperty(JFreeReport.REPORT_PREPARERUN_PROPERTY, Boolean.FALSE);
// finally prepeare the returned start state.
final StartState sretval = (StartState) retval;
if (sretval == null)
{
throw new IllegalStateException("There was no valid pagination done.");
}
// reset the state, so that the datarow points to the first row of the tablemodel.
sretval.resetState();
return sretval;
}
catch (FunctionInitializeException fne)
{
throw new ReportProcessingException("Unable to initialize the functions/expressions.", fne);
}
catch (CloneNotSupportedException cne)
{
throw new ReportProcessingException("Unable to initialize the report, clone error", cne);
}
}
/**
* Processes the report. The generated output is written using the defined
* writer, the report is repaginated before the final writing.
*
* @throws ReportProcessingException if the report processing failed.
*/
public void processReport() throws ReportProcessingException
{
ReportState state = repaginate();
final TableWriter w = (TableWriter) state.getDataRow().get(TABLE_WRITER);
w.setProducer(createProducer(w.getProducer().getGridBoundsCollection()));
w.getProducer().configure(getProperties());
w.setMaxWidth((float) getReport().getDefaultPageFormat().getImageableWidth());
final RepaginationState stateEvent = new RepaginationState(this, 0, 0, 0, 0, false);
final int maxRows = state.getNumberOfRows();
int lastRow = -1;
int eventCount = 0;
final int eventTrigger = maxRows / MAX_EVENTS_PER_RUN;
final boolean failOnError =
getReport().getReportConfiguration().isStrictErrorHandling();
ReportStateProgress progress = null;
while (!state.isFinish())
{
checkInterrupted();
if (lastRow != state.getCurrentDisplayItem())
{
lastRow = state.getCurrentDisplayItem();
if (eventCount == 0)
{
stateEvent.reuse(TableWriter.OUTPUT_LEVEL, state.getCurrentPage(),
state.getCurrentDataItem(), state.getNumberOfRows(), true);
fireStateUpdate(stateEvent);
eventCount += 1;
}
else
{
if (eventCount == eventTrigger)
{
eventCount = 0;
}
else
{
eventCount += 1;
}
}
}
progress = state.createStateProgress(progress);
state = state.advance();
if (failOnError && state.isErrorOccured() == true)
{
throw new ReportEventException("Failed to dispatch an event.", state.getErrors());
}
if (!state.isFinish())
{
if (!state.isProceeding(progress))
{
throw new ReportProcessingException("State did not proceed, bailing out!");
}
}
}
}
/**
* Creates a TableProducer. The TableProducer is responsible to create the table.
*
* @param gridLayoutBounds the grid layout that contain the bounds from the pagination run.
* @return the created table producer, never null.
*/
protected abstract TableProducer createProducer(TableLayoutInfo gridLayoutBounds);
/**
* Creates a dummy TableProducer. The TableProducer is responsible to compute the layout.
*
* @return the created table producer, never null.
*/
protected abstract TableProducer createDummyProducer();
/**
* Defines a property for this output target. Properties are the standard way of configuring
* an output target.
*
* @param property the name of the property to set (<code>null</code> not permitted).
* @param value the value of the property. If the value is <code>null</code>, the property is
* removed from the output target.
*/
public void setProperty(final String property, final Object value)
{
if (property == null)
{
throw new NullPointerException();
}
if (value == null)
{
properties.remove(property);
}
else
{
properties.put(property, value);
}
}
/**
* Queries the property named with <code>property</code>. If the property is not found, <code>
* null</code> is returned.
*
* @param property the name of the property to be queried
*
* @return the value stored under the given property name
*
* @throws java.lang.NullPointerException if <code>property</code> is null
*/
public Object getProperty(final String property)
{
return getProperty(property, null);
}
/**
* Queries the property named with <code>property</code>. If the property is not found, the
* default value is returned.
*
* @param property the name of the property to be queried
* @param defaultValue the defaultvalue returned if there is no such property
*
* @return the value stored under the given property name
*
* @throws NullPointerException if <code>property</code> is null
*/
public Object getProperty(final String property, final Object defaultValue)
{
if (property == null)
{
throw new NullPointerException();
}
final Object retval = properties.get(property);
if (retval == null)
{
return defaultValue;
}
return retval;
}
/**
* Returns an enumeration of the property names.
*
* @return the enumeration.
*/
protected Iterator getPropertyNames()
{
return properties.keySet().iterator();
}
/**
* Gets the internal properties storage.
*
* @return the internal properties storage.
*/
protected Properties getProperties()
{
return properties;
}
/**
* Gets the report configuration prefix for that processor. This prefix defines
* how to map the property names into the global report configuration.
*
* @return the report configuration prefix.
*/
protected abstract String getReportConfigurationPrefix();
/**
* Copies all report configuration properties which match the configuration
* prefix of this table processor into the property set of this processor.
*/
protected void configure()
{
final ReportConfiguration rc = getReport().getReportConfiguration();
final Iterator enum = rc.findPropertyKeys(getReportConfigurationPrefix());
final int prefixLength = getReportConfigurationPrefix().length();
while (enum.hasNext())
{
final String key = (String) enum.next();
final String propKey = key.substring(prefixLength);
if (getProperties().containsKey(propKey))
{
continue;
}
final Object value = rc.getConfigProperty(key);
setProperty(propKey, value);
}
getTableWriter().setMaxWidth((float) getReport().getDefaultPageFormat().getImageableWidth());
}
/**
* Adds a repagination listener. This listener will be informed of
* pagination events.
*
* @param l the listener.
*/
public void addRepaginationListener(final RepaginationListener l)
{
if (l == null)
{
throw new NullPointerException("Listener == null");
}
if (listeners == null)
{
listeners = new ArrayList(5);
}
listenersCache = null;
listeners.add(l);
}
/**
* Removes a repagination listener.
*
* @param l the listener.
*/
public void removeRepaginationListener(final RepaginationListener l)
{
if (l == null)
{
throw new NullPointerException("Listener == null");
}
if (listeners == null)
{
return;
}
listenersCache = null;
listeners.remove(l);
}
/**
* Sends a repagination update to all registered listeners.
*
* @param state the state.
*/
protected void fireStateUpdate(final RepaginationState state)
{
if (listeners == null)
{
return;
}
if (listenersCache == null)
{
listenersCache = listeners.toArray();
}
for (int i = 0; i < listenersCache.length; i++)
{
final RepaginationListener l = (RepaginationListener) listenersCache[i];
l.repaginationUpdate(state);
}
}
/**
* Checks, whether the current thread is interrupted.
*
* @throws org.jfree.report.ReportInterruptedException if the thread is interrupted to
* abort the report processing.
*/
protected void checkInterrupted () throws ReportInterruptedException
{
if (isHandleInterruptedState() && Thread.interrupted())
{
throw new ReportInterruptedException("Current thread is interrupted. Returning.");
}
}
/**
* Returns whether the processor should check the threads interrupted state.
* If this is set to true and the thread was interrupted, then the report processing
* is aborted.
*
* @return true, if the processor should check the current thread state, false otherwise.
*/
public boolean isHandleInterruptedState()
{
return handleInterruptedState;
}
/**
* Defines, whether the processor should check the threads interrupted state.
* If this is set to true and the thread was interrupted, then the report processing
* is aborted.
*
* @param handleInterruptedState true, if the processor should check the current thread state,
* false otherwise.
*/
public void setHandleInterruptedState(final boolean handleInterruptedState)
{
this.handleInterruptedState = handleInterruptedState;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -