⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tablecomponent.java

📁 OLAP 的客户端代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

  private void buildCornerElement(Element parent, int colSpan, int rowSpan) {
    Element corner = cornerBuilder.build(colSpan, rowSpan);
    parent.appendChild(corner);
  }

  /**
   * <pre>
   * C = column axis
   * R = row axis
   * H = row axis heading
   * X = corner element
   *
   * Case 1 (C &lt; H), corner element on top of column axis
   *  
   * H H H X X X
   * H H H C C C
   * R R R 1 2 3
   * R R R 3 4 5
   *
   * Case 2 (C &gt; H), corner element in the left upper corner
   *  
   * X X X C C C
   * H H H C C C
   * R R R 1 2 3
   * R R R 3 4 5
   *
   * Case 3 (C == H), no corner element
   *  
   * H H H C C C
   * H H H C C C
   * R R R 1 2 3
   * R R R 3 4 5
   * </pre>
   */

  private void buildColumns2Dim(Element parent) {
    logger.info("enter buildColumns2Dim");
    int colAxisCount = columnAxisBuilder.getRowCount();
    int rowAxisCount = rowAxisBuilder.getHeaderRowCount();
    int colAxisIndex = 0;
    int rowAxisIndex = 0;
    
    if (logger.isInfoEnabled())
      logger.info("colAxisCount = " + colAxisCount + ", rowAxisCount = " + rowAxisCount);

    if (rowAxisCount > colAxisCount) {
      logger.info("rowAxisCount > colAxisCount");
      // case 1
      int N = rowAxisCount - colAxisCount;
      Element row = append("row", parent);
      rowAxisBuilder.buildHeaderRow(row, rowAxisIndex++);
      buildCornerElement(row, columnAxisBuilder.getColumnCount(), N);
      for (int i = 1; i < N; i++) {
        row = append("row", parent);
        rowAxisBuilder.buildHeaderRow(row, rowAxisIndex++);
      }
      // number of rows left to add
      rowAxisCount -= N;
    } else if (colAxisCount > rowAxisCount) {
      logger.info("colAxisCount > rowAxisCount");
      // case 2
      int N = colAxisCount - rowAxisCount;
      Element row = append("row", parent);
      buildCornerElement(row, rowAxisBuilder.getColumnCount(), N);
      columnAxisBuilder.buildRow(row, colAxisIndex++);
      for (int i = 1; i < N; i++) {
        row = append("row", parent);
        columnAxisBuilder.buildRow(row, colAxisIndex++);
      }
      // number of rows left to add
      colAxisCount -= N;
    }
    
    logger.info("building cells");
    // case 3
    // assert(colAxisCount == rowAxisCount)
    for (int i = 0; i < colAxisCount; i++) {
      Element row = append("row", parent);
      rowAxisBuilder.buildHeaderRow(row, rowAxisIndex++);
      columnAxisBuilder.buildRow(row, colAxisIndex++);
    }
    logger.info("leave buildColumns2Dim");
  }

  private void buildRows2Dim(Element parent) {
    logger.info("enter buildRows2Dim");
    final int N = rowAxisBuilder.getRowCount();
    for (int i = 0; i < N; i++) {
      boolean even = (i % 2 == 0);
      Element row = append("row", parent);
      rowAxisBuilder.buildRow(row, i);
      buildCells(row, even);
    }
    logger.info("leave buildRows2Dim");
  }

  /* ---------------------- common ------------------------------- */

  private void buildCells(Element row, boolean even) {
    final int N = columnAxisBuilder.getColumnCount();
    for (int i = 0; i < N; i++) {
      try {
        Cell cell = (Cell) cellIterator.next();
        Element cellElem = cellBuilder.build(cell, even);
        row.appendChild(cellElem);
      } catch (NoSuchElementException e) {
        logger.error("not enough cells", e);
        e.printStackTrace();
      }

    }
  }

  /* ----------------------- utilities -------------------------- */

  /**
   * utility - creates an element with the given name
   */
  public Element elem(String name) {
    return document.createElement(name);
  }

  /**
   * utility - creates an element and appends it
   */
  public Element append(String name, Element parent) {
    Element elem = document.createElement(name);
    parent.appendChild(elem);
    return elem;
  }

  private void firstChild(Element child, Element parent) {
    Node before = parent.getFirstChild();
    if (before != null)
      parent.insertBefore(child, before);
    else
      parent.appendChild(child);
  }

  /**
   * utility - creates an element an inserts it before the first child
   */
  public Element insert(String name, Element parent) {
    Element elem = document.createElement(name);
    firstChild(elem, parent);
    return elem;
  }

  /**
   * utility - creates a CDATA section
   */
  public Object cdata(String content, Element parent) {
    CDATASection section = document.createCDATASection(content);
    parent.appendChild(section);
    return section;
  }

  /* ----------------------- properties -------------------------------- */

  public OlapModel getOlapModel() {
    return olapModel;
  }

  /**
   * registers an extension. Used at creation time before initialize() is
   * called
   */
  public void addExtension(TableComponentExtension extension) {
    extensionList.add(extension);
    extensionMap.put(extension.getId(), extension);
  }

  /**
   * provides access to the extensions thru JSP scripting
   */
  public Map getExtensions() {
    return extensionMap;
  }

  /**
   * true means that render() will create a new DOM
   */
  public boolean isDirty() {
    return document == null;
  }

  public void setDirty(boolean dirty) {
    document = null;
    // avoid memory leak
    result = null;
    cellIterator = null;
    rootElement = null;
  }

  public void modelChanged(ModelChangeEvent e) {
    setDirty(true);
  }

  public void structureChanged(ModelChangeEvent e) {
    setDirty(true);
  }

  /**
   * Returns the cellBuilder.
   * @return CellBuilder
   */
  public CellBuilder getCellBuilder() {
    return cellBuilder;
  }

  /**
   * Returns the columnAxisBuilder.
   * @return ColumnAxisBuilder
   */
  public ColumnAxisBuilder getColumnAxisBuilder() {
    return columnAxisBuilder;
  }

  /**
   * Returns the cornerBuilder.
   * @return CornerBuilder
   */
  public CornerBuilder getCornerBuilder() {
    return cornerBuilder;
  }

  /**
   * Returns the rowAxisBuilder.
   * @return RowAxisBuilder
   */
  public RowAxisBuilder getRowAxisBuilder() {
    return rowAxisBuilder;
  }

  /**
   * Returns the slicerBuilder.
   * @return SlicerBuilder
   */
  public SlicerBuilder getSlicerBuilder() {
    return slicerBuilder;
  }

  /**
   * Sets the cellBuilder.
   * @param cellBuilder The cellBuilder to set
   */
  public void setCellBuilder(CellBuilder cellBuilder) {
    this.cellBuilder = cellBuilder;
  }

  /**
   * Sets the columnAxisBuilder.
   * @param columnAxisBuilder The columnAxisBuilder to set
   */
  public void setColumnAxisBuilder(ColumnAxisBuilder columnAxisBuilder) {
    this.columnAxisBuilder = columnAxisBuilder;
  }

  /**
   * Sets the cornerBuilder.
   * @param cornerBuilder The cornerBuilder to set
   */
  public void setCornerBuilder(CornerBuilder cornerBuilder) {
    this.cornerBuilder = cornerBuilder;
  }

  /**
   * Sets the rowAxisBuilder.
   * @param rowAxisBuilder The rowAxisBuilder to set
   */
  public void setRowAxisBuilder(RowAxisBuilder rowAxisBuilder) {
    this.rowAxisBuilder = rowAxisBuilder;
  }

  /**
   * Sets the slicerBuilder.
   * @param slicerBuilder The slicerBuilder to set
   */
  public void setSlicerBuilder(SlicerBuilder slicerBuilder) {
    this.slicerBuilder = slicerBuilder;
  }

  /**
   * returns the current result
   */
  public Result getResult() {
    return result;
  }

  /**
   * returns the dimension count of the current result
   */
  public int getDimCount() {
    return dimCount;
  }

  /**
   * returns the root DOM element that is rendered 
   */
  public Element getRootElement() {
    return rootElement;
  }

  /**
   * returns the row axis or null
   */
  public Axis getRowAxis() {
    if (dimCount < 2)
      return null;
    return result.getAxes()[1];
  }

  /**
   * returns the column axis or null
   */
  public Axis getColumnAxis() {
    if (dimCount < 1)
      return null;
    return result.getAxes()[0];
  }

  /**
   * returns the property config object that allows
   * to adjust visible properties
   */
  public PropertyConfig getPropertyConfig() {
    return rowAxisBuilder.getAxisConfig().getPropertyConfig();
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -