Changes between Version 8 and Version 9 of SCRIPTING_ACTIONS_API_R0
- Timestamp:
- 07/16/09 09:42:52 (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
SCRIPTING_ACTIONS_API_R0
v8 v9 57 57 58 58 == Implementation idea == 59 * Decide whether to expose the model classes (org.sophie2.base.model.book.Book, org.sophie2.base.model.book.Page, org.sophie2.base.model.book.Frame, etc.) or to write facadeclasses.59 * Decide whether to expose the model classes (org.sophie2.base.model.book.Book, org.sophie2.base.model.book.Page, org.sophie2.base.model.book.Frame, etc.) or to write adapter classes. 60 60 * The first approach will make scripts very powerful - the user will be able to do with them everything he/she can do with the application. In addition, it won't be necessary to update the facade every time we change something. 61 61 * The second approach however will be more convenient for the user. It will also solve most of the security issues. … … 96 96 * The swing component should be a panel with the combo box. 97 97 * Register it as an extension 98 * Enum {{{ RunScriptLogic}}} implements {{{OperationDef}}}98 * Enum {{{org.sophie2.extra.func.scripting.logic.RunScriptLogic}}} implements {{{OperationDef}}} 99 99 * Move RUN_SCRIPT from {{{ScriptLogic}}} 100 * ...ACTION_RUN_SCRIPT101 * ...100 * ACTION_RUN_SCRIPT 101 * Use this when activating a {{{RunScriptLinkAction}}}. 102 102 103 103 * For the API: 104 104 * Package {{{org.sophie2.extra.func.scripting.facade}}} 105 105 * Class {{{JSBook}}} extends {{{ScriptableObject}}} 106 * Override {{{getClassName}}} to return "Book". That means that Sophie users will see that name instead of "JSBook". 106 * Override {{{getClassName}}} to return "Book". That means that script writers will use "Book" instead of "JSBook". 107 * Create getters and setters according to the analysis. 108 * For example, for the title write {{{String jsGet_title()}}} and {{{void jsSet_title(String title)}}}. This will allow users to benefit from the easy JavaScript syntax: "book.title = 'Design Patterns'". 107 109 * Class {{{JSPage}}} extends {{{ScriptableObject}}} 108 110 * {{{getClassName}}} returns "Page". 109 111 * Class {{{JSFrame}}} extends {{{ScriptableObject}}} 110 112 * {{{getClassName}}} returns "Frame". 113 * Class {{{JSApp}}} extends {{{ScriptableObject}}} 114 * {{{getClassName}}} returns "App". 115 * Create method {{{JSBook jsFunction_newBook()}}} which 111 116 * In {{{RunScriptLogic}}}: 112 * ... 117 * Use {{{ScriptableObject.defineClass(scope, JSBook.class);}}} to expose a given {{{ScriptableObject}}} to JavaScript. 118 * When executing a script from a document window, expose all adapter and facade classes. When the script is used as a link action, do not expose {{{JSApp}}}. 119 * Use 120 {{{ 121 Scriptable scriptableJsBook = context.newObject(scope, "Book"); 122 ScriptableObject.putProperty(scope, "book", scriptableJsBook); 123 JSBook jsBook = (JSBook) Context.jsToJava(scriptableJsBook, JSBook.class); 124 jsBook.setBook(bookRef); 125 }}} 126 to expose a global variable {{{book}}} which represents the book where the script is created. 127 * Expose the app too, if running a script from a document window. 128 * Limit the scope of visible Java classes to only Rhino classes using {{{context.setClassShutter}}}. 113 129 114 130 * Source code: [source:/branches/private/deni/scripting_actions/]