The Java code editor is shown from the
screens & actions tab or the
form component
editor when you click on the
[...] for a
Java code property.
-
The box above the edit area show the available parameters for the Java code property
as well
as the return type. If parameters or return type are classes (and not primitive types),
they
will be shown as hyperlinks. Clicking on such a hyperlink opens the Javadoc in the
external browser.
If you would not like the default browser to be opened, you can configure your own
browser
in the preferences dialog.
To get more information on classes from the com.install4j.* packages,
please choose Help->Show Javadoc Overview from the menu and read the
help topic for the install4j API.
In addition, the Java code editor offers a code gallery
that contains useful snippets that show you how to get started with using the install4j
API.
The code gallery is invoked from the tool bar or by choosing Code->Insert from Code gallery
from the menu.
A number of packages can be used without using fully-qualified class names. Those
packages are:
- java.util.*
- java.io.*
- javax.swing.*
- com.install4j.api.*
- com.install4j.api.beans.*
- com.install4j.api.context.*
- com.install4j.api.events.*
- com.install4j.api.screens.*
- com.install4j.api.actions.*
- com.install4j.api.formcomponents.*
- com.install4j.api.update.*
- com.install4j.api.windows.*
- com.install4j.api.unix.*
You can put a number of import statements as the first lines in the text area in order
to avoid using fully
qualified class names.
-
Java code properties can be
- expressions
An expression doesn't have a trailing semicolon and evaluates to the required return
type.
Example: !context.isUnattended() && !context.isConsole()
The above example would work as the condition expression of an action and skip the
action for
unattended or console installations.
- scripts
A script consists of a series of Java statements with a return statement of the
required return type as the last statement.
Example: if (!context.getBooleanVariable("enterDetails")) context.goForward(2, true, true);
return true;
The above example would work as the validation expression of a screen and skip two
screens forward
(checking the conditions of the target screen as well as executing the actions of
the current screen)
if the variable with name "enterDetails" is not set to "true".
install4j detects automatically whether you have entered an expression or a script.
-
The primary interface to interact with the installer or uninstaller is the context which is always among
the available parameters. The context provides information about the current installation
and gives access to
variables, screens, actions and other elements of the installation or uninstallation.
The parameter is of
type
-
com.install4j.api.context.InstallerContext for screens and actions in the installation mode
-
com.install4j.api.context.UninstallerContext for screens and actions in the uninstallation mode
-
com.install4j.api.context.Context for form components.
Apart from the context, the action, screen or form component to which the Java code
property belongs is
among the available parameters. If you know the actual class, you can cast to it and
modify the object
as needed.
-
The Java editor offers the following code assistance powered by the eclipse platform:
- Code completion
Pressing CTRL-Space
brings up a popup with code completion proposals. Also, typing
a dot (".") shows this popup after a delay if no other character is typed.
While the popup is displayed, you can continue to type or delete characters with Backspace
and
the popup will be updated accordingly. "Camel-hump completion" is supported, i.e.
typing NPE and
hitting CTRL-Space
will propose NullPointerException among other classes.
If you accept a class that is not automatically imported, the fully qualified name
will be inserted.
The completion popup can suggest:
variables and default parameters. Default parameters are displayed in bold font.
packages (when typing an import statement)
classes
fields (when the context is a class)
methods (when the context is a class or the
parameter list of a method)
You can configure code completion behavior in the Java editor settings.
- Problem analysis
The code that you enter is analyzed on the fly and checked for errors and warning
conditions. Errors are
shown as red underlines in the editor and red stripes in the right gutter. Warnings
(such as an unused variable declaration)
are shown as a yellow backgrounds in the editor and yellow stripes in the right gutter.
Hovering the mouse over an error or
warning in the editor as well as hovering the mouse over a stripe in the gutter area
displays the error
or warning message.
The status indicator at the top of the right gutter is
- green
if there are no warnings or errors in the code.
- yellow
if there are warnings but no errors in the code.
- red
if there are errors in the code. In this case the code will not compile and the installer
cannot be generated.
You can configure the threshold for problem analysis in the Java editor settings.
- Context-sensitive Javadoc
Pressing SHIFT-F1
opens the browser at the Javadoc page that describes the element at the cursor
position. If no corresponding Javadoc can be found, a warning message is displayed.
Javadoc for the
Java runtime library can only be displayed if a design time JDK is configured
and a valid Javadoc location is specified in the design time JDK configuration.
You can set the design time JDK in the Java editor settings
All key bindings in the Java code editor are configurable. Choose Settings->Key Map
to display the Key map editor.
-
Screens, actions and form components are wired together with installer variables, please see the
help topic on screens and actions for more
information. Setting and getting installer variables is done through the context parameter
with the
context.getVariable(String variableName) and
context.setVariable(String variableName, Object value) methods. The convenience method
context.getBooleanVariable(String variableName) makes it easier to check conditions.
Any object can be used as the value for a variable. To use installer variables in
text properties
of actions, screens and form components, write them as
${installer:myVariableName}
.
-
If the gutter icon in the top right corner of the dialog is green, your script is
going to compile unless you
have disabled error analysis in the Java editor settings.
In some situations, you might want to try the actual compilation. Choosing
Code->Test Compile from the menu will compile the
script and display any errors in a separate dialog. Saving your script with the [OK]
button will not test the syntactic correctness of the script. When your install4j
project is compiled, the script
will also be compiled and errors will be reported.