From e4fb613557c4e01141cf2be3ad410b94a5790a5d Mon Sep 17 00:00:00 2001
From: apvrille <ludovic.apvrille@eurecom.fr>
Date: Wed, 28 Jun 2017 17:12:41 +0200
Subject: [PATCH] Adding plugin for graphical component: example

---
 .../CustomizerGraphicalComponent.java         |  53 ++++-
 src/main/java/myutil/Plugin.java              |  41 ++++
 .../java/ui/ComponentPluginInterface.java     |  59 ++++++
 src/main/java/ui/GTURTLEModeling.java         |   8 +-
 src/main/java/ui/MainGUI.java                 |  17 ++
 src/main/java/ui/TAction.java                 |  88 ++++-----
 src/main/java/ui/TDiagramPanel.java           |   8 +-
 src/main/java/ui/TGComponentManager.java      |  19 +-
 src/main/java/ui/TGComponentPlugin.java       | 182 +++++++++++++++++-
 src/main/java/ui/TGUIAction.java              |   5 +-
 src/main/java/ui/TToolBar.java                |  22 ++-
 src/main/java/ui/avatarbd/AvatarBDBlock.java  |   1 +
 12 files changed, 433 insertions(+), 70 deletions(-)
 create mode 100755 src/main/java/ui/ComponentPluginInterface.java

diff --git a/plugins/testPluginGraphicalComponent/CustomizerGraphicalComponent.java b/plugins/testPluginGraphicalComponent/CustomizerGraphicalComponent.java
index 5a3648ffeb..f1c840177e 100644
--- a/plugins/testPluginGraphicalComponent/CustomizerGraphicalComponent.java
+++ b/plugins/testPluginGraphicalComponent/CustomizerGraphicalComponent.java
@@ -48,6 +48,7 @@ import java.net.URL;
 import javax.swing.*;
      
 public class CustomizerGraphicalComponent {
+    public static ImageIcon myIcon;
     
     public CustomizerGraphicalComponent() {
     }
@@ -60,7 +61,8 @@ public class CustomizerGraphicalComponent {
 	URL url = CustomizerGraphicalComponent.class.getResource("myicon.gif");
 
         if (url != null)  {
-            return new ImageIcon(url);
+	    myIcon = new ImageIcon(url);
+            return myIcon;
         } 
 	
         return null;
@@ -78,6 +80,55 @@ public class CustomizerGraphicalComponent {
     public static String getVeryShortText() {
 	return "Plugin component";
     }
+
+    public static String getGraphicalComponentClassName() {
+	return "CustomizerGraphicalComponent";
+    }
+
+    public static int getWidth() {
+	return 100;
+    }
+    
+    public static int getHeight() {
+	return 50;
+    }
+
+
+    public boolean isMoveable() {
+	return true;
+    }
+
+    public boolean isRemovable() {
+	return true;
+    }
+
+    public boolean isUserResizable() {
+	return true;
+    }
+
+    public boolean isEditable() {
+	return true;
+    }
+    
+    public void internalDrawing(Graphics g, int _x, int _y, int _width, int _height, String _value) {
+	g.drawRect(_x, _y, _width, _height);
+	g.drawString(_value, _x+5, _y+20);
+    }
+
+    public boolean isOnMe(int _x, int _y, int _width, int _height, int _xP, int _yP) {
+	if ((_xP>_x) && (_xP<_x+_width) && (_yP>_y) && (_yP<_y+_height)) {
+	    return true;
+	}
+	return false;
+    }
+
+    public String editOnDoubleClick(JFrame _frame, String _value) {
+	String s = (String)JOptionPane.showInputDialog(_frame, "My plugin component name",
+						       "setting value", JOptionPane.PLAIN_MESSAGE, myIcon,
+                                                           null,
+                                                           _value);
+	return s;
+    }
     
     public static void main(String[] args) {
     }
diff --git a/src/main/java/myutil/Plugin.java b/src/main/java/myutil/Plugin.java
index 31eb7c30ac..89889ffb5f 100755
--- a/src/main/java/myutil/Plugin.java
+++ b/src/main/java/myutil/Plugin.java
@@ -69,6 +69,35 @@ public class Plugin {
         return name;
     }
 
+    public Class getClass(String _className) {
+	Class<?> c = listOfClasses.get(_className);
+	if (c != null) {
+	    return c;
+	}
+
+	try {
+            if (c == null) {
+                file = new File(name);
+                TraceManager.addDev("Loading plugin=" + name);
+                URL[] urls = new URL[] { file.toURI().toURL() };
+                ClassLoader loader = new URLClassLoader(urls);
+                TraceManager.addDev("Loader created");
+                c = loader.loadClass(_className);
+                if (c == null) {
+                    return null;
+                }
+                listOfClasses.put(_className, c);
+		return c;
+            }
+
+        } catch (Exception e) {
+	    TraceManager.addDev("Exception when using plugin " + name + " with className=" + _className);
+	    return null;
+        }
+
+	return null;
+    }
+
     public Method getMethod(String _className, String _methodName) {
         Class<?> c = listOfClasses.get(_className);
 
@@ -109,6 +138,18 @@ public class Plugin {
 	}
     }
 
+    public static int executeIntMethod(Object instance, String _methodName) throws Exception {
+	Class[] cArg = new Class[0];
+	Method method = instance.getClass().getMethod(_methodName, cArg);
+	return (int)(method.invoke(instance));
+    }
+
+    public static boolean executeBoolMethod(Object instance, String _methodName) throws Exception {
+	Class[] cArg = new Class[0];
+	Method method = instance.getClass().getMethod(_methodName, cArg);
+	return (boolean)(method.invoke(instance));
+    }
+
     
     public ImageIcon executeRetImageIconMethod(String _className, String _methodName) {
 	// We have a valid plugin. We now need to get the Method
diff --git a/src/main/java/ui/ComponentPluginInterface.java b/src/main/java/ui/ComponentPluginInterface.java
new file mode 100755
index 0000000000..94488fcd4f
--- /dev/null
+++ b/src/main/java/ui/ComponentPluginInterface.java
@@ -0,0 +1,59 @@
+/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille, Andrea Enrici
+ * 
+ * ludovic.apvrille AT telecom-paristech.fr
+ * andrea.enrici AT telecom-paristech.fr
+ * 
+ * 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,
+ * that may mean  that it is complicated to manipulate,  and  that  also
+ * therefore means  that it is reserved for developers  and  experienced
+ * professionals having in-depth computer knowledge. Users are therefore
+ * encouraged to load and test the software's suitability as regards their
+ * 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.
+ */
+
+
+
+
+package ui;
+
+import myutil.*;
+import java.awt.*;
+
+/**
+ * Class ComponentPluginInteface
+ * Component having a plugin interface
+ * Creation: 28/06/2017
+ * @version 1.0 28/06/2017
+ * @author Ludovic APVRILLE
+ */
+public interface ComponentPluginInterface {
+
+    public void setPlugin(Plugin _plugin);
+
+}
diff --git a/src/main/java/ui/GTURTLEModeling.java b/src/main/java/ui/GTURTLEModeling.java
index 40c91ff194..2f70acf0d3 100755
--- a/src/main/java/ui/GTURTLEModeling.java
+++ b/src/main/java/ui/GTURTLEModeling.java
@@ -7868,12 +7868,12 @@ public class GTURTLEModeling {
                 if (n.getNodeType() == Node.ELEMENT_NODE) {
                     try {
                         tgc = makeXMLComponent(n, tdp);
-                        //TraceManager.addDev("About to add component= " + tgc);
+                        TraceManager.addDev("About to add component= " + tgc);
                         if ((tgc != null) && (tgc.getFather() == null)) {
-                            //TraceManager.addDev("Component added to diagram tgc=" + tgc);
+                            TraceManager.addDev("Component added to diagram tgc=" + tgc);
                             tdp.addBuiltComponent(tgc);
                         } else {
-                            //TraceManager.addDev("Component not added to diagram");
+                            TraceManager.addDev("Component not added to diagram");
                         }
                     } catch (MalformedModelingException mme) {
                         int type = getTypeOfComponentNode(n);
@@ -7881,7 +7881,7 @@ public class GTURTLEModeling {
                         if (type > 0) {
                             t = "" + type;
                         }
-                        TraceManager.addDev ("a badly formed component Could not be created in the diagram");
+                        TraceManager.addDev ("A badly formed component could not be created in the diagram");
 
                         UICheckingError ce = new UICheckingError(CheckingError.BEHAVIOR_ERROR, "A component could not be correctly loaded - type=" + t);
                         ce.setTDiagramPanel(tdp);
diff --git a/src/main/java/ui/MainGUI.java b/src/main/java/ui/MainGUI.java
index 2a2f5536dd..84d815b131 100644
--- a/src/main/java/ui/MainGUI.java
+++ b/src/main/java/ui/MainGUI.java
@@ -275,6 +275,7 @@ public  class MainGUI implements ActionListener, WindowListener, KeyListener, Pe
 
     private int typeButtonSelected;
     private int idButtonSelected;
+    private Plugin pluginSelected;
 
     private File file;
     private File lotosfile;
@@ -1586,6 +1587,7 @@ public  class MainGUI implements ActionListener, WindowListener, KeyListener, Pe
 
             typeButtonSelected = - 1;
             idButtonSelected = -1;
+	    pluginSelected = null;
 
             //activeDiagramToolBar = null;
 
@@ -5220,9 +5222,24 @@ public  class MainGUI implements ActionListener, WindowListener, KeyListener, Pe
         return typeButtonSelected;
     }
 
+    public Plugin getPluginSelected() {
+	return pluginSelected;
+    }
+
     public void actionOnButton(int type, int id) {
         typeButtonSelected = type;
         idButtonSelected = id;
+	pluginSelected = null;
+        //TDiagramPanel tdp1 = ((TURTLEPanel)(tabs.elementAt(mainTabbedPane.getSelectedIndex()))).tdp;
+        TDiagramPanel tdp1 = getCurrentTDiagramPanel();
+        //TraceManager.addDev("Selected TDiagramPanel=" + tdp1.getName());
+        tdp1.repaint();
+    }
+
+    public void actionOnButton(int type, Plugin _p) {
+        typeButtonSelected = type;
+        idButtonSelected = TGComponentManager.COMPONENT_PLUGIN;
+	pluginSelected = _p;
         //TDiagramPanel tdp1 = ((TURTLEPanel)(tabs.elementAt(mainTabbedPane.getSelectedIndex()))).tdp;
         TDiagramPanel tdp1 = getCurrentTDiagramPanel();
         //TraceManager.addDev("Selected TDiagramPanel=" + tdp1.getName());
diff --git a/src/main/java/ui/TAction.java b/src/main/java/ui/TAction.java
index 959764cabe..7b2f6ab575 100755
--- a/src/main/java/ui/TAction.java
+++ b/src/main/java/ui/TAction.java
@@ -1,26 +1,26 @@
 /* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille
- * 
+ *
  * ludovic.apvrille AT enst.fr
- * 
+ *
  * 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,
@@ -31,7 +31,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.
  */
@@ -51,45 +51,45 @@ import javax.swing.*;
  * @author Ludovic APVRILLE
  */
 public class TAction  {
-	
-	// Action parameters
-	public String ACTION_COMMAND_KEY; 
-   	public String NAME;
-   	public ImageIcon SMALL_ICON;
-   	public ImageIcon LARGE_ICON;
-  	public String SHORT_DESCRIPTION;
-  	public String LONG_DESCRIPTION;
-  	public int MNEMONIC_KEY;
-  	public char KEY;
-  	public boolean hasControl = false;
 
- 	/** 
-	* Creates a new TAction
-  	*/
-     	public TAction(String ActionCommand, String name, ImageIcon smallIcon, ImageIcon largeIcon, String shortDescription, String longDescription, int mneKey) {
-     		ACTION_COMMAND_KEY = ActionCommand;
-     		NAME = name;
-     		SMALL_ICON = smallIcon;
-     		LARGE_ICON = largeIcon;
-     		SHORT_DESCRIPTION = shortDescription;
-     		LONG_DESCRIPTION = longDescription;
-     		MNEMONIC_KEY = mneKey;
-     		KEY = (char)mneKey;
-     		hasControl = false;
-	}
-	
-	public TAction(String ActionCommand, String name, ImageIcon smallIcon, ImageIcon largeIcon, String shortDescription, String longDescription, int mneKey, boolean _hasControl) {
-     		ACTION_COMMAND_KEY = ActionCommand;
-     		NAME = name;
-     		SMALL_ICON = smallIcon;
-     		LARGE_ICON = largeIcon;
-     		SHORT_DESCRIPTION = shortDescription;
-     		LONG_DESCRIPTION = longDescription;
-     		MNEMONIC_KEY = mneKey;
-     		KEY = (char)mneKey;
-     		hasControl = _hasControl;
-	}
-        
+    // Action parameters
+    public String ACTION_COMMAND_KEY;
+    public String NAME;
+    public ImageIcon SMALL_ICON;
+    public ImageIcon LARGE_ICON;
+    public String SHORT_DESCRIPTION;
+    public String LONG_DESCRIPTION;
+    public int MNEMONIC_KEY;
+    public char KEY;
+    public boolean hasControl = false;
+
+    /**
+     * Creates a new TAction
+     */
+    public TAction(String ActionCommand, String name, ImageIcon smallIcon, ImageIcon largeIcon, String shortDescription, String longDescription, int mneKey) {
+        ACTION_COMMAND_KEY = ActionCommand;
+        NAME = name;
+        SMALL_ICON = smallIcon;
+        LARGE_ICON = largeIcon;
+        SHORT_DESCRIPTION = shortDescription;
+        LONG_DESCRIPTION = longDescription;
+        MNEMONIC_KEY = mneKey;
+        KEY = (char)mneKey;
+        hasControl = false;
+    }
+
+    public TAction(String ActionCommand, String name, ImageIcon smallIcon, ImageIcon largeIcon, String shortDescription, String longDescription, int mneKey, boolean _hasControl) {
+        ACTION_COMMAND_KEY = ActionCommand;
+        NAME = name;
+        SMALL_ICON = smallIcon;
+        LARGE_ICON = largeIcon;
+        SHORT_DESCRIPTION = shortDescription;
+        LONG_DESCRIPTION = longDescription;
+        MNEMONIC_KEY = mneKey;
+        KEY = (char)mneKey;
+        hasControl = _hasControl;
+    }
+
     public void setName(String name) {
         NAME = name;
     }
diff --git a/src/main/java/ui/TDiagramPanel.java b/src/main/java/ui/TDiagramPanel.java
index e01f34d6a7..92a087e32d 100755
--- a/src/main/java/ui/TDiagramPanel.java
+++ b/src/main/java/ui/TDiagramPanel.java
@@ -885,13 +885,17 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
 
     // Adding component
     public TGComponent addComponent(int x, int y, boolean swallow) {
-        return addComponent(x, y, mgui.getIdButtonSelected(), swallow);
+	//TraceManager.addDev("Add component");
+        TGComponent tgc = addComponent(x, y, mgui.getIdButtonSelected(), swallow);
+	if (tgc instanceof ComponentPluginInterface) {
+	    ((ComponentPluginInterface)tgc).setPlugin(mgui.getPluginSelected());
+	}
+	return tgc;
     }
 
     public TGComponent addComponent(int x, int y, int id, boolean swallow) {
         TGComponent tgc = TGComponentManager.addComponent(x, y, id, this);
         addComponent(tgc, x, y, swallow, true);
-
         return tgc;
     }
 
diff --git a/src/main/java/ui/TGComponentManager.java b/src/main/java/ui/TGComponentManager.java
index 352b575567..843c5c1fbe 100755
--- a/src/main/java/ui/TGComponentManager.java
+++ b/src/main/java/ui/TGComponentManager.java
@@ -487,6 +487,8 @@ public class TGComponentManager {
     public static final int SYSMLSEC_METHODOLOGY_REF_ATTACK = 5712;
     public static final int SYSMLSEC_METHODOLOGY_CONNECTOR = 5718;
 
+    // PLUGIN
+    public static final int COMPONENT_PLUGIN = 10000;
 
     public static final int EDIT = -1;
     public static final int COMPONENT = 0;
@@ -503,7 +505,11 @@ public class TGComponentManager {
     public final static TGComponent addComponent(int x, int y, int id, TDiagramPanel tdp) {
         TGComponent tgc = null;
         switch (id) {
-            // AVATAR
+            // PLUGIN
+	case COMPONENT_PLUGIN:
+            tgc = new TGComponentPlugin(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp);
+            break;
+	    // AVATAR
         case AVATARBD_BLOCK:
             tgc = new AvatarBDBlock(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp);
             break;
@@ -1335,11 +1341,14 @@ public class TGComponentManager {
 
 
     public final static int getType(TGComponent tgc) {
-        // AVATAR
-        // AVATAR BD
-        if (tgc instanceof AvatarBDBlock) {
+	// PLUGIN
+        if (tgc instanceof TGComponentPlugin) {
+            return COMPONENT_PLUGIN;
+
+	    // AVATAR BD    
+        } else if (tgc instanceof AvatarBDBlock) {
             return AVATARBD_BLOCK;
-        } else if (tgc instanceof AvatarBDDataType) {
+	} else if (tgc instanceof AvatarBDDataType) {
             return AVATARBD_DATATYPE;
         } else if (tgc instanceof AvatarBDCompositionConnector) {
             return AVATARBD_COMPOSITION_CONNECTOR;
diff --git a/src/main/java/ui/TGComponentPlugin.java b/src/main/java/ui/TGComponentPlugin.java
index 416028d15e..18a6e3a144 100755
--- a/src/main/java/ui/TGComponentPlugin.java
+++ b/src/main/java/ui/TGComponentPlugin.java
@@ -44,6 +44,12 @@ package ui;
 
 import myutil.*;
 import java.awt.*;
+import javax.swing.*;
+
+import java.lang.reflect.Method;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 
 /**
  * Class TGComponentPlugin
@@ -52,26 +58,196 @@ import java.awt.*;
  * @version 1.0 27/06/2017
  * @author Ludovic APVRILLE
  */
-public class TGComponentPlugin extends TGComponent {
+public class TGComponentPlugin extends TGComponent implements ComponentPluginInterface {
 
     private Plugin componentPlugin;
     private String className;
+    private Class<?> classRef;
+    private Object instance;
+    private Method methodInternalDrawing;
+    private Method methodIsOnMe;
+    private Method methodEditOnDoubleClick;
 
     public TGComponentPlugin(int _x, int _y, int _minX, int _maxX, int _minY, int _maxY, boolean _pos, TGComponent _father, TDiagramPanel _tdp) {
 	super(_x, _y, _minX, _maxX, _minY, _maxY, _pos, _father, _tdp);
-    }
+	width = 0;
+	height = 0;
 
+	value = "custom component";
+    }
 
+    public void setPlugin(Plugin _plugin) {
+	componentPlugin = _plugin;
+    }
 
     public void internalDrawing(Graphics g) {
+	try {
+	    if (methodInternalDrawing == null) {
+		createInstance();
+		TraceManager.addDev("instance =" + instance);
+		Class[] cArg = new Class[6];
+		cArg[0] = Graphics.class;
+		cArg[1] = int.class;
+		cArg[2] = int.class;
+		cArg[3] = int.class;
+		cArg[4] = int.class;
+		cArg[5] = String.class;
+		methodInternalDrawing = classRef.getMethod("internalDrawing", cArg);
+		TraceManager.addDev("Method =" + methodInternalDrawing);
+	    }
+	    methodInternalDrawing.invoke(instance, g, x, y, width, height, value);
+	    
+	} catch (Exception e) {
+	    TraceManager.addDev("Exception method:" + e.getMessage());
+	    g.drawString("No plugin available.", x, y);
+	}
 	
     }
+
+    private void createInstance() {
+	try {
+	    if (componentPlugin == null) {
+		//TraceManager.addDev("null component Plugin");
+	    }
+	    if (instance == null) {
+		//TraceManager.addDev("[create instance] Name of the plugin:" + componentPlugin.getName());
+		String className = componentPlugin.executeRetStringMethod("CustomizerGraphicalComponent", "getGraphicalComponentClassName");
+		classRef = componentPlugin.getClass(className);
+		//TraceManager.addDev("[create instance] classRef:" + classRef);
+		instance = classRef.newInstance();
+		if (width == 0) {
+		    width = Plugin.executeIntMethod(instance, "getWidth");
+		}
+		if (height == 0) {
+		    height = Plugin.executeIntMethod(instance, "getHeight");
+		}
+		moveable = Plugin.executeBoolMethod(instance, "isMoveable");
+		removable = Plugin.executeBoolMethod(instance, "isRemovable");
+		userResizable = Plugin.executeBoolMethod(instance, "isUserResizable");
+		editable = Plugin.executeBoolMethod(instance, "isEditable");
+
+		//TraceManager.addDev("Moveable=" + moveable);	
+	    }
+	} catch (Exception e) {
+	    TraceManager.addDev("No class with Plugin name");
+	}
+    }
     
     public TGComponent isOnMe(int _x, int _y) {
-	return this;
+	try {
+	    if (methodIsOnMe == null) {
+		createInstance();
+		//TraceManager.addDev("instance =" + instance);
+		Class[] cArg = new Class[6];
+		cArg[0] = int.class;
+		cArg[1] = int.class;
+		cArg[2] = int.class;
+		cArg[3] = int.class;
+		cArg[4] = int.class;
+		cArg[5] = int.class;
+		methodIsOnMe = classRef.getMethod("isOnMe", cArg);
+		//TraceManager.addDev("Method=" + methodIsOnMe);
+	    }
+	    if ((boolean)(methodIsOnMe.invoke(instance, x, y, width, height, _x, _y))) {
+		return this;
+	    }
+	    return null;
+	} catch (Exception e) {
+	    TraceManager.addDev("Error when executing isOnMe method in Plugin: "  + e.getMessage());
+	    return null;
+	}
+    }
+
+    public boolean editOndoubleClick(JFrame frame) {
+	try {
+	    if (methodEditOnDoubleClick == null) {
+		createInstance();
+		//TraceManager.addDev("instance / editOnDoubleClick =" + instance);
+		Class[] cArg = new Class[2];
+		cArg[0] = JFrame.class;
+		cArg[1] = String.class;
+		//TraceManager.addDev("Getting method");
+		methodEditOnDoubleClick = classRef.getMethod("editOnDoubleClick", cArg);
+		//TraceManager.addDev("Method methodEditOnDoubleClick =" + methodEditOnDoubleClick);
+	    }
+	    String tmp = (String)(methodEditOnDoubleClick.invoke(instance, frame, value));
+	    if (tmp != null) {
+		value = tmp;
+		return true;
+	    }
+	    return false;
+	} catch (Exception e) {
+	    TraceManager.addDev("Error when executing editOnDoubleClick method in Plugin: "  + e.getMessage());
+	    return false;
+	}
     }
     
     public void setState(int s) {
 	state = s;
     }
+
+    protected String translateExtraParam() {
+        StringBuffer sb = new StringBuffer("<extraparam>\n");
+	if (componentPlugin != null) {
+	    sb.append("<PluginName value=\"" + componentPlugin.getName() + "\" />\n");
+	}
+        sb.append("</extraparam>\n");
+        return new String(sb);
+    }
+
+    @Override
+    public void loadExtraParam(NodeList nl, int decX, int decY, int decId) throws MalformedModelingException{
+
+        String s;
+        String tmpGlobalCode = "";
+
+        try {
+            NodeList nli;
+            Node n1, n2;
+            Element elt;
+            String pName;
+	    //boolean mustAddCryptoFunctions = false;
+
+
+            //System.out.println("Loading attributes");
+            //System.out.println(nl.toString());
+
+	    //TraceManager.addDev("LEP Begin Block  = " + this + " trace=");
+	    //Thread.currentThread().dumpStack();
+
+            for(int i=0; i<nl.getLength(); i++) {
+                n1 = nl.item(i);
+                //System.out.println(n1);
+                if (n1.getNodeType() == Node.ELEMENT_NODE) {
+                    nli = n1.getChildNodes();
+                    for(int j=0; j<nli.getLength(); j++) {
+                        n2 = nli.item(j);
+                        //System.out.println(n2);
+                        if (n2.getNodeType() == Node.ELEMENT_NODE) {
+                            elt = (Element) n2;
+                            if (elt.getTagName().equals("PluginName")) {
+				pName = elt.getAttribute("value");
+				componentPlugin = PluginManager.pluginManager.getPluginOrCreate(pName);
+				if (componentPlugin != null) {
+				    createInstance();
+				} else {
+				    TraceManager.addDev("No corresponding plugin");
+				}
+			    }
+			}
+                    }
+                }
+            }
+	    
+        } catch (Exception e) {
+	    TraceManager.addDev("Error when loading plugin component");
+            throw new MalformedModelingException();
+        }
+    }
+    
+    public int getType() {
+	return TGComponentManager.COMPONENT_PLUGIN;
+    }
+    
 }
+
diff --git a/src/main/java/ui/TGUIAction.java b/src/main/java/ui/TGUIAction.java
index 6bbac8034f..2869df6e79 100755
--- a/src/main/java/ui/TGUIAction.java
+++ b/src/main/java/ui/TGUIAction.java
@@ -621,6 +621,7 @@ public class TGUIAction extends AbstractAction {
     public static final String LARGE_ICON = "LargeIcon";
 
     public TGUIAction(TAction _t) {
+	putValue(Action.ACTION_COMMAND_KEY, _t.ACTION_COMMAND_KEY);
 	putValue(Action.NAME, _t.NAME);
         putValue(Action.SMALL_ICON, _t.SMALL_ICON);
         putValue(LARGE_ICON, _t.LARGE_ICON);
@@ -663,7 +664,7 @@ public class TGUIAction extends AbstractAction {
         actions[ACT_NEW_DESIGN] = new TAction("new-command-design", "New design", IconManager.imgic14, IconManager.imgic14, "New design", "New TURTLE design", 0);
         actions[ACT_NEW_ANALYSIS] = new TAction("new-command-analysis", "New analysis", IconManager.imgic17, IconManager.imgic17, "New analysis", "New TURTLE analysis", 0);
         actions[ACT_OPEN] = new TAction("open-command","Open", IconManager.imgic22, IconManager.imgic23, "Open", "Open an existing TTooll model",'O', true);
-        actions[ACT_OPEN_FROM_NETWORK] = new TAction("open-command-from-network","Open from TTool repository", IconManager.imgic22, IconManager.imgic23, "Open from TTool repository", "Open an existing TTool model from the TTool repository (TTool website)",'O', true);
+        actions[ACT_OPEN_FROM_NETWORK] = new TAction("open-command-from-network","Open from TTool repository", IconManager.imgic22, IconManager.imgic23, "Open from TTool repository", "Open an existing TTool model from the TTool repository (TTool website)",'0', true);
         actions[ACT_OPEN_LAST] = new TAction("openlast-command","Open file: " + ConfigurationTTool.LastOpenFile, IconManager.imgic22, IconManager.imgic23, "Open: " + ConfigurationTTool.LastOpenFile, "Open the lastly saved TTool model", 0);
         actions[ACT_MERGE] = new TAction("merge-command","Merge", IconManager.imgic22, IconManager.imgic23, "Merge", "Merge the current TTool modeling with another one saved in a file ", 0);
         actions[ACT_SAVE] = new TAction("save-command", "Save",IconManager.imgic24, IconManager.imgic25, "Save", "Save an opened or a new TTool modeling", 'S', true);
@@ -1242,7 +1243,7 @@ public class TGUIAction extends AbstractAction {
         if (listeners == null) {
             listeners = new EventListenerList();
         }
-	TraceManager.addDev("Action listener added");
+	//TraceManager.addDev("Action listener added");
         listeners.add(ActionListener.class, l);
     }
 
diff --git a/src/main/java/ui/TToolBar.java b/src/main/java/ui/TToolBar.java
index c56cb8ba81..c9c81a9162 100755
--- a/src/main/java/ui/TToolBar.java
+++ b/src/main/java/ui/TToolBar.java
@@ -95,18 +95,18 @@ public abstract class TToolBar extends JToolBar implements ActionListener {
                     ImageIcon img = p.executeRetImageIconMethod("CustomizerGraphicalComponent", "getImageIcon");
                     if ((img != null)  && (shortText != null)) {
                         TraceManager.addDev("Plugin: " + p.getName() + " short name:" + shortText);
-                        TAction t = new TAction("command-" + i, shortText, img, img, veryShortText, longText, 0);
+                        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);
+			tguia.addActionListener(this);
 			//button.addActionListener(this);
 
-			JButton toto = new JButton("Test");
+			/*JButton toto = new JButton("Test");
 			toto.addActionListener(this);
-			add(toto);
+			add(toto);*/
 			//TraceManager.addDev("Action listener...");
                     }
                 }
@@ -114,15 +114,18 @@ public abstract class TToolBar extends JToolBar implements ActionListener {
         }
     }
 
-    public void actionPerformed(ActionEvent e) {
-	TraceManager.addDev("Action listener of TToolBar");
-	TraceManager.addDev("Action on event " + e + " source=" + e.getSource());
-	Object o = e.getSource();
+    public void actionPerformed(ActionEvent evt) {
+	//TraceManager.addDev("Action listener of TToolBar");
+	//TraceManager.addDev("Action on event " + e + "\n\nsource=" + e.getSource());
+	//Object o = e.getSource();
 	int index = 0;
 	Plugin p = null;
 	TGUIAction act = null;
+	String command = evt.getActionCommand();
+	//TraceManager.addDev("command=" + command);
 	for(TGUIAction t: pluginActions) {
-	    if (t == o) {
+	    //TraceManager.addDev(" command of action:" + t.getActionCommand());
+	    if (t.getActionCommand().compareTo(command) == 0) {
 		p = plugins.get(index);
 		act = t;
 		break;
@@ -132,6 +135,7 @@ public abstract class TToolBar extends JToolBar implements ActionListener {
 
 	if ((act != null) && (p != null)) {
 	    TraceManager.addDev("Action on plugin " + p);
+	    mgui.actionOnButton(TGComponentManager.COMPONENT, p);
 	}
 
     }
diff --git a/src/main/java/ui/avatarbd/AvatarBDBlock.java b/src/main/java/ui/avatarbd/AvatarBDBlock.java
index b6a346f3f7..9b259ddff4 100644
--- a/src/main/java/ui/avatarbd/AvatarBDBlock.java
+++ b/src/main/java/ui/avatarbd/AvatarBDBlock.java
@@ -979,6 +979,7 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S
         } catch (Exception e) {
             throw new MalformedModelingException();
         }
+	
 
 	if (isCryptoBlock()) {
 	    addCryptoElements();
-- 
GitLab