Changes between Version 10 and Version 11 of GROUP_SCRIPTING_R0
- Timestamp:
- 07/11/09 11:05:51 (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
TabularUnified GROUP_SCRIPTING_R0
v10 v11 56 56 * RwProp<String> scriptText - the javascript source code text 57 57 * subpackage {{{persistence}}} 58 * class {{{Script Persister}}} extends {{{Persister<String, Storage>}}}58 * class {{{ScriptResPersister}}} extends {{{Persister<String, Storage>}}} 59 59 * schema "resource:script|storage|r3" 60 60 * the storage should have one child for the script text 61 61 * this persister is needed when the parent book is persisted. 62 * class {{{ScriptFilePersister}}} extends {{{Persister<Storage, File>}}} 63 * schema "storage|file|js" 64 * the script is persisted as a plain text file with ".js" extension 65 * register the persisters as extensions 62 * register the persister as an extension 66 63 67 64 * view: … … 71 68 * INSERT_SCRIPT_FILE 72 69 * RUN_SCRIPT 73 * EDIT_SCRIPT 70 * TEXT_CHANGED 71 * OPEN_WINDOW 74 72 * document window for resource viewing, editing and running: 75 73 * class {{{ScriptDocumentWindow}}} extends {{{DefaultDocumentWindow}}} implements {{{DocumentView}}} 76 * RwProp<ResourceRef> model - the script resource that is displayed 74 * In DocumentWindow add Prop<ResourceRef> modelDocument() 75 * RwProp<ResourceRef> modelDocument - the script resource that is displayed 77 76 * resource property {{{swingFrameSync}}} that adds the following components to {{{swingComponent}}}: 78 * a text area that fires EDIT_SCRIPT 79 * and "Run" {{{LogicR3Button}}} that fires RUN_SCRIPT 77 * a text area that fires TEXT_CHANGED 78 * "Run" {{{LogicR3Button}}} that fires RUN_SCRIPT 79 * a text area for the script result or error messages 80 80 * class {{{ScriptDocumentWindowProvider}}} implements {{{DocumentWindowProvider}}} (see last section) 81 81 * getWindow should return a new {{{ScriptDocumentWindow}}} for the given script resource … … 85 85 * {{{getResourceKind()}}} should return the kind in {{{ScriptResource}}} 86 86 * {{{filterKind()}}} should return "Script" 87 * nested private static class {{{ScriptResourcePreview}}}87 * nested static class {{{ScriptResourcePreview}}} which is a {{{SwingVisualElement}}} 88 88 * constructor with argument of type {{{ScriptResource}}} 89 * in {{{swingComponent}}} create a new JPanel, analogic to the panel in {{{ScriptDocumentWindow}}} 90 * components should fire the same events as in {{{ScriptDocumentWindow}}} 89 * in {{{swingComponent}}} create a new JPanel with: 90 * read-only JTextArea that displays the script content 91 * "Open" LogicR3Button that fires OPEN_WINDOW 91 92 * {{{getVisualElement(Resource element)}}} should return a new instance of {{{ScriptResourcePreview}}} 93 * In ResourceDetailsPalette create a property RwProp<SwingVisualElement> previewVisualElement 94 * use @Own annotation because the parent is required in the logic of OPEN_WINDOW 92 95 * register the class as an extension 93 96 94 97 * logic: 95 98 * enum ScriptingLogic that implements OperationDef: 96 * all of the following items should listen for an event with the sameid99 * all of the following items should listen for an event with the corresponding id 97 100 * INSERT_SCRIPT 98 101 * listens for the event in {{{InsertScriptItem}}} 99 102 * creates a new empty {{{ScriptResource}}} in current book (use {{{CurrentBookUtil.getCurrentBook}}}) 100 103 * adds it to {{{App.documents}}} (see last section for details) 104 * sets it as current 101 105 * INSERT_SCRIPT_FILE 102 106 * listens for the event in {{{InsertScriptFileItem}}} … … 104 108 * using the persisters, creates a new {{{ScriptResource}}} in current book 105 109 * adds it to {{{App.documents}}} (see last section) 110 * sets it as current 106 111 * RUN_SCRIPT 107 112 * write the following temporary solution: … … 109 114 * initialize the standard objects (Object, Function, etc.) using {{{Scriptable scope = cx.initStandardObjects();}}} 110 115 * evaluate the resource's text: {{{Object result = cx.evaluateString(scope, s, "<cmd>", 1, null);}}} 111 * if there's a result, open a message box to display the result by creating a new {{{MessageDialogInput}}} and invoking {{{DialogManager#showDialog}}} 116 * display the result in the result text area. 117 * if org.mozilla.javascript.EcmaError or org.mozilla.javascript.EvaluatorException is thrown, display the message in the result text area 112 118 * exit from the context with {{{Context.exit();}}}. Call this from a finally block. 113 * EDIT_SCRIPT119 * TEXT_CHANGED 114 120 * the following solution can be optimized: 115 * create a new AutoChange that changes the text in the resource with that from the text area. Register the change to script's book. 121 * create a new AutoChange that changes the text in the resource with that from the text area. Register the change to the script resource. 122 * OPEN_WINDOW 123 * get the source which is of type {{{ScriptResourcePreview}}} 124 * add its model to the list {{{App.documents}}}, but only if it is not already added 125 * set the document as current 116 126 * register the enum as an extension 117 127 … … 120 130 * Create an interface {{{org.sophie2.main.app.commons.windows.DocumentWindowProvider}}} 121 131 * String getResourceKind() - Gets the resource kind of the resource for which this provider should create appropriate document window. 122 * DocumentWindow getWindow(ResourceRef ref) - Creates a new concrete implementation of {{{DocumentWindow}}} for the given resource.132 * DocumentWindowProvider getWindowProvider(ResourceRef ref) - Creates a new concrete implementation of {{{DocumentWindowProvider}}} for the given resource. 123 133 * Create an extension point in {{{MainAppModule}}} for document window providers 124 134 * Class {{{org.sophie2.main.app.commons.windows.BookDocumentWindowProvider}}} implements {{{DocumentWindowProvider}}} and creates book document windows 125 135 * Register it as an extension 126 136 * Class {{{org.sophie2.main.app.commons.windows.DocumentWindowProviderFactory}}} 127 * static DocumentWindow createWindow(ResourceRef ref)137 * static DocumentWindowProvider getWindowProvider(ResourceRef ref) 128 138 * iterates over all extensions in the extension point 129 * if an appropriate provider is found, creates a document window with it 130 * Remove the properties {{{currentBook}}} and {{{lastCurrentBook}}} in {{{App}}}. 131 * Create analogical property {{{lastCurrentWindow}}} in {{{AppDocumentsDesktop}}}. 132 * Refactor the {{{AppDocumentsDesktop.currentWindow}}}. 133 * Replace all calls of currentBook with calls of currentWindow. 134 * On book closing close all children resources too (currently they can be scripts). 139 * if an appropriate provider is found, returns it 140 * Refactor {{{AppDocumentsDesktop.windows}}}: 141 * create a class DocumentInfo that has two fields - ResourceRef ref and DocumentWindowProvider provider 142 * create a hash map with keys of type DocumentInfo and values of type DocumentWindow 143 * override equals and hashCode methods 144 * create a hashCode in ResourceRef too 145 * replace the TrackingProList with ComposingProList 146 * iterate over all open documents and use the factory to find the appropriate provider 147 * if the cache (the hash map) contains DocumentInfo with these resource reference and provider, return the window 148 * if not, create a new window with the factory and store it in the cache 135 149 136 150 * Source code: [source:/branches/private/deni/scripting/] 151 * Tests: [source:/branches/private/deni/scripting/modules/org.sophie2.extra.func.scripting/src/test/java/org/sophie2/extra/func/scripting] 137 152 138 153 = Implementation = 139 ^(Describe and link the implementation results here (from the wiki or the repository).)^ 154 * Source code: [source:/branches/private/deni/scripting/] 140 155 141 156 = Testing =