Пример #1
0
 public void setSelectedObjectsFromDB() {
   this.selectingObject = true;
   this.list.clearSelection();
   int offsetIdx = 0;
   ArrayList<Integer> selectedIndices = new ArrayList<Integer>();
   for (ObjectStructure s : this.currentChannels) {
     BasicDBList selectedObjects =
         Core.mongoConnector.getSelectedObjects(currentNucId, s.getIdx());
     if (selectedObjects != null && !selectedObjects.isEmpty()) {
       for (Object o : selectedObjects) selectedIndices.add((Integer) o + offsetIdx);
     }
     offsetIdx += s.getObjects().length;
   }
   if (!selectedIndices.isEmpty()) {
     int[] selectedIdx = new int[selectedIndices.size()];
     for (int i = 0; i < selectedIdx.length; i++) selectedIdx[i] = selectedIndices.get(i);
     this.list.setSelectedIndices(selectedIdx);
   }
   this.selectingObject = false;
 }
  /**
   * Reads the given {@link BasicDBList} into a collection of the given {@link TypeInformation}.
   *
   * @param targetType must not be {@literal null}.
   * @param sourceValue must not be {@literal null}.
   * @param path must not be {@literal null}.
   * @return the converted {@link Collection} or array, will never be {@literal null}.
   */
  private Object readCollectionOrArray(
      TypeInformation<?> targetType, BasicDBList sourceValue, ObjectPath path) {

    Assert.notNull(targetType, "Target type must not be null!");
    Assert.notNull(path, "Object path must not be null!");

    Class<?> collectionType = targetType.getType();

    if (sourceValue.isEmpty()) {
      return getPotentiallyConvertedSimpleRead(new HashSet<Object>(), collectionType);
    }

    TypeInformation<?> componentType = targetType.getComponentType();
    Class<?> rawComponentType = componentType == null ? null : componentType.getType();

    collectionType =
        Collection.class.isAssignableFrom(collectionType) ? collectionType : List.class;
    Collection<Object> items =
        targetType.getType().isArray()
            ? new ArrayList<Object>()
            : CollectionFactory.createCollection(
                collectionType, rawComponentType, sourceValue.size());

    for (int i = 0; i < sourceValue.size(); i++) {

      Object dbObjItem = sourceValue.get(i);

      if (dbObjItem instanceof DBRef) {
        items.add(
            DBRef.class.equals(rawComponentType)
                ? dbObjItem
                : read(componentType, readRef((DBRef) dbObjItem), path));
      } else if (dbObjItem instanceof DBObject) {
        items.add(read(componentType, (DBObject) dbObjItem, path));
      } else {
        items.add(getPotentiallyConvertedSimpleRead(dbObjItem, rawComponentType));
      }
    }

    return getPotentiallyConvertedSimpleRead(items, targetType.getType());
  }