/** Associate Button Pressed */
  private void cmd_associate() {
    int productRow = xProductTable.getSelectedRow();
    log.config("Row=" + productRow);

    KeyNamePair product = (KeyNamePair) xProductTable.getValueAt(productRow, 0);

    doInsert(product.getKey(), 0);

    //  ** Load Table **
    tableInit_option = 1;
    tableInit();
    tableLoad(xAssociateTable);

    //  ** Load Table **
    tableInit_option = 2;
    tableInit();
    tableLoad(xProductTable);

    bDisassociate.setEnabled(true);
    bNewProduct.setEnabled(false);

    // Coloco la referencia como asociada
    // MVMRVendorProdRef vendorProdRef = new MVMRVendorProdRef(Env.getCtx(),
    // LineRefProv.getXX_VMR_VendorProdRef_ID(), null);
    // vendorProdRef.setXX_IsAssociated(true);
    // vendorProdRef.save();

  } //  cmd_associate
  /**
   * Fill the table using m_sql
   *
   * @param table table
   */
  private static void tableLoad(MiniTable table) {
    //	log.finest(m_sql + " - " +  m_groupBy);
    String sql =
        MRole.getDefault()
                .addAccessSQL(m_sql.toString(), "tab", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO)
            + m_groupBy
            + m_orderBy;

    log.finest(sql);
    try {
      Statement stmt = DB.createStatement();
      ResultSet rs = stmt.executeQuery(sql);
      table.loadTable(rs);
      stmt.close();
    } catch (SQLException e) {
      log.log(Level.SEVERE, sql, e);
    }
  } //  tableLoad
  /** Dynamic Init. Table Layout, Visual, Listener */
  private void dynInit() {

    ColumnInfo[] layout =
        new ColumnInfo[] {
          new ColumnInfo(Msg.translate(Env.getCtx(), "M_Product_ID"), ".", KeyNamePair.class), //  1
          new ColumnInfo(Msg.translate(Env.getCtx(), "Name"), ".", String.class) //  2
        };

    xProductTable.prepareTable(layout, "", "", false, "");
    xAssociateTable.prepareTable(layout, "", "", true, "");

    xAssociateTable.setAutoResizeMode(3);
    xProductTable.setAutoResizeMode(3);

    //  Visual
    CompiereColor.setBackground(this);

    //  Listener
    xProductTable.getSelectionModel().addListSelectionListener(this);
    xAssociateTable.getModel().addTableModelListener(this);
    bDisassociate.addActionListener(this);
    bNewProduct.addActionListener(this);

    // pregunto si hay productos asociados para ver si cargo las tablas
    boolean ready = verify();

    if (ready == false) {

      tableInit_option = 0;
      tableInit();
      tableLoad(xProductTable);

    } else {
      tableInit_option = 1;
      tableInit();
      tableLoad(xAssociateTable);

      bNewProduct.setEnabled(false);
      bDisassociate.setEnabled(true);
    }

    xProductTable.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {

              int rowP = xProductTable.getSelectedRow();

              if (!(rowP == -1)) {
                cmd_associate();
              }
            }
          }
        });

    //  Init
    statusBar.setStatusLine("");
    statusBar.setStatusDB(0);

    MOrder order = new MOrder(Env.getCtx(), LineRefProv.getC_Order_ID(), null);

    boolean block = false;
    String oS = order.getXX_OrderStatus();
    String compS = order.getDocStatus();
    if (oS.equals("AN") || compS.equals("CO")) {
      block = true;
    }

    if (order.isXX_OrderReadyStatus() && order.getXX_OrderType().equalsIgnoreCase("Nacional"))
      block = true;

    if (order.getXX_OrderType().equalsIgnoreCase("Importada")
        && order.get_ValueAsInt("XX_ImportingCompany_ID") != 0) {

      if (order.get_ValueAsInt("XX_ImportingCompany_ID")
          != Env.getCtx().getContextAsInt("#XX_L_VSI_CLIENTCENTROBECO_ID")) {
        block = true;
      }
    }

    if (order.getXX_StoreDistribution().equals("Y") || block) {
      xProductTable.setEnabled(false);
      xAssociateTable.setEnabled(false);
      bNewProduct.setEnabled(false);
      bDisassociate.setEnabled(false);
    }
  } //  dynInit