private Object getValueWithoutWebEditorsFormat(int row, int column) { Object r = original.getValueAt(row, column); if (r instanceof Boolean) { if (((Boolean) r).booleanValue()) return XavaResources.getString(locale, "yes"); return XavaResources.getString(locale, "no"); } if (withValidValues) { MetaProperty p = getMetaProperty(column); if (p.hasValidValues()) { return p.getValidValueLabel(locale, original.getValueAt(row, column)); } } if (r instanceof java.util.Date) { MetaProperty p = getMetaProperty(column); // In order to use the type declared by the developer // and not the one returned by JDBC or the JPA engine if (java.sql.Time.class.isAssignableFrom(p.getType())) { return DateFormat.getTimeInstance(DateFormat.SHORT, locale).format(r); } if (java.sql.Timestamp.class.isAssignableFrom(p.getType())) { DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); return dateFormat.format(r); } return DateFormat.getDateInstance(DateFormat.SHORT, locale).format(r); } if (r instanceof BigDecimal) { return formatBigDecimal(r, locale); } return r; }
private Object getValueWithWebEditorsFormat(int row, int column) { Object r = original.getValueAt(row, column); MetaProperty metaProperty = getMetaProperty(column); String result = WebEditors.format(this.request, metaProperty, r, null, "", true); if (isHtml(result)) { // this avoids that the report shows html content result = WebEditors.format(this.request, metaProperty, r, null, "", false); } return result; }
/** Overrides <code>JComponent</code>'s <code>getToolTipText</code> */ public String getToolTipText(MouseEvent e) { String tip = null; java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); // int colIndex = columnAtPoint(p); // int realColumnIndex = convertColumnIndexToModel(colIndex); TableModel model = getModel(); tip = (String) model.getValueAt(rowIndex, 1); return tip; }
public void calculaSumas() { try { TableModel tm = this.tablaPrincipal.getModel(); int tamTabla = tm.getRowCount(); double costo, cantidad, totalFila, sumaTotal; sumaTotal = 0.0; for (int i = 0; i < tamTabla; i++) { if (tm.getValueAt(i, 2) != null && tm.getValueAt(i, 3) != null) { costo = Double.valueOf(String.valueOf(tm.getValueAt(i, 2))); cantidad = Double.valueOf(String.valueOf(tm.getValueAt(i, 3))); totalFila = costo * cantidad; tm.setValueAt(totalFila, i, 4); sumaTotal += totalFila; } } txtSumaTotal.setText(String.valueOf(sumaTotal)); } catch (Exception e) { Dialogos.lanzarAlerta("Cantidades invalidas, puede que algun numero este mal escrito"); } }
private int[] getWidths(TableModel tableModel) { int[] widths = new int[tableModel.getColumnCount()]; for (int r = 0; r < Math.min(tableModel.getRowCount(), 500); r++) { // 500 is not for performance, but for using only a sample of data with huge table for (int c = 0; c < tableModel.getColumnCount(); c++) { Object o = tableModel.getValueAt(r, c); if (o instanceof String) { String s = ((String) o).trim(); if (s.length() > widths[c]) widths[c] = s.length(); } } } return widths; }
private static void setColumnWidths(JTable table, MetricTableSpecification tableSpecification) { final TableModel model = table.getModel(); final TableColumnModel columnModel = table.getColumnModel(); final List<Integer> columnWidths = tableSpecification.getColumnWidths(); final List<String> columnOrder = tableSpecification.getColumnOrder(); if (columnWidths != null && !columnWidths.isEmpty()) { final int columnCount = model.getColumnCount(); for (int i = 0; i < columnCount; i++) { final String columnName = model.getColumnName(i); final int index = columnOrder.indexOf(columnName); if (index != -1) { final Integer width = columnWidths.get(index); final TableColumn column = columnModel.getColumn(i); column.setPreferredWidth(width.intValue()); } } } else { final Graphics graphics = table.getGraphics(); final Font font = table.getFont(); final FontMetrics fontMetrics = table.getFontMetrics(font); final int rowCount = model.getRowCount(); int maxFirstColumnWidth = 100; for (int i = 0; i < rowCount; i++) { final String name = (String) model.getValueAt(i, 0); if (name != null) { final Rectangle2D stringBounds = fontMetrics.getStringBounds(name, graphics); final double stringWidth = stringBounds.getWidth(); if (stringWidth > maxFirstColumnWidth) { maxFirstColumnWidth = (int) stringWidth; } } } final int allocatedFirstColumnWidth = Math.min(300, maxFirstColumnWidth + 5); final TableColumn column = columnModel.getColumn(0); column.setPreferredWidth(allocatedFirstColumnWidth); } }
/** * Return a label for the given point on the graph axis * * @param value the value on the graph * @return the label for the given value */ private String getLeafLabel(double value) { String label = Double.toString(value); try { int v = (int) value; int r = idxMap.getSrc(v); if (r < 0 || r >= tm.getRowCount()) { return ""; } if (labelColumn >= 0 && labelColumn < tm.getColumnCount()) { Object o = tm.getValueAt(r, labelColumn); return o != null ? o.toString() : ""; } } catch (Exception ex) { ExceptionHandler.popupException("" + ex); } try { label = Integer.toString((int) value); } catch (Exception ex) { ExceptionHandler.popupException("" + ex); } return label; }
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { Locales.setCurrent(request); if (Users.getCurrent() == null) { // for a bug in websphere portal 5.1 with Domino LDAP Users.setCurrent((String) request.getSession().getAttribute("xava.user")); } request.getParameter("application"); // for a bug in websphere 5.1 request.getParameter("module"); // for a bug in websphere 5.1 Tab tab = (Tab) request.getSession().getAttribute("xava_reportTab"); int[] selectedRowsNumber = (int[]) request.getSession().getAttribute("xava_selectedRowsReportTab"); Map[] selectedKeys = (Map[]) request.getSession().getAttribute("xava_selectedKeysReportTab"); int[] selectedRows = getSelectedRows(selectedRowsNumber, selectedKeys, tab); request.getSession().removeAttribute("xava_selectedRowsReportTab"); Integer columnCountLimit = (Integer) request.getSession().getAttribute("xava_columnCountLimitReportTab"); request.getSession().removeAttribute("xava_columnCountLimitReportTab"); setDefaultSchema(request); String user = (String) request.getSession().getAttribute("xava_user"); request.getSession().removeAttribute("xava_user"); Users.setCurrent(user); String uri = request.getRequestURI(); if (uri.endsWith(".pdf")) { InputStream is; JRDataSource ds; Map parameters = new HashMap(); synchronized (tab) { tab.setRequest(request); parameters.put("Title", tab.getTitle()); parameters.put("Organization", getOrganization()); parameters.put("Date", getCurrentDate()); for (String totalProperty : tab.getTotalPropertiesNames()) { parameters.put(totalProperty + "__TOTAL__", getTotal(request, tab, totalProperty)); } TableModel tableModel = getTableModel(request, tab, selectedRows, false, true, null); tableModel.getValueAt(0, 0); if (tableModel.getRowCount() == 0) { generateNoRowsPage(response); return; } is = getReport(request, response, tab, tableModel, columnCountLimit); ds = new JRTableModelDataSource(tableModel); } JasperPrint jprint = JasperFillManager.fillReport(is, parameters, ds); response.setContentType("application/pdf"); response.setHeader( "Content-Disposition", "inline; filename=\"" + getFileName(tab) + ".pdf\""); JasperExportManager.exportReportToPdfStream(jprint, response.getOutputStream()); } else if (uri.endsWith(".csv")) { String csvEncoding = XavaPreferences.getInstance().getCSVEncoding(); if (!Is.emptyString(csvEncoding)) { response.setCharacterEncoding(csvEncoding); } response.setContentType("text/x-csv"); response.setHeader( "Content-Disposition", "inline; filename=\"" + getFileName(tab) + ".csv\""); synchronized (tab) { tab.setRequest(request); response .getWriter() .print( TableModels.toCSV( getTableModel(request, tab, selectedRows, true, false, columnCountLimit))); } } else { throw new ServletException( XavaResources.getString("report_type_not_supported", "", ".pdf .csv")); } } catch (Exception ex) { log.error(ex.getMessage(), ex); throw new ServletException(XavaResources.getString("report_error")); } finally { request.getSession().removeAttribute("xava_reportTab"); } }
public Object getValueAt(int row, int column) { return tableModel.getValueAt(modelIndex(row), column); }