Interface ViewerContext

All Known Implementing Classes:
SwingViewerContext

public interface ViewerContext
The ViewerContext interface is used for reacting to and handling events occurring in the Viewer which usually would require showing a dialog or some action. The default ViewerContext, SwingViewerContext, for example, takes all errors and displays them in a small error dialog, and shows a simple info dialog when one is requested.

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 Type
    Method
    Description
    This method is called when the export action is to be performed.
    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
    showHelp(String helpPageKey, Component comp)
    Opens a HelpPage with a key in a window that corresponds to the component.
    void
    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

      void showError(Throwable e, Object source)
      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

      void showStatusMessage(ReportView view, String message, boolean isError)
      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 null
      message - the message to be displayed
      isError - true if the message is an error message, false otherwise.
      Since:
      8.1
    • print

      Progress print(ReportView view)
      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

      ExportProgress export(ReportView view)
      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

      void showUrl(String url, Properties props) throws MalformedURLException
      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

      boolean showPrompts(PromptData[] prompts, RenderData renderData)
      Handles a prompt request from the server. The chosen value of the prompts in the array must be set in the PromptData objects using PromptData.setChosenValues(Object).
      Parameters:
      prompts - list of required prompts
      renderData - RenderData of the report requiring prompts
      Returns:
      true if prompts were successfully set, false if the prompt dialog was canceled
      Since:
      9.2
    • showHelp

      void showHelp(String helpPageKey, Component comp)
      Opens a HelpPage with a key in a window that corresponds to the component.
      Parameters:
      helpPageKey - key of the page to open
      comp - component to use when opening the window
      Since:
      15.0