Ejemplo n.º 1
0
  public static boolean checkIfAllowed(Model model, ArmylistWargearGroup group) {
    Iterator requiredItems = group.getRequiredItems().iterator();
    while (requiredItems.hasNext()) {
      String item = (String) requiredItems.next();
      String groupName = item.substring(0, item.lastIndexOf("."));
      String itemName = item.substring(item.lastIndexOf(".") + 1);

      System.out.println("Found required item. Group: " + groupName + " item: " + itemName);

      Iterator selected = model.getSelectedWargear(groupName).iterator();
      boolean found = false;
      while (selected.hasNext()) {
        String name = ((ArmylistWargearItem) selected.next()).getName();
        if (name.equalsIgnoreCase(itemName)) {
          found = true;
          break;
        }
      }
      if (!found) {
        System.out.println("Not found!!! -FALSE");
        return false;
      }
    }

    return true;
  }
  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;
  }