Exemplo n.º 1
0
  /**
   * Caret Listener
   *
   * @param e event
   */
  public void caretUpdate(CaretEvent e) {
    log.finest("Dot=" + e.getDot() + ",Last=" + m_lastDot + ", Mark=" + e.getMark());
    //	Selection
    if (e.getDot() != e.getMark()) {
      m_lastDot = e.getDot();
      return;
    }
    //

    //	Is the current position a fixed character?
    if (e.getDot() + 1 > m_mask.length() || m_mask.charAt(e.getDot()) != DELIMITER) {
      m_lastDot = e.getDot();
      return;
    }

    //	Direction?
    int newDot = -1;
    if (m_lastDot > e.getDot()) // 	<-
    newDot = e.getDot() - 1;
    else //	-> (or same)
    newDot = e.getDot() + 1;
    if (e.getDot() == 0) // 	first
    newDot = 1;
    else if (e.getDot() == m_mask.length() - 1) // 	last
    newDot = e.getDot() - 1;
    //
    log.fine(
        "OnFixedChar=" + m_mask.charAt(e.getDot()) + ", newDot=" + newDot + ", last=" + m_lastDot);
    //
    m_lastDot = e.getDot();
    if (newDot >= 0 && newDot < getText().length()) m_tc.setCaretPosition(newDot);
  } //	caretUpdate
Exemplo n.º 2
0
  /**
   * ************************************************************************ Delete String
   *
   * @param origOffset Offeset
   * @param length length
   * @throws BadLocationException
   */
  @Override
  public void remove(int origOffset, int length) throws BadLocationException {
    log.finest("Offset=" + origOffset + " Length=" + length);
    if (origOffset < 0 || length < 0)
      throw new IllegalArgumentException("MDocNumber.remove - invalid argument");

    int offset = origOffset;
    if (length != 1) {
      super.remove(offset, length);
      return;
    }
    /** Manual Entry */
    String content = getText();
    //	remove all Thousands
    if (content.indexOf(m_groupingSeparator) != -1) {
      StringBuffer result = new StringBuffer();
      for (int i = 0; i < content.length(); i++) {
        if (content.charAt(i) == m_groupingSeparator && i != origOffset) {
          if (i < offset) offset--;
        } else result.append(content.charAt(i));
      }
      super.remove(0, content.length());
      super.insertString(0, result.toString(), null);
      m_tc.setCaretPosition(offset);
    } //	remove Thousands
    super.remove(offset, length);
  } //	remove
Exemplo n.º 3
0
  /** Refresh Query */
  private void refresh() {
    String sql = m_sql;
    int pos = m_sql.lastIndexOf(" ORDER BY ");
    if (!showAll.isSelected()) {
      sql = m_sql.substring(0, pos) + s_sqlWhereSameWarehouse;
      if (s_sqlMinLife.length() > 0) sql += s_sqlMinLife;
      sql += m_sql.substring(pos);
    }
    //
    log.finest(sql);
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      pstmt = DB.prepareStatement(sql, null);
      pstmt.setInt(1, m_M_Product_ID);
      if (!showAll.isSelected()) {
        pstmt.setInt(2, m_M_Warehouse_ID);
      }

      rs = pstmt.executeQuery();
      m_table.loadTable(rs);
    } catch (Exception e) {
      log.log(Level.SEVERE, sql, e);
    } finally {
      DB.close(rs, pstmt);
      rs = null;
      pstmt = null;
    }
    enableButtons();
  }
Exemplo n.º 4
0
 /**
  * ************************************************************************ Start Workflow.
  *
  * @param AD_Workflow_ID workflow
  * @return true if started
  */
 private boolean startWorkflow(int AD_Workflow_ID) {
   log.fine(AD_Workflow_ID + " - " + m_pi);
   boolean started = false;
   if (DB.isRemoteProcess()) {
     log.info("trying to running on the server");
     Server server = CConnection.get().getServer();
     try {
       if (server != null) { // 	See ServerBean
         log.info("running on the server");
         m_pi = server.workflow(m_wscctx, m_pi, AD_Workflow_ID);
         log.finest("server => " + m_pi);
         started = true;
       }
     } catch (Exception ex) {
       log.log(Level.SEVERE, "AppsServer error", ex);
       started = false;
     }
   }
   //	Run locally
   if (!started && !m_IsServerProcess) {
     log.info("running locally");
     MWorkflow wf = MWorkflow.get(m_wscctx, AD_Workflow_ID);
     MWFProcess wfProcess = null;
     if (m_pi.isBatch()) wfProcess = wf.start(m_pi); // 	may return null
     else wfProcess = wf.startWait(m_pi); // 	may return null
     started = wfProcess != null;
   }
   return started;
 } //  startWorkflow
Exemplo n.º 5
0
 /**
  * Set Editor to value
  *
  * @param value value
  */
 public void setValue(Object value) {
   log.finest("Value=" + value);
   if (value == null) m_oldText = "";
   else m_oldText = m_format.format(value);
   //	only set when not updated here
   if (m_setting) return;
   m_text.setText(m_oldText);
   m_initialText = m_oldText;
   m_modified = false;
 } //	setValue
Exemplo n.º 6
0
 /**
  * ************************************************************************ Start Java Process
  * Class. instanciate the class implementing the interface ProcessCall. The class can be a
  * Server/Client class (when in Package org compiere.process or org.compiere.model) or a client
  * only class (e.g. in org.compiere.report)
  *
  * @return true if success
  */
 private boolean startProcess() {
   log.fine(m_pi.toString());
   boolean started = false;
   if (DB.isRemoteProcess()) {
     Server server = CConnection.get().getServer();
     try {
       if (server != null) { // 	See ServerBean
         m_pi = server.process(m_wscctx, m_pi);
         log.finest("server => " + m_pi);
         started = true;
       }
     } catch (UndeclaredThrowableException ex) {
       Throwable cause = ex.getCause();
       if (cause != null) {
         if (cause instanceof InvalidClassException)
           log.log(
               Level.SEVERE, "Version Server <> Client: " + cause.toString() + " - " + m_pi, ex);
         else
           log.log(Level.SEVERE, "AppsServer error(1b): " + cause.toString() + " - " + m_pi, ex);
       } else log.log(Level.SEVERE, " AppsServer error(1) - " + m_pi, ex);
       started = false;
     } catch (Exception ex) {
       Throwable cause = ex.getCause();
       if (cause == null) cause = ex;
       log.log(Level.SEVERE, "AppsServer error - " + m_pi, cause);
       started = false;
     }
   }
   //	Run locally
   if (!started && !m_IsServerProcess) {
     ProcessCall myObject = null;
     try {
       Class myClass = Class.forName(m_pi.getClassName());
       myObject = (ProcessCall) myClass.newInstance();
       if (myObject == null) m_pi.setSummary("No Instance for " + m_pi.getClassName(), true);
       else myObject.startProcess(m_wscctx, m_pi, m_trx);
       if (m_trx != null) {
         m_trx.commit();
         m_trx.close();
       }
     } catch (Exception e) {
       if (m_trx != null) {
         m_trx.rollback();
         m_trx.close();
       }
       m_pi.setSummary("Error starting Class " + m_pi.getClassName(), true);
       log.log(Level.SEVERE, m_pi.getClassName(), e);
     }
   }
   return !m_pi.isError();
 } //  startProcess
  /**
   * 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
Exemplo n.º 8
0
  /**
   * Delete String
   *
   * @param offset offset
   * @param length length
   * @throws BadLocationException
   */
  @Override
  public void remove(int offset, int length) throws BadLocationException {
    log.finest("Offset=" + offset + ",Length=" + length);

    //	begin of string
    if (offset == 0 || length == 0) {
      //	empty the field
      //  if the length is 0 or greater or equal with the mask length - teo_sarca, [ 1660595 ] Date
      // field: incorrect functionality on paste
      if (length >= m_mask.length() || length == 0) super.remove(offset, length);
      return;
    }

    //	one position behind delimiter
    if (offset - 1 >= 0 && offset - 1 < m_mask.length() && m_mask.charAt(offset - 1) == DELIMITER) {
      if (offset - 2 >= 0) m_tc.setCaretPosition(offset - 2);
      else return;
    } else m_tc.setCaretPosition(offset - 1);
  } //	deleteString
Exemplo n.º 9
0
  /**
   * Key Listener. - Escape - Restore old Text - firstChange - signal change
   *
   * @param e event
   */
  public void keyReleased(KeyEvent e) {
    log.finest("Key=" + e.getKeyCode() + " - " + e.getKeyChar() + " -> " + m_text.getText());

    //  ESC
    if (e.getKeyCode() == KeyEvent.VK_ESCAPE) m_text.setText(m_initialText);

    m_modified = true;
    m_setting = true;
    try {
      if (e.getKeyCode() == KeyEvent.VK_ENTER) // 	10
      {
        fireVetoableChange(m_columnName, m_oldText, getValue());
        fireActionPerformed();
      }
      // else
      // {
      //	indicate change
      // fireVetoableChange (m_columnName, m_oldText, null);
      // }
    } catch (PropertyVetoException pve) {
    }
    m_setting = false;
  } //	keyReleased
Exemplo n.º 10
0
  /**
   * ************************************************************************ Insert String
   *
   * @param origOffset
   * @param string
   * @param attr
   * @throws BadLocationException
   */
  @Override
  public void insertString(int origOffset, String string, AttributeSet attr)
      throws BadLocationException {
    log.finest("Offset=" + origOffset + " String=" + string + " Length=" + string.length());
    if (origOffset < 0 || string == null) throw new IllegalArgumentException("Invalid argument");

    int offset = origOffset;
    int length = string.length();
    //	From DataBinder (assuming correct format)
    if (length != 1) {
      super.insertString(offset, string, attr);
      return;
    }

    /** Manual Entry */
    String content = getText();
    //	remove all Thousands
    if (content.indexOf(m_groupingSeparator) != -1) {
      StringBuffer result = new StringBuffer();
      for (int i = 0; i < content.length(); i++) {
        if (content.charAt(i) == m_groupingSeparator) {
          if (i < offset) offset--;
        } else result.append(content.charAt(i));
      }
      super.remove(0, content.length());
      super.insertString(0, result.toString(), attr);
      //
      m_tc.setCaretPosition(offset);
      //	ADebug.trace(ADebug.l6_Database, "Clear Thousands (" + m_format.toPattern() + ")" + content
      // + " -> " + result.toString());
      content = result.toString();
    } //	remove Thousands

    /**
     * ******************************************************************** Check Character entered
     */
    char c = string.charAt(0);
    if (Character.isDigit(c)) // c >= '0' && c <= '9')
    {
      //	ADebug.trace(ADebug.l6_Database, "Digit=" + c);
      super.insertString(offset, string, attr);
      return;
    }

    //	Decimal - remove other decimals
    //	Thousand - treat as Decimal
    else if (c == m_decimalSeparator || c == m_groupingSeparator || c == '.' || c == ',') {
      //	log.info("Decimal=" + c + " (ds=" + m_decimalSeparator + "; gs=" + m_groupingSeparator +
      // ")");
      //  no decimals on integers
      if (m_displayType == DisplayType.Integer) return;
      int pos = content.indexOf(m_decimalSeparator);

      //	put decimal in
      String decimal = String.valueOf(m_decimalSeparator);
      super.insertString(offset, decimal, attr);

      //	remove other decimals
      if (pos != 0) {
        content = getText();
        StringBuffer result = new StringBuffer();
        int correction = 0;
        for (int i = 0; i < content.length(); i++) {
          if (content.charAt(i) == m_decimalSeparator) {
            if (i == offset) result.append(content.charAt(i));
            else if (i < offset) correction++;
          } else result.append(content.charAt(i));
        }
        super.remove(0, content.length());
        super.insertString(0, result.toString(), attr);
        m_tc.setCaretPosition(offset - correction + 1);
      } //	remove other decimals
    } //	decimal or thousand

    //	something else
    else if (VNumber.AUTO_POPUP || "=+-/*%".indexOf(c) > -1) {

      //	Minus - put minus on start of string
      if (c == m_minusSign && offset == 0) {
        //	no minus possible
        if (m_displayType == DisplayType.Integer) return;
        //	add at start of string
        else super.insertString(0, "-", attr);
      } else {
        log.fine("Input=" + c + " (" + (int) c + ")");

        if (c == m_percentSign && offset > 0) {
          // don't convert integers to percent. 1% = 0?
          if (m_displayType == DisplayType.Integer) return;
          // divide by 100
          else {
            String value = getText();
            BigDecimal percentValue = new BigDecimal(0.0);
            try {
              if (value != null && value.length() > 0) {
                Number number = m_format.parse(value);
                percentValue = new BigDecimal(number.toString());
                percentValue =
                    percentValue.divide(
                        new BigDecimal(100.0),
                        m_format.getMaximumFractionDigits(),
                        BigDecimal.ROUND_HALF_UP);
                m_tc.setText(m_format.format(percentValue));
              }
            } catch (ParseException pe) {
              log.info("InvalidEntry - " + pe.getMessage());
            }
          }
        } else {

          String result =
              VNumber.startCalculator(m_tc, getText(), m_format, m_displayType, m_title, c);
          super.remove(0, content.length());

          // insertString(0, result, attr);
          m_tc.setText(result);
        }
      }
    } else ADialog.beep();
  } //	insertString
  /** Start dialog */
  private void cmd_dialog() {
    //
    Integer oldValue = (Integer) getValue();
    int oldValueInt = oldValue == null ? 0 : oldValue.intValue();
    int M_AttributeSetInstance_ID = oldValueInt;
    int M_Product_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "M_Product_ID");
    int M_ProductBOM_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "M_ProductBOM_ID");

    log.config(
        "M_Product_ID="
            + M_Product_ID
            + "/"
            + M_ProductBOM_ID
            + ",M_AttributeSetInstance_ID="
            + M_AttributeSetInstance_ID
            + ", AD_Column_ID="
            + gridField.getAD_Column_ID());

    //	M_Product.M_AttributeSetInstance_ID = 8418
    boolean productWindow = (gridField.getAD_Column_ID() == 8418); // 	HARDCODED

    //	Exclude ability to enter ASI
    boolean exclude = true;

    if (M_Product_ID != 0) {
      MProduct product = MProduct.get(Env.getCtx(), M_Product_ID);
      int M_AttributeSet_ID = Services.get(IProductBL.class).getM_AttributeSet_ID(product);
      if (M_AttributeSet_ID != 0) {
        final IAttributeExcludeBL excludeBL = Services.get(IAttributeExcludeBL.class);
        final I_M_AttributeSet attributeSet =
            InterfaceWrapperHelper.create(
                Env.getCtx(), M_AttributeSet_ID, I_M_AttributeSet.class, ITrx.TRXNAME_None);
        final I_M_AttributeSetExclude asExclude =
            excludeBL.getAttributeSetExclude(
                attributeSet, gridField.getAD_Column_ID(), Env.isSOTrx(Env.getCtx(), m_WindowNo));
        if ((null == asExclude) || (!excludeBL.isFullExclude(asExclude))) {
          exclude = false;
        }
      }
    }

    boolean changed = false;
    if (M_ProductBOM_ID != 0) // 	Use BOM Component
    M_Product_ID = M_ProductBOM_ID;
    //
    if (!productWindow && (M_Product_ID == 0 || exclude)) {
      changed = true;
      getComponent().setText(null);
      M_AttributeSetInstance_ID = 0;
    } else {
      WPAttributeDialog vad =
          new WPAttributeDialog(
              M_AttributeSetInstance_ID,
              M_Product_ID,
              m_C_BPartner_ID,
              productWindow,
              gridField.getAD_Column_ID(),
              m_WindowNo);
      if (vad.isChanged()) {
        getComponent().setText(vad.getM_AttributeSetInstanceName());
        M_AttributeSetInstance_ID = vad.getM_AttributeSetInstance_ID();
        if (m_GridTab != null && !productWindow && vad.getM_Locator_ID() > 0)
          m_GridTab.setValue("M_Locator_ID", vad.getM_Locator_ID());
        changed = true;
      }
    }
    /**
     * Selection { // Get Model MAttributeSetInstance masi = MAttributeSetInstance.get(Env.getCtx(),
     * M_AttributeSetInstance_ID, M_Product_ID); if (masi == null) { log.log(Level.SEVERE, "No Model
     * for M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID + ", M_Product_ID=" +
     * M_Product_ID); } else { Env.setContext(Env.getCtx(), m_WindowNo, "M_AttributeSet_ID",
     * masi.getM_AttributeSet_ID()); // Get Attribute Set MAttributeSet as =
     * masi.getMAttributeSet(); // Product has no Attribute Set if (as == null)
     * ADialog.error(m_WindowNo, this, "PAttributeNoAttributeSet"); // Product has no Instance
     * Attributes else if (!as.isInstanceAttribute()) ADialog.error(m_WindowNo, this,
     * "PAttributeNoInstanceAttribute"); else { int M_Warehouse_ID = Env.getContextAsInt (Env.getCtx
     * (), m_WindowNo, "M_Warehouse_ID"); int M_Locator_ID = Env.getContextAsInt (Env.getCtx (),
     * m_WindowNo, "M_Locator_ID"); String title = ""; PAttributeInstance pai = new
     * PAttributeInstance ( Env.getFrame(this), title, M_Warehouse_ID, M_Locator_ID, M_Product_ID,
     * m_C_BPartner_ID); if (pai.getM_AttributeSetInstance_ID() != -1) {
     * m_text.setText(pai.getM_AttributeSetInstanceName()); M_AttributeSetInstance_ID =
     * pai.getM_AttributeSetInstance_ID(); changed = true; } } } }
     */

    //	Set Value
    if (changed) {
      log.finest("Changed M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID);
      m_value = new Object(); // 	force re-query display
      if (M_AttributeSetInstance_ID == 0) setValue(null);
      else setValue(new Integer(M_AttributeSetInstance_ID));

      ValueChangeEvent vce =
          new ValueChangeEvent(this, gridField.getColumnName(), new Object(), getValue());
      fireValueChange(vce);
      if (M_AttributeSetInstance_ID == oldValueInt && m_GridTab != null && gridField != null) {
        //  force Change - user does not realize that embedded object is already saved.
        m_GridTab.processFieldChange(gridField);
      }
    } //	change
  } //  cmd_file
Exemplo n.º 12
0
  /**
   * Insert String
   *
   * @param offset offset
   * @param string string
   * @param attr attributes
   * @throws BadLocationException
   */
  @Override
  public void insertString(int offset, String string, AttributeSet attr)
      throws BadLocationException {
    log.finest(
        "Offset="
            + offset
            + ",String="
            + string
            + ",Attr="
            + attr
            + ",OldText="
            + getText()
            + ",OldLength="
            + getText().length());

    //	manual entry
    //	DBTextDataBinder.updateText sends stuff at once - length=8
    if (string != null && string.length() == 1) {
      //	ignore if too long
      if (offset >= m_mask.length()) return;

      //	is it an empty field?
      int length = getText().length();
      if (offset == 0 && length == 0) {
        Date today = new Date(System.currentTimeMillis());
        String dateStr = m_format.format(today);
        super.insertString(0, string + dateStr.substring(1), attr);
        m_tc.setCaretPosition(1);
        return;
      }

      //	is it a digit ?
      try {
        Integer.parseInt(string);
      } catch (Exception pe) {
        // hengsin, [ 1660175 ] Date field - anoying popup
        // startDateDialog();
        ADialog.beep();
        return;
      }

      //	try to get date in field, if invalid, get today's
      /*try
      {
      	char[] cc = getText().toCharArray();
      	cc[offset] = string.charAt(0);
      	m_format.parse(new String(cc));
      }
      catch (ParseException pe)
      {
      	startDateDialog();
      	return;
      }*/

      //	positioned before the delimiter - jump over delimiter
      if (offset != m_mask.length() - 1 && m_mask.charAt(offset + 1) == DELIMITER)
        m_tc.setCaretPosition(offset + 2);

      //	positioned at the delimiter
      if (m_mask.charAt(offset) == DELIMITER) {
        offset++;
        m_tc.setCaretPosition(offset + 1);
      }
      super.remove(offset, 1); // 	replace current position
    }

    //	Set new character
    super.insertString(offset, string, attr);
    //	New value set Cursor
    if (offset == 0 && string != null && string.length() > 1) m_tc.setCaretPosition(0);
  } //	insertString