svn commit: r13755 - trunk/src_new/org/argouml/ui/explorer/ExplorerTree.java

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: tfmorris
Date: 2007-11-11 02:40:49-0800
New Revision: 13755

Modified:
   trunk/src_new/org/argouml/ui/explorer/ExplorerTree.java

Log:
Disable deep search for selections.  It's too slow with big models.

Modified: trunk/src_new/org/argouml/ui/explorer/ExplorerTree.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/ui/explorer/ExplorerTree.java?view=diff&rev=13755&p1=trunk/src_new/org/argouml/ui/explorer/ExplorerTree.java&p2=trunk/src_new/org/argouml/ui/explorer/ExplorerTree.java&r1=13754&r2=13755
==============================================================================
--- trunk/src_new/org/argouml/ui/explorer/ExplorerTree.java	(original)
+++ trunk/src_new/org/argouml/ui/explorer/ExplorerTree.java	2007-11-11 02:40:49-0800
@@ -83,6 +83,7 @@
      */
     public ExplorerTree() {
         super();
+
         this.setModel(new ExplorerTreeModel(ProjectManager.getManager()
 			                    .getCurrentProject(), this));
         this.addMouseListener(new ExplorerMouseListener(this));
@@ -232,6 +233,7 @@
             setShowStereotype(ps.getShowStereotypesValue());
 
             if (getModel() instanceof ExplorerTreeModel) {
+
                 ((ExplorerTreeModel) getModel()).updateChildren(tee.getPath());
             }
         }
@@ -280,11 +282,14 @@
      */
     private void setSelection(Object[] targets) {
         updatingSelectionViaTreeSelection = true;
+
         this.clearSelection();
         addTargetsInternal(targets);
         updatingSelectionViaTreeSelection = false;
     }
 
+
+    
     private void addTargetsInternal(Object[] addedTargets) {
         if (addedTargets.length < 1) {
             return;
@@ -296,13 +301,14 @@
             } else {
                 targets.add(t);
             }
+            // TODO: The following can be removed if selectAll gets fixed
+            selectVisible(t);
         }
 
-        ExplorerTreeModel model = (ExplorerTreeModel) getModel();
-        ExplorerTreeNode root = (ExplorerTreeNode) model.getRoot();
-        
-        
-        selectChildren(model, root, targets);
+        // TODO: This doesn't perform well enough with large models to have
+        // it enabled by default.  If the performance can't be improved, 
+        // perhaps we can introduce a manual "find in explorer tree" action.
+//        selectAll(targets);
     
         int[] selectedRows = getSelectionRows();
         if (selectedRows != null && selectedRows.length > 0) {
@@ -314,21 +320,45 @@
         }
     }
 
+    /**
+     * Select any targets which are visible in the explorer pane
+     */
+    private void selectVisible(Object target) {
+        for (int j = 0; j < getRowCount(); j++) {
+            Object rowItem =
+                    ((DefaultMutableTreeNode) getPathForRow(j)
+                            .getLastPathComponent()).getUserObject();
+            if (rowItem == target) {
+                addSelectionRow(j);
+            }
+        }
+    }
+
+
+    /**
+     * Search the entire tree and select all instances of targets found.
+     */
+    private void selectAll(Set targets) {
+        ExplorerTreeModel model = (ExplorerTreeModel) getModel();
+        ExplorerTreeNode root = (ExplorerTreeNode) model.getRoot();  
+        selectChildren(model, root, targets);
+    }
+    
     /*
-     * Perform recursive search of subtree rooted at 'node', selecting all nodes which 
-     * have a userObject matching one of our targets.
+     * Perform recursive search of subtree rooted at 'node', selecting all nodes
+     * which have a userObject matching one of our targets.
      */
-    private void selectChildren(ExplorerTreeModel model, ExplorerTreeNode node, Set targets) {
+    private void selectChildren(ExplorerTreeModel model, ExplorerTreeNode node,
+            Set targets) {
         if (targets.isEmpty()) {
             return;
         }
+
         Object nodeObject = node.getUserObject();
         if (nodeObject != null) {
             for (Object t : targets) {
                 if (t == nodeObject) {
-                    updatingSelectionViaTreeSelection = true;
                     addSelectionPath(new TreePath(node.getPath()));
-                    updatingSelectionViaTreeSelection = false;
                     // target may appear multiple places in the tree, so 
                     // we don't stop here (but it's expensive to search
                     // the whole tree) - tfm - 20070904
@@ -343,9 +373,10 @@
         while (e.hasMoreElements()) {
             selectChildren(model, (ExplorerTreeNode) e.nextElement(), targets);
         }
-
     }
 
+
+
     /**
      * Manages selecting the item to show in Argo's other
      * views based on the highlighted row.
@@ -473,16 +504,20 @@
         public void targetAdded(TargetEvent e) {
             if (!updatingSelection) {
                 updatingSelection = true;
-                Object[] addedTargets = e.getAddedTargets();
-                addTargetsInternal(addedTargets);
+                Object[] targets = e.getAddedTargets();
+                
+                updatingSelectionViaTreeSelection = true;
+                addTargetsInternal(targets);
+                updatingSelectionViaTreeSelection = false;
                 updatingSelection = false;
             }
             // setTargets(e.getNewTargets());
         }
 
+
         /*
          * @see org.argouml.ui.targetmanager.TargetListener#targetRemoved(
-	 *         org.argouml.ui.targetmanager.TargetEvent)
+         *      org.argouml.ui.targetmanager.TargetEvent)
          */
         public void targetRemoved(TargetEvent e) {
             if (!updatingSelection) {
@@ -527,7 +562,6 @@
         }
     }
 
-
     /**
      * The UID.
      */
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.