diff --git a/plugins/testPluginGraphicalComponent/CustomizerGraphicalComponent.java b/plugins/testPluginGraphicalComponent/CustomizerGraphicalComponent.java index f1c840177ec399f58ade34dd3e2cbefea878008f..f21856fead30e67e9b7c31846595c31769f2a9d4 100644 --- a/plugins/testPluginGraphicalComponent/CustomizerGraphicalComponent.java +++ b/plugins/testPluginGraphicalComponent/CustomizerGraphicalComponent.java @@ -53,6 +53,11 @@ public class CustomizerGraphicalComponent { public CustomizerGraphicalComponent() { } + + public static String hasGraphicalComponent() { + return "CustomizerGraphicalComponent"; + } + public static String getPanelClassName() { return "TMLArchiDiagramPanel"; } diff --git a/src/main/java/myutil/Plugin.java b/src/main/java/myutil/Plugin.java index 48faf49c06ee958575a77413dbd6c502d04553e7..283a90bbc4971c793ecac6785061eb54c06e0d7a 100755 --- a/src/main/java/myutil/Plugin.java +++ b/src/main/java/myutil/Plugin.java @@ -61,6 +61,9 @@ public class Plugin { private File file; private HashMap<String, Class> listOfClasses; private Class classAvatarCodeGenerator; + private Class classDiplodocusCodeGenerator; + private Class classGraphicalComponent; + public Plugin(String _path, String _name) { path = _path; @@ -77,7 +80,6 @@ public class Plugin { } public boolean hasAvatarCodeGenerator() { - String ret = executeRetStringMethod(removeJar(name), "hasAvatarCodeGenerator"); if (ret != null) { classAvatarCodeGenerator = getClass(ret); @@ -86,10 +88,66 @@ public class Plugin { return false; } + + public boolean hasDiplodocusCodeGenerator() { + String ret = executeRetStringMethod(removeJar(name), "hasDiplodocusCodeGenerator"); + if (ret != null) { + classDiplodocusCodeGenerator = getClass(ret); + return true; + } + + return false; + } + + public String getDiplodocusCodeGeneratorIdentifier() { + String desc = executeRetStringMethod(classDiplodocusCodeGenerator, "getIdentifier"); + return desc; + } + + + public boolean hasGraphicalComponent() { + String ret = executeRetStringMethod(removeJar(name), "hasGraphicalComponent"); + if (ret != null) { + classGraphicalComponent = getClass(ret); + String diagOk = executeRetStringMethod(classGraphicalComponent, "getPanelClassName"); + if (diagOk != null) { + return true; + } + } + classGraphicalComponent = null; + return false; + } + + public boolean hasGraphicalComponent(String _diagID) { + TraceManager.addDev("Test GC with diag=" + _diagID); + String ret = executeRetStringMethod(removeJar(name), "hasGraphicalComponent"); + if (ret != null) { + classGraphicalComponent = getClass(ret); + String diagOk = executeRetStringMethod(classGraphicalComponent, "getPanelClassName"); + if (diagOk != null) { + if (diagOk.compareTo(_diagID) == 0) { + TraceManager.addDev("Found graphical component in plugin:" + name); + return true; + } + } + } + classGraphicalComponent = null; + + return false; + } public Class getClassAvatarCodeGenerator() { return classAvatarCodeGenerator; } + + public Class getClassGraphicalComponent() { + return classGraphicalComponent; + } + + public Class getClassDiplodocusCodeGenerator() { + return classDiplodocusCodeGenerator; + } + public Class getClass(String _className) { Class<?> c = listOfClasses.get(_className); @@ -190,17 +248,26 @@ public class Plugin { Method method = instance.getClass().getMethod(_methodName, cArg); return (boolean)(method.invoke(instance)); } + + public static boolean executeBoolStringMethod(Object instance, String value, String _methodName) throws Exception { + Class[] cArg = new Class[1]; + cArg[0] = String.class; + TraceManager.addDev("Looking for method=" + _methodName + " in instance " + instance); + Method method = instance.getClass().getMethod(_methodName, cArg); + return (boolean)(method.invoke(instance, value)); + } + - public ImageIcon executeRetImageIconMethod(String _className, String _methodName) { + public ImageIcon executeRetImageIconMethod(Class<?> c, String _methodName) { // We have a valid plugin. We now need to get the Method - Method m = getMethod(_className, _methodName); + try { + Method m = c.getMethod(_methodName); if (m == null) { return null; } - try { - return (ImageIcon)(m.invoke(null)); + return (ImageIcon)(m.invoke(null)); } catch (Exception e) { TraceManager.addDev("Exception occured when executing method " + _methodName); return null; diff --git a/src/main/java/myutil/PluginManager.java b/src/main/java/myutil/PluginManager.java index 60a740a9d4601f558b991a932da00f557b1e7087..e126ea5efd7fde5616713b591014789aec17a835 100755 --- a/src/main/java/myutil/PluginManager.java +++ b/src/main/java/myutil/PluginManager.java @@ -43,6 +43,7 @@ package myutil; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.LinkedList; import java.awt.*; @@ -80,6 +81,28 @@ public class PluginManager { return null; } + public LinkedList<Plugin> getPluginDiplodocusCodeGenerator() { + LinkedList<Plugin> lplugins = new LinkedList<Plugin>(); + for(Plugin plugin: plugins) { + if (plugin.hasDiplodocusCodeGenerator()) { + lplugins.add(plugin); + TraceManager.addDev(" Found diplodocus code generator plugin"); + } + } + return lplugins; + } + + public LinkedList<Plugin> getPluginGraphicalComponent(String diag) { + LinkedList<Plugin> lplugins = new LinkedList<Plugin>(); + for(Plugin plugin: plugins) { + if (plugin.hasGraphicalComponent(diag)) { + lplugins.add(plugin); + TraceManager.addDev(" Found graphical plugin"); + } + } + return lplugins; + } + public void addPlugin(Plugin _plugin) { plugins.add(_plugin); } diff --git a/src/main/java/ui/MainGUI.java b/src/main/java/ui/MainGUI.java index fc2201540100ffafd8eb41954cb10a031ab3a71d..3863688bb873cf90b9f12d8f91647db32b8cd7c4 100644 --- a/src/main/java/ui/MainGUI.java +++ b/src/main/java/ui/MainGUI.java @@ -4233,11 +4233,9 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe // path = file.getAbsolutePath(); // } JDialogCCodeGeneration jgen = new JDialogCCodeGeneration( frame, this, "Application code generation and compilation", - ConfigurationTTool.SystemCHost, ConfigurationTTool.CCodeDirectory, + ConfigurationTTool.CCodeDirectory, "make -C " + ConfigurationTTool.CCodeDirectory, - ConfigurationTTool.SystemCCodeExecuteCommand, - ConfigurationTTool.SystemCCodeInteractiveExecuteCommand, - ConfigurationTTool.GGraphPath, gtm ); + gtm ); // jgen.setSize(500, 750); GraphicLib.centerOnParent(jgen, 500, 750); jgen.setVisible(true); diff --git a/src/main/java/ui/TGComponentPlugin.java b/src/main/java/ui/TGComponentPlugin.java index 90df7a03ae0df9465f497cb95b3493cb8ecae24a..8535edf7d88e82b8ab07049f8ecd941b2542fde1 100755 --- a/src/main/java/ui/TGComponentPlugin.java +++ b/src/main/java/ui/TGComponentPlugin.java @@ -112,10 +112,11 @@ public class TGComponentPlugin extends TGComponent implements ComponentPluginInt } if (instance == null) { //TraceManager.addDev("[create instance] Name of the plugin:" + componentPlugin.getName()); - String className = componentPlugin.executeRetStringMethod("CustomizerGraphicalComponent", "getGraphicalComponentClassName"); - classRef = componentPlugin.getClass(className); + //String className = componentPlugin.executeRetStringMethod(componentPlugin.getClassGraphicalComponent(), "getGraphicalComponentClassName"); + //classRef = componentPlugin.getClass(className); //TraceManager.addDev("[create instance] classRef:" + classRef); - instance = classRef.newInstance(); + classRef = componentPlugin.getClassGraphicalComponent(); + instance = componentPlugin.getClassGraphicalComponent().newInstance(); if (width == 0) { width = Plugin.executeIntMethod(instance, "getWidth"); } @@ -228,9 +229,11 @@ public class TGComponentPlugin extends TGComponent implements ComponentPluginInt elt = (Element) n2; if (elt.getTagName().equals("PluginName")) { pName = elt.getAttribute("value"); - componentPlugin = PluginManager.pluginManager.getPluginOrCreate(pName); + componentPlugin = PluginManager.pluginManager.getPlugin(pName); if (componentPlugin != null) { - createInstance(); + if (componentPlugin.hasGraphicalComponent()) { + createInstance(); + } } else { TraceManager.addDev("No corresponding plugin"); } diff --git a/src/main/java/ui/TToolBar.java b/src/main/java/ui/TToolBar.java index add31cb3dcd21d8d3ca73324c02e6363a438768b..6ded5e3eca015b16c498a940e0c916716f246da1 100755 --- a/src/main/java/ui/TToolBar.java +++ b/src/main/java/ui/TToolBar.java @@ -84,35 +84,30 @@ public abstract class TToolBar extends JToolBar implements ActionListener { pluginActions = new ArrayList<TGUIAction>(); plugins = new ArrayList<Plugin>(); this.addSeparator(); - for(int i=0; i<ConfigurationTTool.PLUGIN_GRAPHICAL_COMPONENT.length; i++) { - Plugin p = PluginManager.pluginManager.getPluginOrCreate(ConfigurationTTool.PLUGIN_GRAPHICAL_COMPONENT[i]); - if (p != null) { - String panelName = p.executeRetStringMethod("CustomizerGraphicalComponent", "getPanelClassName"); - if (panelName != null) { - if (panelName.compareTo(diag) == 0){ - String shortText = p.executeRetStringMethod("CustomizerGraphicalComponent", "getShortText"); - String longText = p.executeRetStringMethod("CustomizerGraphicalComponent", "getLongText"); - String veryShortText = p.executeRetStringMethod("CustomizerGraphicalComponent", "getVeryShortText"); - ImageIcon img = p.executeRetImageIconMethod("CustomizerGraphicalComponent", "getImageIcon"); - if ((img != null) && (shortText != null)) { - TraceManager.addDev("Plugin: " + p.getName() + " short name:" + shortText); - TAction t = new TAction("command-" + p.getName(), shortText, img, img, veryShortText, longText, 0); - TGUIAction tguia = new TGUIAction(t); - pluginActions.add(tguia); - plugins.add(p); - JButton button = add(tguia); - button.addMouseListener(mgui.mouseHandler); - tguia.addActionListener(this); - //button.addActionListener(this); - - /*JButton toto = new JButton("Test"); - toto.addActionListener(this); - add(toto);*/ - //TraceManager.addDev("Action listener..."); - } - } - } - } + LinkedList<Plugin> list = PluginManager.pluginManager.getPluginGraphicalComponent(diag); + TraceManager.addDev("List of " + list.size() + " graphical components"); + for(Plugin p: list) { + //Plugin p = PluginManager.pluginManager.getPluginOrCreate(ConfigurationTTool.PLUGIN_GRAPHICAL_COMPONENT[i]); + String shortText = p.executeRetStringMethod(p.getClassGraphicalComponent(), "getShortText"); + String longText = p.executeRetStringMethod(p.getClassGraphicalComponent(), "getLongText"); + String veryShortText = p.executeRetStringMethod(p.getClassGraphicalComponent(), "getVeryShortText"); + ImageIcon img = p.executeRetImageIconMethod(p.getClassGraphicalComponent(), "getImageIcon"); + if ((img != null) && (shortText != null)) { + TraceManager.addDev("Plugin: " + p.getName() + " short name:" + shortText); + TAction t = new TAction("command-" + p.getName(), shortText, img, img, veryShortText, longText, 0); + TGUIAction tguia = new TGUIAction(t); + pluginActions.add(tguia); + plugins.add(p); + JButton button = add(tguia); + button.addMouseListener(mgui.mouseHandler); + tguia.addActionListener(this); + //button.addActionListener(this); + + /*JButton toto = new JButton("Test"); + toto.addActionListener(this); + add(toto);*/ + //TraceManager.addDev("Action listener..."); + } } } diff --git a/src/main/java/ui/tmldd/TMLArchiDiagramToolBar.java b/src/main/java/ui/tmldd/TMLArchiDiagramToolBar.java index 570ec87d414d366a3c372be6ad3a6f330bd50e33..37e24b2c2d239c9b7427989e6328896e4ba51280 100755 --- a/src/main/java/ui/tmldd/TMLArchiDiagramToolBar.java +++ b/src/main/java/ui/tmldd/TMLArchiDiagramToolBar.java @@ -140,12 +140,14 @@ public class TMLArchiDiagramToolBar extends TToolBar implements ActionListener button.addMouseListener(mgui.mouseHandler); button = this.add(mgui.actions[TGUIAction.TMLARCHI_MEMORYNODE]); button.addMouseListener(mgui.mouseHandler); + this.addSeparator(); if (MainGUI.experimentalOn) { button = this.add(mgui.actions[TGUIAction.TMLARCHI_CPNODE]); button.addMouseListener(mgui.mouseHandler); button = this.add(mgui.actions[TGUIAction.TMLARCHI_EVENT_ARTIFACT]); button.addMouseListener(mgui.mouseHandler); + this.addSeparator(); } button = this.add(mgui.actions[TGUIAction.TMLARCHI_COMMUNICATION_ARTIFACT]); button.addMouseListener(mgui.mouseHandler); @@ -155,7 +157,6 @@ public class TMLArchiDiagramToolBar extends TToolBar implements ActionListener button.addMouseListener(mgui.mouseHandler); this.addSeparator(); - button = this.add(mgui.actions[TGUIAction.ACT_TOGGLE_ATTR]); button = this.add(mgui.actions[TGUIAction.TMLARCHI_COMMUNICATION_ARTIFACT]); button.addMouseListener(mgui.mouseHandler); button = this.add(mgui.actions[TGUIAction.TMLARCHI_PORT_ARTIFACT]); @@ -169,9 +170,6 @@ public class TMLArchiDiagramToolBar extends TToolBar implements ActionListener button = this.add(mgui.actions[TGUIAction.ACT_TOGGLE_ATTR]); button.addMouseListener(mgui.mouseHandler); - button = this.add(mgui.actions[TGUIAction.ACT_TOGGLE_DIPLO_ID]); - button.addMouseListener(mgui.mouseHandler); - this.addSeparator(); button = this.add(mgui.actions[TGUIAction.ACT_TOGGLE_DIPLO_ID]); diff --git a/src/main/java/ui/window/JDialogCCodeGeneration.java b/src/main/java/ui/window/JDialogCCodeGeneration.java index 0d84b20abbbe2657354c24c32164062a8055db48..26d4ec10e44a8b944c5c2b2b190b00ab8c8b2b9a 100755 --- a/src/main/java/ui/window/JDialogCCodeGeneration.java +++ b/src/main/java/ui/window/JDialogCCodeGeneration.java @@ -1,27 +1,27 @@ /* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille, Andrea Enrici - * + * * ludovic.apvrille AT telecom-paristech.fr * andrea.enrici AT telecom-paristech.f - * + * * This software is a computer program whose purpose is to allow the * edition of TURTLE analysis, design and deployment diagrams, to * allow the generation of RT-LOTOS or Java code from this diagram, * and at last to allow the analysis of formal validation traces * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP * from INRIA Rhone-Alpes. - * + * * This software is governed by the CeCILL license under French law and * abiding by the rules of distribution of free software. You can use, * modify and/ or redistribute the software under the terms of the CeCILL * license as circulated by CEA, CNRS and INRIA at the following URL * "http://www.cecill.info". - * + * * As a counterpart to the access to the source code and rights to copy, * modify and redistribute granted by the license, users are provided only * with a limited warranty and the software's author, the holder of the * economic rights, and the successive licensors have only limited * liability. - * + * * In this respect, the user's attention is drawn to the risks associated * with loading, using, modifying and/or developing or reproducing the * software by the user in light of its specific status of free software, @@ -32,7 +32,7 @@ * requirements in conditions enabling the security of their systems and/or * data to be ensured and, more generally, to use and operate it in the * same conditions as regards security. - * + * * The fact that you are presently reading this means that you have had * knowledge of the CeCILL license and that you accept its terms. */ @@ -44,13 +44,10 @@ package ui.window; import launcher.LauncherException; import launcher.RshClient; -import myutil.FileUtils; -import myutil.GraphicLib; -import myutil.MasterProcessInterface; -import myutil.ScrolledJTextArea; -import ui.GTURTLEModeling; +import myutil.*; import ui.util.IconManager; -import ui.MainGUI; +import ui.*; +import tmltranslator.*; import javax.swing.*; import javax.swing.event.ListSelectionEvent; @@ -62,6 +59,7 @@ import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; +import java.util.*; /** @@ -71,27 +69,30 @@ import java.io.InputStreamReader; * @version 1.2 27/04/2015 * @author Andrea ENRICI, Ludovic APVRILLE */ -public class JDialogCCodeGeneration extends javax.swing.JDialog implements ActionListener, Runnable, MasterProcessInterface, ListSelectionListener { +public class JDialogCCodeGeneration extends javax.swing.JDialog implements ActionListener, Runnable { protected MainGUI mgui; private static String textSysC1 = "Generate C code in"; private static String textSysC2 = "Compile C code in"; - private static String textSysC4 = "Run simulation to completion:"; - private static String textSysC5 = "Run interactive simulation:"; - private static String textSysC6 = "Run formal verification:"; + //private static String textSysC4 = "Run simulation to completion:"; + //private static String textSysC5 = "Run interactive simulation:"; + //private static String textSysC6 = "Run formal verification:"; - private static String unitCycle = "1"; + //private static String unitCycle = "1"; - private static String[] simus = { "SystemC Simulator - LabSoC version", - "C++ Simulator - LabSoc version" }; + //private static String[] simus = { "SystemC Simulator - LabSoC version", + //"C++ Simulator - LabSoc version" }; + + private static String DEFAULT_GENERATOR = "TTool integrated C generator"; + private static int selectedItem = 1; protected static String pathCode; protected static String pathCompiler; - protected static String pathExecute; - protected static String pathInteractiveExecute; - protected static String pathFormalExecute; + //protected static String pathExecute; + //protected static String pathInteractiveExecute; + // protected static String pathFormalExecute; protected static boolean interactiveSimulationSelected = true; //protected static boolean optimizeModeSelected = true; @@ -108,15 +109,17 @@ public class JDialogCCodeGeneration extends javax.swing.JDialog implements Actio protected JButton stop; protected JButton close; - protected JRadioButton exe, exeint, exeformal; - protected ButtonGroup exegroup; - protected JLabel gen, comp; - protected JTextField code1, code2, compiler1, exe1, exe2, exe3, exe2int, exe2formal; + protected JLabel gen, comp; + protected JTextField code1, code2, compiler1; + //exe1, exe2, exe3, exe2int, exe2formal; protected JTabbedPane jp1; protected JScrollPane jsp; protected JCheckBox removeCppFiles, removeXFiles;//, debugmode, optimizemode; protected JComboBox versionSimulator; + protected Vector<String> generators; + protected JComboBox<String> generatorsBox; + private Thread t; private boolean go = false; private boolean hasError = false; @@ -129,16 +132,16 @@ public class JDialogCCodeGeneration extends javax.swing.JDialog implements Actio private int automatic; private boolean wasClosed = false; - private GTURTLEModeling gtm; + private GTURTLEModeling gtm; /** Creates new form */ - public JDialogCCodeGeneration(Frame f, MainGUI _mgui, String title, String _hostSystemC, String _pathCode, String _pathCompiler, String _pathExecute, String _pathInteractiveExecute, String _graphPath, GTURTLEModeling _gtm ) { + public JDialogCCodeGeneration(Frame f, MainGUI _mgui, String title, String _pathCode, String _pathCompiler, GTURTLEModeling _gtm ) { super(f, title, true); mgui = _mgui; - gtm = _gtm; + gtm = _gtm; if (pathCode == null) { pathCode = _pathCode; @@ -147,26 +150,6 @@ public class JDialogCCodeGeneration extends javax.swing.JDialog implements Actio if (pathCompiler == null) pathCompiler = _pathCompiler; - if (pathExecute == null) - pathExecute = _pathExecute; - - if (pathInteractiveExecute == null) { - if (_graphPath != null) { - _pathInteractiveExecute += " -gpath " + _graphPath; - } - pathInteractiveExecute = _pathInteractiveExecute; - } - - if (pathFormalExecute == null) { - pathFormalExecute = pathInteractiveExecute; - - int index = pathFormalExecute.indexOf("-server"); - if (index != -1) { - pathFormalExecute = pathFormalExecute.substring(0, index) + pathFormalExecute.substring(index+7, pathFormalExecute.length()); - pathFormalExecute += " -explo"; - } - } - hostSystemC = _hostSystemC; initComponents(); myInitComponents(); pack(); @@ -180,8 +163,6 @@ public class JDialogCCodeGeneration extends javax.swing.JDialog implements Actio protected void myInitComponents() { mode = NOT_STARTED; setButtons(); - setList(); - updateInteractiveSimulation(); } protected void initComponents() { @@ -190,7 +171,7 @@ public class JDialogCCodeGeneration extends javax.swing.JDialog implements Actio setFont(new Font("Helvetica", Font.PLAIN, 14)); c.setLayout(new BorderLayout()); - // Issue #41 Ordering of tabbed panes + // Issue #41 Ordering of tabbed panes jp1 = GraphicLib.createTabbedPane();//new JTabbedPane(); JPanel jp01 = new JPanel(); @@ -229,9 +210,24 @@ public class JDialogCCodeGeneration extends javax.swing.JDialog implements Actio code1.setEnabled(false); jp01.add(code1, c01); + jp01.add(new JLabel(" "), c01); c01.gridwidth = GridBagConstraints.REMAINDER; //end row + generators = new Vector<String>(); + generators.add(DEFAULT_GENERATOR); + fillGeneratorsWithPlugins(generators); + + generatorsBox = new JComboBox<>(generators); + if (generators.size() > 1) { + generatorsBox.setSelectedIndex(1); + } + jp01.add(generatorsBox, c01); + c01.gridwidth = GridBagConstraints.REMAINDER; //end row + + jp01.add(new JLabel(" "), c01); + c01.gridwidth = GridBagConstraints.REMAINDER; //end row + removeCppFiles = new JCheckBox("Remove old .h, .c, .o files"); removeCppFiles.setSelected(true); jp01.add(removeCppFiles, c01); @@ -241,12 +237,12 @@ public class JDialogCCodeGeneration extends javax.swing.JDialog implements Actio jp01.add(removeXFiles, c01); /*debugmode = new JCheckBox("Put debug information in code"); - debugmode.setSelected(false); - jp01.add(debugmode, c01);*/ + debugmode.setSelected(false); + jp01.add(debugmode, c01);*/ /*optimizemode = new JCheckBox("Optimize code"); - optimizemode.setSelected(optimizeModeSelected); - jp01.add(optimizemode, c01);*/ + optimizemode.setSelected(optimizeModeSelected); + jp01.add(optimizemode, c01);*/ jp01.add(new JLabel(" "), c01); @@ -277,50 +273,7 @@ public class JDialogCCodeGeneration extends javax.swing.JDialog implements Actio jp1.add("Compile", jp02); - // Panel 03 - c03.gridheight = 1; - c03.weighty = 1.0; - c03.weightx = 1.0; - c03.gridwidth = GridBagConstraints.REMAINDER; //end row - c03.fill = GridBagConstraints.BOTH; - c03.gridheight = 1; - exegroup = new ButtonGroup(); - - jp03.add(new JLabel(" "), c03); - c02.gridwidth = GridBagConstraints.REMAINDER; //end row - - exe = new JRadioButton(textSysC4, false); - exe.addActionListener(this); - exegroup.add(exe); - jp03.add(exe, c03); - - exe2 = new JTextField(pathExecute, 100); - jp03.add(exe2, c02); - - jp03.add(new JLabel(" "), c02); - c02.gridwidth = GridBagConstraints.REMAINDER; //end row - - exeint = new JRadioButton(textSysC5, true); - exeint.addActionListener(this); - exegroup.add(exeint); - jp03.add(exeint, c03); - exe2int = new JTextField(pathInteractiveExecute, 100); - jp03.add(exe2int, c02); - - jp03.add(new JLabel(" "), c03); - c02.gridwidth = GridBagConstraints.REMAINDER; //end row - - exeformal = new JRadioButton(textSysC6, true); - exeformal.addActionListener(this); - exegroup.add(exeformal); - jp03.add(exeformal, c03); - exe2formal = new JTextField(pathFormalExecute, 100); - jp03.add(exe2formal, c02); - - jp03.add(new JLabel(" "), c03); - - //jp1.add("Execute", jp03); c.add(jp1, BorderLayout.NORTH); if (automatic > 0) { @@ -332,7 +285,7 @@ public class JDialogCCodeGeneration extends javax.swing.JDialog implements Actio jta.setMargin(new Insets(10, 10, 10, 10)); jta.setTabSize(3); if (automatic == 0) { - jta.append("Select options and then, click on 'start' to launch C code compilation\n\n"); + jta.append("Select options and then,\n click on 'start' to launch C code generation and compilation\n\n"); } Font f = new Font("Courrier", Font.BOLD, 12); jta.setFont(f); @@ -369,18 +322,11 @@ public class JDialogCCodeGeneration extends javax.swing.JDialog implements Actio } - public void updateInteractiveSimulation() { - if (automatic == 0) { - exe2.setEnabled(exe.isSelected()); - exe2int.setEnabled(exeint.isSelected()); - exe2formal.setEnabled(exeformal.isSelected()); - } - } public void actionPerformed(ActionEvent evt) { String command = evt.getActionCommand(); // Compare the action command to the known actions. - updateInteractiveSimulation(); + if (command.equals("Start")) { startProcess(); } else if (command.equals("Stop")) { @@ -445,32 +391,32 @@ public class JDialogCCodeGeneration extends javax.swing.JDialog implements Actio hasError = false; try { - if (automatic > 0) { - hasError = generateCode(); - testGo(); - compileCode(); - testGo(); - } - else { - if( jp1.getSelectedIndex() == 0 ) { //Code generation - hasError = generateCode(); - } - testGo(); - // Compilation - if( jp1.getSelectedIndex() == 1 ) { - compileCode(); - } - if( ( hasError == false ) && ( jp1.getSelectedIndex() < 1 ) ) { - jp1.setSelectedIndex( jp1.getSelectedIndex() + 1 ); + if (automatic > 0) { + hasError = generateCode(); + testGo(); + compileCode(); + testGo(); + } + else { + if( jp1.getSelectedIndex() == 0 ) { //Code generation + hasError = generateCode(); + } + testGo(); + // Compilation + if( jp1.getSelectedIndex() == 1 ) { + compileCode(); + } + if( ( hasError == false ) && ( jp1.getSelectedIndex() < 1 ) ) { + jp1.setSelectedIndex( jp1.getSelectedIndex() + 1 ); + } } - } - } - catch( InterruptedException ie ) { - jta.append("Process interrupted!\n"); - } - jta.append("\n\nReady to process next command...\n"); - - checkMode(); + } + catch( InterruptedException ie ) { + jta.append("Process interrupted!\n"); + } + jta.append("\n\nReady to process next command...\n"); + + checkMode(); setButtons(); } @@ -478,67 +424,110 @@ public class JDialogCCodeGeneration extends javax.swing.JDialog implements Actio String list; int cycle = 0; - boolean error = false; + boolean error = false; jta.append( "Generating C code...\n\n" ); - if( removeCppFiles.isSelected() ) { - jta.append( "Removing all .h files...\n" ); - list = FileUtils.deleteFiles( code1.getText(), ".h" ); - if( list.length() == 0 ) { - jta.append("No files were deleted\n"); - } - else { - jta.append("Files deleted:\n" + list + "\n"); - } - jta.append("\nRemoving all .c files...\n"); - list = FileUtils.deleteFiles( code1.getText(), ".c" ); - if( list.length() == 0 ) { - jta.append( "No files were deleted\n" ); - } - else { - jta.append("Files deleted:\n" + list + "\n"); - } - jta.append("\nRemoving all .o files...\n"); - list = FileUtils.deleteFiles( code1.getText(), ".o" ); - if( list.length() == 0 ) { - jta.append( "No files were deleted\n" ); - } - else { - jta.append( "Files deleted:\n" + list + "\n" ); - } + if( removeCppFiles.isSelected() ) { + jta.append( "Removing all .h files...\n" ); + list = FileUtils.deleteFiles( code1.getText(), ".h" ); + if( list.length() == 0 ) { + jta.append("No files were deleted\n"); + } + else { + jta.append("Files deleted:\n" + list + "\n"); + } + jta.append("\nRemoving all .c files...\n"); + list = FileUtils.deleteFiles( code1.getText(), ".c" ); + if( list.length() == 0 ) { + jta.append( "No files were deleted\n" ); + } + else { + jta.append("Files deleted:\n" + list + "\n"); + } + jta.append("\nRemoving all .o files...\n"); + list = FileUtils.deleteFiles( code1.getText(), ".o" ); + if( list.length() == 0 ) { + jta.append( "No files were deleted\n" ); + } + else { + jta.append( "Files deleted:\n" + list + "\n" ); + } } if (removeXFiles.isSelected()) { - jta.append( "\nRemoving all .x files...\n" ); - list = FileUtils.deleteFiles( code1.getText(), ".x" ); - if( list.length() == 0 ) { - jta.append("No files were deleted\n"); - } - else { - jta.append("Files deleted:\n" + list + "\n"); - } + jta.append( "\nRemoving all .x files...\n" ); + list = FileUtils.deleteFiles( code1.getText(), ".x" ); + if( list.length() == 0 ) { + jta.append("No files were deleted\n"); + } + else { + jta.append("Files deleted:\n" + list + "\n"); + } } testGo(); - error = gtm.generateCCode( code1.getText() ); - if( !error ) { - File dir = new File( code1.getText() ); - StringBuffer s = new StringBuffer(); - jta.append( "\nSource files successfully generated:\n" ); - for( File f: dir.listFiles() ) { - try { - if( f.getCanonicalPath().contains(".c") || f.getCanonicalPath().contains(".h") ) { - s.append( f.getCanonicalPath() + "\n" ); - } - } - catch( IOException ioe ) { - jta.append("Error: " + ioe.getMessage() + "\n"); - mode = STOPPED; - setButtons(); - return true; - } - } - jta.append( s.toString() ); - } - return error; + if (generatorsBox.getSelectedIndex() == 0) { + error = gtm.generateCCode( code1.getText() ); + if( !error ) { + File dir = new File( code1.getText() ); + StringBuffer s = new StringBuffer(); + jta.append( "\nSource files successfully generated:\n" ); + for( File f: dir.listFiles() ) { + try { + if( f.getCanonicalPath().contains(".c") || f.getCanonicalPath().contains(".h") ) { + s.append( f.getCanonicalPath() + "\n" ); + } + } + catch( IOException ioe ) { + jta.append("Error: " + ioe.getMessage() + "\n"); + mode = STOPPED; + setButtons(); + return true; + } + } + jta.append( s.toString() ); + } + } else { + // code generation by plugin! + int index = generatorsBox.getSelectedIndex() - 1; + int cpt = 0; + Plugin foundPlugin = null; + LinkedList<Plugin> listP = PluginManager.pluginManager.getPluginDiplodocusCodeGenerator(); + for(Plugin p: listP) { + String desc = p.getDiplodocusCodeGeneratorIdentifier(); + if (desc != null) { + if (index == cpt) { + foundPlugin = p; + break; + } + } + } + + if (foundPlugin == null) { + jta.append("Invalid plugin\n"); + + } else { + // We have a valid plugin + // We first need to get an XML representation of the current mapping + TMLMapping tmap = gtm.getTMLMapping(); + + if (tmap == null) { + jta.append("Invalid mapping\n"); + } else { + String XML = tmap.toXML(); + try { + Object instance = foundPlugin.getClassDiplodocusCodeGenerator().newInstance(); + if (instance == null) { + jta.append("Invalid plugin: could not create an instance\n"); + } else { + boolean ret = foundPlugin.executeBoolStringMethod(instance, XML, "generateCode"); + } + } catch (Exception e) { + jta.append("Exception when calling plugin:" + e.getMessage()); + } + } + } + + } + return error; } //End of method generateCode() public void compileCode() throws InterruptedException { @@ -559,20 +548,20 @@ public class JDialogCCodeGeneration extends javax.swing.JDialog implements Actio } } - protected void processCmd( String cmd, JTextArea _jta ) throws Exception { + protected void processCmd( String cmd, JTextArea _jta ) throws Exception { - String s; - Process p; - p = Runtime.getRuntime().exec( cmd ); - BufferedReader br = new BufferedReader( new InputStreamReader( p.getInputStream() ) ); - while( ( s = br.readLine() ) != null ) { - _jta.append( s + "\n" ); - } - p.waitFor(); - p.destroy(); - if( p.exitValue() != 0 ) { - throw new Exception( "Make exit status: " + p.exitValue() ); - } + String s; + Process p; + p = Runtime.getRuntime().exec( cmd ); + BufferedReader br = new BufferedReader( new InputStreamReader( p.getInputStream() ) ); + while( ( s = br.readLine() ) != null ) { + _jta.append( s + "\n" ); + } + p.waitFor(); + p.destroy(); + if( p.exitValue() != 0 ) { + throw new Exception( "Make exit status: " + p.exitValue() ); + } } protected void checkMode() { @@ -607,28 +596,22 @@ public class JDialogCCodeGeneration extends javax.swing.JDialog implements Actio } } - public boolean hasToContinue() { - return (go == true); + public void fillGeneratorsWithPlugins(Vector<String> v) { + LinkedList<Plugin> list = PluginManager.pluginManager.getPluginDiplodocusCodeGenerator(); + for(Plugin p: list) { + String desc = p.getDiplodocusCodeGeneratorIdentifier(); + if (desc != null) { + v.add(desc); + } + } } - public void appendOut(String s) { - jta.append(s); - } + + + - public void setError() { - hasError = true; - } - - public String getPathInteractiveExecute() { - return pathInteractiveExecute; - } + - // List selection listener - public void valueChanged(ListSelectionEvent e) { - setList(); - } - - private void setList() { - } + -} //End of class +} //End of class