Package javax.swing.table

Examples of javax.swing.table.TableModel


      throws ParseException
  {
    final URL in = ObjectUtilities.getResource
        ("org/pentaho/reporting/engine/classic/demo/opensource/opensource.xml", StraightToPlainText.class);
    final MasterReport report = parseReport(in);
    final TableModel data = new OpenSourceProjects();
    report.setDataFactory(new TableDataFactory
        ("default", data));
    savePlainText(report, filename);
  }
View Full Code Here


  public static void main(String[] args)
      throws ReportProcessingException
  {
    ClassicEngineBoot.getInstance().start();

    final TableModel data = new DefaultTableModel(1, 1);
    final MasterReport report = TestSystem.loadReport("org/pentaho/reporting/engine/classic/extensions/junit/pages/valign-report.xml", data);
    if (report == null)
    {
      System.exit(1);
    }
View Full Code Here

  }

  public void testPageSystem()   throws Exception
  {
    ClassicEngineBoot.getInstance().start();
    final TableModel data = new DefaultTableModel(2000, 1);
    MasterReport report = parseReport(getReportDefinitionSource());
    report.setDataFactory(new TableDataFactory
        ("default", data)); //$NON-NLS-1$;
    assertTrue(FunctionalityTestLib.execGraphics2D(report));
  }
View Full Code Here

    // second run. Now with padding ..
    final ProcessingContext prc = new DefaultProcessingContext();
    final GlobalMasterRow gmr = GlobalMasterRow.createReportRow
        (prc, new DefaultDataSchemaDefinition(), new ParameterDataRow(), null, false);
    final TableModel data = createTableModel();
    MasterDataRow wdata = gmr.deriveWithQueryData(new ReportDataRow(data));
    int advanceCount = 0;
    wdata = wdata.startCrosstabMode(specification);
    logger.debug("Region:  " + wdata.getGlobalView().get("Region"));
    logger.debug("Product: " + wdata.getGlobalView().get("Product"));
    logger.debug("Year:    " + wdata.getGlobalView().get("Time"));
    Object grpVal = wdata.getGlobalView().get("Region");
    while (wdata.isAdvanceable())
    {
      logger.debug("-- Advance -- ");
      MasterDataRow nextdata = wdata.advance();
      Object nextGrpVal = nextdata.getGlobalView().get("Region");
      if (ObjectUtilities.equal(grpVal, nextGrpVal) == false)
      {
        nextdata = nextdata.resetRowCursor();
      }

      logger.debug("Do Advance Count: " + nextdata.getReportDataRow().getCursor());
      logger.debug("Region:  " + nextdata.getGlobalView().get("Region"));
      logger.debug("Product: " + nextdata.getGlobalView().get("Product"));
      logger.debug("Year:    " + nextdata.getGlobalView().get("Time"));
      advanceCount += 1;
      wdata = nextdata;
      grpVal = nextGrpVal;
    }
    if (advanceCount != (data.getRowCount() - 1))
    {
      throw new IllegalStateException("Expected " + (data.getRowCount() - 1) + " but got " + advanceCount);
    }

  }
View Full Code Here

  private static CrosstabSpecification buildCS()
  {
    final ProcessingContext prc = new DefaultProcessingContext();
    final GlobalMasterRow gmr = GlobalMasterRow.createReportRow
        (prc, new DefaultDataSchemaDefinition(), new ParameterDataRow(), null, false);
    final TableModel data = createTableModel();
    MasterDataRow wdata = gmr.deriveWithQueryData(new ReportDataRow(data));
    final CrosstabSpecification cs = new SortedMergeCrosstabSpecification
        (createDummyKey(), new String[]{"Product", "Time"});
    int advanceCount = 0;
    System.out.println(wdata.getReportDataRow().getCursor());
    cs.startRow();
    cs.add(wdata.getGlobalView());
    Object grpVal = wdata.getGlobalView().get("Region");
    while (wdata.isAdvanceable())
    {
      final MasterDataRow nextdata = wdata.advance();
      Object nextGrpVal = nextdata.getGlobalView().get("Region");
      if (ObjectUtilities.equal(grpVal, nextGrpVal) == false)
      {
        cs.endRow();
        cs.startRow();
      }

      cs.add(nextdata.getGlobalView());
      logger.debug("Prepare Advance Count: " + nextdata.getReportDataRow().getCursor());
      advanceCount += 1;
      wdata = nextdata;
      grpVal = nextGrpVal;
    }
    cs.endRow();
    if (advanceCount != (data.getRowCount() - 1))
    {
      throw new IllegalStateException("Expected 6 but got " + advanceCount);
    }
    return cs;
  }
View Full Code Here

    fireTableChanged(new TableModelEvent(this, TableModelEvent.HEADER_ROW));
  }

  public int compareRowsByColumn(int row1, int row2, int column) {
    Class type = model.getColumnClass(column);
    TableModel data = model;

    // Check for nulls

    Object o1 = data.getValueAt(row1, column);
    Object o2 = data.getValueAt(row2, column);

    // If both values are null return 0
    if (o1 == null && o2 == null) {
      return 0;
    } else if (o1 == null) { // Define null less than everything.
      return -1;
    } else if (o2 == null) {
      return 1;
    }

    /* We copy all returned values from the getValue call in case
    an optimised model is reusing one object to return many values.
    The Number subclasses in the JDK are immutable and so will not be used in
    this way but other subclasses of Number might want to do this to save
    space and avoid unnecessary heap allocation.
    */
    if (type.getSuperclass() == java.lang.Number.class) {
      Number n1 = (Number) data.getValueAt(row1, column);
      double d1 = n1.doubleValue();
      Number n2 = (Number) data.getValueAt(row2, column);
      double d2 = n2.doubleValue();

      if (d1 < d2)
        return -1;
      else if (d1 > d2)
        return 1;
      else
        return 0;
    } else if (type == java.util.Date.class) {
      Date d1 = (Date) data.getValueAt(row1, column);
      long n1 = d1.getTime();
      Date d2 = (Date) data.getValueAt(row2, column);
      long n2 = d2.getTime();

      if (n1 < n2)
        return -1;
      else if (n1 > n2)
        return 1;
      else
        return 0;
    } else if (type == String.class) {
      String s1 = (String) data.getValueAt(row1, column);
      String s2 = (String) data.getValueAt(row2, column);
      int result = s1.compareTo(s2);

      if (result < 0)
        return -1;
      else if (result > 0)
        return 1;
      else
        return 0;
    } else if (type == Boolean.class) {
      Boolean bool1 = (Boolean) data.getValueAt(row1, column);
      boolean b1 = bool1.booleanValue();
      Boolean bool2 = (Boolean) data.getValueAt(row2, column);
      boolean b2 = bool2.booleanValue();

      if (b1 == b2)
        return 0;
      else if (b1) // Define false < true
        return 1;
      else
        return -1;
    } else if (type == Comparable.class) {
      Comparable c1 = (Comparable) data.getValueAt(row1, column);
      Comparable c2 = (Comparable) data.getValueAt(row2, column);
      return c1.compareTo(c2);
    } else {
      Object v1 = data.getValueAt(row1, column);
      String s1 = v1.toString();
      Object v2 = data.getValueAt(row2, column);
      String s2 = v2.toString();
      int result = s1.compareTo(s2);

      if (result < 0)
        return -1;
View Full Code Here

  {

    try
    {
      final DataFactory dataFactory = context.getRuntime().getDataFactory();
      final TableModel tableModel = dataFactory.queryData(query,
          new QueryDataRowWrapper(context.getDataRow(), queryLimit, queryTimeout));
      if (tableModel == null)
      {
        return null;
      }
      final int columnCount = tableModel.getColumnCount();
      if (tableModel.getRowCount() == 0 || columnCount == 0)
      {
        return null;
      }
      if (columnName == null)
      {
        return tableModel.getValueAt(0, 0);
      }
      for (int column = 0; column < columnCount; column++)
      {
        if (columnName.equals(tableModel.getColumnName(column)))
        {
          final ArrayList values = new ArrayList();
          final int rowCount = tableModel.getRowCount();
          for (int row = 0; row < rowCount; row++)
          {
            values.add(tableModel.getValueAt(row, column));
          }
          return values.toArray();
        }
      }
    }
View Full Code Here

  {

    try
    {
      final DataFactory dataFactory = context.getRuntime().getDataFactory();
      final TableModel tableModel = dataFactory.queryData(query,
          new QueryDataRowWrapper(context.getDataRow(), 1, queryTimeout));
      if (tableModel == null)
      {
        return null;
      }

      final int columnCount = tableModel.getColumnCount();
      if (tableModel.getRowCount() == 0 || columnCount == 0)
      {
        return null;
      }
      if (column == null)
      {
        return tableModel.getValueAt(0, 0);
      }
      for (int i = 0; i < columnCount; i++)
      {
        if (column.equals(tableModel.getColumnName(i)))
        {
          return tableModel.getValueAt(0, i);
        }
      }
    }
    catch (Exception e)
    {
View Full Code Here

   * @param parameters are ignored for this factory.
   * @return the report data or null.
   */
  public TableModel queryData(final String query, final DataRow parameters) throws ReportDataFactoryException
  {
    final TableModel tableModel = tables.get(query);
    if (tableModel == null)
    {
      throw new ReportDataFactoryException("The specified query '" + query + "' is not recognized.");
    }
    return tableModel;
View Full Code Here

      {
        mappings[i] = new ParameterMapping(fields[i], fields[i]);
      }

      final QueryParametersDataRow params = new QueryParametersDataRow(getDataRow(), mappings);
      final TableModel tableModel = dataFactory.queryData(query, new QueryDataRowWrapper(params, 1, queryTimeout));
      if (tableModel == null)
      {
        return;
      }
      final int columnCount = tableModel.getColumnCount();
      if (tableModel.getRowCount() == 0 || columnCount == 0)
      {
        return;
      }
      if (resultColumn == null)
      {
        value = tableModel.getValueAt(0, 0);
        return;
      }
      for (int i = 0; i < columnCount; i++)
      {
        if (resultColumn.equals(tableModel.getColumnName(i)))
        {
          value = tableModel.getValueAt(0, i);
          return;
        }
      }
      // do nothing ..
    }
View Full Code Here

TOP

Related Classes of javax.swing.table.TableModel

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.