コード例 #1
0
ファイル: TreeService.java プロジェクト: 77321660/platform
  @Transactional(readOnly = false)
  public void save(T entity) {

    @SuppressWarnings("unchecked")
    Class<T> entityClass = Reflections.getClassGenricType(getClass(), 1);

    // 如果没有设置父节点,则代表为跟节点,有则获取父节点实体
    if (entity.getParent() == null
        || StringUtils.isBlank(entity.getParentId())
        || "0".equals(entity.getParentId())) {
      entity.setParent(null);
    } else {
      entity.setParent(super.get(entity.getParentId()));
    }
    if (entity.getParent() == null) {
      T parentEntity = null;
      try {
        parentEntity = entityClass.getConstructor(String.class).newInstance("0");
      } catch (Exception e) {
        throw new ServiceException(e);
      }
      entity.setParent(parentEntity);
      entity.getParent().setParentIds(StringUtils.EMPTY);
    }

    // 获取修改前的parentIds,用于更新子节点的parentIds
    String oldParentIds = entity.getParentIds();

    // 设置新的父节点串
    entity.setParentIds(entity.getParent().getParentIds() + entity.getParent().getId() + ",");

    // 保存或更新实体
    super.save(entity);

    // 更新子节点 parentIds
    T o = null;
    try {
      o = entityClass.newInstance();
    } catch (Exception e) {
      throw new ServiceException(e);
    }
    o.setParentIds("%," + entity.getId() + ",%");
    List<T> list = dao.findByParentIdsLike(o);
    for (T e : list) {
      if (e.getParentIds() != null && oldParentIds != null) {
        e.setParentIds(e.getParentIds().replace(oldParentIds, entity.getParentIds()));
        preUpdateChild(entity, e);
        dao.updateParentIds(e);
      }
    }
  }
コード例 #2
0
 /**
  * Add a child node to a parent
  *
  * @param parent
  * @param child
  * @return
  */
 public <T extends TreeNode> T addNewChild(T parent, T child) {
   if (!parent.getChildren().contains(child)) {
     parent.getChildren().add(child);
     child.setParent(parent);
   }
   update(parent);
   return (T) parent.getChildren().getLast();
 }
コード例 #3
0
ファイル: ERXML.java プロジェクト: hypronet/wonder
 /**
  * Adds a new node to this element.
  *
  * @param <T> the type of the node to add
  * @param child the child to add
  * @return the added child
  */
 public <T extends ERXML.Node> T add(T child) {
   child.setParent(this);
   if (_children == null) {
     _children = new LinkedList<Node>();
   }
   _children.add(child);
   return child;
 }
コード例 #4
0
  /** Test of setParent method, of class AbstractSqlTemplateLoader. */
  @Test
  public void testSetParent() {
    assertThat(instance.load("123", "aaa"), is(nullValue()));

    SqlTemplateLoader parent = mock(SqlTemplateLoader.class);
    SqlTemplate templ = mock(SqlTemplate.class);
    when(parent.load("123", "aaa", UTF_8)).thenReturn(templ);

    instance.setParent(parent);
    assertThat(instance.load("123", "aaa"), is(sameInstance(templ)));
  }
コード例 #5
0
  @SuppressWarnings("unchecked")
  @Override
  public IntervalAndSubIntervals<T> clone() {
    IntervalAndSubIntervals<T> copy = (IntervalAndSubIntervals<T>) super.clone();
    copy.reset();

    for (T m : this) {
      T mcopy = (T) m.clone();
      mcopy.setParent(copy);
      copy.add(mcopy);
    }

    return copy;
  }
コード例 #6
0
ファイル: EjbTaskFactory.java プロジェクト: pkay1412/utils
 public T build(T parent, String code, String name) {
   try {
     T t = clTask.newInstance();
     t.setParent(parent);
     t.setCode(code);
     t.setName(name);
     return t;
   } catch (InstantiationException e) {
     e.printStackTrace();
   } catch (IllegalAccessException e) {
     e.printStackTrace();
   }
   throw new RuntimeException("x");
 }
コード例 #7
0
  /** Apply a variant. */
  @Override
  @SuppressWarnings("unchecked")
  public IntervalAndSubIntervals<T> apply(Variant variant) {
    if (!shouldApply(variant)) return this;

    IntervalAndSubIntervals<T> newMarker = (IntervalAndSubIntervals<T>) super.apply(variant);
    if (newMarker == null) return null;
    newMarker.reset();

    for (T m : this) {
      T mcopy = (T) m.apply(variant);

      // Do not add if interval is completely removed
      if (mcopy != null) {
        mcopy.setParent(newMarker);
        newMarker.add(mcopy);
      }
    }

    return newMarker;
  }
コード例 #8
0
ファイル: SceneNode.java プロジェクト: danijelz/gurella
 public <T extends SceneNodeComponent & Poolable> T newComponent(Class<T> componentType) {
   T component = PoolService.obtain(componentType);
   component.setParent(this);
   return component;
 }
コード例 #9
0
 public void addNode(T node) {
   node.setParent(this);
   children.add(node);
 }
コード例 #10
0
ファイル: ScrollableControl.java プロジェクト: paulvi/xiliary
 public void setParent(Composite parent) {
   scrollable.setParent(parent);
 }