List of usage examples for javax.swing.table TableModel getColumnCount
public int getColumnCount();
From source file:org.pentaho.reporting.engine.classic.core.sorting.SortingDataFactory.java
protected TableModel postProcess(final String query, final DataRow parameters, final TableModel tableModel) { if (tableModel == null) { logger.debug("No data, therefore no sorting."); return null; }/* w ww. j ava 2 s. c o m*/ if (tableModel.getRowCount() == 1 || tableModel.getColumnCount() == 0) { logger.debug("Empty data, therefore no sorting."); return tableModel; } Object o = parameters.get(DataFactory.QUERY_SORT); if ((o instanceof List<?>) == false) { logger.debug("Sort constraints are not in list format."); return tableModel; } List<SortConstraint> sort = validate((List<?>) o); List<SortConstraint> resolvedConstraints = resolveColumnAliases(tableModel, sort); if (resolvedConstraints.isEmpty()) { logger.debug("Resolved sort constraints are empty."); return tableModel; } return sort(tableModel, resolvedConstraints); }
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; }// www.j a v a 2 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); }/*from w w w .j a va2 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 ww w .j av a 2s . 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.java2 s . c om*/ } 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; }
From source file:org.pentaho.reporting.engine.classic.extensions.datasources.pmd.SimplePmdDataFactory.java
private TableModel buildTableModel(final DatabaseMeta databaseMeta, final Query queryObject, final MappedQuery mappedQuery, final DataRow parameters) throws ReportDataFactoryException { initializeDataFactory(databaseMeta, parameters); final ReportParameterValues computedParameterSet = new ReportParameterValues(); computedParameterSet.put(DataFactory.QUERY_LIMIT, parameters.get(DataFactory.QUERY_LIMIT)); computedParameterSet.put(DataFactory.QUERY_TIMEOUT, parameters.get(DataFactory.QUERY_TIMEOUT)); final String[] parameterNames = computeQueryParameter(queryObject, mappedQuery, parameters, computedParameterSet);/*from w w w. j a va2 s .c o m*/ // Add in model parameters if not overridden in report - PRD-3862 // Check to see if timeout is already in the report computeQueryTimeout(queryObject, computedParameterSet); // Check to see if limit is already in the report computeQueryLimit(queryObject, computedParameterSet); // End PRD-3862 fix try { final String sqlQuery = mappedQuery.getQuery(); final TableModel tableModel = sqlReportDataFactory.parametrizeAndQuery(computedParameterSet, sqlQuery, parameterNames); // now lets wrap up the model into a meta-data aware model .. final List<Selection> selections = queryObject.getSelections(); if (selections.size() != tableModel.getColumnCount()) { throw new ReportDataFactoryException("Whatever the query returned, it does not look familiar"); } // cast is safe, as the SQL-Datasource is guaranteed to return a // MetaTableModel return new PmdMetaTableModel((MetaTableModel) tableModel, queryObject.getSelections()); } catch (final SQLTimeoutException e) { //it catch exception only for java 1.6 and jdbc 4 throw new ReportDataFactoryQueryTimeoutException(); } catch (final SQLException e) { //it catch other exception end timeout for jdbc3, so add message from jdbc driver to message throw new ReportDataFactoryException("SQL-query did not execute successfully. " + e.getMessage(), e); } }
From source file:org.pentaho.reporting.engine.classic.extensions.modules.mailer.MailProcessor.java
private static void processRecipients(final MailDefinition definition, final MimeMessage message, final DataFactory dataFactory, final DataRow parameterDataRow) throws ReportDataFactoryException, MessagingException { if (definition.getRecipientsQuery() != null && dataFactory.isQueryExecutable(definition.getRecipientsQuery(), parameterDataRow)) { final TableModel model = wrapWithParameters( dataFactory.queryData(definition.getRecipientsQuery(), parameterDataRow), parameterDataRow); for (int r = 0; r < model.getRowCount(); r++) { String address = null; String name = null;//w w w .j av a 2s. c om String type = "TO"; if (model.getColumnCount() >= 3) { type = (String) model.getValueAt(0, 2); } if (model.getColumnCount() >= 2) { name = (String) model.getValueAt(0, 1); } if (model.getColumnCount() >= 1) { address = (String) model.getValueAt(0, 0); } if (address == null) { continue; } if (name == null) { message.addRecipient(parseType(type), new InternetAddress(address, true)); } else { try { message.addRecipient(parseType(type), new InternetAddress(address, name, "UTF-8")); } catch (UnsupportedEncodingException e) { // Should not happen - UTF-8 is safe to use throw new MessagingException("Failed to encode recipient", e); } } } } }
From source file:org.pentaho.reporting.engine.classic.extensions.modules.mailer.MailProcessor.java
private static DataRow createReportParameterDataRow(final TableModel burstingData, final int row) { final int columnCount = burstingData.getColumnCount(); final String[] columnNames = new String[columnCount]; final Object[] columnValues = new Object[columnCount]; for (int i = 0; i < columnCount; i++) { columnValues[i] = burstingData.getValueAt(row, i); columnNames[i] = burstingData.getColumnName(i); }//from w w w . j a v a2s . co m return new StaticDataRow(columnNames, columnValues); }
From source file:org.pentaho.reporting.platform.plugin.cache.PentahoDataCache.java
public synchronized TableModel put(final DataCacheKey key, final TableModel model) { if (log.isDebugEnabled()) { log.debug("put() called"); }//from ww w. j a v a 2s . co m final IPentahoSession session = PentahoSessionHolder.getSession(); if (cacheManager != null) { if (model.getRowCount() > maximumRows) { if (log.isDebugEnabled()) { log.debug("too many rows (" + model.getRowCount() + " > " + maximumRows + ") not caching."); } return model; } // Only copy if safe to do so. Check for whitelist of good column types .. if (CachableTableModel.isSafeToCache(model) == false) { if (log.isDebugEnabled()) { log.debug("model is not safe to cache. not caching."); } return model; } if (log.isDebugEnabled()) { log.debug("placing model in cache for session " + session.getId() + " (rows=" + model.getColumnCount() + ")"); } final TableModel cacheModel = new CachableTableModel(model); cacheManager.putInRegionCache(CACHE_NAME, new CompositeKey(session.getId(), key), cacheModel); } return model; }
From source file:org.pentaho.reporting.ui.datasources.table.TableEditor.java
/** * Creates default columns for the table from the data model using the <code>getColumnCount</code> method defined in * the <code>TableModel</code> interface. * <p/>// w ww .j av a 2 s . c om * Clears any existing columns before creating the new columns based on information from the model. * * @see #getAutoCreateColumnsFromModel */ public void createDefaultColumnsFromModel() { final TableModel m = getModel(); if (m != null) { // Remove any current columns final TableColumnModel cm = getColumnModel(); while (cm.getColumnCount() > 0) { cm.removeColumn(cm.getColumn(0)); } // Create new columns from the data model info for (int i = 0; i < m.getColumnCount(); i++) { if (i == 0) { final TableColumn column = new TableColumn(i); column.setCellRenderer(tableHeader.getDefaultRenderer()); addColumn(column); continue; } final EditableHeaderTableColumn newColumn = new EditableHeaderTableColumn(i); newColumn.setHeaderEditor(new TypedHeaderCellEditor()); addColumn(newColumn); } } }