We designed the RPE Launcher User Interface to be a generic, good for all UI that would be easily used by any RPE user. And while we met the first goal, the UI is indeed very generic, we haven’t really made the UI as simple as many users were expecting.
One of the things requested often is the ability to prompt the end-user ( the person generating the documents) to enter the variable values. We are working to improve the RPE user experience but in the meantime there is a nice little trick that provides “variable prompts” to any RPE version.
The code uses Swing and this means it is quite different from the RPE Launcher/Studio UI which uses Eclipse JFace and SWT. And while the JFace/SWT UI looks better and is faster, for the task at hand Swing is to be preferred since its much simpler to code from Java Script.
To get a variable value from the user the simplest code to use in the variable’s assignment expression is :
// you can calculate this value var defaultValue = "Some value"; // the first argument is the label of the editor field while the second is the default value to put in the field var input = javax.swing.JOptionPane.showInputDialog('Enter the value for the XYZ variable : ', defaultValue); // return the value provided by the user input;
There are various flavors of the showInputDialog function including one that allows the user to select the value from a list instead of typing it and customize other aspects of the dialog such as it’s title and icon.
var options = new java.util.ArrayList(); options.add( "Project A"); options.add( "Project X"); options.add( "Project Z"); // 1st argument is parent component - use null // 2nd argument is the label of the selection // 3rd argument is the dialog's title // 4th argument is the message type // 5th argument is the icon - if null a default icon matching the message type will be used // 6th is the list of values // 7th argument is the initial value to select from the list var input = javax.swing.JOptionPane.showInputDialog( null, 'Select the the project to use: ', 'RPE Variable Prompt', javax.swing.JOptionPane.QUESTION_MESSAGE, null, options.toArray(), "Project X"); // debug message java.lang.System.out.println( "You entered: " + input); // return the value provided by the user input;
This results in the following dialog being shown to the user:
The example template is available here. In the example I ask for the name of the author of the document, which the user has to type, and a project name which the user can select from a list. For the default value of the author’s name I use the login name of the current user as obtained from the system.For debug purposes I print the value read from the user in the console.
NOTE if you want to use this technique on your templates I suggest grouping all the assignments at the beginning of the template so that document generations are not waiting for an answer from a user that left to grab a cup of coffee expecting the document will be finished by the time he/she returns. Another recommendation is to mark the variable as internal such that it does not show up in the Document Specification view.