/*
 * BIPresentationFilter.java
 *
 * Copyright (c) 2003, Oracle Corporation. 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.
 */
package samples.javaclient.analyzer;

import javax.naming.directory.Attributes;
import javax.naming.directory.SearchControls;

import javax.swing.Icon;

import oracle.dss.bicontext.BIFilter;
import oracle.dss.bicontext.BISearchControls;
import oracle.dss.bicontext.BISearchResult;
import oracle.dss.persistence.gui.PersistenceObjectFilter;
import oracle.dss.util.persistence.PersistableConstants;

/**
 * Filter used for displaying only presentations (Crosstabs and Graphs) 
 * and folders in the PersistenceObjectChooser (Open or Save As dialog) or in the 
 * {@link CatalogExplorer}.
 * <p>
 * This class implements two interfaces:
 * <ul><li>
 * As a BIFilter, a BIPresentationFilter allows the CatalogExplorer to filter
 * search results and display only graphs, crosstabs, and folders.
 * The BIPresentationFilter is set on the CatalogExplorer in 
 * the {@link Analyzer#jbInit} method.</li>
 * <li>
 * As a PersistenceObjectFilter, a BIPresentationFilter allows a 
 * PersistenceObjectChooser to display only graphs, crosstabs, and folders
 * in an Open or Save As dialog.
 * The {@link AnalyzerUtilities#showOpenDialog} method and the 
 * {@link AnalyzerUtilities#showSaveAsDialog} method set the 
 * BIPresentationFilter on the PersistenceObjectChooser.</li></ul>
 */
public class BIPresentationFilter implements BIFilter, PersistenceObjectFilter  {
  /**
   * String to display in the Object Type drop-down of the PersistenceObjectChooser:
   * "Presentations".
   */
  private static final String PRESENTATIONS = "Presentations";

  /**
   * Constructor.
   */
  public BIPresentationFilter() {
  }

  /**
   * Indicates whether to include a result in the enumeration of 
   * search results.
   * This method filters out all search results except those that are 
   * Graphs, Crosstabs, or Folders.
   * <p>
   * This is for the BIFilter interface.
   * 
   * @param The result to evaluate.
   * 
   * @return <code>true</code> if the result has the object type of 
   *          oracle.dss.util.persistence.PersistableConstants.FOLDER,
   *          oracle.dss.util.persistence.PersistableConstants.GRAPH, or
   *          oracle.dss.util.persistence.PersistableConstants.CROSSTAB,
   *          <code>false</code> if the object type is anything else.
   */
  public boolean evaluate(BISearchResult result) {
    if (result.getObjectType().equals(PersistableConstants.FOLDER) ||
      result.getObjectType().equals(PersistableConstants.GRAPH) ||
      result.getObjectType().equals(PersistableConstants.CROSSTAB))
      return true;
    else
      return false;   
  }

  /**
   * Gets the text to display in the Object Type drop-down of the
   * PersistenceObjectChooser.
   * <p>
   * This is for the PersistenceObjectFilter interface.
   * 
   * @return {@link #PRESENTATIONS}.
   */
  public String getDisplayText() {
    return PRESENTATIONS;
  }

  /**
   * Null implementation for the PersistenceObjectFilter interface.
   * @return null.
   */
  public Icon getDisplayIcon() {
    return null;
  }

  /**
   * Null implementation of hidden method in PersistenceObjectChooser interface.
   * @return null.
   */
  public String getFilterExpression() {
    return null;
  }

  /**
   * Null implementation for the PersistenceObjectFilter interface.
   * @return null.
   */
  public Attributes getMatchingAttributes() {
    return null;
  }

  /**
   * Gets the SearchControls that defines the search filter.
   * This method instantiates a BISearchControls object and then
   * sets a new BIPresentationFilter on it.
   * <p>
   * This is for the PersistenceObjectFilter interface.
   * 
   * @return A SearchControls with a BIPresentationFilter set on it.
   */
  public SearchControls getSearchControls() {
      BISearchControls biControl = new BISearchControls();
      biControl.setResultFilter(new BIPresentationFilter());
      return biControl;
  }
  
}