svn commit: r18280 - trunk/src: argouml-app/src/org/argouml/ui argouml-core-model-mdr/src/org/argouml/model/mdr argouml-core-model-mdr/tests/org/argouml/model/mdr

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: tfmorris
Date: 2010-04-17 13:07:16-0700
New Revision: 18280

Modified:
   trunk/src/argouml-app/src/org/argouml/ui/SettingsTabProfile.java
   trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/XmiReferenceResolverImpl.java
   trunk/src/argouml-core-model-mdr/tests/org/argouml/model/mdr/TestReadCompressedFilesAndHref.java

Log:
RESOLVED - task 5946: Move recursive profile subdirectory search from MDR to GUI 
http://argouml.tigris.org/issues/show_bug.cgi?id=5946

Modified: trunk/src/argouml-app/src/org/argouml/ui/SettingsTabProfile.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/ui/SettingsTabProfile.java?view=diff&pathrev=18280&r1=18279&r2=18280
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/ui/SettingsTabProfile.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/ui/SettingsTabProfile.java	2010-04-17 13:07:16-0700
@@ -49,6 +49,7 @@
 import java.awt.event.ItemListener;
 import java.io.File;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 
 import javax.swing.BoxLayout;
@@ -389,10 +390,12 @@
             }
 
         } else if (arg0.getSource() == removeDirectory) {
-            if (directoryList.getSelectedIndex() != -1) {
-                int idx = directoryList.getSelectedIndex();
-                ((MutableComboBoxModel) directoryList.getModel())
-                        .removeElementAt(idx);
+            MutableComboBoxModel model = 
+                ((MutableComboBoxModel) directoryList.getModel()); 
+            int[] indices = directoryList.getSelectedIndices(); 
+            for (int i = indices.length-1; i >=0; i--) {
+                int idx = indices[i];
+                model.removeElementAt(idx);
             }
         } else if (arg0.getSource() == refreshProfiles) {
             boolean refresh = JOptionPane.showConfirmDialog(this, Translator
@@ -424,18 +427,34 @@
             if (ret == JFileChooser.APPROVE_OPTION) {
                 File file = fileChooser.getSelectedFile();
 
-                String path = file.getAbsolutePath();
-
-                ((MutableComboBoxModel) directoryList.getModel())
-                        .addElement(path);
+                // find and add all subdirectories
+                Collection<File> dirs = new ArrayList<File>();
+                collectSubdirs(file, dirs);
+                
+                MutableComboBoxModel cbModel = 
+                    ((MutableComboBoxModel) directoryList.getModel());
+                for (File dir : dirs) {
+                    cbModel.addElement(dir.getAbsolutePath());
+                }
             }
-
         }
 
         availableList.validate();
         defaultList.validate();
     }
 
+    private void collectSubdirs(File file, Collection<File> subdirs) {
+        subdirs.add(file);
+        File[] files = file.listFiles();
+        if (files != null) {
+            for (File f : files) {
+                if (f.isDirectory() & !f.isHidden()) {
+                    collectSubdirs(f, subdirs);
+                }
+            }
+        }
+    }
+
     /**
      * @return the internationalization key that containing the name of this tab
      * @see org.argouml.application.api.GUISettingsTabInterface#getTabKey()
@@ -452,9 +471,6 @@
         return this;
     }
 
-
-
-
     public void handleResetToDefault() {
         if (!initialized) {
             buildPanel();
@@ -463,7 +479,6 @@
     }
 
     public void handleSettingsTabCancel() {
-
     }
 
     public void handleSettingsTabRefresh() {

Modified: trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/XmiReferenceResolverImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/XmiReferenceResolverImpl.java?view=diff&pathrev=18280&r1=18279&r2=18280
==============================================================================
--- trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/XmiReferenceResolverImpl.java	(original)
+++ trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/XmiReferenceResolverImpl.java	2010-04-17 13:07:16-0700
@@ -47,7 +47,6 @@
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
@@ -464,22 +463,20 @@
                     + modulesPath.size());
         }
         for (String moduleDirectory : modulesPath) {
-            Collection<File> candidates = findAllCandidateModulePaths(
-                moduleDirectory, moduleName);
-            for (File candidate : candidates) {
-                if (LOG.isDebugEnabled()) {
-                    LOG.debug("candidate '" + candidate.toString()
-                            + "' exists=" + candidate.exists());
-                }
-                if (candidate.exists()) {
-                    String urlString;
-                    try {
-                        urlString = candidate.toURI().toURL().toExternalForm();
-                    } catch (MalformedURLException e) {
-                        return null;
-                    }
-                    return fixupURL(urlString);
+            File candidate = new File(moduleDirectory, moduleName);
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("candidate '" + candidate.toString() + "' exists="
+                        + candidate.exists());
+            }
+            if (candidate.exists()) {
+                String urlString;
+                try {
+                    urlString = candidate.toURI().toURL().toExternalForm();
+                } catch (MalformedURLException e) {
+                    return null;
                 }
+
+                return fixupURL(urlString);
             }
         }
         if (public2SystemIds.containsKey(moduleName)) {
@@ -493,40 +490,6 @@
         return null;
     }
 
-    private static Collection<File> findAllCandidateModulePaths(
-            String basePath, String fileName) {
-        Collection<File> candidates = new ArrayList<File>();
-        if (basePath != null && basePath.length() > 0) {
-            Collection<File> dirs = new ArrayList<File>();
-            // TODO: This should be done (if desired/needed) by the calling
-            // code, not here.  It's not always the case that searching all
-            // subdirectories is desirable.
-            dirs = findAllInternalDirectories(new File(basePath));
-            for (File dir : dirs) {
-                candidates.add(new File(dir, fileName));
-            }
-        } else {
-            candidates.add(new File(fileName));
-        }
-        return candidates;
-    }
-
-    private static Collection<File> findAllInternalDirectories(File baseDir) {
-        List<File> dirs = new ArrayList<File>();
-        if (baseDir.exists() && baseDir.isDirectory()) {
-            dirs.add(baseDir);
-            File[] files = baseDir.listFiles();
-            if (files != null) { // API says not possible, but it happens
-                for (File file : files) {
-                    if (file.isDirectory()) {
-                        dirs.add(file);
-                        dirs.addAll(findAllInternalDirectories(file));
-                    }
-                }
-            }
-        }
-        return dirs;
-    }
 
     /**
      * Gets the suffix of the <code>systemId</code>.

Modified: trunk/src/argouml-core-model-mdr/tests/org/argouml/model/mdr/TestReadCompressedFilesAndHref.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model-mdr/tests/org/argouml/model/mdr/TestReadCompressedFilesAndHref.java?view=diff&pathrev=18280&r1=18279&r2=18280
==============================================================================
--- trunk/src/argouml-core-model-mdr/tests/org/argouml/model/mdr/TestReadCompressedFilesAndHref.java	(original)
+++ trunk/src/argouml-core-model-mdr/tests/org/argouml/model/mdr/TestReadCompressedFilesAndHref.java	2010-04-17 13:07:16-0700
@@ -40,6 +40,8 @@
 package org.argouml.model.mdr;
 
 import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
 
 import org.apache.log4j.Logger;
 import org.xml.sax.InputSource;
@@ -97,8 +99,9 @@
         LOG.info("Begin " + testName + "()");
         XmiReaderImpl reader = new XmiReaderImpl(modelImplementation);
         if (profilesPath != null) {
-            String file = getClass().getResource(profilesPath).getFile();
-            reader.addSearchPath(file);
+            String path = getClass().getResource(profilesPath).getPath();
+            File file = new File(path);
+            setProfilePathSubdirs(reader, file);
         }
         try {
             InputSource inputSource = new InputSource(
@@ -111,4 +114,25 @@
         }
         assertTrue(modelPath + " model is loaded", true);
     }
+    
+    private void setProfilePathSubdirs(XmiReaderImpl reader, File directory) {
+        Collection<File> dirs = new ArrayList<File>();
+        collectSubdirs(directory, dirs);
+
+        for (File dir : dirs) {
+            reader.addSearchPath(dir.getAbsolutePath());
+        }
+    }
+    
+    private void collectSubdirs(File file, Collection<File> subdirs) {
+        subdirs.add(file);
+        File[] files = file.listFiles();
+        if (files != null) {
+            for (File f : files) {
+                if (f.isDirectory() & !f.isHidden()) {
+                    collectSubdirs(f, subdirs);
+                }
+            }
+        }
+    }
 }

------------------------------------------------------
http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=2587035

To unsubscribe from this discussion, e-mail: [[email protected]].
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.