protected LumberLog fromResultSet(ResultSet rs) throws SQLException {
    LumberLog lumberLog = new LumberLog();
    lumberLog.setId(rs.getLong("id"));
    lumberLog.setLength(rs.getDouble("length"));
    lumberLog.setRealLength(rs.getLong("reallength"));
    lumberLog.setVolume(rs.getDouble("volume"));
    lumberLog.setRealVolume(rs.getDouble("realvolume"));
    lumberLog.setSmallRadius(rs.getDouble("small_diameter"));
    lumberLog.setBigRadius(rs.getDouble("big_diameter"));
    lumberLog.setLumberType(rs.getLong("lumbertype"));
    lumberLog.setLumberClass(rs.getLong("lumberclass"));
    lumberLog.setCutPlanId(rs.getLong("planId"));
    LumberStack stack = new LumberStack();
    stack.setName(rs.getString("stackName"));
    stack.setId(rs.getLong("stack"));
    lumberLog.setStack(stack);
    IDPlate plate = new IDPlate();
    plate.setId(rs.getLong("idplate"));
    plate.setLabel(rs.getString("plateName"));
    lumberLog.setPlate(plate);
    lumberLog.setSupplierId(rs.getLong("SupplierId"));
    lumberLog.setTransportCertifiateId(rs.getLong("TransportCertificateId"));
    if (rs.wasNull()) {
      lumberLog.setTransportCertifiateId(null);
    }
    lumberLog.setMarginPercent(rs.getInt("Margin"));
    lumberLog.setMarginVolume(rs.getDouble("MarginVolume"));
    lumberLog.setMarginRealVolume(rs.getDouble("RealMarginVolume"));

    return lumberLog;
  }
  @Override
  public void actionPerformed(ActionEvent e) {

    if (e.getActionCommand().startsWith("FILTRU")) {
      int length = Integer.parseInt(e.getActionCommand().substring(6));
      for (int index = 0; index < selection.size(); index++) {
        JCheckBox chk1 = (JCheckBox) selection.get(index);
        int productLength = Integer.parseInt(chk1.getName().substring(6));
        if (!filtru2m.isSelected() && !filtru3m.isSelected() && !filtru4m.isSelected()) {
          chk1.getParent().setVisible(true);
          continue;
        }
        if (productLength < 3000 && productLength >= 2000 && filtru2m.isSelected()) {
          chk1.getParent().setVisible(true);
        } else if (productLength < 4000 && productLength >= 3000 && filtru3m.isSelected()) {
          chk1.getParent().setVisible(true);
        } else if (productLength < 5000 && productLength >= 4000 && filtru4m.isSelected()) {
          chk1.getParent().setVisible(true);
        } else {
          chk1.getParent().setVisible(false);
        }
      }
      this.revalidate();
      return;
    }
    boolean valid = true;

    JLabel lenLabel = (JLabel) ((JPanel) getComponent(0)).getComponent(0);
    JFormattedTextField lenRadius =
        (JFormattedTextField) ((JPanel) getComponent(0)).getComponent(1);
    JComboBox<String> lenRadiusMetric =
        (JComboBox<String>) ((JPanel) getComponent(0)).getComponent(2);
    lenLabel.setForeground(Color.black);
    if (lenRadius.getValue() == null) {
      valid = false;
      lenLabel.setForeground(Color.red);
    }
    JLabel smallLabel = (JLabel) ((JPanel) getComponent(1)).getComponent(0);
    JFormattedTextField smallRadius =
        (JFormattedTextField) ((JPanel) getComponent(1)).getComponent(1);
    JComboBox<String> smallRadiusMetric =
        (JComboBox<String>) ((JPanel) getComponent(1)).getComponent(2);
    smallLabel.setForeground(Color.black);
    if (smallRadius.getValue() == null) {
      valid = false;
      smallLabel.setForeground(Color.red);
    }

    JLabel bigLabel = (JLabel) ((JPanel) getComponent(2)).getComponent(0);
    JFormattedTextField bigRadius =
        (JFormattedTextField) ((JPanel) getComponent(2)).getComponent(1);
    JComboBox<String> bigRadiusMetric =
        (JComboBox<String>) ((JPanel) getComponent(2)).getComponent(2);
    bigLabel.setForeground(Color.black);
    if (bigRadius.getValue() == null) {
      valid = false;
      bigLabel.setForeground(Color.red);
    }

    double minimumValue =
        METRIC.toMilimeter((Long) smallRadius.getValue(), smallRadiusMetric.getSelectedIndex());
    double maxmimumValue =
        METRIC.toMilimeter((Long) bigRadius.getValue(), bigRadiusMetric.getSelectedIndex());

    if (minimumValue > maxmimumValue) {
      smallLabel.setForeground(Color.red);
      bigLabel.setForeground(Color.red);
      valid = false;
    }

    boolean one = false;
    for (JCheckBox chk : selection) {
      if (chk.isSelected()) {
        one = true;
        break;
      }
    }
    if (!one) {
      label2.setForeground(Color.red);
      valid = false;
    } else {
      label2.setForeground(Color.black);
    }

    if (!valid) {
      return;
    }

    List<Product> selectedProducts = new ArrayList<Product>();
    for (int index = 0; index < selection.size(); index++) {
      if (selection.get(index).isSelected()) {
        selectedProducts.add(products.get(index));
      }
    }

    Map<String, Object> targetData = new HashMap<String, Object>();
    targetData.put("IDPLATE_LABEL", "Test");
    targetData.put("SELECTED_PRODUCTS", selectedProducts);
    DefaultCutOptionsCalculatorData data = new DefaultCutOptionsCalculatorData();
    data.setSelectedProducts(selectedProducts);

    List<LumberStack> stacks = LumberStackDAO.getAllstack();
    List<LumberLog> lumberLogs = new ArrayList<>();
    for (long start = (Long) smallRadius.getValue(); start < (Long) bigRadius.getValue(); start++) {
      LumberLog lumberLog = new LumberLog();
      lumberLog.setSmallRadius((double) start);
      List<Double> middleRadius = new ArrayList<>();
      middleRadius.add((double) start);
      lumberLog.setMediumRadius(middleRadius);
      lumberLog.setBigRadius((double) start);
      double lengthValue =
          METRIC.toMilimeter((Long) lenRadius.getValue(), lenRadiusMetric.getSelectedIndex());
      lumberLog.setLength(lengthValue);
      lumberLog.setRealLength((long) lengthValue);
      IDPlate plate = new IDPlate();
      plate.setId(-1L);
      LumberStack stack = LumberLogUtil.findLumberStack(lumberLog, stacks);
      String label = "Diametru " + start;
      if (stack != null) {
        label += " " + stack.getName();
      }
      plate.setLabel(label);
      lumberLog.setPlate(plate);
      LumberLogUtil.calculateVolume(lumberLog);
      lumberLogs.add(lumberLog);
    }
    data.setLumberLogs(lumberLogs);
    new CutOptionsTargetFrame(targetData, data);
    GUITools.closeParentDialog(this);
  }