Package org.odftoolkit.odfdom.dom.element.table

Examples of org.odftoolkit.odfdom.dom.element.table.TableTableRowElement


    }
    // the row has repeated row number > 1 && the index is 0
    // or the row has repeated row num = 1
    Node aPrevNode = maRowElement.getPreviousSibling();
    Node aCurNode = maRowElement;
    TableTableRowElement lastRow;
    while (true) {
      if (aPrevNode == null) {
        // does not have previous sibling, then get the parent
        // because aCurNode might be the child element of
        // table-header-rows, table-rows, table-row-group
        Node parentNode = aCurNode.getParentNode();
        // if the parent is table, then it means that this row is the
        // first row in this table
        // it has no previous row
        if (parentNode instanceof TableTableElement) {
          return null;
        }
        aPrevNode = parentNode.getPreviousSibling();
      }
      // else the previous node might be table-header-rows, table-rows,
      // table-row-group
      if (aPrevNode != null) {
        try {
          if (aPrevNode instanceof TableTableRowElement) {
            return table
                .getRowInstance((TableTableRowElement) aPrevNode, ((TableTableRowElement) aPrevNode)
                    .getTableNumberRowsRepeatedAttribute().intValue() - 1);
          } else if (aPrevNode instanceof TableTableRowsElement
              || aPrevNode instanceof TableTableHeaderRowsElement
              || aPrevNode instanceof TableTableRowGroupElement) {
            XPath xpath = ((OdfContentDom) aPrevNode.getOwnerDocument()).getXPath();
            synchronized (mDocument) {
              lastRow = (TableTableRowElement) xpath.evaluate(".//table:table-row[last()]", aPrevNode,
                  XPathConstants.NODE);
            }
            if (lastRow != null) {
              return table.getRowInstance(lastRow, lastRow.getTableNumberRowsRepeatedAttribute()
                  .intValue() - 1);
            }
          } else {
            aCurNode = aPrevNode;
            aPrevNode = aPrevNode.getPreviousSibling();
View Full Code Here


        return table.getRowInstance(maRowElement, mnRepeatedIndex + 1);
      }
    }
    Node aNextNode = maRowElement.getNextSibling();
    Node aCurNode = maRowElement;
    TableTableRowElement firstRow;
    while (true) {
      if (aNextNode == null) {
        // does not have next sibling, then get the parent
        // because aCurNode might be the child element of
        // table-header-rows, table-rows, table-row-group
View Full Code Here

   * @return the index of the row
   */
  public int getRowIndex() {
    int result = 0;
    TableTableElement mTableElement = getTableElement();
    TableTableRowElement rowEle = null;
    for (Node n : new DomNodeList(mTableElement.getChildNodes())) {
      if (n instanceof TableTableHeaderRowsElement) {
        TableTableHeaderRowsElement headers = (TableTableHeaderRowsElement) n;
        for (Node m : new DomNodeList(headers.getChildNodes())) {
          if (m instanceof TableTableRowElement) {
            rowEle = (TableTableRowElement) m;
            if (rowEle == getOdfElement()) {
              return result + mnRepeatedIndex;
            }
            result += rowEle.getTableNumberRowsRepeatedAttribute();
          }
        }
      }
      if (n instanceof TableTableRowElement) {
        rowEle = (TableTableRowElement) n;
View Full Code Here

    int repeateNum = getRowsRepeatedNumber();
    if (repeateNum > 1) {
      OdfTable table = getTable();
      TableTableElement tableEle = table.getOdfElement();
      //change this repeated row to several single rows
      TableTableRowElement ownerRowElement = null;
      int repeatedRowIndex = mnRepeatedIndex;
      Node refElement = maRowElement;
      Node oldRowElement = maRowElement;
      for (int i = repeateNum - 1; i >= 0; i--) {
        TableTableRowElement newRow = (TableTableRowElement) maRowElement.cloneNode(true);
        newRow.removeAttributeNS(OdfDocumentNamespace.TABLE.getUri(), "number-rows-repeated");
        tableEle.insertBefore(newRow, refElement);
        refElement = newRow;
        if (repeatedRowIndex == i) {
          ownerRowElement = newRow;
        } else {
View Full Code Here

    }
    //the row has repeated row number > 1 && the index is 0
    //or the row has repeated row num = 1
    Node aPrevNode = maRowElement.getPreviousSibling();
    Node aCurNode = maRowElement;
    TableTableRowElement lastRow;
    while (true) {
      if (aPrevNode == null) {
        //does not have previous sibling, then get the parent
        //because aCurNode might be the child element of table-header-rows, table-rows, table-row-group
        Node parentNode = aCurNode.getParentNode();
        //if the parent is table, then it means that this row is the first row in this table
        //it has no previous row
        if (parentNode instanceof TableTableElement) {
          return null;
        }
        aPrevNode = parentNode.getPreviousSibling();
      }
      //else the previous node might be table-header-rows, table-rows, table-row-group
      if (aPrevNode != null) {
        try {
          if (aPrevNode instanceof TableTableRowElement) {
            return table.getRowInstance((TableTableRowElement) aPrevNode,
                ((TableTableRowElement) aPrevNode).getTableNumberRowsRepeatedAttribute().intValue() - 1);
          } else if (aPrevNode instanceof TableTableRowsElement
              || aPrevNode instanceof TableTableHeaderRowsElement
              || aPrevNode instanceof TableTableRowGroupElement) {
            XPath xpath = ((OdfContentDom) aPrevNode.getOwnerDocument()).getXPath();
            synchronized (mDocument) {
              lastRow = (TableTableRowElement) xpath.evaluate(".//table:table-row[last()]", aPrevNode, XPathConstants.NODE);
            }
            if (lastRow != null) {
              return table.getRowInstance(lastRow, lastRow.getTableNumberRowsRepeatedAttribute().intValue() - 1);
            }
          } else {
            aCurNode = aPrevNode;
            aPrevNode = aPrevNode.getPreviousSibling();
          }
View Full Code Here

      }
    }

    Node aNextNode = maRowElement.getNextSibling();
    Node aCurNode = maRowElement;   
    TableTableRowElement firstRow;
    while (true) {
      if (aNextNode == null) {
        //does not have next sibling, then get the parent
        //because aCurNode might be the child element of table-header-rows, table-rows, table-row-group
        Node parentNode = aCurNode.getParentNode();
View Full Code Here

   * @return the index of the row
   */
  public int getRowIndex() {
    int result = 0;
    TableTableElement mTableElement = getTableElement();
    TableTableRowElement rowEle = null;
    for (Node n : new DomNodeList(mTableElement.getChildNodes())) {
      if (n instanceof TableTableHeaderRowsElement) {
        TableTableHeaderRowsElement headers = (TableTableHeaderRowsElement) n;
        for (Node m : new DomNodeList(headers.getChildNodes())) {
          if (m instanceof TableTableRowElement) {
            rowEle = (TableTableRowElement) m;
            if (rowEle == getOdfElement()) {
              return result + mnRepeatedIndex;
            }
            result += rowEle.getTableNumberRowsRepeatedAttribute();
          }
        }
      }
      if (n instanceof TableTableRowElement) {
        rowEle = (TableTableRowElement) n;
View Full Code Here

  }

  private void updateTableCells(OdfDocument odfdoc, String tablename,
      double[] values, String[] labels) {
    int i = 0, j = 0;
    TableTableRowElement td;
    TableTableCellElement cell;
    OdfFileDom dom;
    NodeList tableList;
    TableTableElement myTable;
    NodeList lst;
    OdfTextParagraph p;
    OfficeSpreadsheetElement spreadsheet = null;

    try {
      dom = odfdoc.getContentDom();
      tableList = dom.getElementsByTagNameNS(
          OdfDocumentNamespace.TABLE.getUri(), "table");
      spreadsheet = (OfficeSpreadsheetElement) dom.getElementsByTagNameNS(
          OdfDocumentNamespace.OFFICE.getUri(), "spreadsheet").item(0);

      i = 0;
      if (tableList.getLength() > 0) {
        for (; i < tableList.getLength(); i++) {
          String currentname = ((TableTableElement) tableList.item(i)).getTableNameAttribute();
          if (currentname == null) {
            currentname = "";
          }
          if (currentname.equalsIgnoreCase(tablename)) {
            break;
          }
        }
      }
      if (i < tableList.getLength()) //table with the specific table name is found
      {
        myTable = (TableTableElement) tableList.item(i);
      } else { //table with the specific table name is not found. Create table
        myTable = dom.newOdfElement(TableTableElement.class);
        myTable.setTableNameAttribute(tablename);
        spreadsheet.appendChild(myTable);
      }

      lst = myTable.getElementsByTagNameNS(OdfDocumentNamespace.TABLE.getUri(), "table-row");
      if (lst.getLength() == 0) { //the first table row is not existed. Create table row
        td = dom.newOdfElement(TableTableRowElement.class);
        cell = dom.newOdfElement(TableTableCellElement.class);
        p = dom.newOdfElement(OdfTextParagraph.class);
        if (tablename.startsWith("Memory")) {
          p.setTextContent("memory(b)");
        } else {
          p.setTextContent("time(ms)");
        }
        td.appendChild(cell);
        cell.appendChild(p);
        myTable.appendChild(td);
      } else {
        td = (TableTableRowElement) lst.item(0); //the first table row is existed.
      }
      cell = dom.newOdfElement(TableTableCellElement.class);
      td.appendChild(cell);
      p = dom.newOdfElement(OdfTextParagraph.class);
      p.setTextContent(testTag);
      cell.appendChild(p);


      for (i = 1; i < values.length + 1; i++) {
        if (i < lst.getLength()) { //table row is existed
          td = (TableTableRowElement) lst.item(i);
        } else { //table row is not existed.
          td = dom.newOdfElement(TableTableRowElement.class);
          myTable.appendChild(td);
          //append first cell with labels
          cell = dom.newOdfElement(TableTableCellElement.class);
          td.appendChild(cell);
          p = dom.newOdfElement(OdfTextParagraph.class);
          p.setTextContent(labels[j]);
          cell.appendChild(p);
        }
        cell = dom.newOdfElement(TableTableCellElement.class);
        cell.setOfficeValueTypeAttribute("float");
        cell.setOfficeValueAttribute(new Double(values[j]));
        p = dom.newOdfElement(OdfTextParagraph.class);
        p.setTextContent(values[j] + "");
        cell.appendChild(p);
        td.appendChild(cell);
        j++;
      }
    } catch (Exception e) {
      LOG.log(Level.SEVERE, null, e);
    }
View Full Code Here

      NodeList lst = odfdoc.getContentDom().getElementsByTagNameNS(OdfDocumentNamespace.TABLE.getUri(), "table-cell");
      for (int i = 0; i < lst.getLength(); i++) {
        Node node = lst.item(i);
        Assert.assertTrue(node instanceof TableTableCellElement);
        TableTableCellElement td = (TableTableCellElement) lst.item(i);
        TableTableRowElement tr = (TableTableRowElement) td.getParentNode();
        Assert.assertNotNull(tr);

        OdfTable table = OdfTableRow.getInstance(tr).getTable();
        Assert.assertNotNull(table);
        Assert.assertTrue(table == OdfTableCell.getInstance(td).getTable());
View Full Code Here

    mytable.setTableNameAttribute("Cars Sheet");

    // remove first empty row of table.
    mytable.removeChild(mytable.getFirstChild().getNextSibling());

    TableTableRowElement row = (TableTableRowElement) mytable.appendChild(new TableTableRowElement(odt));
    TableTableCellElement cell = (TableTableCellElement) row.appendChild(new TableTableCellElement(odt));

    OdfTextParagraph p = new OdfTextParagraph(odt);
    p.appendChild(odt.createTextNode("Corvette"));
    cell.appendChild(p);

    // 2nd Table
    TableTableElement my2table = new TableTableElement(odt);

    Element spreadsheetElement = (Element) odt.getElementsByTagNameNS(OdfDocumentNamespace.OFFICE.getUri(), "spreadsheet").item(0);
    my2table.setAttributeNS(OdfDocumentNamespace.TABLE.getUri(), "table:name", "BikesSheet");
    spreadsheetElement.appendChild(my2table);

    TableTableRowElement row2 = (TableTableRowElement) my2table.appendChild(new TableTableRowElement(odt));
    TableTableCellElement cell2 = (TableTableCellElement) row2.appendChild(new TableTableCellElement(odt));

    OdfTextParagraph p2 = new OdfTextParagraph(odt);
    p2.appendChild(odt.createTextNode("Bandit 600"));
    cell2.appendChild(p2);
View Full Code Here

TOP

Related Classes of org.odftoolkit.odfdom.dom.element.table.TableTableRowElement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.