public static BindingInfo create(Binding<?> binding, Key<?> boundKey, Object instance) {
   BindingInfo bindingInfo = new BindingInfo();
   bindingInfo.key = binding.getKey();
   bindingInfo.boundKey = boundKey;
   bindingInfo.boundInstance = instance;
   bindingInfo.scope = binding.acceptScopingVisitor(new GuiceScopingVisitor());
   return bindingInfo;
 }
 public String toString() {
   return "BindingQName="
       + (binding == null
           ? ""
           : (binding.getName()
               + ", ServiceQName="
               + (binding.getService() == null ? "" : binding.getService().getName())))
       + ", QName="
       + name;
 }
  public synchronized void resetRoot() {
    if (tableModelListener != null) {
      int nodeFoundSetsSize = nodeFoundSets.size();
      for (int i = 0; i < nodeFoundSetsSize; i++) {
        if (nodeFoundSets.get(i) instanceof ISwingFoundSet) {
          ((ISwingFoundSet) nodeFoundSets.get(i)).removeTableModelListener(tableModelListener);
        }
      }
    }

    nodeFoundSets.clear();

    DefaultMutableTreeNode root = (DefaultMutableTreeNode) getRoot();
    removeModificationListenerRecursiv(root); // remove all nodes modification listeners
    root.removeAllChildren();

    DefaultMutableTreeNode child;

    ArrayList rootFoundSets = bindingInfo.getRootFoundSets();
    IFoundSet rootFs;
    for (int j = 0; j < rootFoundSets.size(); j++) {
      rootFs = (IFoundSet) rootFoundSets.get(j);
      for (int i = 0; i < rootFs.getSize(); i++) {
        rootFs.getRecord(i);
        child = createChildNode(root, rootFs, i);
      }
      // check child item to detect dir/leaf status (need this for icon display)
      Enumeration<DefaultMutableTreeNode> childEnum = root.children();
      while (childEnum.hasMoreElements()) childEnum.nextElement().isLeaf();
      addListenerToFoundSet(rootFs);
    }
  }
  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;
  }
Example #5
0
 protected void handleEvent(Event event) {
   for (BindingInfo bi : _dataTargets) {
     final Component dt = bi.getComponent();
     final Binding binding = bi.getBinding();
     final DataBinder binder = binding.getBinder();
     final Component dataTarget =
         DataBinder.isTemplate(dt) ? DataBinder.lookupClone(event.getTarget(), dt) : dt;
     if (dataTarget != null) {
       binding.loadAttribute(dataTarget);
     } else { // #bug 2897202
       final List<Component> clones = scanClones(binder, dt);
       for (final Component dataTarget1 : clones) {
         binding.loadAttribute(dataTarget1);
       }
     }
   }
 }
 public boolean isSameAs(EndpointInfo epInfo) {
   if (this == epInfo) {
     return true;
   }
   if (epInfo == null) {
     return false;
   }
   return binding.getName().equals(epInfo.binding.getName())
       && service.getName().equals(epInfo.service.getName())
       && name.equals(epInfo.name);
 }
    private void addInjectionPointDependencies(InjectionPoint injectionPoint) {
      // Do not consider dependencies coming from optional injections.
      if (injectionPoint.isOptional()) {
        return;
      }

      for (Dependency<?> dependency : injectionPoint.getDependencies()) {
        Key<?> key = dependency.getKey();

        bindingsObserved.add(BindingInfo.create(key));
      }
    }
  @Override
  public <T> T getTraversedExtensor(T defaultValue, Class<T> type) {
    T value = getExtensor(type);

    if (value == null) {
      if (value == null && binding != null) {
        value = binding.getExtensor(type);
      }

      if (service != null && value == null) {
        value = service.getExtensor(type);
      }

      if (value == null) {
        value = defaultValue;
      }
    }

    return value;
  }
    public static BindingInfo create(Key<?> boundKey) {
      BindingInfo bindingInfo = new BindingInfo();
      bindingInfo.boundKey = boundKey;

      return bindingInfo;
    }
Example #10
0
 protected Void addBindingInfo(Binding<? extends T> binding, Key<?> boundKey, Object instance) {
   bindingsObserved.add(BindingInfo.create(binding, boundKey, instance));
   return null;
 }
Example #11
0
    protected void handleEvent(Event event) {
      final Component target = event.getTarget();
      final String triggerEventName = event.getName();
      final List<BindingInfo> tmplist = new ArrayList<BindingInfo>(_dataTargets.size());
      final List<Object> values = new LinkedList<Object>();
      final List<Component> refs = new LinkedList<Component>();
      final List<Binding> bindings = new LinkedList<Binding>();

      // fire onSave for each binding
      for (BindingInfo bi : _dataTargets) {
        final Component dt = bi.getComponent();
        final Binding binding = bi.getBinding();
        final DataBinder binder = binding.getBinder();
        final Component dataTarget =
            DataBinder.isTemplate(dt) ? DataBinder.lookupClone(target, dt) : dt;
        // bug# 1904389: NullPointerException if save-when in collection binding
        // event.getTarget() might not inside the collection item (i.e. row, listitem, etc.)
        // then binder.lookupClone() will return null dataTarget.
        if (dataTarget != null) {
          final Object[] vals = binding.getAttributeValues(dataTarget);
          if (vals != null) {
            tmplist.add(new BindingInfo(binding, dataTarget, vals));
            values.add(vals[0]);
            refs.add(dataTarget);
            bindings.add(binding);
            Events.sendEvent(
                new BindingSaveEvent("onBindingSave", dataTarget, target, binding, vals[0]));
          }
        } else {
          // bi.getComponent a template and a null dataTarget, meaning all collection items has to
          // be handled. Search the owner to iterate all cloned items.
          final List<Component> clones = scanClones(binder, dt);
          for (Component dataTarget1 : clones) {
            final Object[] vals = binding.getAttributeValues(dataTarget1);
            if (vals != null) {
              tmplist.add(new BindingInfo(binding, dataTarget1, vals));
              values.add(vals[0]);
              refs.add(dataTarget1);
              bindings.add(binding);
              Events.sendEvent(
                  new BindingSaveEvent("onBindingSave", dataTarget1, target, binding, vals[0]));
            }
          }
        }
      }

      // fire onValidate for target component
      Events.sendEvent(
          new BindingValidateEvent("onBindingValidate", target, refs, bindings, values));

      // saveAttribute for each binding
      Component loadOnSaveProxy = null;
      Component dataTarget = null;
      DataBinder binder = null;
      final List<Object> loadOnSaveInfos = new ArrayList<Object>(tmplist.size());
      for (BindingInfo bi : tmplist) {
        dataTarget = bi.getComponent();
        final Binding binding = bi.getBinding();
        if (binder == null) {
          binder = binding.getBinder();
        }
        final Object[] vals = bi.getAttributeValues();
        binding.saveAttributeValue(dataTarget, vals, loadOnSaveInfos, triggerEventName);
        if (loadOnSaveProxy == null && dataTarget.isListenerAvailable("onLoadOnSave", true)) {
          loadOnSaveProxy = dataTarget;
        }
      }

      // bug #1895856 : data binding LoadOnSave works only on the last save-when component
      // do loadOnSave
      // if (dataTarget != null) {
      //		Events.postEvent(new Event("onLoadOnSave", dataTarget, loadOnSaveInfos));
      //	}

      // (use first working dataTarget as proxy)
      // feature#2990932, allow disable load-on-save mechanism
      if (loadOnSaveProxy != null && binder.isLoadOnSave()) {
        Events.postEvent(new Event("onLoadOnSave", loadOnSaveProxy, loadOnSaveInfos));
      }
    }
  // 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);
          }
        }
      }
    }
  }