@SuppressWarnings({"unchecked", "rawtypes"})
private void doInsert(TreeModel parent, List<TreeModel> children, int index, boolean addChildren, boolean supressEvent) {
if (parent != null && children != null && children.size() > 0) {
M modelParent = unwrap(parent);
for (int i = children.size() - 1; i >= 0; i--) {
TreeModel child = children.get(i);
parent.insert(child, index);
M m = unwrap(child);
all.add(m);
registerModel(m);
if (storeSorter != null) {
applySort((List) parent.getChildren());
if (!supressEvent) {
TreeStoreEvent evt = createStoreEvent();;
evt.setParent(modelParent);
evt.setIndex(parent.indexOf(child));
evt.setChildren(Arrays.asList(m));
fireEvent(Add, evt);
}
}
}
if (!supressEvent && storeSorter == null) {
TreeStoreEvent evt = createStoreEvent();;
evt.setParent(modelParent);
evt.setChildren(unwrap(children));
evt.setIndex(index);
fireEvent(Add, evt);
}
if (addChildren) {
for (TreeModel sub : children) {
M model = unwrap(sub);
if (model instanceof TreeModel) {
TreeModel treeSub = (TreeModel) model;
List<M> c = (List) treeSub.getChildren();
if (c.size() > 0) {
List<TreeModel> insert = new ArrayList<TreeModel>();
for (M m : c) {
insert.add(wrap(m));
}