示例#1
0
  /**
   * Save (Insert new) Row of Tab
   *
   * @param windowNo relative window
   * @param AD_Tab_ID tab
   * @param curRow insert after relative row number in results
   * @param context current (relevant) context of new row
   * @return error message or null
   */
  public ChangeVO insertRow(
      int windowNo, int AD_Tab_ID, int queryResultID, int curRow, Map<String, String> context) {
    if (context == null || context.size() == 0) return new ChangeVO(true, "No Context");
    UITab tab = getTab(AD_Tab_ID);
    if (tab == null) {
      log.config("Not found AD_Tab_ID=" + AD_Tab_ID);
      return new ChangeVO(true, "@NotFound@ @AD_Tab_ID@=" + AD_Tab_ID);
    }

    log.info("Line Amt:" + context.get("LineNetAmt"));
    CContext ctx = new CContext(m_context.entrySet());
    ctx.addWindow(windowNo, context);
    ChangeVO retValue = tab.saveRow(ctx, windowNo, true);
    if (retValue.hasError()) return retValue;
    // Update Results
    ArrayList<String[]> data = m_results.get(queryResultID);
    if (data == null) retValue.addError("Data Not Found");
    else {
      String[] dataRow = retValue.rowData;
      if (curRow >= data.size()) data.add(dataRow);
      else data.add(curRow, dataRow);
      retValue.trxInfo = GridTab.getTrxInfo(tab.getTableName(), ctx, windowNo, tab.getTabNo());
    }
    return retValue;
  } // insertRow
示例#2
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++;
   }
 }
示例#3
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
示例#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);
 }
示例#5
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
示例#6
0
 /**
  * Get a menu tree representation based on a AD_Tree_ID
  *
  * @param AD_Tree_ID A tree based on AD_Menu
  * @return menu as array list
  */
 private ArrayList<CTreeNode> getMenuTree(int AD_Tree_ID, boolean edit) {
   MTree tree = new MTree(m_context, AD_Tree_ID, edit, true, true, null); // Language
   // set
   // in
   // WLogin
   // Trim tree
   CTreeNode root = tree.getRoot();
   Enumeration<?> en = root.preorderEnumeration();
   while (en.hasMoreElements()) {
     CTreeNode nd = (CTreeNode) en.nextElement();
     if (nd.isTask() || nd.isWorkbench() // || nd.isWorkFlow()
     // server
     ) {
       CTreeNode parent = (CTreeNode) nd.getParent();
       parent.remove(nd);
     }
   }
   tree.trimTree();
   en = root.preorderEnumeration();
   ArrayList<CTreeNode> retValue = new ArrayList<CTreeNode>();
   while (en.hasMoreElements()) {
     CTreeNode nd = (CTreeNode) en.nextElement();
     // Issue #420: removed menu entries for un-implemented forms
     if (nd.getAD_Form_ID() == 119 || nd.getAD_Form_ID() == 102
     //					|| nd.getAD_Workflow_ID() == 106
     //					|| nd.getAD_Workflow_ID() == 104
     //					// Review
     //					|| nd.getAD_Workflow_ID() == 112
     //					// Setup
     //					|| nd.getAD_Workflow_ID() == 113
     //					|| nd.getAD_Workflow_ID() == 110
     //					|| nd.getAD_Workflow_ID() == 111
     // || nd.getAD_Process_ID() == 205
     ) {
     } else retValue.add(nd);
   }
   return retValue;
 }
示例#7
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();
 }
示例#8
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++;
    }
  }