diff --git a/doc/dev_infrastructure/ttool_development_infrastructure.tex b/doc/dev_infrastructure/ttool_development_infrastructure.tex index 9ee2edc1a98de5b72e8c0b161b3a2d0cbc768f3d..d2b5148551d8d4169259a1d9f57000a1fe5a54d7 100644 --- a/doc/dev_infrastructure/ttool_development_infrastructure.tex +++ b/doc/dev_infrastructure/ttool_development_infrastructure.tex @@ -1612,13 +1612,13 @@ Path: ../plugins Has graphical component? false Has Avatar code generator? true Has Diplodocus code generator? false -Custom commands: getPanelClassName getWidth getHeight setDefaultWidth +Custom commands: getPanelClassName getWidth getHeight setDefaultWidthS \end{verbatim} -\end{itemize} + \item \textit{plugin info-command <plugin name> <command name>}: provides information on a given command provided by a plugin \begin{verbatim} -$ plugin info-command CustomizerGraphicalComponent.jar setDefaultWidth -static void setDefaultWidth(int defaultWidth): makes it possible to set the default width +$ plugin info-command CustomizerGraphicalComponent.jar setDefaultWidthS +static void setDefaultWidthS(String defaultWidth): makes it possible to set the default width \end{verbatim} \end{itemize} @@ -1632,13 +1632,44 @@ A plugin that may be used by the command line interface must define the followin \subsubsection{Custom commands} -A plugin can define a list of custom commands. These commands can take only \textit{String} as parameter and can return either nothing or a String. They have to be implemented with a method having the same name as the command. The method must also be \textbf{static}. +A plugin can define a list of custom commands. These commands can take only \textit{String} as parameter (maximum 4 String) and can return either nothing or a String. They have to be implemented with a method having the same name as the command. The method must also be \textbf{static}. For instance: \begin{verbatim} public static String getWidthS() { return "100"; } + +public static void setDefaultWidthS(String defaultWith) { + try { + DEFAULT_WIDTH = Integer.decode(defaultWith);; + } catch (Exception e) { + + } + } + +\end{verbatim} + +The "exec" sub command of the "plugin" command can be used to execute custom functions. "exec" takes the following arguments: +\begin{itemize} +\item plugin name +\item method name +\item if the called method returns a String, the returned String can be stored in a variable specified as "-ret <name of variable>" +\item Then the input arguments of the method follow. +\end{itemize} + +For instance, to execute the method "getWidthS" of plugin "CustomizerGraphicalComponent.jar" and store the result in variable "s", do as follows: +\begin{verbatim} +1> plugin exec CustomizerGraphicalComponent.jar getWidthS -ret x +Command executed +2> print var x +Variable x = 100 +Command executed +\end{verbatim} + +The following example shows how to provide an argument to a custom command. +\begin{verbatim} +1> plugin exec CustomizerGraphicalComponent.jar setDefaultWidth 200 \end{verbatim} diff --git a/modeling/DIPLODOCUS/SmartCardProtocol.xml b/modeling/DIPLODOCUS/SmartCardProtocol.xml index a500e7e01bbebcf5c39d7e2c443cc25b51eac8b1..0d8a3e267732481b09b34512c39ff99afb6e2d94 100755 --- a/modeling/DIPLODOCUS/SmartCardProtocol.xml +++ b/modeling/DIPLODOCUS/SmartCardProtocol.xml @@ -8,16 +8,16 @@ <cdparam x="535" y="347" /> <sizeparam width="0" height="0" minWidth="0" minHeight="0" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <infoparam name="connector" value="Connector between ports" /> -<P1 x="556" y="347" id="169" /> -<P2 x="547" y="382" id="216" /> +<P1 x="556" y="321" id="169" /> +<P2 x="534" y="395" id="216" /> <AutomaticDrawing data="true" /> </CONNECTOR> <CONNECTOR type="126" id="3" > <cdparam x="820" y="398" /> <sizeparam width="0" height="0" minWidth="0" minHeight="0" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <infoparam name="connector" value="Connector between ports" /> -<P1 x="1025" y="497" id="63" /> -<P2 x="761" y="574" id="184" /> +<P1 x="1025" y="471" id="63" /> +<P2 x="761" y="548" id="184" /> <Point x="887" y="577" /> <AutomaticDrawing data="true" /> </CONNECTOR><SUBCOMPONENT type="-1" id="2" > @@ -34,15 +34,15 @@ <sizeparam width="0" height="0" minWidth="0" minHeight="0" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <infoparam name="connector" value="Connector between ports" /> <P1 x="710" y="403" id="186" /> -<P2 x="693" y="347" id="147" /> +<P2 x="693" y="321" id="147" /> <AutomaticDrawing data="true" /> </CONNECTOR> <CONNECTOR type="126" id="5" > <cdparam x="522" y="390" /> <sizeparam width="0" height="0" minWidth="0" minHeight="0" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <infoparam name="connector" value="Connector between ports" /> -<P1 x="521" y="382" id="211" /> -<P2 x="466" y="335" id="41" /> +<P1 x="534" y="369" id="211" /> +<P2 x="453" y="322" id="41" /> <AutomaticDrawing data="true" /> </CONNECTOR> <CONNECTOR type="126" id="6" > @@ -57,16 +57,16 @@ <cdparam x="656" y="426" /> <sizeparam width="0" height="0" minWidth="0" minHeight="0" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <infoparam name="connector" value="Connector between ports" /> -<P1 x="816" y="552" id="190" /> -<P2 x="969" y="495" id="77" /> +<P1 x="805" y="542" id="190" /> +<P2 x="969" y="474" id="77" /> <AutomaticDrawing data="true" /> </CONNECTOR> <CONNECTOR type="126" id="8" > <cdparam x="656" y="400" /> <sizeparam width="0" height="0" minWidth="0" minHeight="0" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <infoparam name="connector" value="Connector between ports" /> -<P1 x="816" y="519" id="192" /> -<P2 x="921" y="476" id="75" /> +<P1 x="805" y="509" id="192" /> +<P2 x="931" y="466" id="75" /> <AutomaticDrawing data="true" /> </CONNECTOR> <CONNECTOR type="126" id="9" > @@ -74,126 +74,126 @@ <sizeparam width="0" height="0" minWidth="0" minHeight="0" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <infoparam name="connector" value="Connector between ports" /> <P1 x="751" y="406" id="200" /> -<P2 x="829" y="375" id="105" /> +<P2 x="842" y="362" id="105" /> <AutomaticDrawing data="true" /> </CONNECTOR> <CONNECTOR type="126" id="10" > <cdparam x="689" y="292" /> <sizeparam width="0" height="0" minWidth="0" minHeight="0" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <infoparam name="connector" value="Connector between ports" /> -<P1 x="855" y="375" id="109" /> -<P2 x="921" y="362" id="85" /> +<P1 x="842" y="388" id="109" /> +<P2 x="931" y="352" id="85" /> <AutomaticDrawing data="true" /> </CONNECTOR> <CONNECTOR type="126" id="11" > <cdparam x="656" y="377" /> <sizeparam width="0" height="0" minWidth="0" minHeight="0" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <infoparam name="connector" value="Connector between ports" /> -<P1 x="816" y="491" id="196" /> -<P2 x="921" y="453" id="83" /> +<P1 x="805" y="481" id="196" /> +<P2 x="931" y="443" id="83" /> <AutomaticDrawing data="true" /> </CONNECTOR> <CONNECTOR type="126" id="12" > <cdparam x="656" y="351" /> <sizeparam width="0" height="0" minWidth="0" minHeight="0" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <infoparam name="connector" value="Connector between ports" /> -<P1 x="816" y="458" id="194" /> -<P2 x="921" y="426" id="81" /> +<P1 x="805" y="448" id="194" /> +<P2 x="931" y="416" id="81" /> <AutomaticDrawing data="true" /> </CONNECTOR> <CONNECTOR type="126" id="13" > <cdparam x="741" y="296" /> <sizeparam width="0" height="0" minWidth="0" minHeight="0" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <infoparam name="connector" value="Connector between ports" /> -<P1 x="921" y="397" id="79" /> -<P2 x="816" y="429" id="198" /> +<P1 x="931" y="387" id="79" /> +<P2 x="805" y="419" id="198" /> <AutomaticDrawing data="true" /> </CONNECTOR> <CONNECTOR type="126" id="14" > <cdparam x="735" y="260" /> <sizeparam width="0" height="0" minWidth="0" minHeight="0" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <infoparam name="connector" value="Connector between ports" /> -<P1 x="918" y="330" id="87" /> -<P2 x="747" y="282" id="159" /> +<P1 x="931" y="317" id="87" /> +<P2 x="734" y="269" id="159" /> <AutomaticDrawing data="true" /> </CONNECTOR> <CONNECTOR type="126" id="15" > <cdparam x="641" y="230" /> <sizeparam width="0" height="0" minWidth="0" minHeight="0" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <infoparam name="connector" value="Connector between ports" /> -<P1 x="747" y="248" id="157" /> -<P2 x="918" y="291" id="89" /> +<P1 x="734" y="235" id="157" /> +<P2 x="931" y="278" id="89" /> <AutomaticDrawing data="true" /> </CONNECTOR> <CONNECTOR type="126" id="16" > <cdparam x="641" y="195" /> <sizeparam width="0" height="0" minWidth="0" minHeight="0" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <infoparam name="connector" value="Connector between ports" /> -<P1 x="747" y="203" id="155" /> -<P2 x="918" y="248" id="91" /> +<P1 x="734" y="190" id="155" /> +<P2 x="931" y="235" id="91" /> <AutomaticDrawing data="true" /> </CONNECTOR> <CONNECTOR type="126" id="17" > <cdparam x="740" y="353" /> <sizeparam width="0" height="0" minWidth="0" minHeight="0" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <infoparam name="connector" value="Connector between ports" /> -<P1 x="829" y="375" id="104" /> -<P2 x="747" y="314" id="153" /> +<P1 x="842" y="362" id="104" /> +<P2 x="734" y="301" id="153" /> <AutomaticDrawing data="true" /> </CONNECTOR> <CONNECTOR type="126" id="18" > <cdparam x="460" y="270" /> <sizeparam width="0" height="0" minWidth="0" minHeight="0" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <infoparam name="connector" value="Connector between ports" /> -<P1 x="521" y="303" id="163" /> -<P2 x="466" y="303" id="35" /> +<P1 x="534" y="290" id="163" /> +<P2 x="453" y="290" id="35" /> <AutomaticDrawing data="true" /> </CONNECTOR> <CONNECTOR type="126" id="19" > <cdparam x="387" y="129" /> <sizeparam width="0" height="0" minWidth="0" minHeight="0" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <infoparam name="connector" value="Connector between ports" /> -<P1 x="464" y="126" id="31" /> -<P2 x="524" y="126" id="151" /> +<P1 x="453" y="116" id="31" /> +<P2 x="534" y="116" id="151" /> <AutomaticDrawing data="true" /> </CONNECTOR> <CONNECTOR type="126" id="20" > <cdparam x="389" y="200" /> <sizeparam width="0" height="0" minWidth="0" minHeight="0" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <infoparam name="connector" value="Connector between ports" /> -<P1 x="466" y="215" id="37" /> -<P2 x="521" y="215" id="165" /> +<P1 x="453" y="202" id="37" /> +<P2 x="534" y="202" id="165" /> <AutomaticDrawing data="true" /> </CONNECTOR> <CONNECTOR type="126" id="21" > <cdparam x="460" y="236" /> <sizeparam width="0" height="0" minWidth="0" minHeight="0" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <infoparam name="connector" value="Connector between ports" /> -<P1 x="521" y="260" id="167" /> -<P2 x="466" y="260" id="39" /> +<P1 x="534" y="247" id="167" /> +<P2 x="453" y="247" id="39" /> <AutomaticDrawing data="true" /> </CONNECTOR> <CONNECTOR type="126" id="22" > <cdparam x="389" y="163" /> <sizeparam width="0" height="0" minWidth="0" minHeight="0" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <infoparam name="connector" value="Connector between ports" /> -<P1 x="466" y="169" id="33" /> -<P2 x="521" y="169" id="161" /> +<P1 x="453" y="156" id="33" /> +<P2 x="534" y="156" id="161" /> <AutomaticDrawing data="true" /> </CONNECTOR> <CONNECTOR type="126" id="23" > <cdparam x="967" y="190" /> <sizeparam width="0" height="0" minWidth="0" minHeight="0" maxWidth="1000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <infoparam name="connector from TGComponent to TGComponent" value="Connector between ports" /> -<P1 x="918" y="198" id="93" /> -<P2 x="747" y="124" id="173" /> +<P1 x="931" y="185" id="93" /> +<P2 x="734" y="111" id="173" /> <AutomaticDrawing data="true" /> </CONNECTOR> <CONNECTOR type="126" id="24" > <cdparam x="1028" y="535" /> <sizeparam width="0" height="0" minWidth="0" minHeight="0" maxWidth="1000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <infoparam name="connector from TGComponent to TGComponent" value="Connector between ports" /> -<P1 x="630" y="345" id="149" /> +<P1 x="630" y="324" id="149" /> <P2 x="669" y="406" id="188" /> <AutomaticDrawing data="true" /> </CONNECTOR> @@ -201,24 +201,24 @@ <cdparam x="1308" y="303" /> <sizeparam width="0" height="0" minWidth="0" minHeight="0" maxWidth="1000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <infoparam name="connector from TGComponent to TGComponent" value="Connector between ports" /> -<P1 x="1222" y="378" id="127" /> -<P2 x="1178" y="380" id="73" /> +<P1 x="1232" y="368" id="127" /> +<P2 x="1167" y="370" id="73" /> <AutomaticDrawing data="true" /> </CONNECTOR> <CONNECTOR type="126" id="26" > <cdparam x="1172" y="437" /> <sizeparam width="0" height="0" minWidth="0" minHeight="0" maxWidth="1000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <infoparam name="connector from TGComponent to TGComponent" value="Connector between ports" /> -<P1 x="1178" y="415" id="71" /> -<P2 x="1222" y="413" id="125" /> +<P1 x="1167" y="405" id="71" /> +<P2 x="1232" y="403" id="125" /> <AutomaticDrawing data="true" /> </CONNECTOR> <CONNECTOR type="126" id="29" > <cdparam x="1041" y="162" /> <sizeparam width="0" height="0" minWidth="0" minHeight="0" maxWidth="1000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <infoparam name="connector from TGComponent to TGComponent" value="Connector between ports" /> -<P1 x="1178" y="208" id="69" /> -<P2 x="1178" y="276" id="67" /> +<P1 x="1167" y="198" id="69" /> +<P2 x="1167" y="266" id="67" /> <Point x="1227" y="207" /> <Point x="1227" y="247" /> <AutomaticDrawing data="true" /> @@ -243,8 +243,8 @@ <cdparam x="877" y="343" /> <sizeparam width="0" height="0" minWidth="0" minHeight="0" maxWidth="1000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <infoparam name="connector from TGComponent to TGComponent" value="Connector between ports" /> -<P1 x="1178" y="454" id="65" /> -<P2 x="1222" y="441" id="123" /> +<P1 x="1167" y="444" id="65" /> +<P2 x="1232" y="431" id="123" /> <AutomaticDrawing data="true" /> </CONNECTOR> <COMPONENT type="1202" id="53" > diff --git a/plugins/testPluginGraphicalComponent/CustomizerGraphicalComponent.java b/plugins/testPluginGraphicalComponent/CustomizerGraphicalComponent.java index f64f728563395e6a279823d4a692c2212107a344..e25772c712f4df94f1f3f774e9c7645265d3d26a 100644 --- a/plugins/testPluginGraphicalComponent/CustomizerGraphicalComponent.java +++ b/plugins/testPluginGraphicalComponent/CustomizerGraphicalComponent.java @@ -52,11 +52,11 @@ public class CustomizerGraphicalComponent { private final static String[] CLI_COMMANDS = {"getPanelClassName", "getWidthS", "getHeightS", - "setDefaultWidth"}; + "setDefaultWidthS"}; private final static String[] CLI_PROTOTYPES = {"getPanelClassName: returns a String", "getWidthS: returns a String", "getHeightS: returns a String", - "setDefaultWidth <int defaultWidth>: returns void"}; + "setDefaultWidthS <String defaultWidth>: returns void"}; private final static String[] CLI_HELP_COMMANDS = { "returns the associated panel name of the component", @@ -155,6 +155,14 @@ public class CustomizerGraphicalComponent { DEFAULT_WIDTH = defaultWith; } + public static void setDefaultWidthS(String defaultWith) { + try { + DEFAULT_WIDTH = Integer.decode(defaultWith);; + } catch (Exception e) { + + } + } + public boolean isMoveable() { return true; diff --git a/src/main/java/cli/PluginAction.java b/src/main/java/cli/PluginAction.java index c246a397e9d7f0e399cd24896144c34981ccd4f9..500947f9506bb54363991664d656f49feb4450ea 100644 --- a/src/main/java/cli/PluginAction.java +++ b/src/main/java/cli/PluginAction.java @@ -230,6 +230,8 @@ public class PluginAction extends Command { }; // execute command + + Command executeCommand = new Command() { public String getCommand() { return EXECUTE_COMMAND_IN_PLUGIN; @@ -240,7 +242,8 @@ public class PluginAction extends Command { } public String getDescription() { - return "Execute a command. exec <pluginname> <command> [variable for return value (if applicable)] [arg1] [arg2] ..."; + return "Execute a command. exec <pluginname> <command> [-ret variable for return value (if applicable)] " + + "[arg1] [arg2] ..."; } public String executeCommand(String command, Interpreter interpreter) { @@ -258,13 +261,41 @@ public class PluginAction extends Command { return "No such plugin"; } - String s = p.getHelpOnCommandLineInterfaceFunction(commands[1]); + String methodName = commands[1]; + if ((methodName == null) || (methodName.length() == 0)) { + return "No such command"; + } - if ((s == null) || (s.length() == 0)) { - return "No such function"; + // Look for a return variable + String retVar = null; + int indexArg = 2; + if (commands.length > 3) { + if (commands[2].compareTo("-ret") == 0) { + retVar = commands[3]; + indexArg = 4; + TraceManager.addDev("Using variable for return:" + retVar); + } + } + + + + String[] tab = new String[commands.length-indexArg]; + for(int i=0; i<tab.length; i++) { + tab[i] = commands[i+indexArg]; + } + + TraceManager.addDev("Using " + tab.length + " arguments"); + + // Start the command + String ret = p.callCommandLineCommand(methodName, tab); + + TraceManager.addDev("Ret= " +ret); + + // Store new variable + if ((ret != null) && (retVar != null)) { + interpreter.addVariable(retVar, ret); } - System.out.println(s); return null; } diff --git a/src/main/java/myutil/Plugin.java b/src/main/java/myutil/Plugin.java index 206af642dba1ae0ffc8e98f0177bbf758d2fa722..863ac31d74c4fe7d4437da0d136b771d5c19662b 100644 --- a/src/main/java/myutil/Plugin.java +++ b/src/main/java/myutil/Plugin.java @@ -361,6 +361,48 @@ public class Plugin { } } + public String callCommandLineCommand(String _methodName, String[] args) { + if (classCommandLineInterface == null) { + hasCommandLineInterface(); + if (classCommandLineInterface == null) { + TraceManager.addDev("No class for command line"); + return null; + } + } + + return callCommandLineCommand(classCommandLineInterface, _methodName, args); + } + + public String callCommandLineCommand(Class<?> c, String _methodName, String[] args) { + Class[] cArg = new Class[args.length]; + for (int i=0; i<args.length; i++) { + cArg[i] = String.class; + } + + try { + Method m = c.getMethod(_methodName, cArg); + switch(args.length) { + case 0: + return (String) (m.invoke(null)); + case 1: + return (String) (m.invoke(null, args[0])); + case 2: + return (String) (m.invoke(null, args[0], args[1])); + case 3: + return (String) (m.invoke(null, args[0], args[1], args[2])); + case 4: + return (String) (m.invoke(null, args[0], args[1], args[2], args[3])); + + } + + + } catch (Exception e) { + TraceManager.addDev("Exception occurred when executing method " + _methodName + " in plugin " + this.getName()); + return null; + } + return null; + } + public ImageIcon executeRetImageIconMethod(Class<?> c, String _methodName) { // We have a valid plugin. We now need to get the Method diff --git a/src/main/java/ui/util/IconManager.java b/src/main/java/ui/util/IconManager.java index 1c4c67f6e9d49540844467022b9d55dfe1459e3a..1aa19f558a6481a41dfa34ac826c31d7ebdf4c9a 100755 --- a/src/main/java/ui/util/IconManager.java +++ b/src/main/java/ui/util/IconManager.java @@ -198,7 +198,7 @@ public class IconManager { private static String icon8 = "turtle_16.gif"; private static String icon9 = "diplodocus2_16.gif"; - + //Added by Solange private static String icon0 = "hideifce.gif"; //Added by Solange, the component icon