svn commit: r16987 - trunk/src/argouml-app/src/org/argouml/uml/ui/ActionImportFromSources.java

Thomas Neustupny <[email protected]>
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: thn
Date: 2009-03-28 04:02:13-0700
New Revision: 16987

Modified:
   trunk/src/argouml-app/src/org/argouml/uml/ui/ActionImportFromSources.java

Log:
command line support for import

Modified: trunk/src/argouml-app/src/org/argouml/uml/ui/ActionImportFromSources.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/ui/ActionImportFromSources.java?view=diff&pathrev=16987&r1=16986&r2=16987
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/ui/ActionImportFromSources.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/ui/ActionImportFromSources.java	2009-03-28 04:02:13-0700
@@ -26,15 +26,23 @@
 package org.argouml.uml.ui;
 
 import java.awt.event.ActionEvent;
+import java.io.File;
+import java.util.Collection;
+import java.util.List;
 
 import javax.swing.Action;
+import javax.swing.JFrame;
 
 import org.apache.log4j.Logger;
+import org.argouml.application.api.CommandLineInterface;
 import org.argouml.application.helpers.ResourceLoaderWrapper;
 import org.argouml.i18n.Translator;
 import org.argouml.ui.ExceptionDialog;
+import org.argouml.uml.reveng.FileImportUtils;
 import org.argouml.uml.reveng.Import;
+import org.argouml.uml.reveng.ImportInterface;
 import org.argouml.uml.reveng.ImporterManager;
+import org.argouml.uml.reveng.ui.ImportStatusScreen;
 import org.argouml.util.ArgoFrame;
 import org.tigris.gef.undo.UndoableAction;
 
@@ -42,7 +50,7 @@
 /** Action to trigger importing from sources.
  * @stereotype singleton
  */
-public class ActionImportFromSources extends UndoableAction {
+public class ActionImportFromSources extends UndoableAction implements CommandLineInterface {
 
     /**
      * Logger.
@@ -59,7 +67,7 @@
     /**
      *  The constructor.
      */
-    protected ActionImportFromSources() {
+    public ActionImportFromSources() {
         // this is never downlighted...
         super(Translator.localize("action.import-sources"),
                 ResourceLoaderWrapper.lookupIcon("action.import-sources"));
@@ -92,5 +100,46 @@
     public static ActionImportFromSources getInstance() {
         return SINGLETON;
     }
+
+    /**
+     * Command line command for importing a directory or file.
+     * 
+     * @param argument Formatted string (<importmodule>:<importpath>)
+     * @return true if the command was performed successfully.
+*/
+    public boolean doCommand(String argument) {
+        if (argument == null) {
+            LOG.error("An argument has to be provided.");
+            return false;
+        }
+        int index = argument.indexOf(':');
+        if (index == -1 || argument.length() <= index) {
+            LOG.error("Argument must be <importmodule>:<importpath>");
+            return false;
+        }
+        Import imp = new Import(null);
+        Collection languages = imp.getLanguages();
+        if (languages == null || languages.isEmpty()) {
+            LOG.error("No importers available.");
+            return false;
+        }
+        String importerName = argument.substring(0, index);
+        ImportInterface importer = imp.getImporter(importerName);
+        if (importer == null) {
+            LOG.error("No import support for language " + importerName);
+            return false;
+        }
+        imp.setCurrentModule(importer);
+        File file = new File(argument.substring(index + 1));
+        if (!file.exists()) {
+            LOG.error("The specified file/directory doesn't exist.");
+            return false;
+        }
+        imp.setFiles(new File[]{file});
+        ImportStatusScreen iss =
+            new ImportStatusScreen(new JFrame(), "Importing", "Splash");
+        imp.doImport(iss);
+        return true;
+    }
 }
 /* end class ActionImportFromSources */

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

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.