6.4. Menu Page Listener

The menu page and URL publishing options provide a convenient deployment vehicle for reports and charts. Using these interfaces, users can easily deploy charts and reports to the Web without any coding. However, by themselves these interfaces do not provide any significant run-time customization capability. Report and chart templates are run in a pretty much as is format.

For users who would like to provide some additional logic, or run-time customization to reports and charts, ERES provides the Menu Page Listener interface which is part of the ERES extension package. Using this method, users can implement listeners that will intercept the report or chart prior to export, and use the APIs to modify it.

6.4.1. ERES Listener Manager

The ERES Listener Manager is a user-implemented class that is used to manage several listeners that monitor events on the server, including the Menu Page Listener. In order to implement the Menu Page Listener, users must implement the Listener Manager. Below is a sample Listener Manager class:

package extensionClasses;

import quadbase.reportorganizer.ext.*;

public class MyEresListenerManager extends DefaultListenerManager {

      public MyEresListenerManager() {}

      public EresSchedulerListener getSchedulerListener() {

            return new MyEresSchedulerListener(); 

      }

      public MenuPageListener getMenuPageListener() {

            return new MyMenuPageListener(); 

      } 

}
      

Users can impelement the ERESListenerManager interface or extend DefaultListenerManager. The above code implements two listeners, the Scheduler Listener and the Menu Page Listener. The Scheduler Listener takes effect when a schedule job executes. For more information about this interface, see Section 7.7.5.2 - ICallBackScheduler Interface

6.4.1.1. Deploying the Listener Manager

You can specify the Listener Manager class as a server option for ERES. You can set this in one of two places. The first option is the Admin Console. You can specify the class in the Server Options tab. For more information about server configuration options, see Section 1.4.1.3 - Server Options. You can also specify the class by modifying the QB.properties under <ERESInstallDir>/WEB-INF/classes. However, editing configuration files directly is not recommended and should be done only in case when the ERES server cannot be started because incorrect values have been provided through the Admin Console.

6.4.2. Using the Menu Page Listener

The following code shows a sample implementation of the Menu Page Listener:

package extensionClasses;

import java.lang.*;
import java.awt.*;
import quadbase.reportorganizer.ext.*;
import quadbase.reportdesigner.ReportAPI.*;
import quadbase.reportdesigner.ReportElements.*;
import quadbase.reportdesigner.util.*;
import quadbase.ChartAPI.*;
import quadbase.reportdesigner.report.Formula;

public class MyMenuPageListener implements MenuPageListener {

      public QbReport modifyBeforeRun(QbReport report, String username) {

            System.out.println("Calling Menu Page Listener...");

            try {

                  // Create a new label to show user that is running the report
                  ReportCell userLabel = new ReportCell();
                  userLabel.setText("Report Run By: " + username);
                  userLabel.setFont(new Font("Arial", Font.PLAIN, 8));
                  userLabel.setAlign(IAlignConstants.ALIGN_RIGHT);
                  userLabel.setHeight(0.2);
                  userLabel.setWidth(1.6);
                  userLabel.setY(0);
                  userLabel.setX(5.90);

                  // Create a new formula to show the report run date/time
                  ReportCell runDate = new ReportCell();
                  Formula runDateFormula = new Formula("ReportRunDate", "\"Report Run Date: \" + printDateTime(getCurrentDateTime(), \"MMM dd, yyyy h:mm a\")");
                  report.addFormula(runDateFormula);
                  runDate.setFormulaObj(runDateFormula);
                  runDate.setFont(new Font("Arial", Font.PLAIN, 8));
                  runDate.setAlign(IAlignConstants.ALIGN_RIGHT);
                  runDate.setHeight(0.2);
                  runDate.setWidth(2.5);
                  runDate.setY(0.2);
                  runDate.setX(5.0);

                  // Add new cells to page header section
                  report.getPageHeader().addData(userLabel);
                  report.getPageHeader().addData(runDate);

                  // Adjust section height if necessary
                  if (report.getPageHeader().getHeight() < 0.4)
                        report.getPageHeader().setHeight(0.4); 

            } catch (Exception ex) {

                  ex.printStackTrace(); 

            }

            return report; 

      }

      public QbChart modifyBeforeRun(QbChart chart, String username) {

            System.out.println("Calling Menu Page Listener");

            try {

                  // Define an array of chart colors
                  Color gold = new Color(227,215,130);
                  Color salmon = new Color(199,85,90);
                  Color burgandy = new Color(125,18,66);
                  Color slate = new Color(81,119,156);
                  Color teal = new Color(130,203,217);
                  Color blue = new Color(26,42,103);
                  Color beige = new Color(188,204,177);
                  Color[] chartColors = {gold, salmon, burgandy, slate, teal, blue, beige};

                  // Apply new colors to the chart
                  chart.gethDataPoints().setColors(chartColors); 

            } catch (Exception ex) {

                  ex.printStackTrace(); 

            }

            return chart; 

      } 

}
      

This example implements to modifyBeforeRun methods, one for charts and one for reports. With this code deployed, every time a report is run, the username, and the run time is added to the report header. Every time a chart is run, the chart colors are modified to use the palette defined in the method. Note that this is only one example. Any report/chart API code can be used in these interfaces to modify the reports and charts prior to export. For more information about the Report API, see Section 7.1 - ERES Report API.