List of usage examples for javax.swing.table TableModel getColumnClass
public Class<?> getColumnClass(int columnIndex);
From source file:Main.java
/** * Auto fit the column of a table./*from ww w . j a va2 s . c om*/ * @param table the table for which to auto fit the columns. * @param columnIndex the index of the column to auto fit. * @param maxWidth the maximum width that a column can take (like Integer.MAX_WIDTH). */ public static void autoFitTableColumn(JTable table, int columnIndex, int maxWidth) { TableModel model = table.getModel(); TableCellRenderer headerRenderer = table.getTableHeader().getDefaultRenderer(); int rowCount = table.getRowCount(); for (int i = columnIndex >= 0 ? columnIndex : model.getColumnCount() - 1; i >= 0; i--) { TableColumn column = table.getColumnModel().getColumn(i); int headerWidth = headerRenderer .getTableCellRendererComponent(table, column.getHeaderValue(), false, false, 0, 0) .getPreferredSize().width; int cellWidth = 0; for (int j = 0; j < rowCount; j++) { Component comp = table.getDefaultRenderer(model.getColumnClass(i)) .getTableCellRendererComponent(table, table.getValueAt(j, i), false, false, 0, i); int preferredWidth = comp.getPreferredSize().width; // Artificial space to look nicer. preferredWidth += 10; cellWidth = Math.max(cellWidth, preferredWidth); } // Artificial space for the sort icon. headerWidth += 20; column.setPreferredWidth(Math.min(Math.max(headerWidth, cellWidth) + table.getRowMargin(), maxWidth)); if (columnIndex >= 0) { break; } } }
From source file:Main.java
/** * Adjusts the widths and heights of the cells of the supplied table to fit their contents. *///from w w w .j a va2 s . c o m public static void sizeToContents(JTable table) { TableModel model = table.getModel(); TableColumn column = null; Component comp = null; int ccount = table.getColumnModel().getColumnCount(), rcount = model.getRowCount(), cellHeight = 0; for (int cc = 0; cc < ccount; cc++) { int headerWidth = 0, cellWidth = 0; column = table.getColumnModel().getColumn(cc); try { comp = column.getHeaderRenderer().getTableCellRendererComponent(null, column.getHeaderValue(), false, false, 0, 0); headerWidth = comp.getPreferredSize().width; } catch (NullPointerException e) { // getHeaderRenderer() this doesn't work in 1.3 } for (int rr = 0; rr < rcount; rr++) { Object cellValue = model.getValueAt(rr, cc); comp = table.getDefaultRenderer(model.getColumnClass(cc)).getTableCellRendererComponent(table, cellValue, false, false, 0, cc); Dimension psize = comp.getPreferredSize(); cellWidth = Math.max(psize.width, cellWidth); cellHeight = Math.max(psize.height, cellHeight); } column.setPreferredWidth(Math.max(headerWidth, cellWidth)); } if (cellHeight > 0) { table.setRowHeight(cellHeight); } }
From source file:com.limegroup.gnutella.gui.GUIUtils.java
/** * It will adjust the column width to match the widest element. * (You might not want to use this for every column, consider some columns might be really long) * @param model/*from w ww. ja v a2s . c o m*/ * @param columnIndex * @param table * @return */ public static void adjustColumnWidth(TableModel model, int columnIndex, int maxWidth, int rightPadding, JTable table) { if (columnIndex > model.getColumnCount() - 1) { //invalid column index return; } if (!model.getColumnClass(columnIndex).equals(String.class)) { return; } String longestValue = ""; for (int row = 0; row < model.getRowCount(); row++) { String strValue = (String) model.getValueAt(row, columnIndex); if (strValue != null && strValue.length() > longestValue.length()) { longestValue = strValue; } } Graphics g = table.getGraphics(); try { int suggestedWidth = (int) g.getFontMetrics(table.getFont()).getStringBounds(longestValue, g) .getWidth(); table.getColumnModel().getColumn(columnIndex) .setPreferredWidth(((suggestedWidth > maxWidth) ? maxWidth : suggestedWidth) + rightPadding); } catch (Exception e) { table.getColumnModel().getColumn(columnIndex).setPreferredWidth(maxWidth); e.printStackTrace(); } }
From source file:edu.ku.brc.specify.config.init.PrintTableHelper.java
/** * @param model/*from www . j a v a 2s. c o m*/ * @return * @throws Exception */ public DynamicReport buildReport(final TableModel model, final PageSetupDlg pageSetupDlg) throws Exception { // Find a Sans Serif Font on the System String fontName = null; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); for (java.awt.Font font : ge.getAllFonts()) { String fName = font.getFamily().toLowerCase(); if (StringUtils.contains(fName, "sansserif") || StringUtils.contains(fName, "arial") || StringUtils.contains(fName, "verdana")) { fontName = font.getFamily(); break; } } if (fontName == null) { fontName = Font._FONT_TIMES_NEW_ROMAN; } /** * Creates the DynamicReportBuilder and sets the basic options for the report */ FastReportBuilder drb = new FastReportBuilder(); Style columDetail = new Style(); //columDetail.setBorder(Border.THIN); Style columDetailWhite = new Style(); //columDetailWhite.setBorder(Border.THIN); columDetailWhite.setBackgroundColor(Color.WHITE); columDetailWhite.setFont(new Font(10, fontName, false)); columDetailWhite.setHorizontalAlign(HorizontalAlign.CENTER); columDetailWhite.setBlankWhenNull(true); Style columDetailWhiteBold = new Style(); //columDetailWhiteBold.setBorder(Border.THIN); columDetailWhiteBold.setBackgroundColor(Color.WHITE); Style titleStyle = new Style(); titleStyle.setFont(new Font(12, fontName, true)); // Odd Row Style Style oddRowStyle = new Style(); //oddRowStyle.setBorder(Border.NO_BORDER); oddRowStyle.setHorizontalAlign(HorizontalAlign.CENTER); Color veryLightGrey = new Color(240, 240, 240); oddRowStyle.setBackgroundColor(veryLightGrey); oddRowStyle.setTransparency(Transparency.OPAQUE); // Create Column Headers for the Report for (int i = 0; i < model.getColumnCount(); i++) { String colName = model.getColumnName(i); Class<?> dataClass = model.getColumnClass(i); if (dataClass == Object.class) { if (model.getRowCount() > 0) { Object data = model.getValueAt(0, i); if (data != null) { dataClass = data.getClass(); } else { // Column in first row was null so search down the rows // for a non-empty cell for (int j = 1; j < model.getRowCount(); j++) { data = model.getValueAt(j, i); if (dataClass != null) { dataClass = data.getClass(); break; } } if (dataClass == null) { dataClass = String.class; } } } } ColumnBuilder colBldr = ColumnBuilder.getInstance().setColumnProperty(colName, dataClass.getName()); int bracketInx = colName.indexOf('['); if (bracketInx > -1) { colName = colName.substring(0, bracketInx - 1); } colBldr.setTitle(colName); colBldr.setStyle(columDetailWhite); AbstractColumn column = colBldr.build(); drb.addColumn(column); Style headerStyle = new Style(); headerStyle.setFont(new Font(11, fontName, true)); //headerStyle.setBorder(Border.THIN); headerStyle.setHorizontalAlign(HorizontalAlign.CENTER); headerStyle.setVerticalAlign(VerticalAlign.MIDDLE); headerStyle.setBackgroundColor(new Color(80, 80, 80)); headerStyle.setTransparency(Transparency.OPAQUE); headerStyle.setTextColor(new Color(255, 255, 255)); column.setHeaderStyle(headerStyle); } drb.setTitle(pageSetupDlg.getPageTitle()); drb.setTitleStyle(titleStyle); drb.setLeftMargin(20); drb.setRightMargin(20); drb.setTopMargin(10); drb.setBottomMargin(10); drb.setPrintBackgroundOnOddRows(true); drb.setOddRowBackgroundStyle(oddRowStyle); drb.setColumnsPerPage(new Integer(1)); drb.setUseFullPageWidth(true); drb.setColumnSpace(new Integer(5)); // This next line causes an exception // Event with DynamicReport 3.0.12 and JasperReposrts 3.7.3 //drb.addAutoText(AutoText.AUTOTEXT_PAGE_X_OF_Y, AutoText.POSITION_FOOTER, AutoText.ALIGMENT_CENTER); Page[] pageSizes = new Page[] { Page.Page_Letter_Portrait(), Page.Page_Legal_Portrait(), Page.Page_A4_Portrait(), Page.Page_Letter_Landscape(), Page.Page_Legal_Landscape(), Page.Page_A4_Landscape() }; int pageSizeInx = pageSetupDlg.getPageSize() + (pageSetupDlg.isPortrait() ? 0 : 3); drb.setPageSizeAndOrientation(pageSizes[pageSizeInx]); DynamicReport dr = drb.build(); return dr; }
From source file:edu.ku.brc.specify.tasks.ReportsBaseTask.java
/** * @param model//w w w. j ava2s . com * @return * @throws Exception */ public DynamicReport buildReport(final TableModel model, final PageSetupDlg pageSetupDlg) throws Exception { // Find a Sans Serif Font on the System String fontName = null; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); for (java.awt.Font font : ge.getAllFonts()) { String fName = font.getFamily().toLowerCase(); if (StringUtils.contains(fName, "sansserif") || StringUtils.contains(fName, "arial") || StringUtils.contains(fName, "verdana")) { fontName = font.getFamily(); } } if (fontName == null) { fontName = Font._FONT_TIMES_NEW_ROMAN; } /** * Creates the DynamicReportBuilder and sets the basic options for the report */ FastReportBuilder drb = new FastReportBuilder(); Style columDetail = new Style(); //columDetail.setBorder(Border.THIN); Style columDetailWhite = new Style(); //columDetailWhite.setBorder(Border.THIN); columDetailWhite.setBackgroundColor(Color.WHITE); columDetailWhite.setFont(new Font(10, fontName, true)); columDetailWhite.setHorizontalAlign(HorizontalAlign.CENTER); columDetailWhite.setBlankWhenNull(true); Style columDetailWhiteBold = new Style(); //columDetailWhiteBold.setBorder(Border.THIN); columDetailWhiteBold.setBackgroundColor(Color.WHITE); Style titleStyle = new Style(); titleStyle.setFont(new Font(14, fontName, true)); /*Style numberStyle = new Style(); numberStyle.setHorizontalAlign(HorizontalAlign.RIGHT); Style amountStyle = new Style(); amountStyle.setHorizontalAlign(HorizontalAlign.RIGHT); amountStyle.setBackgroundColor(Color.cyan); amountStyle.setTransparency(Transparency.OPAQUE);*/ //Font dataRowFont = new Font(10, Font._FONT_VERDANA, true); // Odd Row Style Style oddRowStyle = new Style(); //oddRowStyle.setBorder(Border.NO_BORDER); //oddRowStyle.setFont(dataRowFont); oddRowStyle.setHorizontalAlign(HorizontalAlign.CENTER); Color veryLightGrey = new Color(240, 240, 240); oddRowStyle.setBackgroundColor(veryLightGrey); oddRowStyle.setTransparency(Transparency.OPAQUE); // Event Row Style //Style evenRowStyle = new Style(); //evenRowStyle.setBorder(Border.NO_BORDER); //evenRowStyle.setFont(dataRowFont); // Create Column Headers for the Report for (int i = 0; i < model.getColumnCount(); i++) { String colName = model.getColumnName(i); Class<?> dataClass = model.getColumnClass(i); if (dataClass == Object.class) { if (model.getRowCount() > 0) { Object data = model.getValueAt(0, i); if (data != null) { dataClass = data.getClass(); } else { // Column in first row was null so search down the rows // for a non-empty cell for (int j = 1; j < model.getRowCount(); j++) { data = model.getValueAt(j, i); if (dataClass != null) { dataClass = data.getClass(); break; } } if (dataClass == null) { dataClass = String.class; } } } } ColumnBuilder colBldr = ColumnBuilder.getInstance().setColumnProperty(colName, dataClass.getName()); int bracketInx = colName.indexOf('['); if (bracketInx > -1) { colName = colName.substring(0, bracketInx - 1); } colBldr.setTitle(colName); //colBldr.setWidth(new Integer(100)); colBldr.setStyle(columDetailWhite); //colBldr.setHeaderStyle(columDetailWhite); AbstractColumn column = colBldr.build(); drb.addColumn(column); Style headerStyle = new Style(); headerStyle.setFont(new Font(12, fontName, true)); //headerStyle.setBorder(Border.THIN); headerStyle.setHorizontalAlign(HorizontalAlign.CENTER); headerStyle.setVerticalAlign(VerticalAlign.MIDDLE); headerStyle.setBackgroundColor(new Color(80, 80, 80)); headerStyle.setTransparency(Transparency.OPAQUE); headerStyle.setTextColor(new Color(255, 255, 255)); column.setHeaderStyle(headerStyle); } drb.setTitle(pageSetupDlg.getPageTitle()); drb.setTitleStyle(titleStyle); //drb.setTitleHeight(new Integer(30)); //drb.setSubtitleHeight(new Integer(20)); //drb.setDetailHeight(new Integer(15)); //drb.setDefaultStyles(null, null, null, evenRowStyle); drb.setLeftMargin(20); drb.setRightMargin(20); drb.setTopMargin(10); drb.setBottomMargin(10); drb.setPrintBackgroundOnOddRows(true); drb.setOddRowBackgroundStyle(oddRowStyle); drb.setColumnsPerPage(new Integer(1)); drb.setUseFullPageWidth(true); drb.setColumnSpace(new Integer(5)); // This next line causes an exception // Event with DynamicReport 3.0.12 and JasperReposrts 3.7.3 //drb.addAutoText(AutoText.AUTOTEXT_PAGE_X_OF_Y, AutoText.POSITION_FOOTER, AutoText.ALIGMENT_CENTER); Page[] pageSizes = new Page[] { Page.Page_Letter_Portrait(), Page.Page_Legal_Portrait(), Page.Page_A4_Portrait(), Page.Page_Letter_Landscape(), Page.Page_Legal_Landscape(), Page.Page_A4_Landscape() }; int pageSizeInx = pageSetupDlg.getPageSize() + (pageSetupDlg.isPortrait() ? 0 : 3); drb.setPageSizeAndOrientation(pageSizes[pageSizeInx]); DynamicReport dr = drb.build(); return dr; }
From source file:edu.ku.brc.specify.tasks.subpane.wb.WorkbenchPaneSS.java
/** * Adjust all the column width for the data in the column, this may be handles with JDK 1.6 (6.) * @param tableArg the table that should have it's columns adjusted *//*from w w w. jav a 2 s . co m*/ private void initColumnSizes(final JTable tableArg, final JButton theSaveBtn) throws Exception { TableModel tblModel = tableArg.getModel(); TableColumn column = null; Component comp = null; int headerWidth = 0; int cellWidth = 0; Element uploadDefs = null; if (WorkbenchTask.isCustomizedSchema()) { uploadDefs = XMLHelper.readFileToDOM4J( new File(UIRegistry.getAppDataDir() + File.separator + "specify_workbench_upload_def.xml")); } else { uploadDefs = XMLHelper.readDOMFromConfigDir("specify_workbench_upload_def.xml"); } //UIRegistry.getInstance().hookUpUndoableEditListener(cellEditor); Vector<WorkbenchTemplateMappingItem> wbtmis = new Vector<WorkbenchTemplateMappingItem>(); wbtmis.addAll(workbench.getWorkbenchTemplate().getWorkbenchTemplateMappingItems()); Collections.sort(wbtmis); DBTableIdMgr databaseSchema = WorkbenchTask.getDatabaseSchema(); columnMaxWidths = new Integer[tableArg.getColumnCount()]; for (int i = 0; i < wbtmis.size() /*tableArg.getColumnCount()*/; i++) { TableCellRenderer headerRenderer = tableArg.getColumnModel().getColumn(i).getHeaderRenderer(); WorkbenchTemplateMappingItem wbtmi = wbtmis.elementAt(i); // Now go retrieve the data length int fieldWidth = WorkbenchDataItem.getMaxWBCellLength(); DBTableInfo ti = databaseSchema.getInfoById(wbtmi.getSrcTableId()); if (ti != null) { DBFieldInfo fi = ti.getFieldByName(wbtmi.getFieldName()); if (fi != null) { wbtmi.setFieldInfo(fi); //System.out.println(fi.getName()+" "+fi.getLength()+" "+fi.getType()); if (RecordTypeCodeBuilder.getTypeCode(fi) == null && fi.getLength() > 0) { fieldWidth = Math.min(fi.getLength(), WorkbenchDataItem.getMaxWBCellLength()); } } else { log.error("Can't find field with name [" + wbtmi.getFieldName() + "]"); } } else { log.error("Can't find table [" + wbtmi.getSrcTableId() + "]"); } columnMaxWidths[i] = new Integer(fieldWidth); GridCellEditor cellEditor = getCellEditor(wbtmi, fieldWidth, theSaveBtn, uploadDefs); column = tableArg.getColumnModel().getColumn(i); comp = headerRenderer.getTableCellRendererComponent(null, column.getHeaderValue(), false, false, 0, 0); headerWidth = comp.getPreferredSize().width; comp = tableArg.getDefaultRenderer(tblModel.getColumnClass(i)).getTableCellRendererComponent(tableArg, tblModel.getValueAt(0, i), false, false, 0, i); cellWidth = comp.getPreferredSize().width; //comp.setBackground(Color.WHITE); int maxWidth = headerWidth + 10; TableModel m = tableArg.getModel(); FontMetrics fm = comp.getFontMetrics(comp.getFont()); for (int row = 0; row < tableArg.getModel().getRowCount(); row++) { String text = m.getValueAt(row, i).toString(); maxWidth = Math.max(maxWidth, fm.stringWidth(text) + 10); //log.debug(i+" "+maxWidth); } //XXX: Before Swing 1.1 Beta 2, use setMinWidth instead. //log.debug(Math.max(maxWidth, cellWidth)); //log.debug(Math.min(Math.max(maxWidth, cellWidth), 400)); column.setPreferredWidth(Math.min(Math.max(maxWidth, cellWidth), 400)); column.setCellEditor(cellEditor); } //tableArg.setCellEditor(cellEditor); }
From source file:org.apache.cayenne.swing.TableBinding.java
protected void resizeColumns(Object[] sampleLongValues) { TableCellRenderer headerRenderer = table.getTableHeader().getDefaultRenderer(); TableColumnModel columnModel = table.getColumnModel(); TableModel tableModel = table.getModel(); for (int i = 0; i < columnModel.getColumnCount(); i++) { TableColumn column = columnModel.getColumn(i); Component header = headerRenderer.getTableCellRendererComponent(null, column.getHeaderValue(), false, false, 0, 0);/*from w ww . j av a 2s.c om*/ int headerWidth = header.getPreferredSize().width; if (sampleLongValues[i] != null) { Component bigCell = table.getDefaultRenderer(tableModel.getColumnClass(i)) .getTableCellRendererComponent(table, sampleLongValues[i], false, false, 0, i); int cellWidth = bigCell.getPreferredSize().width; column.setPreferredWidth(Math.max(headerWidth, cellWidth)); } else { column.setPreferredWidth(headerWidth); } } }
From source file:org.pentaho.reporting.engine.classic.core.cache.CachingDataFactory.java
/** * Prints a table model to standard output. * * @param mod/*ww w . j a v a 2 s . 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.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 v a2 s . 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();/* w w w . j a v a 2s.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; }