svn commit: r12692 - trunk/src_new/org/argouml/uml/reveng

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: tfmorris
Date: 2007-05-27 22:37:00-0700
New Revision: 12692

Modified:
   trunk/src_new/org/argouml/uml/reveng/FileImportUtils.java
   trunk/src_new/org/argouml/uml/reveng/Import.java
   trunk/src_new/org/argouml/uml/reveng/ImportCommon.java
   trunk/src_new/org/argouml/uml/reveng/ImporterManager.java

Log:
Remove last of old style Import interface.

Add support for cancel while creating file list.

Tighten up typing using Java 5 generics.

Modified: trunk/src_new/org/argouml/uml/reveng/FileImportUtils.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/uml/reveng/FileImportUtils.java?view=diff&rev=12692&p1=trunk/src_new/org/argouml/uml/reveng/FileImportUtils.java&p2=trunk/src_new/org/argouml/uml/reveng/FileImportUtils.java&r1=12691&r2=12692
==============================================================================
--- trunk/src_new/org/argouml/uml/reveng/FileImportUtils.java	(original)
+++ trunk/src_new/org/argouml/uml/reveng/FileImportUtils.java	2007-05-27 22:37:00-0700
@@ -27,8 +27,12 @@
 import java.io.File;

 import java.util.ArrayList;

 import java.util.Collections;

+import java.util.HashSet;

+import java.util.LinkedList;

 import java.util.List;

+import java.util.Set;

 

+import org.argouml.taskmgmt.ProgressMonitor;

 import org.argouml.util.SuffixFilter;

 

 /**

@@ -36,9 +40,8 @@
  */

 public  class FileImportUtils {

 

-   

     /**

-     * This method returns a List of source files to import.<p>

+     * Return a List of source files to import.<p>

      *

      * Processing each file in turn is equivalent to a breadth first

      * search through the directory structure.

@@ -47,39 +50,63 @@
      * @param recurse if true, descend directory tree recursively

      * @param filters array of file suffixes to match for filtering

      * @return a list of files to be imported

+     * @deprecated for 0.25.4 by tfmorris - use 

+     * {@link #getList(File, boolean, SuffixFilter[], ProgressMonitor)}

      */

     public static List getList(File file, boolean recurse,

             SuffixFilter[] filters) {

+        return getList(file, recurse, filters, null);

+    }

+        

+    /**

+     * This method returns a List of source files to import.

+     * <p>

+     * 

+     * Processing each file in turn is equivalent to a breadth first search

+     * through the directory structure.

+     * 

+     * @param file

+     *            file or directory to import

+     * @param recurse

+     *            if true, descend directory tree recursively

+     * @param filters

+     *            array of file suffixes to match for filtering

+     * @param monitor

+     *            a progress monitor which will be monitored for cancellation

+     *            requests. (Progress updates are not provided since the amount

+     *            of time required to get the files is non-deterministic).

+     * @return a list of files to be imported

+     */

+    public static List getList(File file, boolean recurse,

+            SuffixFilter[] filters, ProgressMonitor monitor) {

         if (file == null) {

             return Collections.EMPTY_LIST;

         }

         

-	List res = new ArrayList();

+	List<File> results = new ArrayList<File>();

 

-	List toDoDirectories = new ArrayList();

-	List doneDirectories = new ArrayList();

+	List<File> toDoDirectories = new LinkedList<File>();

+	Set<File> seenDirectories = new HashSet<File>();

 

 	toDoDirectories.add(file);

 

-	while (toDoDirectories.size() > 0) {

-	    File curDir = (File) toDoDirectories.get(0);

-	    toDoDirectories.remove(0);

-	    doneDirectories.add(curDir);

+	while (!toDoDirectories.isEmpty()) {

+            if (monitor != null && monitor.isCanceled()) {

+                return results;

+            }

+	    File curDir = toDoDirectories.remove(0);

 

 	    if (!curDir.isDirectory()) {

 	        // For some reason, this alleged directory is a single file

 	        // This could be that there is some confusion or just

 	        // the normal, that a single file was selected and is

 	        // supposed to be imported.

-	        res.add(curDir);

+	        results.add(curDir);

 	        continue;

 	    }

 

 	    // Get the contents of the directory

-	    String [] files = curDir.list();

-

-	    for (int i = 0; i < files.length; i++) {

-	        File curFile = new File(curDir, files[i]);

+	    for (File curFile : curDir.listFiles()) {

 

 	        // The following test can cause trouble with

 	        // links, because links are accepted as

@@ -88,23 +115,19 @@
 	        // reason we don't do this traversing recursively.

 	        if (curFile.isDirectory()) {

 	            // If this file is a directory

-	            if (recurse) {

-	                if (doneDirectories.indexOf(curFile) >= 0

-	                        || toDoDirectories.indexOf(curFile) >= 0) {

-	                    // This one is already seen or to be seen.

-	                } else {

-	                    toDoDirectories.add(curFile);

-	                }

+	            if (recurse && !seenDirectories.contains(curFile)) {

+	                toDoDirectories.add(curFile);

+                        seenDirectories.add(curFile);

 	            }

 	        } else {

 	            if (matchesSuffix(curFile, filters)) {

-	                res.add(curFile);

+	                results.add(curFile);

 	            }

 	        }

 	    }

 	}

 

-	return res;

+	return results;

     }

 

     /**


Modified: trunk/src_new/org/argouml/uml/reveng/Import.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/uml/reveng/Import.java?view=diff&rev=12692&p1=trunk/src_new/org/argouml/uml/reveng/Import.java&p2=trunk/src_new/org/argouml/uml/reveng/Import.java&r1=12691&r2=12692
==============================================================================
--- trunk/src_new/org/argouml/uml/reveng/Import.java	(original)
+++ trunk/src_new/org/argouml/uml/reveng/Import.java	2007-05-27 22:37:00-0700
@@ -253,7 +253,9 @@
             boolean crea = true;
             boolean mini = true;
             boolean layo = true;
-            String flags = Configuration.getString(Argo.KEY_IMPORT_GENERAL_SETTINGS_FLAGS);
+            String flags =
+                    Configuration
+                            .getString(Argo.KEY_IMPORT_GENERAL_SETTINGS_FLAGS);
             if (flags != null && flags.length() > 0) {
                 StringTokenizer st = new StringTokenizer(flags, ",");
                 if (st.hasMoreTokens() && st.nextToken().equals("false")) {
@@ -388,20 +390,12 @@
      * Get the extension panel for the configuration settings.
      */
     private JComponent getConfigPanelExtension() {
-        JComponent result;
-        if (getCurrentModule() instanceof ImportInterface) {
-            // New style importers don't provide a config panel
-            if (importConfigPanel == null) {
-                importConfigPanel = new ConfigPanelExtension();
-            }
-            result = importConfigPanel;
-        } else {
-            throw new RuntimeException("Unrecognized module type");
-        }
-        if (result == null) {
-            result = new JPanel();
+        // New style importers don't provide a config panel
+        // TODO: This needs review for the new style importers - tfm - 20070527
+        if (importConfigPanel == null) {
+            importConfigPanel = new ConfigPanelExtension();
         }
-        return result;
+        return importConfigPanel;
     }
 
     private class SelectedLanguageListener implements ActionListener {
@@ -432,7 +426,7 @@
         public void actionPerformed(ActionEvent e) {
             JComboBox cb = (JComboBox) e.getSource();
             String selected = (String) cb.getSelectedItem();
-            Object oldModule = getCurrentModule();
+            ImportInterface oldModule = getCurrentModule();
             setCurrentModule(getModules().get(selected));
             if (getCurrentModule() instanceof ImportInterface) {
                 updateFilters(
@@ -542,8 +536,7 @@
         final JFileChooser chooser = new ImportFileChooser(this, directory);
 
         chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
-        updateFilters(chooser, null, ((ImportInterface) getCurrentModule())
-                .getSuffixFilters());
+        updateFilters(chooser, null, getCurrentModule().getSuffixFilters());
 
         return chooser;
     }
@@ -612,8 +605,7 @@
             if (getSelectedFile() != null) {
                 String path = getSelectedFile().getParent();
                 String filename =
-                    getSelectedFile().getName();
-                filename = path + SEPARATOR + filename;
+                        path + SEPARATOR + getSelectedFile().getName();
                 Globals.setLastDirectory(path);
                 if (filename != null) {
                     theImport.disposeDialog();
@@ -928,6 +920,7 @@
                         .localize("dialog.import.classpath.text"));
         ta.setLineWrap(true);
         ta.setWrapStyleWord(true);
+        ta.setFocusable(false);
         getContentPane().add(ta, BorderLayout.NORTH);
 
         // paths list
@@ -935,7 +928,7 @@
         paths = new JList(pathsModel);
         paths.setVisibleRowCount(5);
         JScrollPane listScroller = new JScrollPane(paths);
-        listScroller.setPreferredSize(new Dimension(250, 80));
+        listScroller.setPreferredSize(new Dimension(300, 100));
         getContentPane().add(listScroller, BorderLayout.CENTER);
 
         initList();
@@ -943,9 +936,9 @@
         // controls
         JPanel controlsPanel = new JPanel();
         controlsPanel.setLayout(new GridLayout(0, 3));
-        addFile = new JButton("Add");
-        removeFile = new JButton("Remove");
-        ok = new JButton("Ok");
+        addFile = new JButton(Translator.localize("button.add"));
+        removeFile = new JButton(Translator.localize("button.remove"));
+        ok = new JButton(Translator.localize("button.ok"));
         controlsPanel.add(addFile);
         controlsPanel.add(removeFile);
         controlsPanel.add(ok);
@@ -960,6 +953,7 @@
         setLocation(scrSize.width / 2 - contentPaneSize.width / 2,
             scrSize.height / 2 - contentPaneSize.height / 2);
         pack();
+        ok.requestFocusInWindow();
         setVisible(true);
         this.setModal(true);        //MVW   Issue 2539.
     }

Modified: trunk/src_new/org/argouml/uml/reveng/ImportCommon.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/uml/reveng/ImportCommon.java?view=diff&rev=12692&p1=trunk/src_new/org/argouml/uml/reveng/ImportCommon.java&p2=trunk/src_new/org/argouml/uml/reveng/ImportCommon.java&r1=12691&r2=12692
==============================================================================
--- trunk/src_new/org/argouml/uml/reveng/ImportCommon.java	(original)
+++ trunk/src_new/org/argouml/uml/reveng/ImportCommon.java	2007-05-27 22:37:00-0700
@@ -30,12 +30,10 @@
 import java.net.URL;

 import java.util.ArrayList;

 import java.util.Collection;

-import java.util.Enumeration;

+import java.util.Collections;

 import java.util.HashSet;

 import java.util.Hashtable;

-import java.util.Iterator;

 import java.util.List;

-import java.util.Set;

 import java.util.StringTokenizer;

 import java.util.Vector;

 

@@ -46,7 +44,6 @@
 import org.argouml.kernel.Project;

 import org.argouml.kernel.ProjectManager;

 import org.argouml.model.Model;

-import org.argouml.moduleloader.ModuleInterface;

 import org.argouml.taskmgmt.ProgressMonitor;

 import org.argouml.ui.explorer.ExplorerEventAdaptor;

 import org.argouml.uml.diagram.static_structure.ClassDiagramGraphModel;

@@ -77,12 +74,12 @@
     /**

      * keys are module name, values are PluggableImport instance.

      */

-    private Hashtable modules;

+    private Hashtable<String, ImportInterface> modules;

 

     /**

      * Current language module.

      */

-    private Object currentModule;

+    private ImportInterface currentModule;

 

 

     /**

@@ -99,12 +96,11 @@
 

     protected ImportCommon() {

         super();

-        modules = new Hashtable();

+        modules = new Hashtable<String, ImportInterface>();

 

-        Set newPlugins = ImporterManager.getInstance().getImporters();

-        for (Iterator it = newPlugins.iterator(); it.hasNext();) {

-            ModuleInterface mod = (ModuleInterface) it.next();

-            modules.put(mod.getName(), mod);

+        for (ImportInterface importer : ImporterManager.getInstance()

+                .getImporters()) {

+            modules.put(importer.getName(), importer);

         }

         if (modules.size() == 0) {

             throw new RuntimeException("Internal error. "

@@ -180,26 +176,23 @@
      * Get the files. For old style modules, this asks the module for the list.

      * For new style modules we generate it ourselves based on their specified

      * file suffixes.

-     *

+     * @param monitor progress monitor which can be used to cancel long running 

+     * request

      * @return the list of files to be imported

      */

-    protected List getFileList() {

+    protected List getFileList(ProgressMonitor monitor) {

         List files;

-        if (currentModule instanceof ImportInterface) {

-            files = FileImportUtils.getList(

-                    getSelectedFile(), isDescendSelected(),

-                    ((ImportInterface) currentModule)

-                            .getSuffixFilters());

-            // New style importer - we did the file selection

-            if (getSelectedFile().isDirectory()) {

-                setSrcPath(getSelectedFile().getAbsolutePath());

-            } else {

-                setSrcPath(null);

-            }

+        files =

+                FileImportUtils.getList(

+                        getSelectedFile(), isDescendSelected(), currentModule

+                                .getSuffixFilters(), monitor);

+        if (getSelectedFile().isDirectory()) {

+            setSrcPath(getSelectedFile().getAbsolutePath());

         } else {

-            throw new RuntimeException("Unrecognized module type");

+            setSrcPath(null);

         }

 

+

         if (isChangedOnlySelected()) {

             // filter out all unchanged files

             Object model =

@@ -276,7 +269,7 @@
      */

     public abstract boolean isChangedOnlySelected();

 

-    protected Hashtable getModules() {

+    protected Hashtable<String, ImportInterface> getModules() {

         return modules;

     }

 

@@ -288,11 +281,11 @@
         return selectedFile;

     }

 

-    protected void setCurrentModule(Object module) {

+    protected void setCurrentModule(ImportInterface module) {

         currentModule = module;

     }

 

-    protected Object getCurrentModule() {

+    protected ImportInterface getCurrentModule() {

         return currentModule;

     }

 

@@ -301,12 +294,7 @@
      * @return a list of Strings with the names of the languages available

      */

     public List getLanguages() {

-        List languages = new ArrayList();

-        Enumeration iterator = modules.keys();

-        while (iterator.hasMoreElements()) {

-            languages.add((iterator.nextElement()));

-        }

-        return languages;

+        return Collections.unmodifiableList(new ArrayList(modules.keySet()));

     }

 

     /**

@@ -433,12 +421,12 @@
      * initialization.

      * @return a list with Strings representing the classpaths

      */

-    public List getImportClasspath() {

-        List list = new ArrayList();

+    public List<String> getImportClasspath() {

+        List<String> list = new ArrayList<String>();

         URL[] urls = ImportClassLoader.getURLs(Configuration.getString(

                 Argo.KEY_USER_IMPORT_CLASSPATH, "")); //$NON-NLS-1$

-        for (int i = 0; i < urls.length; i++) {

-            list.add(urls[i].getFile());

+        for (URL url : urls) {

+            list.add(url.getFile());

         }

         return list;

     }

@@ -493,7 +481,7 @@
         monitor.setMaximumProgress(MAX_PROGRESS_PREPARE + MAX_PROGRESS_IMPORT);

         int progress = 0;

         monitor.updateSubTask(Translator.localize("dialog.import.preImport"));

-        List files = getFileList();

+        List files = getFileList(monitor);

         progress += MAX_PROGRESS_PREPARE;

         monitor.updateProgress(progress);

         if (files.size() == 0) {

@@ -530,24 +518,22 @@
         initCurrentDiagram();

         final StringBuffer problems = new StringBuffer();

         Collection newElements = new HashSet();

-        if (currentModule instanceof ImportInterface) {

-            try {

-                newElements.addAll(((ImportInterface) currentModule)

-                        .parseFiles(project, filesLeft, this, monitor));

-            } catch (ImportException e) {

-                problems.append(printToBuffer(e));

-            }

-            // New style importers don't create diagrams, so we'll do it

-            // based on the list of newElements that they created

-            if (isCreateDiagramsSelected()) {

-                addFiguresToDiagrams(newElements);

-            }

-        } else {

-            throw new RuntimeException("Unrecognized module type");

+        

+        try {

+            newElements.addAll(currentModule.parseFiles(

+                    project, filesLeft, this, monitor));

+        } catch (ImportException e) {

+            problems.append(printToBuffer(e));

+        }

+        // New style importers don't create diagrams, so we'll do it

+        // based on the list of newElements that they created

+        if (isCreateDiagramsSelected()) {

+            addFiguresToDiagrams(newElements);

         }

 

         // TODO: Skip layout if problems during import?

         if (isDiagramLayoutSelected()) {

+            // TODO: Monitor is getting dismissed before layout is complete

             monitor.updateMainTask(

                     Translator.localize("dialog.import.postImport"));

             monitor.updateSubTask(

@@ -579,8 +565,7 @@
      *            created.

      */

     private void addFiguresToDiagrams(Collection newElements) {

-        for (Iterator it = newElements.iterator(); it.hasNext();) {

-            Object element = it.next();

+        for (Object element : newElements) {

             if (Model.getFacade().isAClassifier(element)

                     || Model.getFacade().isAPackage(element)) {

 


Modified: trunk/src_new/org/argouml/uml/reveng/ImporterManager.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/uml/reveng/ImporterManager.java?view=diff&rev=12692&p1=trunk/src_new/org/argouml/uml/reveng/ImporterManager.java&p2=trunk/src_new/org/argouml/uml/reveng/ImporterManager.java&r1=12691&r2=12692
==============================================================================
--- trunk/src_new/org/argouml/uml/reveng/ImporterManager.java	(original)
+++ trunk/src_new/org/argouml/uml/reveng/ImporterManager.java	2007-05-27 22:37:00-0700
@@ -1,5 +1,5 @@
 // $Id: ImporterManager.java 10735 2006-06-11 17:14:04Z mvw $

-// Copyright (c) 2005-2006 The Regents of the University of California. All

+// Copyright (c) 2005-2007 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

@@ -54,7 +54,7 @@
         return INSTANCE;

     }

 

-    private Set importers = new HashSet();

+    private Set<ImportInterface> importers = new HashSet<ImportInterface>();

 

     /**

      * The constructor.

@@ -108,7 +108,7 @@
     /**

      * @return A copy of the set of importers.

      */

-    public Set getImporters() {

+    public Set<ImportInterface> getImporters() {

         return Collections.unmodifiableSet(importers);

     }
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.