Incorporating User-Interface Panels

In a Java-client Dataview, you can show user-interface panels in a dialog box, or you can use them in the pages of a wizard. You add the panel to the dialog or to the wizard page, then display the dialog or page.

The panel keeps track of the settings that the user chooses, but the settings do not immediately affect the Dataview. If you want to make an immediate change, you can listen for property change events, as described in Listening for Changes in User-Interface Panels.

To apply the settings that the user has chosen, call the apply method of the panel.

Example: Using a panel in a dialog box

The following code displays the Graph Type panel in a dialog box. This code assumes that you have a graph that is named myGraph and a graph toolbar that is named graphToolBar.


// Declare this outside all routines, so that panel is available to the entire class Frame frame = WindowUtils.parentFrame(myGraph); static GraphType panel = new GraphType(myGraph); JButton applyButton = new JButton("Apply"); // create a modal dialog named "Graph Type" JDialog dialog = new JDialog(frame, "Graph Type", true); // add the panel and the apply button to the dialog dialog.getContentPane().setLayout(new BorderLayout()); dialog.getContentPane().add("Center", panel); dialog.getContentPane().add("South", applyButton); // use preferred size dialog.pack(); // set a property change listener on the panel applyButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent event){ // apply the changes from the panel to myGraph panel.apply(); // make the dialog go away setVisible(false); dispose(); } // end actionPerformed }); // end addActionListener // tell the graph toolbar that something has changed graphToolBar.setDataView(myGraph); dialog.show();

Displaying the LayoutPanel

For each Dataview, the LayoutPanel, allows users to rearrange the data that the Dataview displays. Because the panel affects not only the view, but also the data that the view displays, the panel needs access to a special representation of the data. This representation is a LayoutContext. The BI Beans Query object implements the LayoutContext interface.

As users move items in the LayoutPanel, the panel makes changes to the LayoutContext. When you call the apply method of the LayoutPanel, it then applies the changes from the LayoutContext to the original data source for the Dataview.

When you instantiate a LayoutPanel, then, you must supply a LayoutContext to the panel, so that it has something to manipulate while users make changes.

The following code shows how to instantiate a LayoutPanel.


DataSource dataSource = crosstab.getDataSource(); if (dataSource instanceof LayoutContext){ LayoutContext layoutContext = (LayoutContext)dataSource; CrosstabLayout panel = new CrosstabLayout(); // set the crosstab on the panel panel.setPagingControlAttributes(crosstab); // if we were using a graph layout panel, // we would set the grapn on the panel as follows: // panel.setGraph(graph); if(panel.setLayoutContext(layoutContext)){ CrosstabDialog dialog = new CrosstabDialog(frame,panel); dialog.show(); } }

Performance tip: Reuse the panels

After you have instantiated a user-interface panel once, you can reuse the panel to modify a different instance of the same subclass of a Dataview. You do not need to reinstantiate the panel each time you need one. Reusing panels improves performance greatly.

For example, you might have a wizard for creating graphs and a separate wizard for editing graphs. You can use the same Graph Type panel in each wizard.

To reuse a graph panel, call its setGraph method to specify the graph that you want the panel to modify.

To reuse a table or crosstab panel, call the setGridView method of the panel to specify the table or crosstab that you want the panel to modify.