Skip to content
Snippets Groups Projects
Commit 4c1124fe authored by apvrille's avatar apvrille
Browse files

Update on actions and plugin management

parent 7ae4771f
No related branches found
No related tags found
No related merge requests found
plugins/testPluginGraphicalComponent/myicon.gif

98 B

......@@ -149,6 +149,7 @@ public class ConfigurationTTool {
// PLUGINS
public static String PLUGIN_JAVA_CODE_GENERATOR = "";
public static String[] PLUGIN_GRAPHICAL_COMPONENT = new String[0];
// URL for models
public static String URL_MODEL = "http://ttool.telecom-paristech.fr/networkmodels/models.txt";
......@@ -451,11 +452,14 @@ public class ConfigurationTTool {
sb.append("Attack ontology website: " + AttackOntologyWebsite + "\n");
// Plugins
sb.append("Plugins:\n");
sb.append("\nPlugins:\n");
sb.append("Plugin for java code generation: " + PLUGIN_JAVA_CODE_GENERATOR + "\n");
for (int i=0; i<PLUGIN_GRAPHICAL_COMPONENT.length; i++) {
sb.append("Plugin for graphical component: " + PLUGIN_GRAPHICAL_COMPONENT[i] + "\n");
}
// URL
sb.append("URLs:\n");
sb.append("\nURLs:\n");
sb.append("URL for loading models from network: " + URL_MODEL + "\n");
sb.append("\nCustom external commands:\n");
......@@ -736,6 +740,10 @@ public class ConfigurationTTool {
if (nl.getLength() > 0)
PluginJavaCodeGenerator(nl);
nl = doc.getElementsByTagName("PLUGIN_GRAPHICAL_COMPONENT");
if (nl.getLength() > 0)
PluginGraphicalComponent(nl);
nl = doc.getElementsByTagName("URL_MODEL");
if (nl.getLength() > 0)
URLModel(nl);
......@@ -1423,6 +1431,18 @@ public class ConfigurationTTool {
}
}
private static void PluginGraphicalComponent(NodeList nl) throws MalformedConfigurationException {
PLUGIN_GRAPHICAL_COMPONENT = new String[nl.getLength()];
try {
for (int i=0; i<nl.getLength(); i++) {
Element elt = (Element)(nl.item(i));
PLUGIN_GRAPHICAL_COMPONENT[i] = elt.getAttribute("data");
}
} catch (Exception e) {
throw new MalformedConfigurationException(e.getMessage());
}
}
private static void URLModel(NodeList nl) throws MalformedConfigurationException {
try {
Element elt = (Element)(nl.item(0));
......
......@@ -47,6 +47,8 @@ import java.net.URL;
import java.net.URLClassLoader;
import java.util.HashMap;
import javax.swing.*;
/**
* Class Plugin
* Creation: 24/05/2017
......@@ -92,5 +94,35 @@ public class Plugin {
}
public String executeRetStringMethod(String _className, String _methodName) {
// We have a valid plugin. We now need to get the Method
Method m = getMethod(_className, _methodName);
if (m == null) {
return null;
}
try {
return (String)(m.invoke(null));
} catch (Exception e) {
TraceManager.addDev("Exception occured when executing method " + _methodName);
return null;
}
}
public ImageIcon executeRetImageIconMethod(String _className, String _methodName) {
// We have a valid plugin. We now need to get the Method
Method m = getMethod(_className, _methodName);
if (m == null) {
return null;
}
try {
return (ImageIcon)(m.invoke(null));
} catch (Exception e) {
TraceManager.addDev("Exception occured when executing method " + _methodName);
return null;
}
}
}
......@@ -64,6 +64,15 @@ public class PluginManager {
plugins.add(_plugin);
}
public Plugin getPluginOrCreate(String _name) {
Plugin plug = getPlugin(_name);
if (plug != null) {
return plug;
}
return createPlugin(_name);
}
public Plugin getPlugin(String _name) {
for(Plugin plugin: plugins) {
if (plugin.getName().compareTo(_name) == 0) {
......@@ -105,18 +114,9 @@ public class PluginManager {
}
}
// We have a valid plugin. We now need to get the Method
Method m = plugin.getMethod(_className, _methodName);
if (m == null) {
return null;
}
return plugin.executeRetStringMethod(_className, _methodName);
try {
return (String)(m.invoke(null));
} catch (Exception e) {
TraceManager.addDev("Exception occured when executing method " + _methodName);
return null;
}
}
......
......@@ -56,11 +56,4 @@ public class TGComponentPlugin extends TGComponent {
private Plugin componentPlugin;
private String className;
}
......@@ -618,8 +618,6 @@ public class TGUIAction extends AbstractAction {
public static final String LARGE_ICON = "LargeIcon";
public TGUIAction(int id) {
if (actions[0] == null) {
init();
......
......@@ -42,9 +42,12 @@
package ui;
import javax.swing.*;
//import java.awt.*;
import java.util.*;
//import java.awt.event.*;
import myutil.*;
import common.*;
/**
* Class TToolBar
......@@ -55,6 +58,9 @@ import javax.swing.*;
* @see TGComponent
*/
public abstract class TToolBar extends JToolBar {
protected ArrayList<TAction> pluginActions;
//protected ActionListener buttonTB;
protected MainGUI mgui;
/*protected int typeSelected = TGComponentManager.EDIT;
......@@ -72,6 +78,26 @@ public abstract class TToolBar extends JToolBar {
protected abstract void setButtons();
protected abstract void setActive(boolean b);
protected void setPluginButtons(String diag) {
pluginActions = new ArrayList<TAction>();
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 shortText = p.executeRetStringMethod("CustomizerGraphicalComponent", "getShortText");
String longText = p.executeRetStringMethod("CustomizerGraphicalComponent", "getLongText");
String veryShortText = p.executeRetStringMethod("CustomizerGraphicalComponent", "veryShortText");
ImageIcon img = p.executeRetImageIconMethod("CustomizerGraphicalComponent", "getImageIcon");
TraceManager.addDev("Plugin: " + p.getName() + " short name:" + shortText);
TAction t = new TAction("command-" + i, shortText, img, img, veryShortText, longText, 0);
pluginActions.add(t);
/*JButton button = add(t);
button.addMouseListener(mgui.mouseHandler);*/
}
}
}
} // Class
......
......@@ -184,6 +184,8 @@ public class TMLArchiDiagramToolBar extends TToolBar implements ActionListener
box = new JComboBox<>(viewInfos);
this.add(box);
box.addActionListener(this);
setPluginButtons("TMLArchiDiagramPanel");
}
public void setPanel(TMLArchiDiagramPanel _panel) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment