3. Customizing BI Objects

Exercise Objectives

The goal of this exercise is to give you an understanding of how to add and use BI Beans customizers (for graph title and QueryBuilder) to modify the presentation that is displayed in this application.

Exercise Description

You will insert the logic that is required to add the graph title customizer to the application. This tool enables an end user to change the title text and title text properties for a graph. The next step will be to add a customized QueryBuilder to the application. The QueryBuilder enables an end user to change the data that is displayed in a presentation. The QueryBuilder has properties that enable different types of selection functionality to be displayed or hidden for the end user.

Exercise Tasks

Adding a graph title customizer to the application

In this section, you will add a graph title customizer, which enables the user to interact and change the title properties of a graph. This tool will be invoked from a menu item.

First, you will add the menu item and the code to support the menu item. The code will make the appropriate calls to a Panel Dialog class that will be added in the next section. Note: The dialog is called only if the current view is a Graph. More code would be required to make the Title customizer work for a Crosstab. This can be achieved very easily, but is outside the scope of the current tutorial.

To add the graph title customizer menu item:
  1. In the System-Navigator pane, right-click BIApplication1.java and choose UI Editor from the popup menu.
  2. If the Structure pane is not open, then press Ctrl+Shift+S to open it. In the Structure pane, expand Menu and then select m_menubar. Notice that the UI Editor is refreshed to allow menu editing.
  3. In the UI Editor, select Tools. Notice that the menu items appear.
  4. Right-click Change View... and choose Insert Menu item to insert a menu item between Insert Calculation... and Change View....
  5. In the Property Inspector, enter Title Customizer... as the value for the actionCommand property and the text property. Enter m_mnuTitle as the value for the name property. Notice that the new menu item label(text) has changed to Title Customizer....
  6. From the File menu, choose Save to save your work.

To add custom code for the graph title customizer:

  1. In the System-Navigator pane, right-click BIApplication1.java and choose Code Editor from the popup menu.
  2. In the Code Editor, search for the line of code import oracle.bali.ewt.dialog.JEWTDialog; and then copy and paste the following code right below it. These classes, added to the declaration section, are used by the Dialog class, which will be added shortly.

    // Title class that is used by Graph Title Customizer and Dialog Class
    import oracle.dss.graph.gui.Title;
    import javax.swing.border.EmptyBorder;
    import javax.swing.border.Border;
    import javax.swing.JButton;
    import javax.swing.JComponent;
    import javax.swing.BoxLayout;
    import javax.swing.KeyStroke;
    import java.awt.event.KeyEvent;

    import oracle.bali.ewt.button.DialogButtonBar;
    import oracle.bali.ewt.border.GrayPane
    ;
    import oracle.bali.ewt.util.WindowUtils;
    import oracle.dss.graph.gui.BasePanel;

  3. Search for the following line of code:

    private QueryManager getQueryManager() throws Throwable

    and postion the cursor above this line.
  4. Read the following code thoroughly. It adds the title panel and the title dialog class. It also specifies the relevant fields and buttons that the user will interact with to change the title properties. Then, copy and paste this code into the Code Editor at the cursor location that was specified in the previous step:

    // Title Panel Declaration
    private Title m_titlePanel;

    // inner class to display Title formatting Customizer panels in a Dialog
    class PanelDialog extends JDialog implements ActionListener
    {
      // start of constructor
      public PanelDialog(Frame parentFrame, String title, JPanel panel)
      {
        super(parentFrame);
        setTitle(title);
        setModal(true);
        this.panel = panel;
        JComponent content = (JComponent) getContentPane();
        content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
        content.setBorder(_sBorder);
        content.setBackground(UIManager.getColor(oracle.bali.ewt.olaf.ColorScheme.DARK_LOOK));
        GrayPane gp = new GrayPane(this.panel);
        content.add(gp);
        DialogButtonBar buttonPanel = new DialogButtonBar();
        buttonPanel.setBorder(_sBorderButtons);
        JPanel buttonPanel_east = new JPanel();
        // creating and adding apply button
        applyButton = new JButton("Apply");
        buttonPanel.add(applyButton, DialogButtonBar.CONSTRAINT_NULL);
        applyButton.addActionListener(this);
        getRootPane().setDefaultButton(applyButton);
        // creating and adding cancel button
        cancelButton = new JButton("Cancel");
        buttonPanel.add(cancelButton, DialogButtonBar.CONSTRAINT_FINISH);
        cancelButton.addActionListener(this);
        cancelButton.registerKeyboardAction(this,
        KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
        JComponent.WHEN_IN_FOCUSED_WINDOW);
        getContentPane().add(buttonPanel);
        setResizable(false);
        pack();
      }

      // end of constructor

      /**
      * implementing action listener
      *
      * @param e instance of ActionEvent
      */

      public void actionPerformed(ActionEvent e)
      {
        // if cancel button is pressed, then do nothing and close the dialog
        if(e.getSource() == cancelButton) {
          setVisible(false);
          dispose();
          getParent().repaint();
        }
        // if apply button is pressed, then apply the changes to the graph and close the dialog
        else if(e.getSource() == applyButton) {
          if(panel instanceof BasePanel) {
            ((BasePanel)panel).apply();
          }
          setVisible(false);
          dispose();
        }
      }

      // data member
      private JButton applyButton;
      private JButton cancelButton;
      private JPanel panel;

      //   The extra room around the border
      private Border _sBorder = new EmptyBorder(6, 6, 8, 5);
      private Border _sBorderButtons = new EmptyBorder(8, 10, 0, 10);
    }

  5. From the File menu, choose Save.
  6. Right-click BIApplication1.java and choose Make from the popup menu to compile the code. The debug window at the bottom of the JDeveloper screen should indicate "Successful compilation: 0 errors, 0 warnings".

To add an Action Listener for the graph title customizer menu item:

  1. In the System-Navigator pane, right-click BIApplication1.java and choose UI Editor from the popup menu.
  2. If the Structure pane is not open, then press Ctrl+Shift+S to open it. In the Structure pane, expand Menu and then select m_menubar. Notice that the UI Editor is refreshed to allow menu editing.
  3. In the UI Editor, select Tools and select Title Customizer....
  4. In the Property Inspector, select the Events tab at the bottom of the inspector.
  5. Choose the "..." button at the right of the ActionPerformed value.
  6. Enter m_mnuTitle_ActionPerformed as the name and choose OK.
  7. In the open Code Editor, enter the following line as the body of the m_mnuTitle_actionPerformed method:

    if (m_activeView instanceof Graph)
    {

      if (m_titlePanel == null) {
        m_titlePanel = new Title((Graph)m_activeView);
      }
      else {
        m_titlePanel.setGraph((Graph)m_activeView);
      }
      PanelDialog panelDialog = new PanelDialog( WindowUtils.parentFrame(this), "Graph Title   Customizer", m_titlePanel );
      panelDialog.show();
    }

    If the view is a graph, then this code opens a Title Panel for the view to allow the user to change titles (through the code that you added earlier).

  8. From the File menu, choose Save to save your work.

To run the application:

  1. Right-click BIApplication1.Java and choose Run BIApplication1.Java from the popup menu to run the application.
  2. To open the variance report in the application, from the Tools menu, choose View Special Reports then Asian Sales Variance.
  3. From the Tools menu, choose Title Customizer.
  4. Use the Customizer to define the graph Title and Subtitle as follows:
    Title: Sales Variance Report
    Subtitle: Retail Sales Variance for Top 5 Countries based on Sales in Asia
  5. Choose Apply and exit the customizer.
  6. From the File menu, choose Save to store the definition for the Graph presentation.
  7. From the File menu, choose Exit to leave the application.

Customizing the QueryBuilder

This section shows how to specify the QueryBuilder capabilities that will be available for the end user of your application. You will insert additional code in the mnuQB_ActionPerformed method to enable this customization.

The code that you insert modifies the appearance of the QueryBuilder dialog in the folllowing way:

These are a few examples of the customization that can be applied to the QueryBuilder. The rich API of the QueryBuilder makes its functionality available in a variety of ways that enable its use by both power users and casual users in an organization.

To modify the QueryBuilder object:

  1. From the Search menu, choose Find and enter the following code as the text to search for:

    void mnuQB_ActionPerformed(ActionEvent event)

    to locate this line in the Code Editor.
  2. In the mnuQB_ActionPerformed method, search for the following line of code:

    QueryBuilder queryBuilder = new QueryBuilder(getFrame());

    and position the cursor after that line.
  3. Read the following code thoroughly. Then, copy and paste the code into the Code Editor at the location that was specified in the previous step:

    // Choose the main panels
    queryBuilder.setVisiblePanels (QueryBuilder.ITEMS | QueryBuilder.DIMENSIONS | QueryBuilder.LAYOUT);

    // Choose the tabs on the DimensionPanel
    queryBuilder.setVisibleDimensionPanels (QueryBuilder.MEMBERS | QueryBuilder.STEPS | QueryBuilder.PREVIEW);
    // Disallow apply
    queryBuilder.setApplyAllowed(false);
    // Allow the user to switch between dimensions on the DimensionPanel
    queryBuilder.setDimensionVisible(true);
    // Disable changing the hierarchy from the DimensionPanel
    queryBuilder.setHierarchyVisible(false);

  4. Right-click BIApplication1.java and choose Make from the popup menu to compile the code. The debug window at the bottom of the JDeveloper screen should indicate "Successful compilation: 0 errors, 0 warnings".
  5. From the File menu, choose Save to save your project.

To run the application:

  1. To run the application, right-click BIApplication1.java and choose Run BIApplication1.java from the popup menu.
  2. From the Tools menu, choose Edit Query. The capabilities that are available in the QueryBuilder have been reduced. Notice that the Hidden Dimension tab is now invisible. The Apply button is also hidden.
  3. Select the Dimension tab to view the customizations on that tab. Notice that the hierarchy drop-down list is hidden and the Conditions and Favorites tabs are also removed.
  4. Choose Cancel to exit the Query Builder.
  5. From the File menu, choose Exit to close the application and return to JDeveloper.

To learn more about the API and customization options, refer to the BI Beans javadoc.

Exercise Summary

In this exercise, you learned how to add a graph title customizer that is used to edit the title text and to specify title properties. You also learned about QueryBuilder customization options that modify the capabilities available to an end user.

2. Working with Presentations | Overview | 4. Linking Presentations