Esempio n. 1
0
  public void beforeBody(TableModel model) {
    logger.debug("XlsView.init()");

    moneyFormat =
        model
            .getPreferences()
            .getPreference(PreferencesConstants.TABLE_EXPORTABLE + "format.money");
    if (StringUtils.isEmpty(moneyFormat)) {
      moneyFormat = DEFAULT_MONEY_FORMAT;
    }
    percentFormat =
        model
            .getPreferences()
            .getPreference(PreferencesConstants.TABLE_EXPORTABLE + "format.percent");
    if (StringUtils.isEmpty(percentFormat)) {
      percentFormat = DEFAULT_PERCENT_FORMAT;
    }

    wb = new HSSFWorkbook();
    sheet = wb.createSheet();
    wb.setSheetName(0, "Export Workbook");

    styles = initStyles(wb);
    ps = sheet.getPrintSetup();

    sheet.setAutobreaks(true);
    ps.setFitHeight((short) 1);
    ps.setFitWidth((short) 1);

    createHeader(model);
  }
Esempio n. 2
0
  public String getHtmlDisplay(TableModel model, Column column) {
    HtmlBuilder html = new HtmlBuilder();

    String headerClass = null;
    String sortImage = null;
    String sortOrder = null;

    headerClass = column.getHeaderClass();

    if (TableModelUtils.isSorted(model, column.getAlias())) {
      sortOrder = model.getLimit().getSort().getSortOrder();

      if (sortOrder.equals(TableConstants.SORT_DEFAULT)) {
        sortOrder = TableConstants.SORT_ASC;
      } else if (sortOrder.equals(TableConstants.SORT_ASC)) {
        headerClass =
            model.getPreferences().getPreference(PreferencesConstants.TABLE_HEADER_SORT_CLASS);
        sortImage = BuilderUtils.getImage(model, BuilderConstants.SORT_ASC_IMAGE);
        sortOrder = TableConstants.SORT_DESC;
      } else if (sortOrder.equals(TableConstants.SORT_DESC)) {
        headerClass =
            model.getPreferences().getPreference(PreferencesConstants.TABLE_HEADER_SORT_CLASS);
        sortImage = BuilderUtils.getImage(model, BuilderConstants.SORT_DESC_IMAGE);
        sortOrder = TableConstants.SORT_DEFAULT;
      }
    } else {
      sortOrder = TableConstants.SORT_ASC; // the default
    }

    buildHeaderHtml(html, model, column, headerClass, sortImage, sortOrder);

    return html.toString();
  }
Esempio n. 3
0
    public String header(TableModel model) {
        StringBuffer sb = new StringBuffer();

        Export export = model.getExportHandler().getCurrentExport();
        String headerColor = export.getAttributeAsString(HEADER_COLOR);
        String headerBackgroundColor = export.getAttributeAsString(HEADER_BACKGROUND_COLOR);

        sb.append(" <fo:table-header background-color=\"" + headerBackgroundColor + "\" color=\"" + headerColor + "\"> ");

        sb.append(" <fo:table-row> ");

        List columns = model.getColumnHandler().getHeaderColumns();
        for (Iterator iter = columns.iterator(); iter.hasNext();) {
            Column column = (Column) iter.next();
            String title = column.getCellDisplay();
            sb.append(" <fo:table-cell border=\"solid silver .5px\" text-align=\"center\" display-align=\"center\" padding=\"3pt\"> ");
            sb.append(" <fo:block" + getFont() + ">" + title + "</fo:block> ");
            sb.append(" </fo:table-cell> ");
        }

        sb.append(" </fo:table-row> ");

        sb.append(" </fo:table-header> ");

        return sb.toString();
    }
Esempio n. 4
0
 public ModelLimitFactory(TableModel model) {
   this.model = model;
   this.tableId = model.getTableHandler().getTable().getTableId();
   this.prefixWithTableId = model.getTableHandler().prefixWithTableId();
   this.context = model.getContext();
   this.registry = model.getRegistry();
   this.isExported = getExported();
 }
Esempio n. 5
0
  public Object build(TableModel model, Collection studies) throws Exception {

    Export export = model.getExportInstance();
    export.setView(TableConstants.VIEW_XLS);
    export.setViewResolver(TableConstants.VIEW_XLS);
    export.setImageName(TableConstants.VIEW_XLS);
    export.setText(TableConstants.VIEW_XLS);
    export.setFileName("study_report.xls");
    model.addExport(export);

    return build(model, studies, "Search Results", "/pages/report/createStudyReport");
  }
Esempio n. 6
0
    /**
     * TWEST - New Method that answers a StringBuffer containing the totals
     * information. If no totals exist on the model answer an empty buffer.
     * 
     * The totals row will be given the same style as the header row.
     * 
     * @param model
     * @return StringBuffer containing the complete fo statement for totals
     */
    public StringBuffer totals(TableModel model) {

        StringBuffer sb = new StringBuffer();
        Export export = model.getExportHandler().getCurrentExport();
        String headerColor = export.getAttributeAsString(HEADER_COLOR);
        String headerBackgroundColor = export.getAttributeAsString(HEADER_BACKGROUND_COLOR);

        Column firstCalcColumn = model.getColumnHandler().getFirstCalcColumn();

        if (firstCalcColumn != null) {
            int rows = firstCalcColumn.getCalc().length;
            for (int i = 0; i < rows; i++) {
                sb.append("<fo:table-row>");
                for (Iterator iter = model.getColumnHandler().getColumns().iterator(); iter.hasNext();) {
                    Column column = (Column) iter.next();
                    if (column.isFirstColumn()) {
                        String calcTitle = CalcUtils.getFirstCalcColumnTitleByPosition(model, i);
                        sb.append(" <fo:table-cell border=\"solid silver .5px\" text-align=\"center\" display-align=\"center\" padding=\"3pt\" background-color=\"");
                        sb.append(headerBackgroundColor + "\" color=\"" + headerColor + "\">");
                        sb.append(" <fo:block " + getFont() + ">" + calcTitle);
                        sb.append(" </fo:block></fo:table-cell> ");
                        continue;
                    }
                    if (column.isCalculated()) {
                        sb.append(" <fo:table-cell border=\"solid silver .5px\" text-align=\"center\" display-align=\"center\" padding=\"3pt\" background-color=\"");
                        sb.append(headerBackgroundColor + "\" color=\"" + headerColor + "\"> ");
                        sb.append(" <fo:block " + getFont() + ">");
                        CalcResult calcResult = CalcUtils.getCalcResultsByPosition(model, column, i);
                        Number value = calcResult.getValue();
                        if (value != null) {
                            sb.append(ExtremeUtils.formatNumber(column.getFormat(), value, model.getLocale()));
                        } else {
                            sb.append("n/a");
                        }
                        sb.append("</fo:block> ");
                    } else {
                        sb.append(" <fo:table-cell border=\"solid silver .5px\" text-align=\"center\" display-align=\"center\" padding=\"3pt\" background-color=\"");
                        sb.append(headerBackgroundColor + "\" color=\"" + headerColor + "\"> ");
                        sb.append(" <fo:block " + getFont() + ">");
                        sb.append(" ");
                        sb.append("</fo:block> ");
                    }
                    sb.append(" </fo:table-cell> ");
                }
                sb.append("</fo:table-row>");

            }
        }
        return sb;
    }
  /** {@inheritDoc} */
  public String getHtmlDisplay(TableModel model, Column column) {
    ColumnBuilder columnBuilder = new ColumnBuilder(column);

    columnBuilder.tdStart();

    try {
      Object bean = model.getCurrentRowBean();
      String outageid = BeanUtils.getProperty(bean, "outageid");

      @SuppressWarnings("unchecked")
      Collection<String> selectedoutagesIds =
          (Collection<String>)
              model
                  .getContext()
                  .getSessionAttribute(SuppressOutageCheckBoxConstants.SELECTED_OUTAGES);
      if (selectedoutagesIds != null && selectedoutagesIds.contains(outageid)) {
        columnBuilder
            .getHtmlBuilder()
            .input("hidden")
            .name("chkbx_" + outageid)
            .value(SuppressOutageCheckBoxConstants.SELECTED)
            .xclose();
        columnBuilder
            .getHtmlBuilder()
            .input("checkbox")
            .name(BeanUtils.getProperty(bean, "outageid"));
        columnBuilder.getHtmlBuilder().onclick("setOutageState(this)");
        columnBuilder.getHtmlBuilder().checked();
        columnBuilder.getHtmlBuilder().xclose();
      } else {
        columnBuilder
            .getHtmlBuilder()
            .input("hidden")
            .name("chkbx_" + outageid)
            .value(SuppressOutageCheckBoxConstants.UNSELECTED)
            .xclose();
        columnBuilder
            .getHtmlBuilder()
            .input("checkbox")
            .name(BeanUtils.getProperty(bean, "outageid"));
        columnBuilder.getHtmlBuilder().onclick("setOutageState(this)");
        columnBuilder.getHtmlBuilder().xclose();
      }
    } catch (Throwable e) {
    }

    columnBuilder.tdEnd();
    return columnBuilder.toString();
  }
Esempio n. 8
0
 public Object afterBody(TableModel model) {
     if (model.getLimit().getTotalRows() != 0) {
         xlsfo.append(totals(model));
     }
     xlsfo.append(" </fo:table-body> ");
     xlsfo.append(endRoot());
     return xlsfo.toString();
 }
Esempio n. 9
0
    public void beforeBody(TableModel model) {
        this.font = model.getPreferences().getPreference(FONT);

        xlsfo.append(startRoot());
        xlsfo.append(regionBefore(model));
        xlsfo.append(regionAfter());
        xlsfo.append(columnDefinitions(model));
        xlsfo.append(header(model));
        xlsfo.append(" <fo:table-body> ");
    }
Esempio n. 10
0
    public String regionBefore(TableModel model) {
        StringBuffer sb = new StringBuffer();

        Export export = model.getExportHandler().getCurrentExport();

        String headerBackgroundColor = export.getAttributeAsString(HEADER_BACKGROUND_COLOR);

        sb.append(" <fo:static-content flow-name=\"xsl-region-before\"> ");

        String title = export.getAttributeAsString(HEADER_TITLE);

        sb.append(" <fo:block space-after.optimum=\"15pt\" color=\"" + headerBackgroundColor + "\" font-size=\"17pt\" font-family=\"" + getHeadFont() + "'Times'\">" + title + "</fo:block> ");

        sb.append(" </fo:static-content> ");

        return sb.toString();
    }
Esempio n. 11
0
    public String columnDefinitions(TableModel model) {
        StringBuffer sb = new StringBuffer();

        sb.append(" <fo:flow flow-name=\"xsl-region-body\"> ");

        sb.append(" <fo:block" + getFont() + ">");

        sb.append(" <fo:table table-layout=\"fixed\" font-size=\"10pt\"> ");

        double columnCount = model.getColumnHandler().columnCount();

        double colwidth = 10 / columnCount;

        for (int i = 1; i <= columnCount; i++) {
            sb.append(" <fo:table-column column-number=\"" + i + "\" column-width=\"" + colwidth + "in\"/> ");
        }

        return sb.toString();
    }
Esempio n. 12
0
  private void createHeader(TableModel model) {
    rownum = 0;
    cellnum = 0;
    HSSFRow row = sheet.createRow(rownum);

    List columns = model.getColumnHandler().getHeaderColumns();
    for (Iterator iter = columns.iterator(); iter.hasNext(); ) {
      Column column = (Column) iter.next();
      String title = column.getCellDisplay();
      HSSFCell cell = row.createCell(cellnum);

      // modify by springside
      // cell.setEncoding(HSSFCell.ENCODING_UTF_16);
      // end of modify by springside

      cell.setCellStyle((HSSFCellStyle) styles.get("titleStyle"));
      cell.setCellType(HSSFCell.CELL_TYPE_STRING);
      cell.setCellValue(title);
      int valWidth = (title + "").length() * WIDTH_MULT;
      sheet.setColumnWidth(cell.getCellNum(), (short) valWidth);

      cellnum++;
    }
  }
Esempio n. 13
0
 protected boolean showPagination() {
   return model.getTableHandler().getTable().isShowPagination();
 }
Esempio n. 14
0
  protected void buildHeaderHtml(
      HtmlBuilder html,
      TableModel model,
      Column column,
      String headerClass,
      String sortImage,
      String sortOrder) {
    html.td(2);

    if (StringUtils.isNotEmpty(headerClass)) {
      html.styleClass(headerClass);
    }

    if (StringUtils.isNotEmpty(column.getHeaderStyle())) {
      html.style(column.getHeaderStyle());
    }

    if (StringUtils.isNotEmpty(column.getWidth())) {
      html.width(column.getWidth());
    }

    if (column.isSortable()) {
      if (sortOrder.equals(TableConstants.SORT_ASC)) {
        html.onmouseover(
            "this.className='"
                + BuilderConstants.TABLE_HEADER_SORT_CSS
                + "';this.style.cursor='pointer'");
        if (StringUtils.isNotEmpty(headerClass)) {
          html.onmouseout("this.className='" + headerClass + "';this.style.cursor='default'");
        } else {
          html.onmouseout(
              "this.className='"
                  + BuilderConstants.TABLE_HEADER_CSS
                  + "';this.style.cursor='default'");
        }
      }

      if (sortOrder.equals(TableConstants.SORT_DEFAULT)
          || sortOrder.equals(TableConstants.SORT_DESC)) {
        html.onmouseover("this.style.cursor='pointer'");
        html.onmouseout("this.style.cursor='default'");
      }

      html.onclick(new TableActions(model).getSortAction(column, sortOrder));

      boolean showTooltips = model.getTableHandler().getTable().isShowTooltips();
      if (showTooltips) {
        String headercellTooltip =
            model.getMessages().getMessage(MessagesConstants.COLUMN_HEADERCELL_TOOLTIP_SORT);
        html.title(headercellTooltip + " " + column.getTitle());
      }
    }

    html.close();

    html.append(column.getTitle());

    if (column.isSortable()) {
      if (StringUtils.isNotEmpty(sortImage)) {
        html.nbsp();
        html.img();
        html.src(sortImage);
        html.style("border:0");
        html.alt("Arrow");
        html.xclose();
      }
    }

    html.tdEnd();
  }
Esempio n. 15
0
  public Object build(TableModel model, Collection studies, String title, String action)
      throws Exception {

    Table table = model.getTableInstance();
    table.setTitle(title);

    table.setAction(model.getContext().getContextPath() + action);
    table.setTableId("studies");
    table.setItems(studies);
    table.setOnInvokeAction("buildTable('studies')");
    table.setShowPagination(false);
    table.setSortable(true);
    table.setShowExports(false);
    table.setImagePath(model.getContext().getContextPath() + "/images/table/*.gif");
    model.addTable(table);

    Row row = model.getRowInstance();
    row.setInterceptor("edu.duke.cabig.c3pr.web.ajax.StudyRowInterceptor");
    model.addRow(row);

    Column columnTitle = model.getColumnInstance();
    columnTitle.setTitle("Short Title");
    columnTitle.setProperty("shortTitleText");
    model.addColumn(columnTitle);

    Column columnIdentifier = model.getColumnInstance();
    columnIdentifier.setProperty("primaryIdentifier");
    model.addColumn(columnIdentifier);

    Column columnPhase = model.getColumnInstance();
    columnPhase.setTitle("Phase");
    columnPhase.setProperty("phaseCode");
    model.addColumn(columnPhase);

    Column columnStatus = model.getColumnInstance();
    columnStatus.setTitle("Status");
    columnStatus.setProperty("coordinatingCenterStudyStatus.code");
    model.addColumn(columnStatus);

    Column columnCompanion = model.getColumnInstance();
    columnCompanion.setTitle("Companion Indicator");
    columnCompanion.setProperty("companionIndicatorDisplayValue");
    model.addColumn(columnCompanion);

    // Column columnSite = model.getColumnInstance();
    // columnSite.setTitle("Sites");
    // columnSite.setProperty("printStudySites");
    // model.addColumn(columnSite);

    return model.assemble();
  }