Home
Categories
Dictionnary
Download
Project Details
Changes Log
FAQ
License

ScriptManager configuration



The ScriptManager is the main class which is responsible for managing XUL content:
  • By default the parsing of XUL files will not check the validity of the files compared to the XUL grammar. it is possible to set the the files will be validated and also to popup a window if the validation is incorrect rather than show the errors on the command-line
  • By default exceptions encountered in the scripts (for example, a command which refer to a not existing script function) will be shown on the command-line. It is possible to set that they will be shown on an error window, with the associated Stack trace of the exception in the script
  • By default echo instructions (such as print in Javascript) encountered in the scripts will be shown on the command-line. it is possible to specify a logger to log the result of these instructions on a Swing component
  • By default scripts defined for a XUL file are local to this XUL file. However it is possible to specify that scripts are global to all XUL files
  • By default only Javascript scripts can be triggered by widget events. However it is possible to set that all scripts referenced in a XUL document can be triggered by widget events
  • We can set a custom ScriptContext to the manager
  • We can set a custom ScriptFactory to the manager to customize the interface the scripts will have to implement

Checking the validity of XUL files

It is possible to check the validity of the XUL files compared to the XUL schema by using the ScriptManager.validateXULSchema(boolean) method.

Note that:
  • Detecting that a schema is invalid won't change the way the tree is constructed. The result is just an information for the user
  • By default the errors detected during the validation will be shown on the error stream
You can specify that the errors detected during the validation are shown on a swing popup window by the ScriptManager.setParserErrorReporter(ParserErrorReporter) method

The SwingParserErrorReporter will popup a swing window with the errors. For example:

      ScriptManager manager = new DefaultScriptManager();
      manager.validateXULSchema(true);
      manager.setParserErrorReporter(new SwingParserErrorReporter());      

Setting scripts as global to all XUL files

By default scripts defined for a XUL file are local to this XUL file, which means that if you reference the same external script in two XUL files, it will be two different scripts.

However you can specify the loading type of the script manager by ScriptManager.setScriptsLoadingType(short) to set the loading type of the scripts to be ScriptManager.LOADING_GLOBAL. In this case if you reference the same script in two XUL files, it will be the same instance. It can be useful if you want to use a global context for all your XUL files.

Allow all scripts to be triggered by widget events


By default only Javascript scripts can be triggered by widget events.

However it is possible to set that all scripts referenced in a XUL document can be triggered by widget events by ScriptManager.listAllScriptTypes(boolean)

Showing exceptions in a swing popup window


Rather than showing exceptions encountered in the scripts on the error stream, it is possible to set that they will be shown on an error window, with the associated Stack trace of the exception in the script. You can specify the component which will show the exceptions by ScriptManager.setScriptExceptionListener(ScriptExceptionListener) method.

The org.scripthelper.swing.SwingExceptionListener.SwingExceptionListener will show the StackTrace of the exception[1]
You will need to add scriptHelperSwing.jar in the classpath of your IDE to compile. You however don't need to put it on the classpath of your application, because scriptHelperSwing.jar is referenced in javaXUL.jar manifest
. For example:

      ScriptManager manager = new DefaultScriptManager();
      manager.setScriptExceptionListener(new SwingExceptionListener());      

Showing echo messages in a swing component

Main Article: ScriptLogger

Rather than having the message printed on the output stream, you can show the messages on a logger window or a logger area component by the ScriptManager.setScriptLogger(ScriptLogger) method:
  • The org.scripthelper.swing.DefaultSwingScriptLogger is a frame[1]
    You will need to add scriptHelperSwing.jar in the classpath of your IDE to compile. You however don't need to put it on the classpath of your application, because scriptHelperSwing.jar is referenced in javaXUL.jar manifest
  • The org.scripthelper.swing.DefaultSwingScriptLoggerArea is a component which you can integrate in your application[1]
    You will need to add scriptHelperSwing.jar in the classpath of your IDE to compile. You however don't need to put it on the classpath of your application, because scriptHelperSwing.jar is referenced in javaXUL.jar manifest

Setting a custom ScriptContext


It is possible to use a custom ScriptContext for the scripts.

Setting a custom ScriptFactory


It is possible to use your own ScriptFactory rather than the default.

Notes

  1. ^ [1] [2] [3] You will need to add scriptHelperSwing.jar in the classpath of your IDE to compile. You however don't need to put it on the classpath of your application, because scriptHelperSwing.jar is referenced in javaXUL.jar manifest

See also


Categories: api

Copyright 2008-2020 Herve Girod. All Rights Reserved. Documentation and source under the LGPL licence