コード例 #1
0
    /**
     * This gets called whenever one of the ConfigElements we are editing removes a property value.
     */
    public void propertyValueRemoved(ConfigElementEvent evt) {
      ConfigElement src = (ConfigElement) evt.getSource();
      int idx = evt.getIndex();
      PropertyDefinition prop_def = src.getDefinition().getPropertyDefinition(evt.getProperty());
      DefaultMutableTreeNode elt_node = getNodeFor(src);

      // Get the node containing the property description under the source
      // ConfigElement node
      for (Enumeration e = elt_node.children(); e.hasMoreElements(); ) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();
        if (node.getUserObject().equals(prop_def)) {
          // The newly removed property value must be a child to this node
          System.out.println("Removing child " + idx + " from node: " + node.getUserObject());
          DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getChildAt(idx);

          // If the child is an embedded element, stop listening to it
          if (child.getUserObject() instanceof ConfigElement) {
            ConfigElement removed_elt = (ConfigElement) child.getUserObject();
            removed_elt.removeConfigElementListener(this);
          }

          // Physically remove the child from the tree
          removeNodeFromParent(child);
        }
      }
    }
コード例 #2
0
  /** Clears the data in the model. */
  private void clear() {
    // Stop listening to all config elements in the tree
    List nodes = getNodesOfClass(ConfigElement.class);
    for (Iterator itr = nodes.iterator(); itr.hasNext(); ) {
      DefaultMutableTreeNode node = (DefaultMutableTreeNode) itr.next();
      ConfigElement elt = (ConfigElement) node.getUserObject();
      elt.removeConfigElementListener(mElementListener);
    }

    // Clear out all the old nodes from the tree.
    ((DefaultMutableTreeNode) getRoot()).removeAllChildren();
  }