Example #1
0
 public ChangeVO updateRow(
     int windowNo,
     int AD_Tab_ID,
     int queryResultID,
     int relRowNo,
     Map<String, String> context,
     boolean force) {
   if (context == null || context.size() == 0)
     return new ChangeVO(true, Msg.translate(m_context, "NoContext"));
   ArrayList<String[]> data = m_results.get(queryResultID);
   if (data == null || data.size() == 0)
     return new ChangeVO(true, Msg.translate(m_context, "CachedDataNotFound"));
   UITab tab = getTab(AD_Tab_ID);
   if (tab == null) {
     log.config("Not found AD_Tab_ID=" + AD_Tab_ID);
     return new ChangeVO(true, Msg.translate(m_context, "@NotFound@ @AD_Tab_ID@=" + AD_Tab_ID));
   }
   CContext ctx = new CContext(m_context.entrySet());
   ctx.addWindow(windowNo, context);
   ChangeVO retValue;
   if (force) retValue = tab.saveRow(ctx, windowNo, false, null);
   else retValue = tab.saveRow(ctx, windowNo, false, data.get(relRowNo));
   if (retValue.hasError()) return retValue;
   // Update Results
   String[] dataRow = retValue.rowData.clone();
   data.set(relRowNo, dataRow);
   postProcessChangeVO(retValue, windowNo, context, dataRow, tab);
   retValue.trxInfo = GridTab.getTrxInfo(tab.getTableName(), ctx, windowNo, tab.getTabNo());
   if (retValue.isRefreshAll()) {}
   return retValue;
 }
Example #2
0
 /**
  * Refresh current row of Tab
  *
  * @param windowNo relative window
  * @param AD_Tab_ID tab
  * @param relRowNo relative row number in results
  * @param context current (relevant) context of new row
  * @return error message or null
  */
 public ChangeVO refreshRow(
     int windowNo, int AD_Tab_ID, int queryResultID, int relRowNo, 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);
   }
   CContext ctx = new CContext(m_context.entrySet());
   ctx.addWindow(windowNo, context);
   ChangeVO retValue = tab.refreshRow(ctx, windowNo);
   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.clone();
     data.set(relRowNo, dataRow);
     postProcessChangeVO(retValue, windowNo, context, dataRow, tab);
     retValue.trxInfo = GridTab.getTrxInfo(tab.getTableName(), ctx, windowNo, tab.getTabNo());
   }
   return retValue;
 } // refreshRow
Example #3
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++;
    }
  }