Package org.pentaho.reporting.engine.classic.core.util

Examples of org.pentaho.reporting.engine.classic.core.util.TypedTableModel


    }
  }

  public TableModel getTableEditorModel()
  {
    final TypedTableModel tableModel = new TypedTableModel();
    final TableModel model = this.tableModel;
    final int columnCount = model.getColumnCount();
    for (int col = 0; col < columnCount; col++)
    {
      tableModel.addColumn(model.getColumnName(col), model.getColumnClass(col));
    }

    final int rowCount = model.getRowCount();
    for (int r = 0; r < rowCount; r++)
    {
      for (int col = 0; col < columnCount; col++)
      {
        tableModel.setValueAt(model.getValueAt(r, col), r, col);
      }
    }

    return tableModel;
  }
View Full Code Here


      {
        final SheetSelectorDialog selectorDialog = new SheetSelectorDialog(workbook, parent);
        sheetIndex = selectorDialog.getSelectedIndex();
      }

      final TypedTableModel tableModel = new TypedTableModel();
      final Sheet sheet = workbook.getSheetAt(sheetIndex);
      final Iterator rowIterator = sheet.rowIterator();

      if (firstRowIsHeader)
      {
        if (rowIterator.hasNext())
        {
          final Row headerRow = (Row) rowIterator.next();
          final short cellCount = headerRow.getLastCellNum();
          for (short colIdx = 0; colIdx < cellCount; colIdx++)
          {
            final Cell cell = headerRow.getCell(colIdx);
            if (cell != null)
            {
              while(colIdx > tableModel.getColumnCount())
              {
                tableModel.addColumn(Messages.getString("TableDataSourceEditor.Column",
                    String.valueOf(tableModel.getColumnCount())), Object.class);
              }

              final RichTextString string = cell.getRichStringCellValue();
              if (string != null)
              {
                tableModel.addColumn(string.getString(), Object.class);
              }
              else
              {
                tableModel.addColumn(Messages.getString("TableDataSourceEditor.Column", String.valueOf(colIdx)), Object.class);
              }
            }
          }
        }
      }

      Object[] rowData = null;
      while (rowIterator.hasNext())
      {
        final Row row = (Row) rowIterator.next();
        final short cellCount = row.getLastCellNum();
        if (cellCount == -1)
        {
          continue;
        }
        if (rowData == null || rowData.length != cellCount)
        {
          rowData = new Object[cellCount];
        }

        for (short colIdx = 0; colIdx < cellCount; colIdx++)
        {
          final Cell cell = row.getCell(colIdx);

          final Object value;
          if (cell != null)
          {
            if (cell.getCellType() == Cell.CELL_TYPE_STRING)
            {
              final RichTextString string = cell.getRichStringCellValue();
              if (string != null)
              {
                value = string.getString();
              }
              else
              {
                value = null;
              }
            }
            else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC)
            {
              final CellStyle hssfCellStyle = cell.getCellStyle();
              if (isDateFormat(hssfCellStyle.getDataFormat(), hssfCellStyle.getDataFormatString()))
              {
                value = cell.getDateCellValue();
              }
              else
              {
                value = cell.getNumericCellValue();
              }
            }
            else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN)
            {
              value = cell.getBooleanCellValue();
            }
            else
            {
              value = cell.getStringCellValue();
            }
          }
          else
          {
            value = null;
          }

          if (value != null && "".equals(value) == false)
          {
            while (colIdx >= tableModel.getColumnCount())
            {
              tableModel.addColumn(Messages.getString("TableDataSourceEditor.Column",
                  String.valueOf(tableModel.getColumnCount())), Object.class);
            }
          }

          rowData[colIdx] = value;
        }

        if (Thread.currentThread().isInterrupted())
        {
          return;
        }

        tableModel.addRow(rowData);
      }

      final int colCount = tableModel.getColumnCount();
      final int rowCount = tableModel.getRowCount();
      for (int col = 0; col < colCount; col++)
      {
        Class type = null;
        for (int row = 0; row < rowCount; row += 1)
        {
          final Object value = tableModel.getValueAt(row, col);
          if (value == null)
          {
            continue;
          }
          if (type == null)
          {
            type = value.getClass();
          }
          else if (type != Object.class)
          {
            if (type.isInstance(value) == false)
            {
              type = Object.class;
            }
          }
        }

        if (Thread.currentThread().isInterrupted())
        {
          return;
        }

        if (type != null)
        {
          tableModel.setColumnType(col, type);
        }
      }

      parent.importComplete(tableModel);
    }
View Full Code Here

    public void actionPerformed(final ActionEvent e)
    {
      try
      {
        final TypedTableModel model = fetchData("listQueries", Collections.EMPTY_MAP);
        queriesTableModel.clear();
        for (int i = 0; i < model.getRowCount(); i++)
        {
          final String query = (String) model.getValueAt(i, 0);
          final String name = (String) model.getValueAt(i, 1);
          if (StringUtils.isEmpty(name))
          {
            queriesTableModel.addQuery("Anonymous Query #" + i, query);
          }
          else
View Full Code Here

TOP

Related Classes of org.pentaho.reporting.engine.classic.core.util.TypedTableModel

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.