]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Preference pages for selecting OM version. This is difficult to use since preference...
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 11 Feb 2013 08:25:48 +0000 (08:25 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 11 Feb 2013 08:25:48 +0000 (08:25 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@26747 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java
org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/ModelicaPreferenceInitializer.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/ModelicaPreferencePage.java [new file with mode: 0644]

index 002c340a5713eb8d694bc32abe861b251b2ea5ff..0b8a4137ebc670999771aab25e681dcad8abdd9f 100644 (file)
@@ -58,6 +58,9 @@ import org.xml.sax.SAXException;
  *\r
  */\r
 public class ModelicaManager {\r
+    \r
+    private static String builtInOMVersionName = "1.9.0 beta 4 (r15030)";\r
+    private static String builtInOMVersion = "1.9.0";\r
 \r
     public enum OSType {\r
         APPLE, LINUX, SUN, WINDOWS, UNKNOWN\r
@@ -133,7 +136,7 @@ public class ModelicaManager {
                     if(entry != null) {\r
                         URL fileURL = FileLocator.toFileURL(entry);\r
                         File root = new File( URLDecoder.decode(fileURL.getPath(), "UTF-8") );\r
-                        File f = new File(root, "OpenModelica1.8.1");\r
+                        File f = new File(root, "OpenModelica" + builtInOMVersion);\r
                         return f;\r
                     }\r
                 }\r
@@ -150,31 +153,61 @@ public class ModelicaManager {
             case SUN:\r
                 return new File("/usr/bin/omc");\r
             case WINDOWS:\r
-                return new File("c:/OpenModelica1.8.0");\r
+                return new File("c:/OpenModelica" + builtInOMVersion);\r
             default:\r
                 throw new UnsatisfiedLinkError("Unsupported operating system: " + os);\r
         }\r
     }\r
-\r
+    \r
+    public static String getInstalledOpenModelicaVersion() {\r
+        String dir = System.getenv("OPENMODELICAHOME");\r
+        if(dir != null) {\r
+            File omhome = new File(dir);\r
+            if(omhome.isDirectory())\r
+                try {\r
+                    return getOMCVersion(omhome);\r
+                } catch (IOException e) {}\r
+        }\r
+        return null;\r
+    }\r
+    \r
+    public static String getBuiltInOpenModelicaVersion() {\r
+        return builtInOMVersionName;\r
+    }\r
 \r
     \r
+    private static String omcVersion = getOMCVersion();\r
     /**\r
      * Get version of the OpenModelica that is used by this software\r
      * @return\r
      * @throws IOException\r
      */\r
-    public static String getOMCVersion() throws IOException {\r
-        // Add OMC as the first parameter\r
-        File openModelicaHome = getModelicaHome();\r
+    public static String getOMCVersion() {\r
+        if(omcVersion == null) {\r
+            // Add OMC as the first parameter\r
+            File openModelicaHome = getModelicaHome();\r
+            try {\r
+                omcVersion = getOMCVersion(openModelicaHome);\r
+            } catch (IOException e) {\r
+                omcVersion = null;\r
+            }\r
+        }\r
+        return omcVersion;\r
+    }\r
 \r
+    \r
+    private static String getOMCVersion(File OMHome) throws IOException {\r
         ArrayList<String> parameters = new ArrayList<String>();\r
-        parameters.add(openModelicaHome + "\\bin\\omc.exe");\r
+        parameters.add(OMHome + "\\bin\\omc.exe");\r
         parameters.add("++v");\r
 \r
         // Create the build process\r
         ProcessBuilder processBuilder = new ProcessBuilder(parameters)\r
         .redirectErrorStream(true);\r
 \r
+        Map<String, String> env = processBuilder.environment();\r
+        env.put("OPENMODELICAHOME", OMHome.getAbsolutePath());\r
+        \r
         // Start the building process\r
         Process process = processBuilder.start();\r
 \r
@@ -184,7 +217,6 @@ public class ModelicaManager {
         return output;\r
     }\r
 \r
-\r
     /**\r
      * Gets the whole process output in one string\r
      * @param process Process\r
@@ -576,13 +608,17 @@ public class ModelicaManager {
 \r
         try {\r
             ArrayList<String> commands = new ArrayList<String>();\r
-            commands.add(getModelicaHome() + "\\bin\\omc.exe");\r
+            File omHome = getModelicaHome();\r
+            commands.add(omHome + "\\bin\\omc.exe");\r
             commands.add(simulationLocation.fullModel.getAbsolutePath());\r
 \r
             // Create the build process\r
             ProcessBuilder processBuilder = new ProcessBuilder(commands)\r
             .redirectErrorStream(true);\r
 \r
+            Map<String, String> env = processBuilder.environment();\r
+            env.put("OPENMODELICAHOME", omHome.getAbsolutePath());\r
+            \r
             // Start the building process\r
             Process process = processBuilder.start();\r
 \r
index e34af3c44ea39fe4bd55564a5c181db12ae07918..b29bc8911cb7f0467adced30baa9921ba5f32693 100644 (file)
                relationship="right"\r
                relative="org.eclipse.ui.editorss">\r
          </view>\r
-         <!--\r
          <view\r
                id="org.simantics.document.workbench.documentViewer"\r
                minimized="true"\r
                relationship="stack"\r
-               relative="org.simantics.sysdyn.ui.chartPanel">\r
+               relative="org.simantics.jfreechart.chartPanel">\r
          </view>\r
-         -->\r
       </perspectiveExtension>\r
    </extension>\r
    <extension\r
             </visibleWhen>\r
          </command>\r
          <menu\r
-               id="org.simantics.sysdyn.import"\r
+               id="org.simantics.import"\r
                label="Import">\r
             <command\r
                   commandId="org.simantics.sysdyn.ui.importModel"\r
             </command>\r
          </menu>\r
          <menu\r
-               id="org.simantics.sysdyn.export"\r
+               id="org.simantics.export"\r
                label="Export">\r
             <command\r
                   commandId="org.simantics.sysdyn.ui.exportModel"\r
         </namespace>        \r
       </namespace>\r
    </extension>\r
+   <!--\r
+   <extension\r
+         point="org.eclipse.ui.preferencePages">\r
+      <page\r
+            class="org.simantics.sysdyn.ui.preferences.ModelicaPreferencePage"\r
+            id="org.simantics.modelica.preferences"\r
+            name="Modelica">\r
+      </page>\r
+   </extension>\r
+   -->\r
 </plugin>\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/ModelicaPreferenceInitializer.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/ModelicaPreferenceInitializer.java
new file mode 100644 (file)
index 0000000..2014e3a
--- /dev/null
@@ -0,0 +1,29 @@
+/*******************************************************************************\r
+ * Copyright (c) 2013 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.preferences;\r
+\r
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;\r
+import org.eclipse.jface.preference.IPreferenceStore;\r
+import org.simantics.sysdyn.ui.Activator;\r
+\r
+public class ModelicaPreferenceInitializer  extends AbstractPreferenceInitializer {\r
+\r
+    public ModelicaPreferenceInitializer() {\r
+    }\r
+\r
+    @Override\r
+    public void initializeDefaultPreferences() {\r
+      IPreferenceStore store = Activator.getDefault().getPreferenceStore();\r
+      store.setDefault(ModelicaPreferencePage.OM_VERSION, ModelicaPreferencePage.OM_BUILTIN);\r
+    }\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/ModelicaPreferencePage.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/ModelicaPreferencePage.java
new file mode 100644 (file)
index 0000000..63dbde4
--- /dev/null
@@ -0,0 +1,60 @@
+/*******************************************************************************\r
+ * Copyright (c) 2013 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.preferences;\r
+\r
+import org.eclipse.jface.preference.FieldEditorPreferencePage;\r
+import org.eclipse.jface.preference.RadioGroupFieldEditor;\r
+import org.eclipse.ui.IWorkbench;\r
+import org.eclipse.ui.IWorkbenchPreferencePage;\r
+import org.simantics.modelica.ModelicaManager;\r
+import org.simantics.sysdyn.ui.Activator;\r
+\r
+public class ModelicaPreferencePage extends FieldEditorPreferencePage implements\r
+IWorkbenchPreferencePage {\r
+\r
+    public static String OM_VERSION = "OpenModelica Version";\r
+    public static String OM_BUILTIN = "Built-in";\r
+    public static String OM_INSTALLED = "Installed";\r
+    \r
+    public ModelicaPreferencePage() {\r
+        super(GRID);\r
+\r
+    }\r
+\r
+    public void createFieldEditors() {\r
+        String installed = ModelicaManager.getInstalledOpenModelicaVersion();\r
+        String builtIn = ModelicaManager.getBuiltInOpenModelicaVersion();\r
+\r
+        String[][] options;\r
+        if(installed != null) {\r
+            options = new String[][] \r
+                    {{"OpenModelica " + installed + " (local installation)", OM_INSTALLED },\r
+                        {"OpenModelica " + builtIn + " (built-in)", OM_BUILTIN}};\r
+        } else {\r
+            options = new String[][] \r
+                    {{"OpenModelica " + builtIn + " (built-in)", OM_BUILTIN}}; \r
+        }\r
+        \r
+        RadioGroupFieldEditor rg = new RadioGroupFieldEditor(OM_VERSION,\r
+                "Choose the used OpenModelica version", 1,\r
+                options, getFieldEditorParent());\r
+        \r
+        addField(rg);\r
+    }\r
+\r
+    @Override\r
+    public void init(IWorkbench workbench) {\r
+        setPreferenceStore(Activator.getDefault().getPreferenceStore());\r
+//        setDescription("");\r
+    }\r
+\r
+}\r