Logo Search packages:      
Sourcecode: josm-plugins version File versions  Download package

void org::openstreetmap::josm::plugins::validator::ErrorTreePanel::buildTree (  )  [inline]

Builds the errors tree

Definition at line 68 of file ErrorTreePanel.java.

References errors, getRoot(), and treeModel.

Referenced by setErrorList(), and setErrors().

      {
            DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();

            if( errors == null || errors.isEmpty() )
            {
                  treeModel.setRoot(rootNode);
                  return;
            }

        // Remember the currently expanded rows
        Set<Object> oldSelectedRows = new HashSet<Object>();
        Enumeration<TreePath> expanded = getExpandedDescendants( new TreePath(getRoot()) );
        if( expanded != null )
        {
            while( expanded.hasMoreElements() )
            {
                TreePath path = expanded.nextElement();
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); 
                Object userObject = node.getUserObject();
                if( userObject instanceof Severity )
                    oldSelectedRows.add(userObject);
                else if (userObject instanceof String)
                {
                    String msg = (String)userObject;
                    msg = msg.substring(0, msg.lastIndexOf(" ("));
                    oldSelectedRows.add(msg);
                }
            }
        }
        
            Map<Severity, Bag<String, TestError>> errorTree = new HashMap<Severity, Bag<String, TestError>>();
            for(Severity s : Severity.values())
            {
                  errorTree.put(s, new Bag<String, TestError>(20));
            }
            
            for(TestError e : errors)
            {
                  errorTree.get(e.getSeverity()).add(e.getMessage(), e);
            }
            
        List<TreePath> expandedPaths = new ArrayList<TreePath>();
            for(Severity s : Severity.values())
            {
                  Bag<String, TestError> severityErrors = errorTree.get(s);
                  if( severityErrors.isEmpty() )
                        continue;
                  
                  // Severity node
                  DefaultMutableTreeNode severityNode = new DefaultMutableTreeNode(s);
                  rootNode.add(severityNode);
            
                  if( oldSelectedRows.contains(s))
                expandedPaths.add( new TreePath( new Object[] {rootNode, severityNode} ) );
            
                  for(Entry<String, List<TestError>> msgErrors : severityErrors.entrySet()  )
                  {
                        // Message node
                        List<TestError> errors = msgErrors.getValue();
                        String msg = msgErrors.getKey() + " (" + errors.size() + ")";
                        DefaultMutableTreeNode messageNode = new DefaultMutableTreeNode(msg);
                        severityNode.add(messageNode);

                if( oldSelectedRows.contains(msgErrors.getKey()))
                    expandedPaths.add( new TreePath( new Object[] {rootNode, severityNode, messageNode} ) );
                
                        for (TestError error : errors) 
                        {
                              // Error node
                              DefaultMutableTreeNode errorNode = new DefaultMutableTreeNode(error);
                              messageNode.add(errorNode);
                        }
                  }
            }

        treeModel.setRoot(rootNode);
        for( TreePath path : expandedPaths)
        {
            this.expandPath(path);
        }
      }


Generated by  Doxygen 1.6.0   Back to index