Пример #1
0
  /**
   * A group of tool groups have been added.
   *
   * @param name The catalog name
   * @param groups The list of tool groups added
   */
  public void toolGroupsAdded(String name, List<ToolGroup> groups) {
    if (!name.equals(catalog.getName())) return;

    TreePath path = new TreePath(catalogRoot);
    Object[] children = new Object[groups.size()];
    int[] indicies = new int[groups.size()];

    for (int i = 0; i < groups.size(); i++) {
      ToolGroup group = groups.get(i);
      ToolGroupTreeNode child = new ToolGroupTreeNode(group, catalogRoot);
      catalogRoot.insert(child, catalogRoot.getChildCount());

      int index = catalogRoot.getIndex(child);
      indicies[i] = index;
      children[i] = child;
      // System.out.println("Catalog bulk root adding group " + group.getName());
    }

    TreeModelEvent treeEvent = new TreeModelEvent(this, path, indicies, children);
    fireTreeNodesInserted(treeEvent);

    // Add listeners later to make sure we don't end up with any weird
    // side effects of a fast building tree.
    for (int i = 0; i < groups.size(); i++) {
      ToolGroup group = groups.get(i);
      group.addToolGroupListener(this);
    }
  }
Пример #2
0
  /**
   * A tool group has been added. Batched adds will come through the toolsAdded method.
   *
   * @param evt The event that caused this method to be called
   */
  public void toolGroupAdded(ToolGroupEvent evt) {
    ToolGroup group = (ToolGroup) evt.getSource();
    ToolGroup tool = (ToolGroup) evt.getChild();

    TreePath path = buildTreePath(group);

    // System.out.println("group added " + group.getName() + " kid " + tool.getName());

    Object[] children = new Object[1];
    int[] indicies = new int[1];
    int index;

    ToolGroupTreeNode parent = (ToolGroupTreeNode) path.getLastPathComponent();
    ToolGroupTreeNode child = new ToolGroupTreeNode(tool, parent);
    parent.insert(child, parent.getChildCount());

    index = getIndexOfChild(parent, child);
    indicies[0] = index;
    children[0] = child;

    TreeModelEvent treeEvent = new TreeModelEvent(this, path, indicies, children);
    fireTreeNodesInserted(treeEvent);

    tool.addToolGroupListener(this);
  }
Пример #3
0
  /**
   * Get the child of the given parent at that index.
   *
   * @param parent The parent node to ask
   * @param index The position to get the child for
   * @return The TreeNode object at that position
   */
  public Object getChild(Object parent, int index) {
    ToolGroupTreeNode treeNode = (ToolGroupTreeNode) parent;
    ToolGroupTreeNode kid = (ToolGroupTreeNode) treeNode.getChildAt(index);

    // check to see if the kids have been built.
    if (!kid.kidsLoaded) {
      buildChildren(kid);
      kid.kidsLoaded = true;
    }

    return kid;
  }
Пример #4
0
  /**
   * Build children objects for the requested node type. If the node is an attribute then do
   * nothing. Listeners will be added to the root item but not the children. This is to prevent odd
   * mixups if the children have listeners but have not yet had their children built. The viewable
   * tree would get very mixed up then
   *
   * @param root The root object to add children for
   */
  private void buildChildren(ToolGroupTreeNode root) {
    ToolGroupChild toolItem = root.getToolObject();

    if (toolItem instanceof ToolGroup) {
      ToolGroup tg = (ToolGroup) toolItem;
      List<ToolGroupChild> kids = tg.getChildren();

      for (int i = 0; i < kids.size(); i++) {
        ToolGroupChild child = kids.get(i);
        ToolGroupTreeNode kid = new ToolGroupTreeNode(child, root);

        root.insert(kid, i);
      }
    }
  }
Пример #5
0
  /**
   * A tool has been removed. Batched removes will come through the toolsRemoved method.
   *
   * @param name The catalog name
   * @param group The toolGroup removed from
   */
  public void toolGroupRemoved(String name, ToolGroup group) {
    if (!name.equals(catalog.getName())) return;

    group.removeToolGroupListener(this);

    TreePath path = new TreePath(catalogRoot);
    Object[] children = new Object[1];
    int[] indicies = new int[1];

    ToolGroupTreeNode child = catalogRoot.getTreeNodeChild(group);
    int index = catalogRoot.getIndex(child);
    indicies[0] = index;
    children[0] = child;

    catalogRoot.remove(child);

    TreeModelEvent treeEvent = new TreeModelEvent(this, path, indicies, children);
    fireTreeNodesRemoved(treeEvent);
  }
Пример #6
0
  /**
   * A tool has been removed. Batched removes will come through the toolsRemoved method.
   *
   * @param evt The event that caused this method to be called
   */
  public void toolRemoved(ToolGroupEvent evt) {
    ToolGroup group = (ToolGroup) evt.getSource();
    SimpleTool tool = (SimpleTool) evt.getChild();

    TreePath path = buildTreePath(group);

    Object[] children = new Object[1];
    int[] indicies = new int[1];
    int index;

    ToolGroupTreeNode parent = (ToolGroupTreeNode) path.getLastPathComponent();
    ToolGroupTreeNode child = parent.getTreeNodeChild(tool);
    index = getIndexOfChild(parent, child);
    indicies[0] = index;
    children[0] = child;

    parent.remove(child);

    TreeModelEvent treeEvent = new TreeModelEvent(this, path, indicies, children);
    fireTreeNodesRemoved(treeEvent);
  }
Пример #7
0
  /**
   * A tool group has been added. Batched adds will come through the toolsAdded method.
   *
   * @param name The catalog name
   * @param group The toolGroup added to
   */
  public void toolGroupAdded(String name, ToolGroup group) {
    if (!name.equals(catalog.getName())) return;

    TreePath path = new TreePath(catalogRoot);
    Object[] children = new Object[1];
    int[] indicies = new int[1];

    ToolGroupTreeNode child = new ToolGroupTreeNode(group, catalogRoot);
    catalogRoot.insert(child, catalogRoot.getChildCount());

    int index = catalogRoot.getIndex(child);
    indicies[0] = index;
    children[0] = child;

    // System.out.println("Catalog root adding group " + group.getName());

    TreeModelEvent treeEvent = new TreeModelEvent(this, path, indicies, children);
    fireTreeNodesInserted(treeEvent);

    group.addToolGroupListener(this);
  }
Пример #8
0
  /**
   * A group of tool groups have been removed.
   *
   * @param name The catalog name
   * @param groups The list of tool groups that have been removed
   */
  public void toolGroupsRemoved(String name, List<ToolGroup> groups) {
    if (!name.equals(catalog.getName())) return;

    TreePath path = new TreePath(catalogRoot);
    Object[] children = new Object[groups.size()];
    int[] indicies = new int[groups.size()];

    for (int i = 0; i < groups.size(); i++) {
      ToolGroup group = groups.get(i);

      group.removeToolGroupListener(this);

      ToolGroupTreeNode child = catalogRoot.getTreeNodeChild(group);

      int index = catalogRoot.getIndex(child);
      indicies[i] = index;
      children[i] = child;

      catalogRoot.remove(child);
    }

    TreeModelEvent treeEvent = new TreeModelEvent(this, path, indicies, children);
    fireTreeNodesRemoved(treeEvent);
  }
Пример #9
0
  /**
   * Check to see if the given node is a leaf node. Leaf nodes are determined if the DOM object does
   * not support children.
   *
   * @param child The child node to check
   * @return True if the DOM node is a leaf
   */
  public boolean isLeaf(Object child) {
    ToolGroupTreeNode treeNode = (ToolGroupTreeNode) child;
    ToolGroupChild kid = treeNode.getToolObject();

    return (kid instanceof SimpleTool);
  }
Пример #10
0
 /**
  * Get the index of the given child in the parent node.
  *
  * @param parent The parent node to check for
  * @param child The child to find the index of
  * @return The position of the child in the parent
  */
 public int getIndexOfChild(Object parent, Object child) {
   ToolGroupTreeNode treeNode = (ToolGroupTreeNode) parent;
   return treeNode.getIndex((TreeNode) child);
 }
Пример #11
0
 /**
  * Get the number of children the given parent contains. The number is both child elements and
  * attributes as this tree will show both.
  *
  * @param parent The parent to quiz for the number of children
  * @return The number of children of that parent
  */
 public int getChildCount(Object parent) {
   ToolGroupTreeNode treeNode = (ToolGroupTreeNode) parent;
   return treeNode.getChildCount();
 }