private void addGroupToNode(DefaultMutableTreeNode node, ArmylistWargearGroup group) {
    DefaultMutableTreeNode newNode = new DefaultMutableTreeNode();
    newNode.setUserObject(new WargearTreeUserObjectContainer(group, newNode, node));
    node.add(newNode);

    Iterator subGroups = group.getSubGroups().iterator();
    while (subGroups.hasNext()) {
      ArmylistWargearGroup subGroup = (ArmylistWargearGroup) subGroups.next();
      this.addGroupToNode(newNode, subGroup);
    }

    Iterator items = group.getItems().iterator();
    while (items.hasNext()) {
      DefaultMutableTreeNode temp = new DefaultMutableTreeNode();
      ArmylistWargearItem item = (ArmylistWargearItem) items.next();
      WargearTreeUserObjectContainer container =
          new WargearTreeUserObjectContainer(item, temp, newNode);
      container.setItemGroup(group);
      temp.setUserObject(container);
      newNode.add(temp);
    }
  }
  private void newGroup() {
    this.saveData();
    if (this.currentContainer == null) return;

    DefaultMutableTreeNode node = null;

    ArmylistWargearGroup parentGroup = null;
    if (this.currentContainer.getGroup() != null) {
      parentGroup = this.currentContainer.getGroup();
      node = this.currentContainer.getNode();
    }
    if (parentGroup == null && this.currentContainer.getItemGroup() != null) {
      parentGroup = this.currentContainer.getItemGroup();
      node = this.currentContainer.getParent();
    }
    if (parentGroup == null) return;

    ArmylistWargearGroup newGroup = new ArmylistWargearGroup("new group");

    parentGroup.addSubGroup(newGroup);
    this.addGroupToNode(node, newGroup);
    this.wargearTree.updateUI();
  }
  private void newItem() {
    this.saveData();
    if (this.currentContainer == null) return;
    DefaultMutableTreeNode node = null;

    ArmylistWargearItem newItem = new ArmylistWargearItem("no name", this.armylistArmy);

    ArmylistWargearGroup parentGroup = null;
    if (this.currentContainer.getGroup() != null) {
      parentGroup = this.currentContainer.getGroup();
      node = this.currentContainer.getNode();
    }
    if (parentGroup == null && this.currentContainer.getItemGroup() != null) {
      parentGroup = this.currentContainer.getItemGroup();
      node = this.currentContainer.getParent();
    }
    if (parentGroup == null) return;

    parentGroup.addItem(newItem);

    this.addItemToNode(node, newItem, parentGroup);

    this.wargearTree.updateUI();
  }
  public void deleteCurrentGroup() {
    System.out.println("Deleting group " + this.currentContainer.getGroup().getName());

    if (this.currentContainer == null || this.currentGroupPanel == null) return;

    if (this.currentContainer.getParent().getUserObject()
        instanceof WargearTreeUserObjectContainer) {
      ArmylistWargearGroup parent =
          ((WargearTreeUserObjectContainer) this.currentContainer.getParent().getUserObject())
              .getGroup();
      parent.removeSubGroup(this.currentContainer.getGroup());
    } else {
      this.armylistArmy.removeargearGroup(this.currentContainer.getGroup());
    }

    this.editorPane.removeAll();
    this.editorPane.updateUI();

    this.currentContainer.getParent().remove(this.currentContainer.getNode());
    this.wargearTree.updateUI();

    this.currentContainer = null;
    this.currentItemPanel = null;
  }