List of usage examples for javax.swing.table TableModel getColumnName
public String getColumnName(int columnIndex);
columnIndex
. From source file:org.eobjects.analyzer.result.AnnotatedRowResultTest.java
private void performAssertions(AnnotatedRowsResult result) { assertEquals(2, result.getAnnotatedRowCount()); assertEquals("[MockInputColumn[name=foo], MockInputColumn[name=bar]]", result.getInputColumns().toString()); assertEquals("[MockInputColumn[name=foo]]", Arrays.toString(result.getHighlightedColumns())); assertNotNull(result.getRows());//from www .j ava2 s. c o m TableModel tableModel = result.toTableModel(); assertNotNull(tableModel); assertEquals(2, tableModel.getColumnCount()); assertEquals("foo", tableModel.getColumnName(0)); assertEquals("bar", tableModel.getColumnName(1)); tableModel = result.toDistinctValuesTableModel(result.getHighlightedColumns()[0]); assertNotNull(tableModel); assertEquals(2, tableModel.getColumnCount()); assertEquals("foo", tableModel.getColumnName(0)); assertEquals("Count in dataset", tableModel.getColumnName(1)); }
From source file:org.owasp.jbrofuzz.fuzz.io.Save.java
/** * @author daemonmidi@gmail.com//from w w w . j av a 2s . com * @since version 2.5 * @param inputTableModel * @return */ public static JSONArray getTableDataInJSON(final TableModel inputTableModel) { JSONArray tableData = new JSONArray(); final int totalRows = inputTableModel.getRowCount() - 1; final int totalColumns = inputTableModel.getColumnCount() - 1; if (totalRows < 1) { return new JSONArray(); } for (int currentRow = 0; currentRow < totalRows; currentRow++) { for (int currentColumn = 0; currentColumn < totalColumns - 1; currentColumn++) { String name = inputTableModel.getColumnName(currentColumn); String value = inputTableModel.getValueAt(currentColumn, currentRow).toString(); String cellString = "{\"" + name + "\":\"" + value + "\"}"; JSONObject cell; try { cell = new JSONObject(cellString); tableData.put(cell); } catch (JSONException e) { e.printStackTrace(); } } } return tableData; }
From source file:org.pentaho.reporting.engine.classic.core.cache.CachingDataFactory.java
/** * Prints a table model to standard output. * * @param mod/*from w w w.j a v a2s. c o m*/ * the model. */ public static void printTableModelContents(final TableModel mod) { if (mod == null) { throw new NullPointerException(); } logger.debug("Tablemodel contains " + mod.getRowCount() + " rows."); //$NON-NLS-1$ //$NON-NLS-2$ for (int i = 0; i < mod.getColumnCount(); i++) { logger.debug("Column: " + i + " Name = " + mod.getColumnName(i) + "; DataType = " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + mod.getColumnClass(i)); } logger.debug("Checking the data inside"); //$NON-NLS-1$ for (int rows = 0; rows < mod.getRowCount(); rows++) { for (int i = 0; i < mod.getColumnCount(); i++) { final Object value = mod.getValueAt(rows, i); logger.debug("ValueAt (" + rows + ", " + i + ") is " + value); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } } }
From source file:org.pentaho.reporting.engine.classic.core.function.formula.MultiValueQueryFunction.java
private Object performQuery(final ReportFormulaContext context, final String query, final String columnName, final int queryTimeout, final int queryLimit) throws EvaluationException { try {//ww w .ja v a 2 s. co m 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; } for (int column = 0; column < columnCount; column++) { if (columnName == null || columnName.equals(tableModel.getColumnName(column))) { final ArrayList<Object> values = new ArrayList<Object>(); int rowCount = tableModel.getRowCount(); if (queryLimit > 0) { rowCount = Math.min(queryLimit, tableModel.getRowCount()); } for (int row = 0; row < rowCount; row++) { values.add(tableModel.getValueAt(row, column)); } return values.toArray(); } } throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_UNEXPECTED_VALUE); } catch (EvaluationException e) { throw e; } catch (Exception e) { logger.warn("SingleValueQueryFunction: Failed to perform query", e); throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_UNEXPECTED_VALUE); } }
From source file:org.pentaho.reporting.engine.classic.core.function.formula.SingleValueQueryFunction.java
private Object performQuery(final ReportFormulaContext context, final String query, final String column, final int queryTimeout) throws EvaluationException { try {/*www.j av a2 s .co m*/ 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); } } throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_UNEXPECTED_VALUE); } catch (EvaluationException e) { throw e; } catch (Exception e) { SingleValueQueryFunction.logger.warn("SingleValueQueryFunction: Failed to perform query", e); throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_UNEXPECTED_VALUE); } }
From source file:org.pentaho.reporting.engine.classic.core.function.sys.SingleValueQueryFunction.java
/** * Performs the query by collecting the data from the datarow and executing the query. * * @return the computed value./*ww w .j a va2 s . c o m*/ */ private Object performQuery() { if (query == null) { return null; } try { final DataFactory dataFactory = getRuntime().getDataFactory(); final String[] fields = getField(); final int length = fields.length; final ParameterMapping[] mappings = new ParameterMapping[length]; for (int i = 0; i < length; i++) { 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 null; } final int columnCount = tableModel.getColumnCount(); if (tableModel.getRowCount() == 0 || columnCount == 0) { return null; } if (resultColumn == null) { return tableModel.getValueAt(0, 0); } for (int i = 0; i < columnCount; i++) { if (resultColumn.equals(tableModel.getColumnName(i))) { return tableModel.getValueAt(0, i); } } // do nothing .. } catch (Exception e) { logger.warn("SingleValueQueryFunction: Failed to perform query", e); } return null; }
From source file:org.pentaho.reporting.engine.classic.core.sorting.SortingDataFactory.java
private List<SortConstraint> resolveColumnAliases(final TableModel tableModel, final List<SortConstraint> sort) { ArrayList<SortConstraint> result = new ArrayList<SortConstraint>(sort.size()); for (final SortConstraint constraint : sort) { String field = constraint.getField(); if (StringUtils.isEmpty(field)) { DebugLog.log("Sort field is empty"); continue; }/*from w w w .ja va2 s .c o m*/ if (field.startsWith(ClassicEngineBoot.INDEX_COLUMN_PREFIX)) { String idx = field.substring(ClassicEngineBoot.INDEX_COLUMN_PREFIX.length()); try { int idxParsed = Integer.parseInt(idx); if (idxParsed >= 0 && idxParsed < tableModel.getColumnCount()) { String columnName = tableModel.getColumnName(idxParsed); if (!StringUtils.isEmpty(columnName)) { result.add(new SortConstraint(columnName, constraint.isAscending())); } else { DebugLog.log("Resolved column name for column at index " + idxParsed + " is empty."); } } else { logger.debug("Invalid index on indexed column '" + field + "'"); } } catch (final NumberFormatException iae) { logger.debug("Unable to parse non-decimal index on indexed column '" + field + "'", iae); } } else { result.add(constraint); } } return result; }
From source file:org.pentaho.reporting.engine.classic.core.sorting.TableSorter.java
private HashMap<String, Integer> createColumnNameIndex() { HashMap<String, Integer> idx = new HashMap<String, Integer>(); TableModel tableModel = getModel(); int cc = tableModel.getColumnCount(); for (int i = 0; i < cc; i += 1) { idx.put(tableModel.getColumnName(i), i); }// w w w .j a v a 2 s .c o m return idx; }
From source file:org.pentaho.reporting.engine.classic.core.states.datarow.ProcessingDataSchemaCompiler.java
public DataSchema compile(final MasterDataRow masterRow, final ReportEnvironment reportEnvironment) throws ReportDataFactoryException { if (masterRow == null) { throw new NullPointerException(); }/*from w w w . ja va2s . c o m*/ if (isInitialized() == false) { init(); } final DefaultDataAttributes globalAttributes = getGlobalAttributes(); final MetaSelectorRule[] indirectRules = getIndirectRules(); final DirectFieldSelectorRule[] directRules = getDirectRules(); final DataAttributeContext context = getContext(); final ParameterDataRow parameters = masterRow.getParameterDataRow(); final ExpressionDataRow expressionsRow = masterRow.getExpressionDataRow(); final ReportDataRow massDataRow = masterRow.getReportDataRow(); // imported data has been compiled in the subreport ... final ImportedVariablesDataRow importedDataRow = masterRow.getImportedDataRow(); final DefaultDataSchema defaultDataSchema = new DefaultDataSchema(); if (parameters != null) { final MasterDataRow parentRow = masterRow.getParentDataRow(); if (parentRow == null) { processParameters(parameters, null, reportEnvironment, globalAttributes, indirectRules, directRules, defaultDataSchema); } else { // import the parameters that have been computed already .. final String[] parameterNames = parameters.getParentNames(); final String[] innerNames = parameters.getColumnNames(); for (int i = 0; i < parameterNames.length; i++) { final String name = parameterNames[i]; final DataAttributes attributes = parentRow.getDataSchema().getAttributes(name); defaultDataSchema.setAttributes(innerNames[i], attributes); } } } // expressions final Expression[] expressions = expressionsRow.getExpressions(); for (int i = 0; i < expressions.length; i++) { final Expression expression = expressions[i]; final String name = expression.getName(); if (name == null) { continue; } final DefaultDataAttributes computedParameterDataAttributes = new DefaultDataAttributes(); computedParameterDataAttributes.merge(globalAttributes, context); computedParameterDataAttributes.merge(new ExpressionsDataAttributes(expression), context); applyRules(indirectRules, directRules, computedParameterDataAttributes); defaultDataSchema.setAttributes(name, computedParameterDataAttributes); } // massdata if (massDataRow != null) { final GenericDataAttributes parameterDataAttributes = getTableDataAttributes(); final TableModel data = massDataRow.getReportData(); if (data instanceof MetaTableModel == false) { final int count = data.getColumnCount(); for (int i = 0; i < count; i++) { final String colName = data.getColumnName(i); parameterDataAttributes.setup(colName, data.getColumnClass(i), MetaAttributeNames.Core.SOURCE_VALUE_TABLE, colName, globalAttributes); final DefaultDataAttributes computedParameterDataAttributes = new DefaultDataAttributes(); computedParameterDataAttributes.merge(parameterDataAttributes, context); applyRules(indirectRules, directRules, computedParameterDataAttributes); defaultDataSchema.setAttributes(colName, computedParameterDataAttributes); } } else { final MetaTableModel mt = (MetaTableModel) data; final DefaultDataAttributes tableGlobalAttributes = new DefaultDataAttributes(); tableGlobalAttributes.merge(globalAttributes, context); tableGlobalAttributes.merge(mt.getTableAttributes(), context); try { defaultDataSchema.setTableAttributes(tableGlobalAttributes); } catch (CloneNotSupportedException e) { logger.warn("Unable to copy global data-attributes", e); } final int count = data.getColumnCount(); for (int i = 0; i < count; i++) { final String colName = data.getColumnName(i); final DefaultDataAttributes computedParameterDataAttributes = new DefaultDataAttributes(); computedParameterDataAttributes.merge(tableGlobalAttributes, context); computedParameterDataAttributes.merge(mt.getColumnAttributes(i), context); parameterDataAttributes.setup(colName, data.getColumnClass(i), MetaAttributeNames.Core.SOURCE_VALUE_TABLE, null, EmptyDataAttributes.INSTANCE); computedParameterDataAttributes.merge(parameterDataAttributes, context); applyRules(indirectRules, directRules, computedParameterDataAttributes); defaultDataSchema.setAttributes(colName, computedParameterDataAttributes); } } } // imported values ... if (importedDataRow != null) { final String[] columnNames = importedDataRow.getColumnNames(); for (int i = 0; i < columnNames.length; i++) { final String columnName = columnNames[i]; defaultDataSchema.setAttributes(columnName, importedDataRow.getAttributes(columnName)); } } return defaultDataSchema; }
From source file:org.pentaho.reporting.engine.classic.core.wizard.DataSchemaCompiler.java
public DataSchema compile(final TableModel data, final Expression[] expressions, final ParameterDataRow parameters, final ParameterDefinitionEntry[] parameterDefinitions, final ReportEnvironment reportEnvironment) throws ReportDataFactoryException { if (initialized == false) { init();/*from w ww . j a v a2 s . c o m*/ } if (data == null) { throw new NullPointerException(); } final DefaultDataSchema defaultDataSchema = new DefaultDataSchema(); if (reportEnvironment != null) { processReportEnvironment(globalAttributes, indirectRules, directRules, defaultDataSchema); } if (parameters != null) { processParameters(parameters, parameterDefinitions, reportEnvironment, globalAttributes, indirectRules, directRules, defaultDataSchema); } // expressions if (expressions != null) { for (int i = 0; i < expressions.length; i++) { final Expression expression = expressions[i]; final String name = expression.getName(); if (name == null) { continue; } final DefaultDataAttributes computedParameterDataAttributes = new DefaultDataAttributes(); computedParameterDataAttributes.merge(globalAttributes, context); computedParameterDataAttributes.merge(new ExpressionsDataAttributes(expression), context); applyRules(indirectRules, directRules, computedParameterDataAttributes); defaultDataSchema.setAttributes(name, computedParameterDataAttributes); } } if (data instanceof MetaTableModel == false) { final int count = data.getColumnCount(); for (int i = 0; i < count; i++) { final String colName = data.getColumnName(i); if (colName == null) { continue; } tableDataAttributes.setup(colName, data.getColumnClass(i), MetaAttributeNames.Core.SOURCE_VALUE_TABLE, colName, globalAttributes); final DefaultDataAttributes computedParameterDataAttributes = new DefaultDataAttributes(); computedParameterDataAttributes.merge(this.tableDataAttributes, context); applyRules(indirectRules, directRules, computedParameterDataAttributes); defaultDataSchema.setAttributes(colName, computedParameterDataAttributes); } } else { final MetaTableModel mt = (MetaTableModel) data; final DefaultDataAttributes tableGlobalAttributes = new DefaultDataAttributes(); tableGlobalAttributes.merge(globalAttributes, context); tableGlobalAttributes.merge(mt.getTableAttributes(), context); try { defaultDataSchema.setTableAttributes(tableGlobalAttributes); } catch (CloneNotSupportedException e) { logger.warn("Unable to copy global data-attributes", e); } final int count = data.getColumnCount(); for (int i = 0; i < count; i++) { final String colName = data.getColumnName(i); if (colName == null) { continue; } final DefaultDataAttributes computedParameterDataAttributes = new DefaultDataAttributes(); computedParameterDataAttributes.merge(tableGlobalAttributes, context); computedParameterDataAttributes.merge(mt.getColumnAttributes(i), context); tableDataAttributes.setup(colName, data.getColumnClass(i), MetaAttributeNames.Core.SOURCE_VALUE_TABLE, null, EmptyDataAttributes.INSTANCE); computedParameterDataAttributes.merge(tableDataAttributes, context); applyRules(indirectRules, directRules, computedParameterDataAttributes); defaultDataSchema.setAttributes(colName, computedParameterDataAttributes); } } return defaultDataSchema; }