<!--
 * BIDrillOutHome.jsp
 *
 * Copyright © 1994-2004, Oracle. All rights reserved. Oracle grants
 * you ("Licensee") a non-exclusive, royalty-free, worldwide license to use,
 * modify and redistribute this software in source and binary code form, provided
 * that (i) this copyright notice and license appear on all copies of the
 * software; (ii) Licensee does not utilize the software in a manner disparaging
 * to Oracle; and (iii) Licensee does not utilize the software in a manner that
 * violates the terms of any Licensee agreement with Oracle.
 -->
<%@ taglib uri="http://xmlns.oracle.com/bibeans/jsp" prefix="orabi" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ page errorPage="cabo/bi/jsp/error.jsp" %>
<%@ page contentType="text/html;charset=windows-1252"%>

<%-- Import statements --%>
<%@ page import="java.util.Vector"%>

<%@ page import="oracle.dss.dataView.managers.RuleManager"%>
<%@ page import="oracle.dss.dataView.managers.ViewStyle"%>
<%@ page import="oracle.dss.rules.DiscriminatorRule"%>
<%@ page import="oracle.dss.rules.RuleBundle"%>
<%@ page import="oracle.dss.rules.discriminator.QDRDiscriminator"%>
<%@ page import="oracle.dss.thin.beans.crosstab.ThinCrosstab"%>
<%@ page import="oracle.dss.thin.beans.dataView.Presentation"%>
<%@ page import="oracle.dss.thin.beans.gridView.ThinGridView"%>
<%@ page import="oracle.dss.thin.beans.gridView.DrillOutCallback"%>
<%@ page import="oracle.dss.util.DataAccess"%>
<%@ page import="oracle.dss.util.DataDirector"%>
<%@ page import="oracle.dss.util.MetadataMap"%>
<%@ page import="oracle.dss.util.QDR"%>

<%-- Constants --%>
<%! public static final String PRODUCT_ID = "MDM!D_CS_OLAP.SHAWPRODUCTS"; %> 
<%! public static final String GEOGRAPHY_ID = "MDM!D_CS_OLAP.SHAWGEOGRAPHIES"; %>
<%! public static final String GRAPH_POPUP_PAGE = "BIDrillOutGraphPopup.jsp"; %>
<%! public static final String RELATIONAL_POPUP_PAGE = "BIDrillOutRelationalPopup.jsp"; %>

<%-- Start synchronization of the BI tags --%>
<% synchronized(session){ %>
<orabi:BIThinSession id="BIThinSession1"  configuration="/catalogOLAPConfig1.xml" >
  <orabi:Presentation id="drillOutCrosstab"  location="SampleCatalog/Applications/Samples/Reports/JSPDrillout" />
  <orabi:Toolbar id="toolbar1"  presentationId="drillOutCrosstab" />
</orabi:BIThinSession>
<%   
    Object pres1 = pageContext.findAttribute("drillOutCrosstab");
    if (pres1 instanceof Presentation)
    {
      Presentation presentation1 = (Presentation)pres1;
      ThinCrosstab crosstab = (ThinCrosstab)presentation1.getView(); 
      crosstab.setGraphicImagePath(0, "drillOut/info.gif");
      crosstab.setGraphicImagePath(1, "drillOut/graph.gif");
      crosstab.setGraphicImagePath(2, "drillOut/detail.gif");

      // Set the image and tooltip for the row header drill out
      ViewStyle rowViewStyle = crosstab.getRowHeader().getViewStyle();
      rowViewStyle.setGraphicImageIndex(0);
      rowViewStyle.setGraphicImageTooltip("Search for Maps");

      // Set the image and tooltip for the data body drill out to a related Graph.
      // First, create a new ViewStyle
      ViewStyle dataViewStyle = new ViewStyle(); 
      dataViewStyle.setGraphicImageIndex(1);
      dataViewStyle.setGraphicImageTooltip("Show Related Graph");

      // Create the QDR (Qualifying Data Reference) to specify that 
      // the drill-out to Graph images should be displayed 
      // only for the 17" LCD Monitor column
      QDR qdr = new QDR();
      qdr.addDimMemberPair(PRODUCT_ID, "14");
      // Create a QDR Discriminator based on this QDR
      QDRDiscriminator qdrDisc = new QDRDiscriminator(qdr, QDRDiscriminator.SUPERSET);
      // Tell the RuleManager to use this rule when displaying the image in the Crosstab
      RuleManager ruleManager = (RuleManager)crosstab.getGridViewDatabodyStyleManager();
      Vector ruleBundles = new Vector();
      RuleBundle bundle = new RuleBundle();
      bundle.addRule(new DiscriminatorRule(qdrDisc, dataViewStyle));
      ruleBundles.addElement(bundle);

      // Set the image and tooltip for the data body drill out to relational data.
      // First, create a new ViewStyle
      dataViewStyle = new ViewStyle(); 
      dataViewStyle.setGraphicImageIndex(2);
      dataViewStyle.setGraphicImageTooltip("Drill to Relational Data");

      // Create the QDR (Qualifying Data Reference) to specify that 
      // the drill-out to relational detail images should be displayed 
      // only for the 18" LCD Monitor column
      qdr = new QDR();
      qdr.addDimMemberPair(PRODUCT_ID, "21");
      // Create a QDR Discriminator based on this QDR
      qdrDisc = new QDRDiscriminator(qdr, QDRDiscriminator.SUPERSET);
      // Tell the RuleManager to use this rule when displaying the image in the Crosstab
      bundle = new RuleBundle();
      bundle.addRule(new DiscriminatorRule(qdrDisc, dataViewStyle));
      ruleBundles.addElement(bundle);

      ruleManager.setBundles(crosstab, ruleBundles);
      
    
      crosstab.setDrillOutCallback(new DrillOutCallback() {
        // The following method constructs the drill-out URL 
        // for the icon displayed in the Crosstab row header
        public String getHeaderDrillOutURI(ThinGridView gridView, int edge, int layer, int slice)
        {
            String geographyLabel = "";
            
            // Get the header label from the DataAccess
            try
            {
                geographyLabel = (String)gridView.getModel().getDataAccess().getSliceLabel(edge, slice, MetadataMap.METADATA_LONGLABEL);
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
            // Construct a URL which will open a new window
            // with the results of a Google search "Map of <Geography>"
            return ("javascript: window.open(" +
                "'http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=map%20of%20" + geographyLabel + 
                "','','status=yes, width=500,height=500,scrollbars=yes,resizable=yes'); void('');"); 
            
        }

        // The following method constructs the drill-out URL 
        // for the icon displayed in the Crosstab cell
        public String getDataDrillOutURI(ThinGridView gridView, int row, int column)
        {
            String geography      = "";
            String product        = "";
            String geographyLabel = "";
            String productLabel   = "";
   
            String popupPage = GRAPH_POPUP_PAGE;
            
            try
            {
                // Get the current Product and Geography member from the cell QDR
                QDR qdr = gridView.getModel().getDataAccess().getValueQDR(row, column, DataAccess.QDR_WITH_PAGE);
                geography = (String)qdr.getDimMember(GEOGRAPHY_ID).getData();
                product = (String)qdr.getDimMember(PRODUCT_ID).getData();
                
                // Get the labels for the Product and Geography members, knowing the layout of the Crosstab
                geographyLabel = (String)gridView.getModel().getDataAccess().getMemberMetadata(DataDirector.ROW_EDGE, 0, row, MetadataMap.METADATA_LONGLABEL);
                productLabel = (String)gridView.getModel().getDataAccess().getMemberMetadata(DataDirector.COLUMN_EDGE, 1, column, MetadataMap.METADATA_LONGLABEL);
            
                // If the product is 17" LCD, show a Graph,
                // otherwise show relational detail
                popupPage = (product.equals("14"))? GRAPH_POPUP_PAGE : RELATIONAL_POPUP_PAGE;
                
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
            // Pass the Product and Geography members to the popup JSP page
            // which will display a Graph or relational data 
            // for the selected Product and Geography 
            return ("javascript: window.open('" +
            popupPage + "?GEOGRAPHY=" + geography + "&GEOGRAPHY_LABEL=" + geographyLabel + "&PRODUCT=" 
            + product + "&PRODUCT_LABEL=" + productLabel + 
            "','','status=yes, width=600,height=600,scrollbars=yes,resizable=yes'); void('');"); 
        }
    });
  }
%>

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>
      BI Beans Drill to Detail Sample
    </title>
  </head>

  <orabi:BIBody>
    <form name="BIForm" method="POST"  action="BIDrillOutHome.jsp" >
      <orabi:InitBITags parentForm="BIForm"/>
      <!-- Insert your Business Intelligence tags here -->
      <p>
        <orabi:Render targetId="drillOutCrosstab" parentForm="BIForm"/>
      </p>
      
      <!-- The InsertHiddenFields tag adds state fields to the parent form tag -->
      <orabi:InsertHiddenFields parentForm="BIForm"  biThinSessionId="BIThinSession1" />
    </form>
  </orabi:BIBody>
</html>
<% } %>
<!-- End synchronization of the BI tags -->
