Ejemplo n.º 1
0
  protected void fillTable(
      String name,
      BandData parentBand,
      TableManager tableManager,
      XDispatchHelper xDispatchHelper,
      int numberOfRowWithAliases)
      throws com.sun.star.uno.Exception {
    // Lock clipboard, cause uno uses it to grow tables, relevant for desktops
    synchronized (clipboardLock) {
      XTextTable xTextTable = tableManager.getXTextTable();
      if (officeIntegration.isDisplayDeviceAvailable()) {
        clearClipboard();
      }

      List<BandData> childrenByName = parentBand.getChildrenByName(name);
      for (BandData ignored : childrenByName) {
        tableManager.copyRow(
            xDispatchHelper,
            as(XTextDocument.class, xComponent).getCurrentController(),
            numberOfRowWithAliases);
      }

      int i = numberOfRowWithAliases;
      for (BandData child : childrenByName) {
        if (name.equals(child.getName())) {
          fillRow(child, tableManager, i);
          i++;
        }
      }
      tableManager.deleteRow(i);
    }
  }
Ejemplo n.º 2
0
  protected void fillTables(XDispatchHelper xDispatchHelper) throws com.sun.star.uno.Exception {
    List<String> tablesNames = TableManager.getTablesNames(xComponent);

    for (String tableName : tablesNames) {
      TableManager tableManager = new TableManager(xComponent, tableName);
      BandFinder bandFinder = new BandFinder(tableManager).find();

      BandData band = bandFinder.getBand();
      String bandName = bandFinder.getBandName();
      int numberOfRowWithAliases = tableManager.findRowWithAliases();

      if (band != null && numberOfRowWithAliases > -1) {
        XTextTable xTextTable = tableManager.getXTextTable();

        // try to select one cell without it workaround
        int columnCount = xTextTable.getColumns().getCount();
        if (columnCount < 2) {
          xTextTable.getColumns().insertByIndex(columnCount, 1);
        }

        fillTable(
            band.getName(),
            band.getParentBand(),
            tableManager,
            xDispatchHelper,
            numberOfRowWithAliases);

        // end of workaround ->
        if (columnCount < 2) {
          xTextTable.getColumns().removeByIndex(columnCount, 1);
        }
      } else if (numberOfRowWithAliases > -1
          && rootBand.getFirstLevelBandDefinitionNames() != null
          && rootBand.getFirstLevelBandDefinitionNames().contains(bandName)) {
        // if table is linked with band and has aliases on it, but no band data found -
        // we are removing the row
        tableManager.deleteRow(numberOfRowWithAliases);
      }
    }
  }
Ejemplo n.º 3
0
  protected void insertValue(
      XText text, XTextRange textRange, BandData band, String parameterName) {
    String fullParameterName = band.getName() + "." + parameterName;
    Object paramValue = band.getParameterValue(parameterName);

    Map<String, ReportFieldFormat> formats = rootBand.getReportFieldFormats();
    try {
      boolean handled = false;

      if (paramValue != null) {
        if ((formats != null) && (formats.containsKey(fullParameterName))) {
          String format = formats.get(fullParameterName).getFormat();
          // Handle doctags
          for (ContentInliner contentInliner : contentInliners) {
            Matcher matcher = contentInliner.getTagPattern().matcher(format);
            if (matcher.find()) {
              contentInliner.inlineToDoc(officeComponent, textRange, text, paramValue, matcher);
              handled = true;
            }
          }
        }
        if (!handled) {
          String valueString = formatValue(paramValue, parameterName, fullParameterName);
          text.insertString(textRange, valueString, true);
        }
      } else {
        text.insertString(textRange, "", true);
      }
    } catch (Exception ex) {
      throw wrapWithReportingException(
          String.format(
              "An error occurred while inserting parameter [%s] into text line [%s]",
              parameterName, text.getString()),
          ex);
    }
  }