Пример #1
0
 /**
  * Add Field to Grid Tab
  *
  * @author Yamel Senih, [email protected], ERPCyA http://www.erpcya.com 19/05/2014, 11:48:33
  * @param v_lookup
  * @return void
  */
 public void addField(GridField m_Field) {
   //	Valid Null
   if (m_Field == null) return;
   if (model != null) m_Field.setColumnIndex(model.getColumnIndex(m_Field.getColumnName()));
   m_fields.add(m_Field);
   //	Add Dependent On
   //  List of ColumnNames, this field is dependent on
   ArrayList<String> list = m_Field.getDependentOn();
   //	Valid Null
   if (list == null) return;
   //	Iterate
   for (int i = 0; i < list.size(); i++) {
     String m_FieldName = list.get(i);
     m_depOnField.put(m_FieldName, m_Field); //  ColumnName, Field
     LogM.log(
         m_ctx,
         getClass(),
         Level.FINE,
         "Dependent Field Added [" + m_FieldName + ", " + m_Field.getColumnName() + "]");
   }
   //  Add fields all fields are dependent on
   if (m_Field.getColumnName().equals("IsActive")
       || m_Field.getColumnName().equals("Processed")
       || m_Field.getColumnName().equals("Processing"))
     m_depOnField.put(m_Field.getColumnName(), null);
 }
Пример #2
0
 /**
  * Change Display Logic
  *
  * @author Yamel Senih, [email protected], ERPCyA http://www.erpcya.com 06/09/2014, 14:27:59
  * @param m_FieldChanged
  * @return void
  */
 public void changeDisplayDepending(GridField m_FieldChanged) {
   //
   if (!hasDependants(m_FieldChanged.getColumnName())) return;
   //
   ArrayList<GridField> list = getDependantFields(m_FieldChanged.getColumnName());
   for (int index = 0; index < list.size(); index++) {
     GridField m_DependentField = list.get(index);
     //	Valid Null
     if (m_DependentField == null) continue;
     LogM.log(
         m_ctx,
         getClass(),
         Level.FINE,
         "Display Logic dependent child ["
             + m_FieldChanged.getColumnName()
             + " --> "
             + m_DependentField.getColumnName()
             + "]");
     //	Get Field Meta-Data
     InfoField fieldMD = m_DependentField.getField();
     if (fieldMD == null) continue;
     //	Display Logic
     m_DependentField.setVisible(this);
   }
 }
Пример #3
0
 /**
  * Reload depending fields
  *
  * @author Yamel Senih, [email protected], ERPCyA http://www.erpcya.com 30/08/2014, 20:39:26
  * @param m_FieldChanged
  * @return void
  */
 public void changeDepending(GridField m_FieldChanged) {
   //
   if (!hasDependants(m_FieldChanged.getColumnName())) return;
   //
   ArrayList<GridField> list = getDependantFields(m_FieldChanged.getColumnName());
   for (int index = 0; index < list.size(); index++) {
     GridField m_DependentField = list.get(index);
     //	Valid Null
     if (m_DependentField == null) continue;
     LogM.log(
         m_ctx,
         getClass(),
         Level.FINE,
         "Callout process dependent child ["
             + m_FieldChanged.getColumnName()
             + " --> "
             + m_DependentField.getColumnName()
             + "]");
     //	Get Field Meta-Data
     InfoField fieldMD = m_DependentField.getField();
     if (fieldMD == null) continue;
     //	Load
     if (DisplayType.isLookup(fieldMD.DisplayType)) {
       if (fieldMD.DisplayType != DisplayType.SEARCH
           && m_DependentField instanceof VLookupSpinner) {
         VLookupSpinner spinner = (VLookupSpinner) m_DependentField;
         Object oldValue = spinner.getValue();
         spinner.load(true);
         //	set old value
         spinner.setValueNoReload(oldValue);
       }
     }
   }
 }
Пример #4
0
 /**
  * Load Data from Model
  *
  * @author Yamel Senih, [email protected], ERPCyA http://www.erpcya.com 19/05/2014, 13:55:23
  * @param model
  * @return boolean
  */
 public boolean loadData() {
   LogM.log(m_ctx, getClass(), Level.FINE, "loadData()");
   if (model == null) return false;
   //	Get Record Identifier
   int m_Record_ID = model.getID();
   //
   for (GridField vField : m_fields) {
     //
     if (m_Record_ID <= 0) {
       //	Set value to parent field
       if (vField.isParent() || vField.getSPS_Column_ID() == m_TabInfo.getTabSPS_Column_ID()) {
         vField.setValue(
             DisplayType.getContextValue(
                 m_ctx,
                 m_TabParam.getActivityNo(),
                 m_TabParam.getParentTabNo(),
                 vField.getField()));
       } else {
         //	Set Default Value
         String defaultValue = vField.getDefaultValue();
         Object value = null;
         if (defaultValue != null && defaultValue.length() > 0) {
           value =
               DisplayType.parseValue(
                   Env.parseContext(
                       m_ctx,
                       m_TabParam.getActivityNo(),
                       m_TabParam.getParentTabNo(),
                       defaultValue,
                       false,
                       null),
                   vField.getDisplayType());
         } else {
           value = model.get_Value(vField.getColumnIndex());
         }
         //	Set Value
         vField.setValue(value);
       }
     } else {
       //	Set Value from Model
       vField.setValue(model.get_Value(vField.getColumnIndex()));
     }
     //	Set Current Values
     DisplayType.setContextValue(
         m_ctx,
         m_TabParam.getActivityNo(),
         m_TabParam.getTabNo(),
         vField.getField(),
         vField.getValue());
     //	Refresh Display
     changeDisplayDepending(vField);
   }
   //	Set ID to Context
   Env.setContext(
       m_TabParam.getActivityNo(),
       m_TabParam.getTabNo(),
       m_TabInfo.getTableKeyName(),
       m_Record_ID);
   Env.setContext(m_TabParam.getActivityNo(), m_TabInfo.getTableKeyName(), m_Record_ID);
   //	Return
   return true;
 }
Пример #5
0
  /**
   * ************************************************************************ Process Callout(s).
   *
   * <p>The Callout is in the string of "class.method;class.method;" If there is no class name, i.e.
   * only a method name, the class is regarded as CalloutSystem. The class needs to comply with the
   * Interface Callout.
   *
   * <p>For a limited time, the old notation of Sx_matheod / Ux_menthod is maintained.
   *
   * @param field field
   * @return error message or ""
   * @see org.compiere.model.Callout
   */
  public String processCallout(GridField field) {
    String callout = field.getCallout();
    if (callout == null || callout.length() == 0) return "";
    //
    if (isProcessed() && !field.isAlwaysUpdateable()) // 	only active records
    return ""; //	"DocProcessed";

    Object value = field.getValue();
    Object oldValue = field.getOldValue();
    LogM.log(
        m_ctx,
        getClass(),
        Level.FINE,
        field.getColumnName() + "=" + value + " (" + callout + ") - old=" + oldValue);

    StringTokenizer st = new StringTokenizer(callout, ";,", false);
    while (st.hasMoreTokens()) //  for each callout
    {
      String cmd = st.nextToken().trim();

      // detect infinite loop
      if (activeCallouts.contains(cmd)) continue;

      String retValue = "";
      Callout call = null;
      String method = null;
      int methodStart = cmd.lastIndexOf('.');
      try {
        if (methodStart != -1) //  no class
        {
          Class<?> cClass = Class.forName(cmd.substring(0, methodStart));
          call = (Callout) cClass.newInstance();
          method = cmd.substring(methodStart + 1);
        }
      } catch (Exception e) {
        LogM.log(m_ctx, getClass(), Level.SEVERE, "class", e);
        return "Callout Invalid: " + cmd + " (" + e.toString() + ")";
      }

      if (call == null || method == null || method.length() == 0)
        return "Callout Invalid: " + method;

      try {
        activeCallouts.add(cmd);
        activeCalloutInstance.add(call);
        retValue =
            call.start(m_ctx, method, m_TabParam.getActivityNo(), this, field, value, oldValue);
      } catch (Exception e) {
        LogM.log(m_ctx, getClass(), Level.SEVERE, "start", e);
        retValue = "Callout Invalid: " + e.toString();
        return retValue;
      } finally {
        activeCallouts.remove(cmd);
        activeCalloutInstance.remove(call);
      }
      //
      if (retValue != null && retValue.length() != 0) {
        LogM.log(m_ctx, getClass(), Level.SEVERE, "Error: " + retValue);
        return retValue;
      }
    } //  for each callout
    return "";
  } //	processCallout