コード例 #1
0
 public synchronized void lazyLoadChilderenIfNeeded(Object obj) {
   internal_lazyLoadChilderenIfNeeded(obj);
   if (obj instanceof UserNode) {
     UserNode un = (UserNode) obj;
     if (un.getChildCount() > 0) {
       DefaultMutableTreeNode child = (DefaultMutableTreeNode) un.children().nextElement();
       if (child instanceof UserNode) addListenerToFoundSet(((UserNode) child).getFoundSet());
     }
   } else if (obj instanceof RelationNode) {
     RelationNode rn = (RelationNode) obj;
     if (rn.getChildCount() > 0)
       addListenerToFoundSet(((UserNode) rn.children().nextElement()).getFoundSet());
   }
 }
コード例 #2
0
  public boolean hasChild(Object obj) {
    if (obj instanceof UserNode) {
      UserNode un = (UserNode) obj;
      // check if we have multiple child relations
      RelationInfo[] relationInfos = bindingInfo.getNRelationInfos(un);
      if (relationInfos != null && relationInfos.length > 0) {
        return true;
      }

      IRecord rec = un.getRecord();
      if (rec != null) {
        IFoundSet nfs;
        String n_relationName = bindingInfo.getNRelationName(un);
        String m_relationName = bindingInfo.getMRelationName(un);

        nfs = rec.getRelatedFoundSet(n_relationName);

        if (nfs != null && nfs.getSize() > 0) {
          if (m_relationName == null) {
            return true;
          } else {
            for (int ii = 0; ii < nfs.getSize(); ii++) {
              IRecord rel = nfs.getRecord(ii);
              IFoundSet mfs = rel.getRelatedFoundSet(m_relationName);
              if (mfs != null) {
                if (mfs.getSize() > 0) return true;
              }
            }
          }
        }
      }
    } else if (obj instanceof RelationNode) {
      RelationNode un = (RelationNode) obj;

      UserNode parentUserNode = (UserNode) un.getParent();
      IRecord parentRecord = parentUserNode.getRecord();

      IFoundSet nfs =
          parentRecord.getRelatedFoundSet(((RelationInfo) un.getUserObject()).getNRelationName());

      if (nfs != null && nfs.getSize() > 0) {
        return true;
      }
    }

    return false;
  }
コード例 #3
0
  @Override
  public ArrayList<Instruction> generate() {
    ArrayList<Instruction> instructions = new ArrayList<>();
    instructions.addAll(r.generate());

    Instruction.Op op = null;

    switch (r.relOpToken.getLexeme()) {
      case ("=="):
        op = Instruction.Op.beq;
        break;
      case ("!="):
        op = Instruction.Op.bne;
        break;
      case ("<"):
        op = Instruction.Op.blt;
        break;
      case ("<="):
        op = Instruction.Op.ble;
        break;
      case (">"):
        op = Instruction.Op.bgt;
        break;
      case (">="):
        op = Instruction.Op.bge;
        break;
      default:
        break;
    }

    ArrayList<Instruction> thenBlock = tthen.generate();
    ArrayList<Instruction> elseBlock = new ArrayList<>();
    Instruction endTarget = new Instruction(Instruction.Op.noop, null, null);

    if (eelse != null) {
      elseBlock.addAll(eelse.generate());
    }

    elseBlock.add(new Instruction(Instruction.Op.bra, new Result(endTarget), null));

    instructions.add(
        new Instruction(
            op,
            new Result(instructions.get(instructions.size() - 1)),
            new Result(thenBlock.get(0))));

    instructions.addAll(elseBlock);
    instructions.addAll(thenBlock);
    instructions.add(endTarget);

    return instructions;
  }
コード例 #4
0
  // lazy load
  private void internal_lazyLoadChilderenIfNeeded(Object obj) {
    if (obj instanceof UserNode) {
      UserNode un = (UserNode) obj;
      if (!un.isInitialized()) {
        un.flagInitialized();

        // check if we have multiple child relations
        RelationInfo[] relationInfos = bindingInfo.getNRelationInfos(un);
        if (relationInfos != null && relationInfos.length > 0) {
          int id = 0;
          for (RelationInfo relationInfo : relationInfos)
            un.add(new RelationNode(id++, relationInfo));
          return;
        }

        IRecord rec = un.getRecord();
        if (rec != null) {
          IFoundSet nfs;
          String n_relationName = bindingInfo.getNRelationName(un);
          String m_relationName = bindingInfo.getMRelationName(un);

          nfs = rec.getRelatedFoundSet(n_relationName);
          if (nfs != null && nfs.getSize() > 0) {
            if (m_relationName == null) {
              List sortColumns =
                  getSortColumns(
                      (Table) ((IFoundSetInternal) nfs).getTable(),
                      bindingInfo.getChildSortDataprovider(un));
              if (sortColumns != null) {
                try {
                  nfs.sort(sortColumns);
                } catch (Exception ex) {
                  Debug.error(ex);
                }
              }
              for (int i = 0; i < nfs.getSize(); i++) {
                nfs.getRecord(i); // to force next record loading
                createChildNode(un, nfs, i);
              }
            } else {
              ArrayList mfsRecordsSortedIdx = new ArrayList();
              ArrayList mfsSorted = new ArrayList();

              int sortOrder = SortColumn.ASCENDING;

              for (int ii = 0; ii < nfs.getSize(); ii++) {
                IRecord rel = nfs.getRecord(ii);
                IFoundSet mfs = rel.getRelatedFoundSet(m_relationName);
                if (mfs != null) {
                  for (int i = 0; i < mfs.getSize(); i++) {
                    IRecord mfsRec = mfs.getRecord(i);

                    // if sorting add mfs value o right position
                    List sortColumns =
                        getSortColumns(
                            (Table) ((IFoundSetInternal) mfs).getTable(),
                            bindingInfo.getChildSortDataprovider(un));
                    if (sortColumns != null) {
                      SortColumn sortCol = (SortColumn) sortColumns.get(0);
                      String sortDataProvider = sortCol.getDataProviderID();
                      sortOrder = sortCol.getSortOrder();
                      if (mfsRec != null) {
                        if (mfsRec.getValue(sortDataProvider) != null
                            && mfsRec.getValue(sortDataProvider) instanceof Comparable) {
                          Comparable sMfsRecValue = (Comparable) mfsRec.getValue(sortDataProvider);
                          Comparable sSortedValue;
                          int n;
                          for (n = 0; n < mfsRecordsSortedIdx.size(); n++) {
                            int nSortedRecIdx = ((Integer) mfsRecordsSortedIdx.get(n)).intValue();
                            sSortedValue =
                                (Comparable)
                                    ((IFoundSet) mfsSorted.get(n))
                                        .getRecord(nSortedRecIdx)
                                        .getValue(sortDataProvider);

                            if (sSortedValue == null) continue;

                            if (sMfsRecValue
                                    .getClass()
                                    .getName()
                                    .equals(sSortedValue.getClass().getName())
                                && sMfsRecValue.compareTo(sSortedValue) < 0) {
                              break;
                            }
                          }

                          mfsRecordsSortedIdx.add(n, new Integer(i));
                          mfsSorted.add(n, mfs);
                        } else {
                          mfsRecordsSortedIdx.add(0, new Integer(i));
                          mfsSorted.add(0, mfs);
                        }
                      }
                    } else {
                      mfsRecordsSortedIdx.add(new Integer(i));
                      mfsSorted.add(mfs);
                    }
                  }
                }
              }

              // should be done better
              if (sortOrder == SortColumn.ASCENDING) {
                for (int i = 0; i < mfsRecordsSortedIdx.size(); i++) {
                  createChildNode(
                      (DefaultMutableTreeNode) un,
                      (IFoundSet) mfsSorted.get(i),
                      ((Integer) mfsRecordsSortedIdx.get(i)).intValue());
                }
              } else {
                for (int i = mfsRecordsSortedIdx.size() - 1; i >= 0; i--) {
                  createChildNode(
                      (DefaultMutableTreeNode) un,
                      (IFoundSet) mfsSorted.get(i),
                      ((Integer) mfsRecordsSortedIdx.get(i)).intValue());
                }
              }
            }
          }
        }
      }
    } else if (obj instanceof RelationNode) {
      RelationNode un = (RelationNode) obj;
      if (!un.isInitialized()) {
        un.flagInitialized();

        UserNode parentUserNode = (UserNode) un.getParent();
        IRecord parentRecord = parentUserNode.getRecord();

        IFoundSet nfs =
            parentRecord.getRelatedFoundSet(((RelationInfo) un.getUserObject()).getNRelationName());

        if (nfs != null && nfs.getSize() > 0) {
          for (int i = 0; i < nfs.getSize(); i++) {
            createChildNode(un, nfs, i);
            nfs.getRecord(i);
          }
        }
      }
    }
  }