Interface ViewerContext
- All Known Implementing Classes:
SwingViewerContext
You can set the ViewerContext to be used by the viewer in SwingReportViewer.setViewerContext(ViewerContext)
.
For example, if you'd like to implement your own behavior in the case of an error, or would like to
catch certain errors, simply write your own ViewerContext and set the Viewer to use your
ViewerContext instead of the default one. The easiest way would simply be to extend
from SwingViewerContext, the default implementation of ViewerContext and to implement
only the methods you are interested in. For example:
SwingReportViewer viewer = new SwingReportViewer();
viewer.setViewerContext(new SwingViewerContext() {
public void showError(Throwable e, Object source) {
// Your error handling comes here...
}
});
Note that most often the source given for an error will be a ReportView, allowing you to make further adjustments
to your settings for that view.
For example, if an UnknownHostException comes for a ReportView,
you might want to make an adjustment to the ReportView's RenderData object, making it fall back
onto a backup report server instead of the original one:
class MyErrorHandler extends SwingViewerContext {
public void showError( Throwable e, Object source ) {
if (source instanceof ReportView && e.getCause() instanceof UnknownHostException) {
((ReportView)source).getReportData().setReportLocation( "http://www.backupserver.com:9000/?report=file:backupreport.rpt" );
((ReportView)source).reload();
}
}
}
- Since:
- 7.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionexport
(ReportView view) This method is called when the export action is to be performed.print
(ReportView view) This method is called when the print action is to be performed.void
This method will be called whenever an error occurs and thereby allows the implementor of this interface to handle the error as seen fit.void
Opens a HelpPage with a key in a window that corresponds to the component.void
showInfo()
Shows the info screen of this viewer.boolean
showPrompts
(PromptData[] prompts, RenderData renderData) Handles a prompt request from the server.void
showStatusMessage
(ReportView view, String message, boolean isError) Handled when a status message is to be displayed.void
showUrl
(String url, Properties props) Handles opening a URL, e.g. a click on a hyperlink.
-
Method Details
-
showInfo
void showInfo()Shows the info screen of this viewer.- Since:
- 7.0
-
showError
This method will be called whenever an error occurs and thereby allows the implementor of this interface to handle the error as seen fit.- Parameters:
e
- The Throwable of the error that actually occurred.source
- The source where the exception occurred, such as the SwingReportView or SwingPageView.- Since:
- 7.0
-
showStatusMessage
Handled when a status message is to be displayed. Normally the implementor will display this message in the status bar.- Parameters:
view
- the ReportView which is to display the status message, must not be nullmessage
- the message to be displayedisError
- true if the message is an error message, false otherwise.- Since:
- 8.1
-
print
This method is called when the print action is to be performed. By default, this will show a print dialog and then print the given report view's report.- Parameters:
view
- ReportView whose report is to be printed.- Returns:
- the progress
- Since:
- 7.1
-
export
This method is called when the export action is to be performed. By default, this will show the export dialog and then export the currently visible report view's report with the settings given by the user.- Parameters:
view
- ReportView whose report is to be exported- Returns:
- the progress
- Since:
- 7.1
-
showUrl
Handles opening a URL, e.g. a click on a hyperlink. Actually opening the link should run asynchronously, so it won't block the control flow.- Parameters:
url
- String of the hyperlink URL which is to be shown. The length need to be > 0.props
- Extra optional Properties for the URL connection (can be null for no extra properties)- Throws:
MalformedURLException
- The supplied URL String is invalid.- Since:
- 9.0
-
showPrompts
Handles a prompt request from the server. The chosen value of the prompts in the array must be set in the PromptData objects usingPromptData.setChosenValues(Object)
.- Parameters:
prompts
- list of required promptsrenderData
- RenderData of the report requiring prompts- Returns:
- true if prompts were successfully set, false if the prompt dialog was canceled
- Since:
- 9.2
-
showHelp
Opens a HelpPage with a key in a window that corresponds to the component.- Parameters:
helpPageKey
- key of the page to opencomp
- component to use when opening the window- Since:
- 15.0
-