This well structered (and simply extendable) java application can be used, to create a simple user interaction,
to fill some properties or start some other applications/methods, to accomplish the preconditions of any
following main application.
The advantage is, you only define a simple xml file with structered Actions, Inputs , Selections, and you will get a
dialog/controller system, independend of the user interface. The user interface may be a simple text console,
a swing gui, or a html form (created by a Servlet). All items have values, provided by an application environment,
that is nothing more than the model.
Often, people writes its simple 'input masks' with the scripting options of their operation system. This is not
very transparent, not structured, and runs only on one system (like unix or windows).
Start
You can start it through the Shell (shell.bat -->menu),
or you start it through 'java -classpath tsl.jar tsl.tools.menu.AbstractMenu tools/menu/samples/dbeditor.xml'
or : java -jar xmlmenu.jar tools/menu/samples/dbeditor.xml
Command line arguments:
C:\Java\workspace\distributions>java -jar xmlmenu.jar
XmlMenu: Autor Thomas Schneider, Version 0.9, cp 2004
Start : tsl.tools.menu.AbstractMenu {configfile} [ui [serverurl]] [stack]
with :
configfile: xml configuration file with XmlMenu items
ui : user interface class name (e.g.: tsl.tools.menu.GraphicalUI)
stack : command stack or list of autorun commands. e.g.: 0,5,2)
serverurl : if ui is HtmlUI, this is the server url + portnumber
Examples:
tsl.tools.menu.AbstractMenu tools/addressbook.xml tsl.tools.menu.GraphicalUI
tsl.tools.menu.AbstractMenu tools/addressbook.xml tsl.tools.menu.HtmlUI http://localhost:8080/ServletMenu
Configuring the Menu
There are two possibilities to configure the menu:
- in a java environment through thhe methods: AbstractMenu.newInstance(...), menu.add(...), menu.start(...)
- through a given xml configuratioon file (see xsd schema description).
Each menu item can have childs of type menu (-->submenu), and each menu can be one of the following types:
- Action : starts a given java expression
- Option : is only an option (through its name) for the calling parent-menu
- Input : input value with validation (through a class with String constructor( f.e.: Integer(String) )
- Selection : has submenus (childs), can build a dialog (submenus of type Input or Option)
- ActionSelection: combination of Action and Selection. The started Action will fill
the childs to be a selection.
- DynamicSelection: extended ActionSelection. Enables you to create child menus dynamically on runtime
through your own controller class.
The base configuration tag can have extended Properties. Some
main and some properties referring to the selected userinterface.
Main Properties:
- file : where to save the result table (default: menu_result.xml)
- userinterface: type of output and user interaction (extendable!)
tsl.tools.menu.TerminalUI = text terminal (default)
tsl.tools.menu.GraphicalUI = swing gui
tsl.tools.menu.HtmlUI = Serverside Servlet with html forms
- controller: full path to your class, working as a controller for the menu.
The class has to have a constructor with parameter java.util.Map!
The controller can be access through the attribute @controller.
See example tools/dbeditor.xml --> tsl.tools.menu.util.DBMapper
- stack:
TerminalUI:
- style : style of text dialogs
text = simple text lines
bar = solid bars
line = simple line
doubleline = double line (default)
darkgraybar = dark gray bars
graybar = medium gray bars
lightgraybar = light gray bars
- width : maximal count of characters per line (width of text console)
- height : maximal count of lines (height of text console)
HtmlUI:
- url : server url containing the Service 'ServletMenu' (f.e.: http://myhost:8080/ServletMenu)
Each menu item can have a name, a title, an initializing value.
You set a flag, marking a menu item as a duty field:
duty = "true".
A simple predefined character marks the type type of item:
+: This item contains a subselection (submenus)
!: This item is only an action
*: This item is only an input mask for one value
: This item is a pure option for the parent selection
ยง: Duty field
The Visibility:
Normally, all items are visible. But You can set the property depends.
This evaluates the visibility of an item.
For example:
1. depends = "user=Admin.*"
If there is already defined a property with name (or key) 'user' (inside
the AbstractMenu-System-Map), and the value matches the regular expression
'Admin.*' , the item is visible!
2. depends = "user"
If there is already defined a property with name (or key) 'user' (inside
the AbstractMenu-System-Map) the item is visible!
Extended properties refer to the type of menu.
Selection
The selection holds a number of child menus. This child menus
can be of any type (input, selection, action, option, actionselection, dynamicselection).
The userinterface-classes divide simple selections (having no child selections) and complex
selections to represent simple or complex dialogs.
extended properties:
- actionAfterSelection: optional action to be executed after selecting a child element.
The selection has to extensions. The ActionSelection and the DynamicSelection.
ActionSelection
This is an Action, that will be a Selection, after activation. Means, that the
started action have to return something (Array, Collection, Map) that can be
showed as simple Options.
DynamicSelection
The DynamicSelection is an extension of the ActionSelection. The ActionSelection only shows
simple options, generated on runtime, the DynamicSelection shows child menus of any type, created
on runtime.
Input
You can set a validator for the user input.
For example:
validator = "java.lang.Integer"
This means, the inputted text has to be convertable to a integer object.
Basic java types (validators) are:
- java.lang.Integer
- java.lang.Float
- java.lang.Double
- java.lang.Boolean
- java.lang.String
- java.lang.Character
- java.util.Date
But if you need a more specific one, implement and use your own one.
This one has to have a constructor with one parameter of type java.lang.Sting.
Action
The action has to have an expression to start.
For example:
expression = "tsl.tools.shell.TslShell.getFiles(@user.home, *.*, false, false)"
starts the method 'getFiles' of the class 'TslShell' with the
parameters:
@user.home: the '@' marks this as a variable, that will be searched inside the environment.
*.*: simple parameter of type String
false: simple parameter of type boolean
The return value of the started expression will be stored inside the given
result map and it will be returned to the calling (parent) menu item.
Option
Nothing more needed! The option has to be a child of a selection. It is the simpliest object only holding its
name and label. On selecting one option, the result is the name or label of the option. The parent selection
will have this result as value.
The Terminal Menu
The Swing Menu
Your interaction is to select (with keyboard or mouse) a table line, representing a menu item,
followed by a click to the ok button. If you don't select any item, the ok button click will
result in closing this menu item and going back to the previous one.
The Html Menu
The Html menu is not as easy as the other user interfaces, because it creates a conversation between
a client and a server. To use it in this way, you need a server, providing the service 'ServletMenu'.
You can do this for example, starting tomcat or jboss together with tomcat. You have to copy the file
'ServletMenu.war' into the deploy directory of the jboss or tomcat.
This may be ...jboss/server/default/deploy/
Then you start the jboss in the bin directory (on windows systems: ...jboss/bin/run.bat).
For the client side, you have to do the same as you do with the other user interfaces (see Start).
An alternative is to start the menu through your browser. Enter the url of the server, providing the 'SerlvetMenu'.
For example: http://localhost:8080/ServletMenu
The ServletMenu reads and presentates at first the menulist.xml. There you can select the menu configuration file to start.
You have two possibilities to interact:
- Using the input form: Input the desired menu number and hit the submit button
- Following the link in the first column (representing the menu number)