Author: tfmorris
Date: 2008-08-29 01:15:40-0700
New Revision: 15646

Added:
   trunk/src/argouml-app/src/org/argouml/ui/ChildGenSearch.java   (contents, 
props changed)
Modified:
   trunk/src/argouml-app/src/org/argouml/ui/FindDialog.java
   trunk/src/argouml-app/src/org/argouml/ui/TabResults.java
   trunk/src/argouml-app/src/org/argouml/uml/cognitive/ChildGenFind.java

Log:
RESOLVED - task 5325: Public API for Find/Search shouldn't expose internal 
implementations details (GEF utilities) 
http://argouml.tigris.org/issues/show_bug.cgi?id=5325

Added: trunk/src/argouml-app/src/org/argouml/ui/ChildGenSearch.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/ui/ChildGenSearch.java?view=auto&rev=15646
==============================================================================
--- (empty file)
+++ trunk/src/argouml-app/src/org/argouml/ui/ChildGenSearch.java        
2008-08-29 01:15:40-0700
@@ -0,0 +1,70 @@
+// $Id$
+// Copyright (c) 1996-2008 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies.  This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason.  IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.ui;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.argouml.kernel.Project;
+import org.argouml.model.Model;
+import org.argouml.uml.diagram.ArgoDiagram;
+import org.argouml.util.ChildGenerator;
+
+/**
+ * ChildGenerator that returns the "children" of any given part of the project.
+ * It traverses a Project to Diagrams and Models, then uses
+ * getModelElementContents to traverse the Models.
+ * 
+ * @author jrobbins
+ * @author Tom Morris <[EMAIL PROTECTED]>
+ */
+public class ChildGenSearch implements ChildGenerator {
+    
+    /**
+     * Reply a Collection of the children of the given Object
+     * [EMAIL PROTECTED]
+     */
+    public Iterator childIterator(Object o) {
+        // TODO: This could be made more efficient by working with iterators
+        // directly and creating a composite iterator made up of all the 
+        // various sub iterators.
+        List res = new ArrayList();
+        if (o instanceof Project) {
+            Project p = (Project) o;
+            res.addAll(p.getUserDefinedModelList());
+            res.addAll(p.getDiagramList());
+        } else if (o instanceof ArgoDiagram) {
+            ArgoDiagram d = (ArgoDiagram) o;
+            res.addAll(d.getGraphModel().getNodes());
+            res.addAll(d.getGraphModel().getEdges());
+        } else if (Model.getFacade().isAModelElement(o)) {
+            res.addAll(Model.getFacade().getModelElementContents(o));
+        }
+        
+       return res.iterator();
+    }
+
+}

Modified: trunk/src/argouml-app/src/org/argouml/ui/FindDialog.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/ui/FindDialog.java?view=diff&rev=15646&p1=trunk/src/argouml-app/src/org/argouml/ui/FindDialog.java&p2=trunk/src/argouml-app/src/org/argouml/ui/FindDialog.java&r1=15645&r2=15646
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/ui/FindDialog.java    (original)
+++ trunk/src/argouml-app/src/org/argouml/ui/FindDialog.java    2008-08-29 
01:15:40-0700
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 1996-2006 The Regents of the University of California. All
+// Copyright (c) 1996-2008 The Regents of the University of California. All
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 // software and its documentation without fee, and without a written
 // agreement is hereby granted, provided that the above copyright notice
@@ -53,12 +53,11 @@
 import org.argouml.kernel.ProjectManager;
 import org.argouml.model.Model;
 import org.argouml.swingext.SpacerPanel;
-import org.argouml.uml.PredicateFind;
-import org.argouml.uml.cognitive.ChildGenFind;
+import org.argouml.uml.PredicateSearch;
 import org.argouml.util.ArgoDialog;
-import org.tigris.gef.util.Predicate;
-import org.tigris.gef.util.PredicateStringMatch;
-import org.tigris.gef.util.PredicateType;
+import org.argouml.util.Predicate;
+import org.argouml.util.PredicateStringMatch;
+import org.argouml.util.PredicateType;
 
 
 /**
@@ -69,6 +68,11 @@
  * the screen while they work with them).<p>
  *
  * The search is buggy and needs work.
+ * <p>
+ * NOTE: An incompatible change was made to the public API for this class
+ * before the release of ArgoUML 0.26 to remove exposed internal implementation
+ * details (GEF).
+
  */
 public class FindDialog extends ArgoDialog
     implements ActionListener, MouseListener {
@@ -519,10 +523,10 @@
         Predicate pNamePred = PredicateStringMatch.create(pName);
         Predicate dNamePred = PredicateStringMatch.create(dName);
         Predicate typePred = (Predicate) type.getSelectedItem();
-        PredicateFind pred =
-            new PredicateFind(eNamePred, pNamePred, dNamePred, typePred);
+        PredicateSearch pred =
+            new PredicateSearch(eNamePred, pNamePred, dNamePred, typePred);
 
-        ChildGenFind gen = ChildGenFind.getSingleton();
+        ChildGenSearch gen = new ChildGenSearch();
         Object root = ProjectManager.getManager().getCurrentProject();
 
         TabResults newResults = new TabResults();

Modified: trunk/src/argouml-app/src/org/argouml/ui/TabResults.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/ui/TabResults.java?view=diff&rev=15646&p1=trunk/src/argouml-app/src/org/argouml/ui/TabResults.java&p2=trunk/src/argouml-app/src/org/argouml/ui/TabResults.java&r1=15645&r2=15646
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/ui/TabResults.java    (original)
+++ trunk/src/argouml-app/src/org/argouml/ui/TabResults.java    2008-08-29 
01:15:40-0700
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 1996-2007 The Regents of the University of California. All
+// Copyright (c) 1996-2008 The Regents of the University of California. All
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 // software and its documentation without fee, and without a written
 // agreement is hereby granted, provided that the above copyright notice
@@ -34,6 +34,7 @@
 import java.awt.event.MouseListener;
 import java.util.ArrayList;
 import java.util.Enumeration;
+import java.util.Iterator;
 import java.util.List;
 
 import javax.swing.BorderFactory;
@@ -51,14 +52,18 @@
 import org.argouml.i18n.Translator;
 import org.argouml.ui.targetmanager.TargetManager;
 import org.argouml.uml.ChildGenRelated;
-import org.argouml.uml.PredicateFind;
+import org.argouml.uml.PredicateSearch;
 import org.argouml.uml.TMResults;
-import org.tigris.gef.base.Diagram;
-import org.tigris.gef.util.ChildGenerator;
+import org.argouml.uml.diagram.ArgoDiagram;
+import org.argouml.util.ChildGenerator;
+
 
 /**
  * The results tab for the find dialog.
- *
+ * <p>
+ * NOTE: An incompatible change was made to the public API for this class
+ * before the release of ArgoUML 0.26 to remove exposed internal implementation
+ * details (GEF).
  */
 public class TabResults
         extends AbstractArgoJPanel
@@ -80,14 +85,13 @@
      */
     private static final int INSET_PX = 3;
 
-    private PredicateFind pred;
+    private PredicateSearch pred;
     private ChildGenerator cg;
     private Object root;
     private JSplitPane mainPane;
     private List results = new ArrayList();
     private List related = new ArrayList();
-    // TODO: This should be some non-GEF type such as ArgoDiagram.
-    private List<Diagram> diagrams = new ArrayList<Diagram>();
+    private List<ArgoDiagram> diagrams = new ArrayList<ArgoDiagram>();
     private boolean relatedShown;
 
     private JLabel resultsLabel = new JLabel();
@@ -162,9 +166,13 @@
 
     /**
      * @param p the predicate for the search
+     *            <p>
+     *            NOTE: The type of this parameter was changed incompatibly
+     *            before 0.26 from org.argouml.uml.PredicateFind to
+     *            org.argouml.uml.PredicateSearch.
      */
-    public void setPredicate(PredicateFind p) {
-       pred = p;
+    public void setPredicate(PredicateSearch p) {
+        pred = p;
     }
 
     /**
@@ -175,10 +183,14 @@
     }
 
     /**
-     * @param gen the generator
+     * @param gen the generator.
+     *            <p>
+     *            NOTE: The type of this parameter was changed incompatibly
+     *            before 0.26 from org.tigris.gef.util.ChildGenerator to
+     *            org.argouml.util.ChildGenerator.
      */
     public void setGenerator(ChildGenerator gen) {
-       cg = gen;
+        cg = gen;
     }
 
     /**
@@ -279,7 +291,7 @@
 
     private void myDoubleClick(Object src) {
        Object sel = null;
-       Diagram d = null;
+       ArgoDiagram d = null;
        if (src == resultsTable) {
            int row = resultsTable.getSelectionModel().getMinSelectionIndex();
            if (row < 0) {
@@ -384,23 +396,23 @@
      * appear in any other diagram, but we're not going to do the bookkeeping
      * for now.  - tfm 20060214
      */
-    private void depthFirst(Object node, Diagram lastDiagram) {
-       if (node instanceof Diagram) {
-           lastDiagram = (Diagram) node;
+    private void depthFirst(Object node, ArgoDiagram lastDiagram) {
+       if (node instanceof ArgoDiagram) {
+           lastDiagram = (ArgoDiagram) node;
            if (!pred.matchDiagram(lastDiagram)) {
                 return;
             }
            // diagrams are not placed in search results
        }
-       Enumeration elems = cg.gen(node);
-       while (elems.hasMoreElements()) {
-           Object c = elems.nextElement();
-           if (pred.predicate(c)
+       Iterator iterator = cg.childIterator(node);
+       while (iterator.hasNext()) {
+           Object child = iterator.next();
+           if (pred.evaluate(child)
                     && (lastDiagram != null || pred.matchDiagram(""))) {
-               results.add(c);
+               results.add(child);
                diagrams.add(lastDiagram);
            }
-           depthFirst(c, lastDiagram);
+           depthFirst(child, lastDiagram);
        }
     }
 

Modified: trunk/src/argouml-app/src/org/argouml/uml/cognitive/ChildGenFind.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/cognitive/ChildGenFind.java?view=diff&rev=15646&p1=trunk/src/argouml-app/src/org/argouml/uml/cognitive/ChildGenFind.java&p2=trunk/src/argouml-app/src/org/argouml/uml/cognitive/ChildGenFind.java&r1=15645&r2=15646
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/cognitive/ChildGenFind.java       
(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/cognitive/ChildGenFind.java       
2008-08-29 01:15:40-0700
@@ -46,7 +46,9 @@
  * @see org.argouml.cognitive.Agency
  * @stereotype singleton
  * @author jrobbins
+ * @deprecated for 0.26 by tfmorris.  Use [EMAIL PROTECTED] 
org.argouml.ui.ChildGenSearch}.
  */
[EMAIL PROTECTED]
 public class ChildGenFind implements ChildGenerator {
     private static final ChildGenFind SINGLETON = new ChildGenFind();
 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to