Beispiel #1
0
  protected ColumnFamily readColumnFamily(ReadCommand command, int consistency_level)
      throws InvalidRequestException {
    String cfName = command.getColumnFamilyName();
    ThriftValidation.validateKey(command.key);

    if (consistency_level == ConsistencyLevel.ZERO) {
      throw new InvalidRequestException(
          "Consistency level zero may not be applied to read operations");
    }
    if (consistency_level == ConsistencyLevel.ALL) {
      throw new InvalidRequestException(
          "Consistency level all is not yet supported on read operations");
    }

    Row row;
    try {
      row = StorageProxy.readProtocol(command, consistency_level);
    } catch (IOException e) {
      throw new RuntimeException(e);
    } catch (TimeoutException e) {
      throw new RuntimeException(e);
    }

    if (row == null) {
      return null;
    }
    return row.getColumnFamily(cfName);
  }
Beispiel #2
0
 @Override
 public void writeRow(List<?> row) {
   Row record = sheet.createRow(sheet.getLastRowNum() + 1);
   for (int i = 0; i < row.size(); i++) {
     Cell cell = record.createCell(i);
     Object value = row.get(i);
     if (value == null) {
       cell.setCellValue("");
     } else if (value instanceof String) {
       cell.setCellType(Cell.CELL_TYPE_STRING);
       cell.setCellValue((String) value);
     } else if (value instanceof Number) {
       cell.setCellType(Cell.CELL_TYPE_NUMERIC);
       cell.setCellValue(converters.convert(value, Double.class));
     } else if (value instanceof Date || value instanceof DateTime || value instanceof Calendar) {
       cell.setCellType(Cell.CELL_TYPE_NUMERIC);
       cell.setCellStyle(dateCellStyle);
       cell.setCellValue(converters.convert(value, Date.class));
     } else if (value instanceof Boolean) {
       cell.setCellType(Cell.CELL_TYPE_BOOLEAN);
       cell.setCellValue((Boolean) value);
     } else {
       cell.setCellType(Cell.CELL_TYPE_STRING);
       cell.setCellValue(converters.convert(value, String.class));
     }
   }
 }
Beispiel #3
0
 public int compare(Object p1, Object p2) {
   Row r1 = (Row) p1;
   Row r2 = (Row) p2;
   Comparable val1 = (Comparable) r1.get(mFieldName);
   Comparable val2 = (Comparable) r2.get(mFieldName);
   return val1.compareTo(val2);
 }
Beispiel #4
0
 public Row select(String[] pFieldNames) {
   RowFormat newFormat = mFormat.select(pFieldNames);
   Row newRow = (Row) newFormat.getRowFactory().makeRow();
   for (int i = 0; i < pFieldNames.length; i++) {
     String fieldName = pFieldNames[i];
     newRow.set(fieldName, get(fieldName));
   }
   return newRow;
 }
 private static void checkExecuteResultSet(ResultSet rs, String key) {
   assertTrue(!rs.isExhausted());
   Row row = rs.one();
   assertTrue(rs.isExhausted());
   assertEquals(key, row.getString("k"));
   assertEquals("foo", row.getString("t"));
   assertEquals(42, row.getInt("i"));
   assertEquals(24.03f, row.getFloat("f"), 0.1f);
 }
Beispiel #6
0
    private static IndexMetadata build(ColumnMetadata column, Row row) {
      if (row == null) return null;

      String type = row.getString(INDEX_TYPE);
      if (type == null) return null;

      IndexMetadata index = new IndexMetadata(column, type, row.getString(INDEX_NAME));
      return index;
    }
Beispiel #7
0
 @Override
 public void writeHeader() {
   if (header != null) {
     Row record = sheet.createRow(0);
     for (int i = 0; i < header.size(); i++) {
       Cell cell = record.createCell(i);
       cell.setCellValue(header.get(i));
     }
   }
 }
Beispiel #8
0
 static ColumnMetadata build(TableMetadata tm, Row row) {
   try {
     String name = row.getString(COLUMN_NAME);
     AbstractType<?> t = TypeParser.parse(row.getString(VALIDATOR));
     ColumnMetadata cm = new ColumnMetadata(tm, name, Codec.rawTypeToDataType(t), row);
     tm.add(cm);
     return cm;
   } catch (RequestValidationException e) {
     // The server will have validated the type
     throw new RuntimeException(e);
   }
 }
Beispiel #9
0
 /**
  * Reads the current row from result set and adds it to the list.
  *
  * @param resultSet Result set to be read.
  * @param result List to be appended by new row.
  * @param metaData JDBC meta data.
  */
 private static void addRowFromResultSet(
     ResultSet resultSet, List<Row> result, ResultSetMetaData metaData) {
   try {
     Row row = new Row(metaData.getColumnCount());
     for (int i = 1; i <= metaData.getColumnCount(); ++i) {
       row.put(metaData.getColumnLabel(i), resultSet.getObject(i));
     }
     result.add(row);
   } catch (SQLException e) {
     throw new DatabaseException("Can't add row from the result set.", e);
   }
 }
Beispiel #10
0
    private void advance() {

      nextAlignment = null;
      Row nextRow = null;
      while (nextAlignment == null && !rows.isEmpty()) {
        while ((nextRow = rows.poll()) != null) {
          if (nextRow.hasNext()) {
            nextAlignment = nextRow.nextAlignment();
            break;
          }
        }
      }
      if (nextRow != null && nextAlignment != null) {
        rows.add(nextRow);
      }
    }
Beispiel #11
0
    AlignmentIterator(Map<String, List<Row>> groupedAlignmentRows) {
      rows =
          new PriorityQueue(
              5,
              new Comparator<Row>() {

                public int compare(Row o1, Row o2) {
                  return o1.getNextStartPos() - o2.getNextStartPos();
                }
              });

      for (List<Row> alignmentRows : groupedAlignmentRows.values()) {
        for (Row r : alignmentRows) {
          r.resetIdx();
          rows.add(r);
        }
      }

      advance();
    }
Beispiel #12
0
  public Row join(Row pRow, String pField) {
    // dbgMsg("Join!");
    RowFormat newFormat = mFormat.join(pRow.mFormat, pField);
    Row newRow = (Row) newFormat.getRowFactory().makeRow();
    // String[] ourFieldNames = mFormat.getFieldNames();
    // String[] theirFieldNames =pRow.mFormat.getFieldNames();
    // dbgMsg("ourFieldNames="+StringUtils.arrayToString(ourFieldNames, ", "));
    // dbgMsg("theirFieldNames="+StringUtils.arrayToString(theirFieldNames, ", "));

    HashSet ourFields = new HashSet(Arrays.asList(mFormat.getFieldNames()));
    HashSet theirFields = new HashSet(Arrays.asList(pRow.mFormat.getFieldNames()));
    ourFields.remove(pField);
    theirFields.remove(pField);
    HashSet commonFields = new HashSet(ourFields);
    commonFields.retainAll(theirFields);
    ourFields.removeAll(commonFields);
    theirFields.removeAll(commonFields);

    // dbgMsg("join field "+pField);
    // dbgMsg("our fields: "+StringUtils.collectionToString(ourFields, " "));
    // dbgMsg("their fields: "+StringUtils.collectionToString(theirFields, " "));
    // dbgMsg("common fields: "+StringUtils.collectionToString(commonFields, " "));

    // copy join field
    newRow.set(pField, get(pField)); // (copied arbitrarily from...us, as should be same!)

    // copy our fields
    Iterator ourFieldsIter = ourFields.iterator();
    while (ourFieldsIter.hasNext()) {
      String field = (String) ourFieldsIter.next();
      newRow.set(field, (get(field)));
    }

    // copy their fields
    Iterator theirFieldsIter = theirFields.iterator();
    while (theirFieldsIter.hasNext()) {
      String field = (String) theirFieldsIter.next();
      newRow.set(field, (pRow.get(field)));
    }

    // copy common fields (renaming fields becomes necessary)
    Iterator commonFieldsIter = commonFields.iterator();
    while (commonFieldsIter.hasNext()) {
      String field = (String) commonFieldsIter.next();
      newRow.set(field + "1", (get(field)));
      newRow.set(field + "2", (pRow.get(field)));
    }

    return newRow;
  }
Beispiel #13
0
 /**
  * This function re-computes the total number of hours for the selected period. It is ran every
  * time the user edits a text field specifying the number of hours for a particular top-level
  * project. Percentage labels are also updated.
  */
 private void recomputeTotal() {
   double total = 0;
   for (Row row : rows.values()) {
     try {
       row.hours = Double.parseDouble(row.hoursTF.getText());
       total += row.hours;
       row.hoursTF.setForeground(normalColour);
     } catch (NumberFormatException e) {
       row.hoursTF.setForeground(errorColour);
       totalLabel.setText("ERROR");
       totalLabel.setForeground(errorColour);
       return;
     }
   }
   totalLabel.setText(decimalFormat.format(total));
   totalLabel.setForeground(normalColour);
   for (Row row : rows.values()) {
     String percentS = decimalFormat.format(total == 0 ? 0 : 100 * row.hours / total);
     row.percentL.setText("(" + percentS + "%)");
   }
   pack();
 }
  /// Showd Data on grid table
  public void showgrid() {
    for (Component c : find(this.getPage(), "#showsell > rows > row")) {
      c.detach();
    }
    float sumallprice = 0;
    for (int i = 0; i < pointcount; i++) {
      Row r = new Row();
      r.appendChild(new Label(Integer.toString(idpro.get(i))));
      r.appendChild(new Label(nameproduct.get(i)));
      r.appendChild(new Label(Integer.toString(qty.get(i))));
      r.appendChild(new Label(Integer.toString(unitprice.get(i))));
      r.appendChild(new Label(Integer.toString(price.get(i))));
      r.appendChild(new Label(namecus.get(i)));
      Button but = new Button("Delete");
      but.setId("" + i);
      but.addEventListener(
          "onClick",
          new EventListener() {
            public void onEvent(Event ee) {
              nameproduct.remove(Integer.parseInt(ee.getTarget().getId()));
              qty.remove(Integer.parseInt(ee.getTarget().getId()));
              unitprice.remove(Integer.parseInt(ee.getTarget().getId()));
              price.remove(Integer.parseInt(ee.getTarget().getId()));
              namecus.remove(Integer.parseInt(ee.getTarget().getId()));
              pointcount--;
              txtsum.setValue("0");
              txtvat.setValue("0");
              idsumprice.setValue("0");
              showgrid();
            }
          });
      r.appendChild(but);
      Component v = find(this.getPage(), "#showsell > rows").get(0);
      v.appendChild(r);
      sumallprice = sumallprice + price.get(i);
      float vatc1;
      String vatc2;
      for (Customereng vc : Customereng.findAllCustomerengs()) {
        vatc2 = vc.getTax();
        vatc1 = Float.parseFloat(vatc2);

        float vat = (sumallprice * vatc1) / 100;
        float sumtotal = vat + sumallprice;
        txtsum.setValue(Float.toString(sumallprice));
        txtvat.setValue(Float.toString(vat));
        idsumprice.setValue(Float.toString(sumtotal));
      }
    }
  }
  private Collection<Object[]> loadFromSpreadsheet(final InputStream excelFile) throws IOException {
    HSSFWorkbook workbook = new HSSFWorkbook(excelFile);

    data = new ArrayList<Object[]>();
    Sheet sheet = workbook.getSheetAt(0);

    int numberOfColumns = countNonEmptyColumns(sheet);
    List<Object[]> rows = new ArrayList<Object[]>();
    List<Object> rowData = new ArrayList<Object>();

    for (Row row : sheet) {
      if (isEmpty(row)) {
        break;
      } else {
        rowData.clear();
        for (int column = 0; column < numberOfColumns; column++) {
          Cell cell = row.getCell(column);
          rowData.add(objectFrom(workbook, cell));
        }
        rows.add(rowData.toArray());
      }
    }
    return rows;
  }
  protected SRow importRow(Row poiRow, SSheet sheet) {
    SRow row = sheet.getRow(poiRow.getRowNum());
    row.setHeight(UnitUtil.twipToPx(poiRow.getHeight()));
    row.setCustomHeight(poiRow.isCustomHeight());
    row.setHidden(poiRow.getZeroHeight());
    CellStyle rowStyle = poiRow.getRowStyle();
    if (rowStyle != null) {
      row.setCellStyle(importCellStyle(rowStyle));
    }

    for (Cell poiCell : poiRow) {
      importCell(poiCell, poiRow.getRowNum(), sheet);
    }

    return row;
  }
Beispiel #17
0
  /**
   * *********************************************************** Create
   * ***********************************************************
   */
  @SuppressWarnings("rawtypes")
  private void onNodeTypeChanged() {
    ListModelList typeModel = (ListModelList) typeBox.getModel();
    Set selections = typeModel.getSelection();
    if (selections.isEmpty()) return;
    String selection = (String) selections.iterator().next();
    logger.info("Node type set to: " + selection);

    Map<String, String> ntd = GeneralUtil.getNodeDescriptionByLabel(ntds, selection);
    String nodeType = ntd.get("type");
    if (nodeType.equals(Constants.NODE_TYPE_USER)) {
      firstNameRow.setVisible(true);
      firstNameBox.setConstraint("no empty");
      lastNameRow.setVisible(true);
      lastNameBox.setConstraint("no empty");
      midNameRow.setVisible(true);
    } else {
      firstNameRow.setVisible(false);
      firstNameBox.setConstraint("");
      lastNameRow.setVisible(false);
      lastNameBox.setConstraint("");
      midNameRow.setVisible(false);
    }
  }
Beispiel #18
0
  public File generateXLSResponse(QueryResult queryResult, Locale locale, String baseURL) {
    File excelFile = new File("export_parts.xls");
    // Blank workbook
    XSSFWorkbook workbook = new XSSFWorkbook();

    // Create a blank sheet
    XSSFSheet sheet = workbook.createSheet("Parts Data");

    String header = StringUtils.join(queryResult.getQuery().getSelects(), ";");
    String[] columns = header.split(";");

    Map<Integer, String[]> data = new HashMap<>();
    String[] headerFormatted = createXLSHeaderRow(header, columns, locale);
    data.put(1, headerFormatted);

    Map<Integer, String[]> commentsData = new HashMap<>();
    String[] headerComments = createXLSHeaderRowComments(header, columns);
    commentsData.put(1, headerComments);

    List<String> selects = queryResult.getQuery().getSelects();
    int i = 1;
    for (QueryResultRow row : queryResult.getRows()) {
      i++;
      data.put(i, createXLSRow(selects, row, baseURL));
      commentsData.put(i, createXLSRowComments(selects, row));
    }

    // Iterate over data and write to sheet
    Set<Integer> keyset = data.keySet();
    int rownum = 0;

    for (Integer key : keyset) {

      Row row = sheet.createRow(rownum++);
      String[] objArr = data.get(key);
      int cellnum = 0;
      for (String obj : objArr) {
        Cell cell = row.createCell(cellnum++);
        cell.setCellValue(obj);
      }

      CreationHelper factory = workbook.getCreationHelper();
      Drawing drawing = sheet.createDrawingPatriarch();
      String[] commentsObjArr = commentsData.get(key);
      cellnum = 0;
      for (String commentsObj : commentsObjArr) {
        if (commentsObj.length() > 0) {
          Cell cell = row.getCell(cellnum) != null ? row.getCell(cellnum) : row.createCell(cellnum);

          // When the comment box is visible, have it show in a 1x3 space
          ClientAnchor anchor = factory.createClientAnchor();
          anchor.setCol1(cell.getColumnIndex());
          anchor.setCol2(cell.getColumnIndex() + 1);
          anchor.setRow1(row.getRowNum());
          anchor.setRow2(row.getRowNum() + 1);

          Comment comment = drawing.createCellComment(anchor);
          RichTextString str = factory.createRichTextString(commentsObj);
          comment.setString(str);

          // Assign the comment to the cell
          cell.setCellComment(comment);
        }
        cellnum++;
      }
    }

    // Define header style
    Font headerFont = workbook.createFont();
    headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    headerFont.setFontHeightInPoints((short) 10);
    headerFont.setFontName("Courier New");
    headerFont.setItalic(true);
    headerFont.setColor(IndexedColors.WHITE.getIndex());
    CellStyle headerStyle = workbook.createCellStyle();
    headerStyle.setFont(headerFont);
    headerStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    headerStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);

    // Set header style
    for (int j = 0; j < columns.length; j++) {
      Cell cell = sheet.getRow(0).getCell(j);
      cell.setCellStyle(headerStyle);

      if (cell.getCellComment() != null) {
        String comment = cell.getCellComment().getString().toString();

        if (comment.equals(QueryField.CTX_PRODUCT_ID)
            || comment.equals(QueryField.CTX_SERIAL_NUMBER)
            || comment.equals(QueryField.PART_MASTER_NUMBER)) {
          for (int k = 0; k < queryResult.getRows().size(); k++) {
            Cell grayCell =
                sheet.getRow(k + 1).getCell(j) != null
                    ? sheet.getRow(k + 1).getCell(j)
                    : sheet.getRow(k + 1).createCell(j);
            grayCell.setCellStyle(headerStyle);
          }
        }
      }
    }

    try {
      // Write the workbook in file system
      FileOutputStream out = new FileOutputStream(excelFile);
      workbook.write(out);
      out.close();
    } catch (Exception e) {
      LOGGER.log(Level.FINEST, null, e);
    }
    return excelFile;
  }
Beispiel #19
0
 public Row createClone() {
   Row clone = new Row(mFormat, false);
   clone.addAll(this);
   return clone;
 }
 private boolean isEmpty(final Row row) {
   Cell firstCell = row.getCell(0);
   boolean rowIsEmpty = (firstCell == null) || (firstCell.getCellType() == Cell.CELL_TYPE_BLANK);
   return rowIsEmpty;
 }
  public PrimaryKeyController(
      BPMNMinerController bpmnMinerController, List<PrimaryKeyData> pKeyData)
      throws IOException, NoEntityException {
    this.bpmnMinerController = bpmnMinerController;

    this.primaryKeyW =
        (Window)
            bpmnMinerController
                .portalContext
                .getUI()
                .createComponent(
                    getClass().getClassLoader(), "zul/selectPrimaryKey.zul", null, null);
    this.primaryKeyW.setTitle("Select Primary Keys");

    this.cancelButton = (Button) this.primaryKeyW.getFellow("cancelButton");
    this.nextButton = (Button) this.primaryKeyW.getFellow("okButton");

    this.cancelButton.addEventListener(
        "onClick",
        new EventListener<Event>() {
          public void onEvent(Event event) throws Exception {
            cancel();
          }
        });
    this.nextButton.addEventListener(
        "onClick",
        new EventListener<Event>() {
          public void onEvent(Event event) throws Exception {
            next();
          }
        });

    this.rows = (Rows) this.primaryKeyW.getFellow("rows");

    this.data = pKeyData;
    chosenKeysIndex = new int[data.size()];
    int dataIndex = 0;
    // create a new property item for each event type
    for (PrimaryKeyData currentData : data) {

      chosenKeysIndex[dataIndex] = 0;

      // build a list of all keys (sets of attribute names)
      String[] keyList =
          new String
              [currentData
                  .primaryKeys
                  .length]; // change if user can select any attributes for identifiers
      for (int i = 0; i < currentData.primaryKeys.length; i++) {
        HashSet<String> attr = currentData.primaryKeys[i];
        keyList[i] = DiscoverERmodel.keyToString(attr);
      }

      Row row = new Row();
      row.setParent(rows);

      Label activity = new Label(currentData.name);
      activity.setParent(row);

      if (keyList.length > 1) {
        Selectbox selectbox = new Selectbox();
        selectbox.setModel(new ListModelArray<Object>(keyList));
        selectbox.setId("" + dataIndex);
        selectbox.setParent(row);
      } else {
        Label key = new Label(Arrays.toString(keyList));
        key.setParent(row);
      }

      dataIndex++;
    }

    this.primaryKeyW.doModal();
  }
Beispiel #22
0
  public void addBody(Body body)
      throws SAXException, WingException, UIException, SQLException, IOException,
          AuthorizeException {
    // If we are actually editing information of an uploaded file,
    // then display that body instead!
    if (this.editFile != null) {
      editFile.addBody(body);
      return;
    }

    // Get a list of all files in the original bundle
    Item item = submission.getItem();
    Collection collection = submission.getCollection();
    String actionURL =
        contextPath + "/handle/" + collection.getHandle() + "/submit/" + knot.getId() + ".continue";
    boolean disableFileEditing =
        (submissionInfo.isInWorkflow())
            && !ConfigurationManager.getBooleanProperty("workflow", "reviewer.file-edit");
    Bundle[] bundles = item.getBundles("ORIGINAL");
    Bitstream[] bitstreams = new Bitstream[0];
    if (bundles.length > 0) {
      bitstreams = bundles[0].getBitstreams();
    }

    // Part A:
    //  First ask the user if they would like to upload a new file (may be the first one)
    Division div =
        body.addInteractiveDivision(
            "submit-upload", actionURL, Division.METHOD_MULTIPART, "primary submission");
    div.setHead(T_submission_head);
    addSubmissionProgressList(div);

    List upload = null;
    if (!disableFileEditing) {
      // Only add the upload capabilities for new item submissions
      upload = div.addList("submit-upload-new", List.TYPE_FORM);
      upload.setHead(T_head);
      addRioxxVersionSection(upload, item);

      File file = upload.addItem().addFile("file");
      file.setLabel(T_file);
      file.setHelp(T_file_help);
      file.setRequired();

      // if no files found error was thrown by processing class, display it!
      if (this.errorFlag == org.dspace.submit.step.UploadStep.STATUS_NO_FILES_ERROR) {
        file.addError(T_file_error);
      }

      // if an upload error was thrown by processing class, display it!
      if (this.errorFlag == org.dspace.submit.step.UploadStep.STATUS_UPLOAD_ERROR) {
        file.addError(T_upload_error);
      }

      // if virus checking was attempted and failed in error then let the user know
      if (this.errorFlag == org.dspace.submit.step.UploadStep.STATUS_VIRUS_CHECKER_UNAVAILABLE) {
        file.addError(T_virus_checker_error);
      }

      // if virus checking was attempted and a virus found then let the user know
      if (this.errorFlag == org.dspace.submit.step.UploadStep.STATUS_CONTAINS_VIRUS) {
        file.addError(T_virus_error);
      }

      Text description = upload.addItem().addText("description");
      description.setLabel(T_description);
      description.setHelp(T_description_help);

      Button uploadSubmit = upload.addItem().addButton("submit_upload");
      uploadSubmit.setValue(T_submit_upload);
    }

    make_sherpaRomeo_submission(item, div);

    // Part B:
    //  If the user has already uploaded files provide a list for the user.
    if (bitstreams.length > 0 || disableFileEditing) {
      Table summary = div.addTable("submit-upload-summary", (bitstreams.length * 2) + 2, 7);
      summary.setHead(T_head2);

      Row header = summary.addRow(Row.ROLE_HEADER);
      header.addCellContent(T_column0); // primary bitstream
      header.addCellContent(T_column1); // select checkbox
      header.addCellContent(T_column2); // file name
      header.addCellContent(T_column3); // size
      header.addCellContent(T_column4); // description
      header.addCellContent(T_column5); // format
      header.addCellContent(T_column6); // edit button

      for (Bitstream bitstream : bitstreams) {
        int id = bitstream.getID();
        String name = bitstream.getName();
        String url = makeBitstreamLink(item, bitstream);
        long bytes = bitstream.getSize();
        String desc = bitstream.getDescription();
        String algorithm = bitstream.getChecksumAlgorithm();
        String checksum = bitstream.getChecksum();

        Row row = summary.addRow();

        // Add radio-button to select this as the primary bitstream
        Radio primary = row.addCell().addRadio("primary_bitstream_id");
        primary.addOption(String.valueOf(id));

        // If this bitstream is already marked as the primary bitstream
        // mark it as such.
        if (bundles[0].getPrimaryBitstreamID() == id) {
          primary.setOptionSelected(String.valueOf(id));
        }

        if (!disableFileEditing) {
          // Workflow users can not remove files.
          CheckBox remove = row.addCell().addCheckBox("remove");
          remove.setLabel("remove");
          remove.addOption(id);
        } else {
          row.addCell();
        }

        row.addCell().addXref(url, name);
        row.addCellContent(bytes + " bytes");
        if (desc == null || desc.length() == 0) {
          row.addCellContent(T_unknown_name);
        } else {
          row.addCellContent(desc);
        }

        BitstreamFormat format = bitstream.getFormat();
        if (format == null) {
          row.addCellContent(T_unknown_format);
        } else {
          int support = format.getSupportLevel();
          Cell cell = row.addCell();
          cell.addContent(format.getMIMEType());
          cell.addContent(" ");
          switch (support) {
            case 1:
              cell.addContent(T_supported);
              break;
            case 2:
              cell.addContent(T_known);
              break;
            case 3:
              cell.addContent(T_unsupported);
              break;
          }
        }

        Button edit = row.addCell().addButton("submit_edit_" + id);
        edit.setValue(T_submit_edit);

        Row checksumRow = summary.addRow();
        checksumRow.addCell();
        Cell checksumCell = checksumRow.addCell(null, null, 0, 6, null);
        checksumCell.addHighlight("bold").addContent(T_checksum);
        checksumCell.addContent(" ");
        checksumCell.addContent(algorithm + ":" + checksum);
      }

      if (!disableFileEditing) {
        // Workflow users can not remove files.
        Row actionRow = summary.addRow();
        actionRow.addCell();
        Button removeSeleceted =
            actionRow.addCell(null, null, 0, 6, null).addButton("submit_remove_selected");
        removeSeleceted.setValue(T_submit_remove);
      }

      upload = div.addList("submit-upload-new-part2", List.TYPE_FORM);
    }

    // Part C:
    // add standard control/paging buttons
    addControlButtons(upload);
  }
Beispiel #23
0
 private Workbook handleExcel(List objs, Class clz, boolean isXssf, String message) {
   XSSFWorkbook wb = null;
   try {
     if (isXssf) {
       XSSFWorkbook w = new XSSFWorkbook();
     } else {
       HSSFWorkbook w = new HSSFWorkbook();
     }
     wb = new XSSFWorkbook();
     XSSFDataFormat format = wb.createDataFormat();
     XSSFSheet sheet = wb.createSheet(message + "备份记录"); // 取excel工作表对象
     XSSFCellStyle cellStyle = wb.createCellStyle(); // 设置excel单元格样式
     XSSFCellStyle passwordCellStyle = wb.createCellStyle(); // 设置密码单元格样式
     XSSFDataFormat passwordFormat = wb.createDataFormat();
     passwordCellStyle.setDataFormat(passwordFormat.getFormat(";;;"));
     List<ExcelHeader> headers = getHeaderList(clz);
     Collections.sort(headers);
     sheet.addMergedRegion(new CellRangeAddress(0, (short) 0, 0, (short) (headers.size() - 1)));
     Row r0 = sheet.createRow(0);
     Cell cell = r0.createCell(0);
     r0.setHeightInPoints(28);
     cell.setCellValue(message + "备份记录");
     Row r = sheet.createRow(1);
     r.setHeightInPoints(25);
     cell.setCellStyle(cellStyle);
     // 输出标题
     for (int i = 0; i < headers.size(); i++) {
       Cell cell1 = r.createCell(i);
       if (headers.get(i).getTitle().equals("密码")) cell1.setCellStyle(passwordCellStyle);
       else cell1.setCellStyle(cellStyle);
       cell1.setCellValue(headers.get(i).getTitle());
     }
     Object obj = null;
     // 输出用户资料信息
     if (message.indexOf("用户资料 ") > 0) {
       sheet.setColumnWidth(3, 32 * 150);
       sheet.setColumnWidth(4, 32 * 110);
       sheet.setColumnWidth(7, 32 * 120);
       for (int i = 0; i < objs.size(); i++) {
         r = sheet.createRow(i + 2);
         obj = objs.get(i);
         for (int j = 0; j < headers.size(); j++) {
           Cell cell2 = r.createCell(j);
           copyDefaultCellStyle(null, cell2, cellStyle, 0);
           if (getMethodName(headers.get(j)).equals("nabled"))
             cell2.setCellValue(BeanUtils.getProperty(obj, "enabled"));
           else if (getMethodName(headers.get(j)).equals("password")) {
             cell2.setCellStyle(passwordCellStyle);
             cell2.setCellValue(BeanUtils.getProperty(obj, getMethodName(headers.get(j))));
           } else cell2.setCellValue(BeanUtils.getProperty(obj, getMethodName(headers.get(j))));
         }
       }
     }
     // 输出房间使用信息数据
     else {
       sheet.setColumnWidth(0, 32 * 80);
       sheet.setColumnWidth(2, 32 * 100);
       sheet.setColumnWidth(3, 32 * 190);
       sheet.setColumnWidth(4, 32 * 190);
       sheet.setColumnWidth(5, 32 * 190);
       sheet.setColumnWidth(10, 32 * 130);
       for (int i = 0; i < objs.size(); i++) {
         r = sheet.createRow(i + 2);
         obj = objs.get(i);
         for (int j = 0; j < headers.size(); j++) {
           Cell cell2 = r.createCell(j);
           if (j == 3 || j == 4 || j == 5) {
             XSSFCellStyle cs3 = wb.createCellStyle();
             cell2.setCellValue(new Date());
             copyDefaultCellStyle(format, cell2, cs3, 1);
           }
           if (j == 10) {
             XSSFCellStyle cs2 = wb.createCellStyle();
             copyDefaultCellStyle(format, cell2, cs2, 2);
           }
           copyDefaultCellStyle(null, cell2, cellStyle, 0);
           cell2.setCellValue(BeanUtils.getProperty(obj, getMethodName(headers.get(j))));
         }
       }
     }
     // 设置行列的默认宽度和高度
   } catch (IllegalAccessException e) {
     e.printStackTrace();
     logger.error(e);
   } catch (InvocationTargetException e) {
     e.printStackTrace();
     logger.error(e);
   } catch (NoSuchMethodException e) {
     e.printStackTrace();
     logger.error(e);
   }
   return wb;
 }
  public void readProcessSpreadSheet() {
    processSpreadSheet = System.getProperty("processSpreadSheet");
    System.out.println("processSpreadSheet: " + processSpreadSheet);
    if (processCodesList.size() == 0) {
      if (processSpreadSheet != null && !processSpreadSheet.equals("")) {
        Workbook wb1 = null;
        try {
          wb1 = new XSSFWorkbook(processSpreadSheet);
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
        Sheet sheet = wb1.getSheetAt(0);
        Row row;
        Cell cell;

        int rows; // No of rows
        rows = sheet.getPhysicalNumberOfRows();

        int cols = 0; // No of columns
        int tmp = 0;

        // This trick ensures that we get the data properly even if it
        // doesn't start from first few rows
        for (int i = 0; i < 10 || i < rows; i++) {
          row = sheet.getRow(i);
          if (row != null) {
            tmp = sheet.getRow(i).getPhysicalNumberOfCells();
            // out.println("tmp value"+tmp);
            if (tmp > cols) {
              cols = tmp;
            }
          }
        }

        ProcessDefinition tempProcessCode;
        for (int r1 = 0; r1 < rows; r1++) {
          tempProcessCode = new ProcessDefinition();

          row = sheet.getRow(r1);
          if (row != null) {
            if (row.getCell(0) != null) {
              for (int counter = 0; counter < cols; counter++) {
                cell = row.getCell((short) counter);
                // cell = row.getCell(1);
                if (counter == 0) {
                  if (cell != null) {
                    tempProcessCode.setProcessName(cell.getStringCellValue());
                  } else {
                    tempProcessCode.setProcessName("");
                  }
                } else if (counter == 1) {
                  if (cell != null) {
                    tempProcessCode.setProcessCode(cell.getStringCellValue());
                  } else {
                    tempProcessCode.setProcessCode("");
                  }
                } else if (counter == 2) {
                  if (cell != null) {
                    tempProcessCode.setIaeaCode(cell.getStringCellValue());
                  } else {
                    tempProcessCode.setIaeaCode("");
                  }
                } else if (counter == 3) {
                  if (cell != null) {
                    tempProcessCode.setProcessDescription(cell.getStringCellValue());
                    // System.out.println(tempProcessCode.getProcessDescription());
                  } else {
                    tempProcessCode.setProcessDescription("");
                    // System.out.println("Process Description EMpty");
                  }
                }
              }
            }

          } else {
            rows++;
          }
          processCodesList.add(tempProcessCode);
        }
      }
    }
    System.out.println(processCodesList.size());
  }
Beispiel #25
0
  private void saveExcelPoject(File file) throws IOException {
    Workbook wb = new XSSFWorkbook();
    Sheet sheet = wb.createSheet("timeplan");
    // Заголовок в 0 строке
    Row row = sheet.createRow(0);
    Cell cell = row.createCell(0);
    cell.setCellValue("Филиал");
    cell = row.createCell(1);
    cell.setCellValue("Город");
    Calendar cal = Calendar.getInstance();
    cal.set(2017, 0, 5); // Начальная дата проекта
    SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yy");
    for (int i = 0; i < 3 * 52; i++) { // Счетчик по неделям
      cell = row.createCell(i + 2);
      cell.setCellValue(sdf.format(cal.getTime()));
      cal.add(Calendar.WEEK_OF_YEAR, 1); // Следующая неделя
    }

    // sheet.setColumnWidth(0, 256);

    // Цвета ячеек
    CellStyle[] styles = new CellStyle[6];
    styles[0] = wb.createCellStyle();
    styles[0].setFillForegroundColor(HSSFColor.RED.index);
    styles[0].setFillPattern(FillPatternType.SOLID_FOREGROUND);
    styles[1] = wb.createCellStyle();
    styles[1].setFillForegroundColor(HSSFColor.GREEN.index);
    styles[1].setFillPattern(FillPatternType.SOLID_FOREGROUND);
    styles[2] = wb.createCellStyle();
    styles[2].setFillForegroundColor(HSSFColor.BLUE.index);
    styles[2].setFillPattern(FillPatternType.SOLID_FOREGROUND);
    styles[3] = wb.createCellStyle();
    styles[3].setFillForegroundColor(HSSFColor.ROSE.index);
    styles[3].setFillPattern(FillPatternType.SOLID_FOREGROUND);
    styles[4] = wb.createCellStyle();
    styles[4].setFillForegroundColor(HSSFColor.LIGHT_BLUE.index);
    styles[4].setFillPattern(FillPatternType.SOLID_FOREGROUND);
    styles[5] = wb.createCellStyle();
    styles[5].setFillForegroundColor(HSSFColor.LIGHT_GREEN.index);
    styles[5].setFillPattern(FillPatternType.SOLID_FOREGROUND);

    short rowIdx = 0;
    for (Region region : this.regions) {
      row = sheet.createRow(++rowIdx);
      cell = row.createCell(0);
      cell.setCellValue(region.filial);
      cell = row.createCell(1);
      cell.setCellValue(region.name);

      cal = Calendar.getInstance();
      cal.set(2017, 0, 5); // Начальная дата проекта
      for (int i = 0; i < 3 * 52; i++) { // Счетчик по неделям
        short color = region.getDateColorIndex(cal.getTime());
        if (color >= 0) {
          cell = row.createCell(i + 2);
          cell.setCellStyle(styles[color]);
        }

        cal.add(Calendar.WEEK_OF_YEAR, 1); // Следующая неделя
      }
    }

    try (FileOutputStream fileOut = new FileOutputStream(file)) {
      wb.write(fileOut);
    }
  }