8.6. Organizer

8.6.1. Introduction

ERES Organizer can also be called, using the API, with custom choices instead of the default options provided. ERES Organizer can be customized by using the API, both in terms of look and feel and function. Report and Chart Designer, called from the Organizer, can also be customized via the API.

Both ERESOrganizer.jar (located in the ERES/lib directory) and ERESServer.jar (located in the ERES/WEB-INF/lib directory) need to be added to the CLASSPATH for any code using ERES Organizer. The following snippet shows how to connect to ERES Organizer:

QbOrganizer.setServletRunner("http://localhost:8080");
QbOrganizer.setServletContext("ERES/servlet");
QbOrganizer organizer = new QbOrganizer(null, "admin", "admin");
      

The above code sets the connection information to connect to ERES Server and provides the username and password (in the above example, admin and admin) for ERES Organizer.

ERES Organizer can then be shown by getting a handle to the Organizer user interface and setting it visible.

JFrame frame = organizer.getOrganizerUI();
frame.setVisible(true);
      
[Note]Note

You need to copy the contents of the images, orgimages, reportimages, and backgroundImages directories to the working directory of the .class file.

All examples and code given in the manual assume that ERES server is running locally (i.e. on your local machine) and on port 8080. You can change this by going to the source code (you can download the source code by clicking on the Full Source Code link in the corresponding chapter), editing the code to enter the new connection information and recompiling the code.

Also, note that if you have applets that use ERES Report API, the browser must have at least a 1.5 JVM plug in.

8.6.2. Look and Feel

You can specify a look and feel to ERES Organizer before getting a handle to the user interface. By default, ERES Organizer uses the system's look and feel. The look and feel can be set using the following method in QbOrganizer:

public static void setLookAndFeel(javax.swing.LookAndFeel newLookAndFeel);
      

8.6.3. Inserting and Removing Items

You do not have to show ERES Organizer in order to insert and remove items. You can add and delete items from Organizer via the API.

You would use the following method to add an item to the Organizer:

public void insertNewItem(String name, String description, String location, String url, String folderName);
      

For example:

organizer.insertNewItem("Orders_Breakdown", 
	"This is an example report added to Organizer", 
	"OrdersBreakdown.qrp", 
	"http://localhost:8080/ERES/OrdersBreakdown.qrp",
	"/New Project");
      

Full Source Code

Result Screenshot

The above code inserts a new item called Account_Report in the Organizer under the /ReportFiles project folder. The URL and physical location of the file is also passed along with a short description. Please note that to run the above code successfully, you will need to create a project called ReportFiles in Organizer. The recommended way to run the above code is to compile it, then go to the root ERES directory and enter the following command:

java -classpath "../../src/er/bin;./lib/ERESOrganizer.jar;./lib/WEB-INF/ERESServer.jar;./lib/qblicense.jar;./lib/hsqldb.jar;<PATH_TO_COMPILED_CLASS_FILE>" InsertingItem
      

You can also remove items from the Organizer using the following method:

public void removeItem(String name, String folderName);
      

For example:

organizer.removeItem("Orders_Breakdown", "/New Project");
      

Full Source Code

Result Screenshot

The above code deletes Account_Report from the /ReportFiles project folder in ERES Organizer. The recommended way to run the above code is to compile the source code, then go to the root ERES directory and enter the following command:

java -classpath "../../src/er/bin;./lib/ERESOrganizer.jar;./lib/WEB-INF/ERESServer.jar;./lib/qblicense.jar;./lib/hsqldb.jar;<PATH_TO_COMPILED_CLASS_FILE>" RemovingItem
      

8.6.4. Customizing Report and Chart Designer

You can also customize the properties of Report Designer and Chart Designer invoked from the custom Organizer. You can add or remove items from the menu bars and also override the Save function. Please note that when the Save function is overridden, any files saved with a relative path are not relative to the ERES root directory but relative to the working directory of the .class file.

The following example, which can be run as a Java Web Start Application, shows a custom Organizer whose Report Designer's and Chart Designer's Save function are overriden:

QbOrganizer.setServletRunner("http://localhost:8080");
QbOrganizer.setServletContext("ERES/servlet");
QbOrganizer organizer = new QbOrganizer(null, "admin", "admin");

// modify organizer's reportdesigner
organizer.setReportDesignerHandle(new ReportDesignerHandle());

// modify organizer's chartdesigner
organizer.setChartDesignerHandle(new ChartDesignerHandle());

// set organizer visible
JFrame frame = organizer.getOrganizerUI();
frame.setVisible(true);

public static class ReportDesignerHandle implements IReportHandle {

      public ReportDesignerHandle() {};

      public void processDesigner(QbReportDesigner designer) {

            System.out.println("PROCESS REPORT....");

            // modify warning message before inserting drill-down layer
            designer.modifyWarningMessage(designer.SAVE_RPT_BEFORE_DRILLDOWN, "The report designer will save the current report for you, continue?");

            // modify warning message before inserting subreport
            designer.modifyWarningMessage(designer.SAVE_RPT_BEFORE_SUBREPORT, "The report designer will save the current report for you, continue?");

            // customize report IO
            designer.setReportIO(new ReportIO(designer));

            // by pass SAVE AS IO
            designer.setByPassSaveAsIO(new ByPassSaveAsForReport());

            // modify reportdesigner's chartdesigner
            designer.setChartDesignerHandle(new ChartDesignerHandle());

            // remove "SAVE AS" option for Report Designer
            JMenu fileMenu = designer.getReportMenuBar().getMenu(0);
            fileMenu.remove(6);

      }

}

public static class ReportIO implements IReportNavigationIO {

      String fileName = null;
      QbReportDesigner designer = null;

      public ReportIO(QbReportDesigner designer) { this.designer = designer; }

      public void saveFile(byte[] data, String fileName) {

            System.out.println("SAVE REPORT FILE - " + fileName);
            try {

                  FileOutputStream fout = new FileOutputStream(fileName);
                  fout.write(data, 0, data.length);
                  fout.close();

            } catch (Exception ex) {

                  ex.printStackTrace();

            }

            this.fileName = fileName;

      }

      // if parent report is saved, return saved report file location
      // else return null;
      public String isParentReportSaved() {

            System.out.println("IS PARENT REPORT SAVED = NO...");
            return null;

      }

      // overridden save parent report method and return parent report location
      public String saveParentReport() {

            System.out.println("RETURN PARENT REPORT LOCATION");
            return fileName;

      }

}

public static class ByPassSaveAsForReport implements IByPassSaveAsForReport {

      public ByPassSaveAsForReport() {};

      public String getFileName(String originalFileName) {

            System.out.println("BY PASS REPORT SAVE AS OPTION...");
            if (originalFileName == null) return "TEMP_REPORT_FILE.rpt";
            else return originalFileName;

      }

      public Properties getSaveAsProperties(String originalFileName) {

            return new Properties();

      }

}

public static class ChartDesignerHandle implements IChartHandle {

      public ChartDesignerHandle() {};

      public void processDesigner(QbChartDesigner designer) {

            System.out.println("PROCESS CHART....");

            // remove "SAVE AS" option for Chart Designer
            JMenu fileMenu = designer.getChartMenuBar().getMenu(0);
            fileMenu.remove(6);

            designer.setChartIO(new ChartIO());
            designer.setByPassSaveAsIO(new ByPassSaveAsForChart());

      }

}

public static class ChartIO implements IChartIO {

      public ChartIO() {};

      public String saveChartFile(byte[] data, String fileName) {

            System.out.println("SAVE CHART FILE - " + fileName);
            try {

                  FileOutputStream fout = new FileOutputStream(fileName);
                  fout.write(data, 0, data.length);
                  fout.close();

            } catch (Exception ex) {

                  ex.printStackTrace();

            }

            return fileName;

      }

}

public static class ByPassSaveAsForChart implements IByPassSaveAsForChart {

      public ByPassSaveAsForChart() {};

      public String getFileName(String originalFileName) {

            System.out.println("BY PASS CHART SAVE AS OPTION...");
            if (originalFileName == null) return "TEMP_CHART_FILE.cht";
            else return originalFileName;

      }

      public Properties getSaveAsProperties(String originalFileName) {

            return new Properties();

      }

}
      

Full Source Code

The recommended way to run the above code is to compile the source code, then go to the root ERES directory and enter the following command:

java -classpath "../../src/er/bin;./lib/ERESOrganizer.jar;./lib/WEB-INF/ERESServer.jar;./lib/qblicense.jar;./lib/hsqldb.jar;<PATH_TO_COMPILED_CLASS_FILE>" CustomOrganizer
      

8.6.5. Calling Scheduler

You can also get a handle to ERES Scheduler using the following method:

Scheduler scheduler = organizer.getScheduler();
      

You can add schedules to and remove schedules from the Scheduler via the API. For more on this, please refer to Section 8.7 - Scheduler.

8.6.6. Javadoc

Javadoc for the entire API is provided along with ERES. It is located here (Reports and charts) and here (ES functions).

8.6.7. Summary

ERES API provides an easy-to-use and powerful API to customize and show Organizer interface as well as customize Report Designer and Chart Designer interfaces. You can also write code to insert and delete items in Organizer.

Please note that the API requires a JDK 1.8 or above. The ERES API has been tested on Windows, Solaris, Linux, AIX, HP, and Mac platforms.