<commit_before>/*************** <auto-copyright.pl BEGIN do not edit this line> **************
 *
 * VR Juggler is (C) Copyright 1998-2002 by Iowa State University
 *
 * Original Authors:
 *   <NAME>, <NAME>,
 *   <NAME>, <NAME>,
 *   <NAME>, <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * -----------------------------------------------------------------
 * File:          $RCSfile$
 * Date modified: $Date$
 * Version:       $Revision$
 * -----------------------------------------------------------------
 *
 *************** <auto-copyright.pl END do not edit this line> ***************/
package org.vrjuggler.jccl.editors;

import java.util.*;
import javax.swing.tree.*;
import org.vrjuggler.jccl.config.*;
import org.vrjuggler.tweek.ui.JTreeTable;
import org.vrjuggler.tweek.ui.treetable.*;

/**
 * A table model for config chunks. This two-column model will return property
 * names for the first column and property values for the second column.
 */
public class ConfigChunkTreeTableModel
   extends AbstractTreeTableModel
{
   /**
    * Creates a new table model with no config chunk for its data.
    */
   public ConfigChunkTreeTableModel()
   {
      super(new DefaultMutableTreeNode(""));
   }

   /**
    * Creates a new table model with the given config chunk for its data.
    */
   public ConfigChunkTreeTableModel(ConfigChunk chunk)
   {
      this();
      setConfigChunk(chunk);
   }

   /**
    * Sets the config chunk this table model represents.
    */
   public void setConfigChunk(ConfigChunk chunk)
   {
      // First clear out all the old nodes from the tree.
      ((DefaultMutableTreeNode)getRoot()).removeAllChildren();

      this.chunk = chunk;
      setRoot(new DefaultMutableTreeNode(this.chunk));

      // First node is name
      DefaultMutableTreeNode name_node = new DefaultMutableTreeNode(chunk.getName());
      insertNodeInto(name_node, (MutableTreeNode)getRoot(), 0);

      // Second node is type
      DefaultMutableTreeNode type_node = new DefaultMutableTreeNode(
                                                chunk.getDesc().getName());
      insertNodeInto(type_node, (MutableTreeNode)getRoot(), 1);

      for (Iterator itr = this.chunk.getDesc().getPropertyDescs().iterator(); itr.hasNext(); )
      {
         PropertyDesc prop_desc = (PropertyDesc)itr.next();
         addProperty(chunk, prop_desc);
      }
   }

   /**
    * Gets the config chunk this table model represents.
    */
   public ConfigChunk getConfigChunk()
   {
      return chunk;
   }

   /**
    * Adds the nodes necessary to display the property values for the given
    * config chunk described by the given property description.
    */
   private void addProperty(ConfigChunk chunk, PropertyDesc propDesc)
   {
      DefaultMutableTreeNode parent = getNodeFor(chunk);

      // This property has only one value, add it in
      if ((propDesc.getItemsSize() == 1) && (! propDesc.hasVariableNumberOfValues()))
      {
         int idx = parent.getChildCount();
//         System.out.println("Adding property node for single-valued property: "+
//                            propDesc.getToken()+"["+idx+"]");
         Object value = chunk.getProperty(propDesc.getToken()).get();
         DefaultMutableTreeNode value_node = new DefaultMutableTreeNode(value);
         insertNodeInto(value_node, parent, idx);
      }
      // This property has (or can have) more than one value, add a node that is
      // the parent for all its values.
      else
      {
         int idx = parent.getChildCount();
//         System.out.println("Adding property node for multi-valued property: "+
//                            propDesc.getToken()+"["+idx+"]");
         DefaultMutableTreeNode prop_desc_node = new DefaultMutableTreeNode(propDesc);
         insertNodeInto(prop_desc_node, parent, idx);
         parent = prop_desc_node;

         int num_props = chunk.getNumPropertyValues(propDesc.getToken());
         for (int i=0; i<num_props; ++i)
         {
            Object value = chunk.getProperty(propDesc.getToken(), i).get();
            if (! (value instanceof ConfigChunk))
            {
//               System.out.println("Adding property value: "+propDesc.getToken()+"["+i+"]");
               DefaultMutableTreeNode child = new DefaultMutableTreeNode(value);
               int prop_idx = parent.getChildCount();<commit_msg>Bug fixed:	ConfigChunks with a property containing only a single 		embedded chunk would not get expanded.<commit_after>/*************** <auto-copyright.pl BEGIN do not edit this line> **************
 *
 * VR Juggler is (C) Copyright 1998-2002 by Iowa State University
 *
 * Original Authors:
 *   <NAME>, <NAME>,
 *   <NAME>, <NAME>,
 *   <NAME>, <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * -----------------------------------------------------------------
 * File:          $RCSfile$
 * Date modified: $Date$
 * Version:       $Revision$
 * -----------------------------------------------------------------
 *
 *************** <auto-copyright.pl END do not edit this line> ***************/
package org.vrjuggler.jccl.editors;

import java.util.*;
import javax.swing.tree.*;
import org.vrjuggler.jccl.config.*;
import org.vrjuggler.tweek.ui.JTreeTable;
import org.vrjuggler.tweek.ui.treetable.*;

/**
 * A table model for config chunks. This two-column model will return property
 * names for the first column and property values for the second column.
 */
public class ConfigChunkTreeTableModel
   extends AbstractTreeTableModel
{
   /**
    * Creates a new table model with no config chunk for its data.
    */
   public ConfigChunkTreeTableModel()
   {
      super(new DefaultMutableTreeNode(""));
   }

   /**
    * Creates a new table model with the given config chunk for its data.
    */
   public ConfigChunkTreeTableModel(ConfigChunk chunk)
   {
      this();
      setConfigChunk(chunk);
   }

   /**
    * Sets the config chunk this table model represents.
    */
   public void setConfigChunk(ConfigChunk chunk)
   {
      // First clear out all the old nodes from the tree.
      ((DefaultMutableTreeNode)getRoot()).removeAllChildren();

      this.chunk = chunk;
      setRoot(new DefaultMutableTreeNode(this.chunk));

      // First node is name
      DefaultMutableTreeNode name_node = new DefaultMutableTreeNode(chunk.getName());
      insertNodeInto(name_node, (MutableTreeNode)getRoot(), 0);

      // Second node is type
      DefaultMutableTreeNode type_node = new DefaultMutableTreeNode(
                                                chunk.getDesc().getName());
      insertNodeInto(type_node, (MutableTreeNode)getRoot(), 1);

      for (Iterator itr = this.chunk.getDesc().getPropertyDescs().iterator(); itr.hasNext(); )
      {
         PropertyDesc prop_desc = (PropertyDesc)itr.next();
         addProperty(chunk, prop_desc);
      }
   }

   /**
    * Gets the config chunk this table model represents.
    */
   public ConfigChunk getConfigChunk()
   {
      return chunk;
   }

   /**
    * Adds the nodes necessary to display the property values for the given
    * config chunk described by the given property description.
    */
   private void addProperty(ConfigChunk chunk, PropertyDesc propDesc)
   {
      DefaultMutableTreeNode parent = getNodeFor(chunk);

      // This property has only one value, add it in
      if ((propDesc.getItemsSize() == 1) && (! propDesc.hasVariableNumberOfValues())
         && (propDesc.getValType() != ValType.EMBEDDEDCHUNK))
      {
         int idx = parent.getChildCount();
//         System.out.println("Adding property node for single-valued property: "+
//                            propDesc.getToken()+"["+idx+"]");
         Object value = chunk.getProperty(propDesc.getToken()).get();
         DefaultMutableTreeNode value_node = new DefaultMutableTreeNode(value);
         insertNodeInto(value_node, parent, idx);
      }
      // This property has (or can have) more than one value, add a node that is
      // the parent for all its values.
      else
      {
         int idx = parent.getChildCount();
//         System.out.println("Adding property node for multi-valued property: "+
//                            propDesc.getToken()+"["+idx+"]");
         DefaultMutableTreeNode prop_desc_node = new DefaultMutableTreeNode(propDesc);
         insertNodeInto(prop_desc_node, parent, idx);
         parent = prop_desc_node;

         int num_props = chunk.getNumPropertyValues(propDesc.getToken());
         for (int i=0; i<num_props; ++i)
         {
            Object value = chunk.getProperty(propDesc.getToken(), i).get();
            if (! (value instanceof ConfigChunk))
            {
//               System.out.println("Adding property value: "+propDesc.getToken()+"["+i+"]");
               DefaultMutableTreeNode child = new DefaultMutableTreeNode(value);
               int prop_idx = parent.getChildCount();
{'fraction_non_alphanumeric': 0.13391727493917274, 'fraction_numerical': 0.005255474452554744, 'mean_word_length': 2.5581717451523547, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7153922', 'n_tokens_mistral': 2753, 'n_tokens_neox': 2655, 'n_words': 884}