/** Descripción de Método */
  private void displayLocator() {
    MLocator l = (MLocator) fLocator.getSelectedItem();

    if (l == null) {
      return;
    }

    //

    m_M_Locator_ID = l.getM_Locator_ID();
    fWarehouseInfo.setText(l.getWarehouseName());
    fX.setText(l.getX());
    fY.setText(l.getY());
    fZ.setText(l.getZ());
    fValue.setText(l.getValue());
    getWarehouseInfo(l.getM_Warehouse_ID());

    // Set Warehouse

    int size = fWarehouse.getItemCount();

    for (int i = 0; i < size; i++) {
      KeyNamePair pp = (KeyNamePair) fWarehouse.getItemAt(i);

      if (pp.getKey() == l.getM_Warehouse_ID()) {
        fWarehouse.setSelectedIndex(i);

        continue;
      }
    }
  } // displayLocator
  /** Descripción de Método */
  private void loadFile() {
    log.info("");

    JFileChooser chooser = new JFileChooser();

    chooser.setDialogType(JFileChooser.OPEN_DIALOG);
    chooser.setDialogTitle(Msg.getMsg(Env.getCtx(), "AttachmentNew"));

    int returnVal = chooser.showOpenDialog(this);

    if (returnVal != JFileChooser.APPROVE_OPTION) {
      return;
    }

    //

    String fileName = chooser.getSelectedFile().getName();

    log.config(fileName);

    File file = chooser.getSelectedFile();

    if (m_attachment.addEntry(file)) {
      cbContent.addItem(fileName);
      cbContent.setSelectedIndex(cbContent.getItemCount() - 1);
      m_change = true;
    }
  } // getFileName
  /** Descripción de Método */
  private void loadAttachments() {
    log.config("");

    // Set Text/Description

    String sText = m_attachment.getTextMsg();

    if (sText == null) {
      text.setText("");
    } else {
      text.setText(sText);
    }

    // Set Combo

    int size = m_attachment.getEntryCount();

    for (int i = 0; i < size; i++) {
      cbContent.addItem(m_attachment.getEntryName(i));
    }

    if (size > 0) {
      cbContent.setSelectedIndex(0);
    } else {
      displayData(0);
    }
  } // loadAttachment
 private void gridOK() {
   int mode = modeCombo.getSelectedIndex();
   //	Create PO
   if (mode == MODE_PO) {
     createPO();
     modeCombo.setSelectedIndex(MODE_VIEW);
     return;
   }
   //	Update Prices
   else if (mode == MODE_PRICE) {
     updatePrices();
     modeCombo.setSelectedIndex(MODE_VIEW);
     return;
   } else if (mode == MODE_VIEW) ;
   m_frame.dispose();
 } //	gridOK
  /**
   * Add Attribute Line
   *
   * @param attribute attribute
   * @param product product level attribute
   * @param readOnly value is read only
   */
  private void addAttributeLine(final MAttribute attribute) {
    final boolean product = m_productWindow;
    final boolean readOnly = false;

    log.fine(attribute + ", Product=" + product + ", R/O=" + readOnly);
    CLabel label = new CLabel(attribute.getName());
    if (product) {
      label.setFont(new Font(label.getFont().getFontName(), Font.BOLD, label.getFont().getSize()));
    }
    if (attribute.getDescription() != null) {
      label.setToolTipText(attribute.getDescription());
    }

    centerPanel.add(label, new ALayoutConstraint(m_row++, 0));
    //
    final int attributeSetInstanceId = asiTemplate.getM_AttributeSetInstance_ID();
    final int attributeId = attribute.getM_Attribute_ID();
    final MAttributeInstance instance = attribute.getMAttributeInstance(attributeSetInstanceId);
    if (MAttribute.ATTRIBUTEVALUETYPE_List.equals(attribute.getAttributeValueType())) {
      InterfaceWrapperHelper.setDynAttribute(
          attribute, Env.DYNATTR_WindowNo, attributeContext.getWindowNo());
      InterfaceWrapperHelper.setDynAttribute(
          attribute, Env.DYNATTR_TabNo, attributeContext.getTabNo()); // tabNo

      final I_M_AttributeValue[] values =
          attribute.getMAttributeValues(getSOTrx()); // optional = null
      final CComboBox<I_M_AttributeValue> editor = new CComboBox<>(values);
      boolean found = false;
      if (instance != null && instance.getM_AttributeValue_ID() > 0) {
        for (int i = 0; i < values.length; i++) {
          if (values[i] != null
              && values[i].getM_AttributeValue_ID() == instance.getM_AttributeValue_ID()) {
            editor.setSelectedIndex(i);
            found = true;
            break;
          }
        }
        if (found)
          log.fine(
              "Attribute=" + attribute.getName() + " #" + values.length + " - found: " + instance);
        else
          log.warning(
              "Attribute="
                  + attribute.getName()
                  + " #"
                  + values.length
                  + " - NOT found: "
                  + instance);
      } // setComboBox
      else {
        log.fine("Attribute=" + attribute.getName() + " #" + values.length + " no instance");
      }
      label.setLabelFor(editor);
      centerPanel.add(editor, null);
      if (readOnly) editor.setEnabled(false);
      else attributeId2editor.put(attributeId, editor);
    } else if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(attribute.getAttributeValueType())) {
      final VNumber editor =
          new VNumber(
              attribute.getName(), // ColumnName
              attribute.isMandatory(), // mandatory
              false, // IsReadOnly
              true, // IsUpdateable
              DisplayType.Number, // DisplayType
              attribute.getName() // Title
              );
      if (instance != null) {
        if (InterfaceWrapperHelper.isNull(instance, I_M_AttributeInstance.COLUMNNAME_ValueNumber)) {
          editor.setValue(null);
        } else {
          editor.setValue(instance.getValueNumber());
        }
      } else {
        // better don't set a default value
        // editor.setValue(Env.ZERO);
      }
      label.setLabelFor(editor);
      centerPanel.add(editor, null);
      if (readOnly) editor.setEnabled(false);
      else attributeId2editor.put(attributeId, editor);
    } else if (MAttribute.ATTRIBUTEVALUETYPE_Date.equals(attribute.getAttributeValueType())) {
      final VDate editor =
          new VDate(
              attribute.getName(), // columnName
              attribute.isMandatory(), // mandatory
              false, // isReadOnly
              true, // isUpdateable
              DisplayType.Date, // displayType
              attribute.getName() // title
              );
      if (instance != null) editor.setValue(instance.getValueDate());
      label.setLabelFor(editor);
      centerPanel.add(editor, null);
      if (readOnly) editor.setEnabled(false);
      else attributeId2editor.put(attributeId, editor);
    } else
    // Text Field
    {
      VString editor =
          new VString(
              attribute.getName(), // ColumnName
              attribute.isMandatory(), // mandatory
              false, // isReadOnly
              true, // isUpdateable
              20, // displayLength
              INSTANCE_VALUE_LENGTH, // fieldLength
              null, // VFormat
              null // ObscureType
              );
      if (instance != null) editor.setText(instance.getValue());
      label.setLabelFor(editor);
      centerPanel.add(editor, null);
      if (readOnly) editor.setEnabled(false);
      else attributeId2editor.put(attributeId, editor);
    }

    //
    // Add our attribute to the list of attributes
    m_attributes.add(attribute);
  } // addAttributeLine
  /** Initialize all panel fields and editors based on {@link #asiTemplate}. */
  private final void initAttributes() {
    final Properties ctx = getCtx();
    final boolean isProductWindow = isProductWindow();
    final boolean isProcessParameter = isProcessParameter();
    final boolean isPureProductASI = isPureProductASI();
    final boolean allowSelectExistingASI = isAllowSelectExistingASI();
    final MAttributeSet as = asiTemplate.getMAttributeSet();
    Check.assumeNotNull(as, "attribute set not null");
    final boolean isASITemplateNew = asiTemplate.getM_AttributeSetInstance_ID() <= 0;

    //
    // Show Select existing ASI (if allowed)
    if (allowSelectExistingASI) {
      // New/Edit - Selection
      if (isASITemplateNew) // new ASI
      cbNewEdit.setText(msgBL.getMsg(ctx, "NewRecord"));
      else cbNewEdit.setText(msgBL.getMsg(ctx, "EditRecord"));
      cbNewEdit.addActionListener(this);
      centerPanel.add(cbNewEdit, new ALayoutConstraint(m_row++, 0));
      bSelectExistingASI.setText(msgBL.getMsg(ctx, "SelectExisting"));
      bSelectExistingASI.addActionListener(this);
      centerPanel.add(bSelectExistingASI, null);
    }

    //
    // Fetch M_Attributes
    final List<MAttribute> attributes;
    if (isProductWindow) {
      attributes = Arrays.asList(as.getMAttributes(false)); // non-instance attributes
    } else if (isPureProductASI) {
      // Regular product's attribute set instance attributes
      attributes = Arrays.asList(as.getMAttributes(true)); // all instance attributes
    } else if (isProcessParameter) {
      final IQueryBuilder<MAttribute> attributesQueryBuilder =
          queryBL
              .createQueryBuilder(MAttribute.class)
              .setContext(ctx, ITrx.TRXNAME_None)
              .addOnlyActiveRecordsFilter()
              .addOnlyContextClient();
      attributesQueryBuilder
          .orderBy()
          .addColumn(I_M_Attribute.COLUMNNAME_Name)
          .addColumn(I_M_Attribute.COLUMNNAME_M_Attribute_ID);
      attributes = attributesQueryBuilder.create().list(MAttribute.class);
    } else {
      attributes = Collections.emptyList();
    }

    //
    // Create attributes UI editors
    for (final MAttribute attribute : attributes) {
      if (!attributeExcludeBL.isExcludedAttribute(
          attribute, as, m_AD_Column_ID, attributeContext.isSOTrx())) {
        addAttributeLine(attribute);
      }
    }

    //
    // Lot
    if (isPureProductASI && as.isLot()) {
      CLabel label = new CLabel(msgBL.translate(ctx, "Lot"));
      label.setLabelFor(fieldLotString);
      centerPanel.add(label, new ALayoutConstraint(m_row++, 0));
      centerPanel.add(fieldLotString, null);
      fieldLotString.setText(asiTemplate.getLot());
      // M_Lot_ID
      // int AD_Column_ID = 9771; // M_AttributeSetInstance.M_Lot_ID
      // fieldLot = new VLookup ("M_Lot_ID", false,false, true,
      // MLookupFactory.get(getCtx(), m_WindowNo, 0, AD_Column_ID, DisplayType.TableDir));
      final String sql =
          "SELECT M_Lot_ID, Name "
              + "FROM M_Lot l "
              + "WHERE EXISTS (SELECT M_Product_ID FROM M_Product p "
              + "WHERE p.M_AttributeSet_ID="
              + asiTemplate.getM_AttributeSet_ID()
              + " AND p.M_Product_ID=l.M_Product_ID)";
      fieldLot = new CComboBox<>(DB.getKeyNamePairs(sql, true));
      label = new CLabel(msgBL.translate(ctx, "M_Lot_ID"));
      label.setLabelFor(fieldLot);
      centerPanel.add(label, new ALayoutConstraint(m_row++, 0));
      centerPanel.add(fieldLot, null);
      if (asiTemplate.getM_Lot_ID() > 0) {
        for (int i = 1; i < fieldLot.getItemCount(); i++) {
          KeyNamePair pp = fieldLot.getItemAt(i);
          if (pp.getKey() == asiTemplate.getM_Lot_ID()) {
            fieldLot.setSelectedIndex(i);
            fieldLotString.setEditable(false);
            break;
          }
        }
      }
      fieldLot.addActionListener(this);
      // New Lot Button
      if (asiTemplate.getMAttributeSet().getM_LotCtl_ID() > 0) {
        if (Env.getUserRolePermissions().isTableAccess(MLot.Table_ID, false)
            && Env.getUserRolePermissions().isTableAccess(MLotCtl.Table_ID, false)
            && !asiTemplate.isExcludeLot(m_AD_Column_ID, attributeContext.isSOTrx())) {
          centerPanel.add(bLot, null);
          bLot.addActionListener(this);
        }
      }
      // Popup
      fieldLot.addMouseListener(new VPAttributeDialog_mouseAdapter(this)); // popup
      mZoom = new CMenuItem(msgBL.getMsg(ctx, "Zoom"), Images.getImageIcon2("Zoom16"));
      mZoom.addActionListener(this);
      popupMenu.add(mZoom);
    } // Lot

    //
    // SerNo
    if (isPureProductASI && as.isSerNo()) {
      CLabel label = new CLabel(msgBL.translate(ctx, "SerNo"));
      label.setLabelFor(fieldSerNo);
      fieldSerNo.setText(asiTemplate.getSerNo());
      centerPanel.add(label, new ALayoutConstraint(m_row++, 0));
      centerPanel.add(fieldSerNo, null);
      // New SerNo Button
      if (asiTemplate.getMAttributeSet().getM_SerNoCtl_ID() != 0) {
        if (Env.getUserRolePermissions().isTableAccess(MSerNoCtl.Table_ID, false)
            && !asiTemplate.isExcludeSerNo(m_AD_Column_ID, attributeContext.isSOTrx())) {
          centerPanel.add(bSerNo, null);
          bSerNo.addActionListener(this);
        }
      }
    } // SerNo

    //
    // GuaranteeDate.
    // We are displaying it if we deal with a pure product ASI (i.e. user is not editing the ASI
    // from product window),
    // and if:
    // * the attribute set requires a GuaranteeDate
    // * or if the ASI has a GuaranteeDate already set
    if (isPureProductASI && (as.isGuaranteeDate() || asiTemplate.getGuaranteeDate() != null)) {
      CLabel label = new CLabel(msgBL.translate(ctx, "GuaranteeDate"));
      label.setLabelFor(fieldGuaranteeDate);
      if (isASITemplateNew) {
        Date guaranteeDate = asiTemplate.getGuaranteeDate();
        if (guaranteeDate == null) {
          guaranteeDate =
              attributesBL.calculateBestBeforeDate(
                  ctx,
                  m_M_Product_ID, // product
                  attributeContext.getC_BPartner_ID(), // vendor bpartner
                  Env.getDate(ctx) // dateReceipt
                  );
        }
        fieldGuaranteeDate.setValue(guaranteeDate);
      } else {
        fieldGuaranteeDate.setValue(asiTemplate.getGuaranteeDate());
      }
      centerPanel.add(label, new ALayoutConstraint(m_row++, 0));
      centerPanel.add(fieldGuaranteeDate, null);
      fieldGuaranteeDateDisplayed = true;
    } // GuaranteeDate

    // Make sure we have at least something to edit or something to select,
    // else there is no point in showing empty this window.
    if (m_row == 0) {
      throw new AdempiereException("@PAttributeNoInfo@");
    }

    //
    // New/Edit Window
    if (allowSelectExistingASI) {
      cbNewEdit.setSelected(isASITemplateNew);
      cmd_newEdit();
    }

    //
    // Attrribute Set Instance Description
    {
      final CLabel labelDescription = new CLabel(msgBL.translate(ctx, "Description"));
      labelDescription.setLabelFor(fieldDescription);
      fieldDescription.setText(asiTemplate.getDescription());
      fieldDescription.setEditable(false);
      centerPanel.add(labelDescription, new ALayoutConstraint(m_row++, 0));
      centerPanel.add(fieldDescription, null);
    }

    // Window usually to wide (??)
    {
      final Dimension dd = centerPanel.getPreferredSize();
      dd.width = Math.min(500, dd.width);
      centerPanel.setPreferredSize(dd);
    }
  } // initAttribute