svn commit: r15814 - trunk/src/argouml-app/src/org/argouml/ui/explorer/rules/GoModelToDiagrams.java

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: mvw
Date: 2008-09-28 00:46:37-0700
New Revision: 15814

Modified:
   trunk/src/argouml-app/src/org/argouml/ui/explorer/rules/GoModelToDiagrams.java

Log:
Fix for issue 5256, according the given patch.

Modified: trunk/src/argouml-app/src/org/argouml/ui/explorer/rules/GoModelToDiagrams.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/ui/explorer/rules/GoModelToDiagrams.java?view=diff&rev=15814&p1=trunk/src/argouml-app/src/org/argouml/ui/explorer/rules/GoModelToDiagrams.java&p2=trunk/src/argouml-app/src/org/argouml/ui/explorer/rules/GoModelToDiagrams.java&r1=15813&r2=15814
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/ui/explorer/rules/GoModelToDiagrams.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/ui/explorer/rules/GoModelToDiagrams.java	2008-09-28 00:46:37-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
@@ -24,14 +24,18 @@
 
 package org.argouml.ui.explorer.rules;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 
 import org.argouml.i18n.Translator;
+import org.argouml.kernel.Project;
 import org.argouml.kernel.ProjectManager;
 import org.argouml.model.Model;
+import org.argouml.uml.diagram.ArgoDiagram;
 
 /**
  * Rule for Model->Diagram.
@@ -50,16 +54,34 @@
     /*
      * @see org.argouml.ui.explorer.rules.PerspectiveRule#getChildren(java.lang.Object)
      */
-    public Collection getChildren(Object parent) {
-        // TODO: This is assuming a single model per project which isn't
-        // true of models received from other UML tools - tfm 20070724
-	if (Model.getFacade().isAModel(parent)) {
-	    return ProjectManager.getManager()
-                        .getCurrentProject().getDiagramList();
+    public Collection getChildren(Object model) {
+	if (Model.getFacade().isAModel(model)) {
+	    List returnList = new ArrayList();
+	    Project proj = ProjectManager.getManager().getCurrentProject();
+            for (ArgoDiagram diagram : proj.getDiagramList()) {
+                if (isInPath(diagram.getNamespace(), model)) {
+                        returnList.add(diagram);
+                }
+            }
+            return returnList;
 	}
 	return Collections.EMPTY_SET;
     }
 
+    private boolean isInPath(Object namespace, Object model) {
+        if (namespace == model) {
+            return true;
+        }
+        Object ns = Model.getFacade().getNamespace(namespace);
+        while (ns != null) {
+            if (model == ns) {
+                return true;
+            }
+            ns = Model.getFacade().getNamespace(ns);
+        }
+        return false;
+    }
+
     /*
      * @see org.argouml.ui.explorer.rules.PerspectiveRule#getDependencies(java.lang.Object)
      */
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.