In order to use the CalcBuilder, you must add it to an application and run the application. During design, you can run an application to create calculations that you save in the BI Beans Catalog. At runtime, you can allow users to create a new calculation or to edit an existing one.
Prepare an application for a CalcBuilder by creating the required objects for the communication and management of data.
Create a CalcBuilder
object and specify its parent component.
Set the MetadataManager
property of the CalcBuilder
object to specify the object that will manage its connections to data
stores and allow retrieval of metadata.
Set the QueryContext
property of the CalcBuilder
object, which allows the CalcBuilder to
evaluate queries to retrieve data such as dimension members.
If you want to set up the CalcBuilder to edit a previously created
calculation, then specify tabbed mode for the Mode
property and invoke
the setBuilderContent
method to specify the CalcStep
object that defines the previously created calculation. Otherwise, the
CalcBuilder creates a new CalcStep
object based on the type
of calculation that a user chooses.
CalcBuilderStepStorage
object instead of the CalcBuilder
object.
See the "Creating Calculations" sample in the BICalc.java
file
for additional information on how to create, save, and edit calculations.
The code in this example assumes that the following variables exist:
metadataManager
-- The MetadataManager
object
that the CalcBuilder uses to retrieve connection and metadata information.
queryContext
-- The QueryContext
object
that the CalcBuilder accesses to evaluate the queries that are
necessary to retrieve data such as dimension members.
componentParent
-- The top-level dialog box
or frame that serves as the parent for the CalcBuilder. By specifying
the top-level dialog or a frame in the constructor for the CalcBuilder,
you ensure that the focus for the CalcBuilder and its associated dialogs
is maintained properly.
Tip: When you use the constructor in this manner, you can also specify an icon for the top-level dialog or a frame that is propagated to the CalcBuilder's panels and associated dialogs. The following sample line of code shows how to set this icon.
componentParent.setIconImage (java.awt.Toolkit.getDefaultToolkit().createImage("myicon.gif"));
The following code sets up a CalcBuilder in wizard mode, which is the default:
/** * Demonstrate the minimal code needed to run the CalcBuilder. * * @param componentParent The Component object that represents * the parent of the CalcBuilder. * @param metadataManager The MetadataManager object that is used to retrieve metadata. * @param queryContext The QueryContext object that is used for evaluation. * * @throws CalcBuilderException if the CalcBuilder cannot be run. */ public void runCalcBuilder (Component componentParent, MetadataManager metadataManager, QueryContext queryContext) throws CalcBuilderException { // Initialize the CalcBuilder CalcBuilder calcBuilder = null; // Check whether the parent is a frame if (componentParent instanceof Frame) { calcBuilder = new CalcBuilder ((Frame)componentParent); } // Check whether the parent is a dialog else if (componentParent instanceof Dialog) { calcBuilder = new CalcBuilder ((Dialog)componentParent); } else { // Default to no parent calcBuilder = new CalcBuilder ((Frame)null); } // Specify the MetadataManager that the CalcBuilder // uses to retrieve metadata. calcBuilder.setMetadataManager (metadataManager); // Specify the QueryContext to use for evaluation calcBuilder.setQueryContext (queryContext); // Run the CalcBuilder boolean bSuccess = calcBuilder.run(); }
Applying a Calculation to a Query
Defining and Referencing Calculations