Ejemplo n.º 1
0
  /**
   * Get Field Lookup Value Direct
   *
   * @param windowNo Window
   * @param AD_Field_ID
   * @param keyValues array of id values
   * @param cache
   * @return list of display values
   */
  public ArrayList<NamePair> getLookupValueDirect(
      int AD_Field_ID, ArrayList<String> keyValues, boolean cache) {
    int windowNo = 0; // No Context
    ArrayList<NamePair> displayValues = new ArrayList<NamePair>();
    UIField field = getField(AD_Field_ID, windowNo);

    // if (cache && field.isLookup())
    // field.getLookup().removeAllElements();
    if (field == null) log.warning("Cannot find AD_Field_ID=" + AD_Field_ID);
    //
    for (int i = 0; i < keyValues.size(); i++) {
      String key = keyValues.get(i);
      String value = null;
      if (field != null) value = field.getLookupDisplay(m_context, windowNo, key, cache);
      if (value == null) {
        /*
         * if(key == null) value = ""; else value = "<" + key + ">";
         */
        value = "";
      }
      NamePair pp = new ValueNamePair(key, value);
      displayValues.add(pp);
    }
    return displayValues;
  } // getLookupValueDirect
Ejemplo n.º 2
0
 /**
  * Get Lookup Data for Field in context
  *
  * @param AD_Field_ID field
  * @param context context
  * @param refresh requery
  * @return lookup pair array
  */
 public ArrayList<NamePair> getLookupData(
     int windowNo, int AD_Field_ID, Map<String, String> context, boolean refresh) {
   UIField field = getField(AD_Field_ID, windowNo);
   if (field == null) {
     log.warning("Cannot find AD_Field_ID=" + AD_Field_ID);
     return null;
   }
   CContext ctx = new CContext(m_context.entrySet());
   ctx.addWindow(windowNo, context);
   if (field.isLookup() || field.isButtonLookup()) return field.getAllLookupData(ctx, windowNo);
   else log.warning("No Lookup: " + field.getColumnName());
   return null;
 } // getLookupData
Ejemplo n.º 3
0
 /**
  * Get Field
  *
  * @param AD_Field_ID id
  * @param windowNo relative windowNo
  * @return field or null
  */
 public UIField getField(int AD_Field_ID, int windowNo) {
   Integer key = Integer.valueOf(AD_Field_ID);
   UIField field = m_fields.get(key);
   if (field == null) {
     UIFieldVOFactory fieldFactory = new UIFieldVOFactory();
     UIFieldVO vo = fieldFactory.get(m_context, AD_Field_ID);
     // m_context.setSOTrx(windowNo, isSOTrx);
     if (vo != null) {
       field = new UIField(vo);
       field.initialize(m_context, windowNo);
       log.warning("Loaded directly: " + field); // SOTrx may not
       // be correct
       m_fields.put(key, field); // save in cache
     }
   } // create new
   return field;
 } // getField
Ejemplo n.º 4
0
 public int searchTabResults(
     int WindowNo,
     int AD_Tab_ID,
     int queryResultID,
     int searchResultID,
     String query,
     int rowCount) {
   UITab tab = getTab(AD_Tab_ID);
   ArrayList<Integer> ids = new ArrayList<Integer>();
   for (UIField field : tab.getFields()) {
     if (field.isSelectionColumn()
         || field.isIdentifier() && FieldType.isText(field.getAD_Reference_ID())) {
       ids.add(field.getAD_Field_ID());
     }
   }
   return searchTabResults(WindowNo, tab, ids, queryResultID, searchResultID, query, rowCount);
 }
Ejemplo n.º 5
0
  /**
   * Field Changed
   *
   * @param windowNo relative window
   * @param AD_Field_ID field
   * @param AD_Tab_ID tab
   * @param oldValue old field value
   * @param newValue new field value
   * @param context record context
   * @return Field Change VO
   */
  public ChangeVO fieldChanged(
      int windowNo,
      int AD_Field_ID,
      int AD_Tab_ID,
      String oldValue,
      String newValue,
      Map<String, String> context) {
    // Same Values
    if (oldValue == null || oldValue.equals(Null.NULLString)) oldValue = "";
    if (newValue == null || newValue.equals(Null.NULLString)) newValue = "";
    if (oldValue.equals(newValue)) return null;
    //
    UITab tab = getTab(AD_Tab_ID);
    if (tab == null) {
      log.config("Not found AD_Tab_ID=" + AD_Tab_ID);
      return null;
    }
    UIField field = getField(AD_Field_ID, windowNo);
    if (field == null) {
      log.warning("Cannot find AD_Field_ID=" + AD_Field_ID);
      return null;
    }

    CContext ctx = new CContext(m_context.entrySet());
    ctx.addWindow(windowNo, context);
    CContext origCtx = new CContext(m_context.entrySet());
    origCtx.addWindow(windowNo, context);
    ChangeVO change = null;
    try {
      // reset the thread active flag, in case the thread is reused later on
      CThreadUtil.setCalloutActive(false);
      change =
          tab.fieldChanged(
              origCtx, ctx, new ArrayList<UIField>(5), windowNo, field, oldValue, newValue);
      CThreadUtil.setCalloutActive(false);
      ctx.setContext(windowNo, field.getColumnName(), change.newConfirmedFieldValue);
    } catch (Exception e) {
      log.severe("fieldChange error:" + field.getColumnName() + e.getMessage());
    } finally {
      CThreadUtil.setCalloutActive(false);
    }

    return change;
  } // fieldChanged
Ejemplo n.º 6
0
 /** Fill Tab and Field arrays */
 private void fillTabsFieldsAndInitFieldsAndCreateDependencyRelations(UIWindow win, int windowNO) {
   ArrayList<UITab> tabs = win.getTabs();
   for (int j = 0; j < tabs.size(); j++) {
     UITab winTab = tabs.get(j);
     Integer tabKey = Integer.valueOf(winTab.getAD_Tab_ID());
     Integer ReferencetabKey = Integer.valueOf(winTab.getReferenced_Tab_ID());
     m_tabs.put(tabKey, winTab);
     m_referencetabs.put(ReferencetabKey, winTab);
     //
     ArrayList<UIField> fields = winTab.getFields();
     for (int k = 0; k < fields.size(); k++) {
       UIField field = fields.get(k);
       field.initialize(m_context, windowNO);
       Integer fieldKey = Integer.valueOf(field.getAD_Field_ID());
       // set the correct value
       if (field.isLookup()) field.getLookup().setContext(m_context, windowNO);
       m_fields.put(fieldKey, field);
     }
     winTab.createDependencyRelations();
   }
 } // fillTabsFields
Ejemplo n.º 7
0
 /**
  * Get Field Lookup Value Direct
  *
  * @param windowNo Window
  * @param AD_Field_ID
  * @param keyValues array of id values
  * @param cache
  * @return list of display values
  */
 public ArrayList<String> getLookupValueOnlyDirect(
     int AD_Field_ID, ArrayList<String> keyValues, boolean cache) {
   int windowNo = 0; // No Context
   ArrayList<String> displayValues = new ArrayList<String>();
   UIField field = getField(AD_Field_ID, windowNo);
   if (field == null) log.warning("Cannot find AD_Field_ID=" + AD_Field_ID);
   //
   for (int i = 0; i < keyValues.size(); i++) {
     String key = keyValues.get(i);
     String value = null;
     if (field != null) value = field.getLookupDisplay(m_context, windowNo, key, cache);
     if (value == null) {
       /*
        * if(key == null) value = ""; else value = "<" + key + ">";
        */
       value = "";
     }
     displayValues.add(value);
   }
   return displayValues;
 } // getLookupValueDirect
Ejemplo n.º 8
0
 private void postProcessChangeVO(
     ChangeVO change, int windowNo, Map<String, String> context, String[] dataRow, UITab tab) {
   // make an updated context to get the necessary listboxvos
   Map<String, String> contextAfterUpdate = new HashMap<String, String>(context);
   int j = 0;
   for (UIField field : tab.getFields()) {
     contextAfterUpdate.put(field.getColumnName(), dataRow[j]);
     j++;
   }
   // now change rowData to remove password, and reload the changed
   // listboxes
   j = 0;
   for (UIField field : tab.getFields()) {
     // return an empty string for passwords etc
     if (field.isEncryptedField()
         || field.isEncryptedColumn()
         || "Password".equals(field.getColumnName())) change.rowData[j] = "";
     if (FieldType.isClientLookup(field.getAD_Reference_ID()) && field.isDependentValue()) {
       if (change.changedDropDowns == null)
         change.changedDropDowns = new HashMap<String, ArrayList<NamePair>>();
       ArrayList<NamePair> values;
       if (field.getAD_Reference_ID() == DisplayTypeConstants.Search) {
         ArrayList<String> t = new ArrayList<String>(1);
         t.add(context.get(field.getColumnName()));
         values = getLookupValueDirect(field.getAD_Field_ID(), t, true);
       } else values = getLookupData(windowNo, field.getAD_Field_ID(), context, true);
       change.changedDropDowns.put(field.getColumnName(), values);
     }
     j++;
   }
 }
Ejemplo n.º 9
0
 // Method to return a list of matches according to fields for a tab, using
 // the cached results
 // this does not store the result in the cache - this behavior is deferred
 // to the caller
 private int searchTabResults(
     int WindowNo,
     UITab tab,
     List<Integer> fieldIds,
     int queryResultID,
     int searchResultID,
     String query,
     int rowCount) {
   ArrayList<String[]> results = m_results.get(queryResultID);
   if (query.trim().equals("")) {
     m_results.put(searchResultID, results);
     return results.size();
   }
   ScoreStrategy scorer = new ScoreStrategy(query);
   ScoreCell[] scores = new ScoreCell[results.size()];
   // first initialize score cells
   int j = 0;
   for (String[] result : results) {
     // initialize score cells
     ScoreCell score = new ScoreCell();
     score.row = result;
     score.score = scorer.createScore();
     scores[j++] = score;
   }
   for (int id : fieldIds) {
     UIField field = getField(id, WindowNo);
     final int idx = tab.getFieldIndex(id);
     if (field.isLookup()) {
       ArrayList<String> fieldValues = new ArrayList<String>(results.size());
       for (String[] row : results) {
         fieldValues.add(row[idx]);
       }
       ArrayList<String> sorts = getLookupValueOnlyDirect(id, fieldValues, true);
       int i = 0;
       for (String value : sorts) {
         scorer.getScore(value, scores[i].score);
         i++;
       }
     } else {
       int i = 0;
       for (String[] row : results) {
         String value = row[idx];
         scorer.getScore(value, scores[i].score);
         i++;
       }
     }
   }
   ArrayList<ScoreCell> matchingScores = new ArrayList<ScoreCell>();
   for (ScoreCell cell : scores) {
     if (cell.score.isMatch) {
       matchingScores.add(cell);
     }
   }
   Collections.sort(matchingScores, scorer);
   ArrayList<String[]> matches = new ArrayList<String[]>();
   for (ScoreCell score : matchingScores) {
     matches.add(score.row);
   }
   m_results.put(searchResultID, matches);
   return matches.size();
 }
Ejemplo n.º 10
0
  public void sortResults(
      int WindowNo, int AD_Tab_ID, int AD_Field_ID, int queryResultID, final boolean ascending) {
    class SortCell {

      String[] row;

      String sort;
    }
    ArrayList<String[]> results = m_results.get(queryResultID);
    if (results == null)
      log.severe("cannot sort. results non-existent for queryResultID:" + queryResultID);
    UITab tab = getTab(AD_Tab_ID);
    final UIField field = getField(AD_Field_ID, WindowNo);
    final int displayType = field.getAD_Reference_ID();
    final int idx = tab.getFieldIndex(AD_Field_ID);
    // if not a lookup, directly sort
    if (!field.isLookup()) {
      if (FieldType.isNumeric(displayType)) {
        Collections.sort(
            results,
            new Comparator<String[]>() {

              @Override
              public int compare(String[] o1, String[] o2) {
                if (o1[idx] == null) o1[idx] = "";
                if (o2[idx] == null) o2[idx] = "";
                BigDecimal s1 = new BigDecimal(o1[idx].equals("") ? "-1e-10" : o1[idx]);
                BigDecimal s2 = new BigDecimal(o2[idx].equals("") ? "-1e-10" : o2[idx]);
                return ascending ? s1.compareTo(s2) : s2.compareTo(s1);
              }
            });
      } else if (FieldType.isDate(displayType)) {
        Collections.sort(
            results,
            new Comparator<String[]>() {

              @Override
              public int compare(String[] o1, String[] o2) {
                if (o1[idx] == null) o1[idx] = "";
                if (o2[idx] == null) o2[idx] = "";
                Long s1 = new Long(o1[idx].equals("") ? "-1000000" : o1[idx]);
                Long s2 = new Long(o2[idx].equals("") ? "-1000000" : o2[idx]);
                return ascending ? s1.compareTo(s2) : s2.compareTo(s1);
              }
            });
      } else {
        Collections.sort(
            results,
            new Comparator<String[]>() {

              @Override
              public int compare(String[] o1, String[] o2) {
                if (o1[idx] == null) o1[idx] = "";
                if (o2[idx] == null) o2[idx] = "";
                String s1 = o1[idx];
                String s2 = o2[idx];
                return ascending ? s1.compareTo(s2) : s2.compareTo(s1);
              }
            });
      }
      return;
    }
    Comparator<SortCell> c =
        new Comparator<SortCell>() {

          public int compare(SortCell o1, SortCell o2) {
            if (ascending) return o1.sort.compareTo(o2.sort);
            else return o2.sort.compareTo(o1.sort);
          }
        };
    // for look up, first get id values
    ArrayList<String> fieldValues = new ArrayList<String>(results.size());
    for (String[] row : results) {
      fieldValues.add(row[idx]);
    }
    // then translate into real values
    ArrayList<String> sorts = getLookupValueOnlyDirect(AD_Field_ID, fieldValues, true);
    ArrayList<SortCell> toBeSorteds = new ArrayList<SortCell>(sorts.size());
    for (int i = 0; i < sorts.size(); i++) {
      SortCell toBeSorted = new SortCell();
      toBeSorted.row = results.get(i);
      toBeSorted.sort = sorts.get(i);
      toBeSorteds.add(toBeSorted);
    }
    // sort
    Collections.sort(toBeSorteds, c);
    // after sorting, replace col with original values
    int i = 0;
    for (SortCell toBeSorted : toBeSorteds) {
      results.set(i, toBeSorted.row);
      i++;
    }
  }