diff options
author | Tim Buschtöns | 2013-08-02 17:34:27 +0000 |
---|---|---|
committer | Tim Buschtöns | 2013-08-02 17:34:27 +0000 |
commit | 6421325a6e7f3bfe7e650a7cfda50d79d1ca9ad4 (patch) | |
tree | 758f72f7dbf0e99f018357d8e51d5b0e9217f8e6 | |
parent | 8c71d4164e6f6047f356df68c979e97f9be9fa4a (diff) | |
download | org.eclipse.rap.incubator.clientscripting-6421325a6e7f3bfe7e650a7cfda50d79d1ca9ad4.tar.gz org.eclipse.rap.incubator.clientscripting-6421325a6e7f3bfe7e650a7cfda50d79d1ca9ad4.tar.xz org.eclipse.rap.incubator.clientscripting-6421325a6e7f3bfe7e650a7cfda50d79d1ca9ad4.zip |
Refactor EventBinding and EventBindingHandler.js
6 files changed, 166 insertions, 149 deletions
diff --git a/bundles/org.eclipse.rap.clientscripting/js/rwt/scripting/EventBinding.js b/bundles/org.eclipse.rap.clientscripting/js/rwt/scripting/EventBinding.js index 2b77613..3d1399c 100644 --- a/bundles/org.eclipse.rap.clientscripting/js/rwt/scripting/EventBinding.js +++ b/bundles/org.eclipse.rap.clientscripting/js/rwt/scripting/EventBinding.js @@ -13,68 +13,58 @@ rwt.qx.Class.createNamespace( "rwt.scripting", {} ); -rwt.scripting.EventBinding = function( source, eventType, targetFunction ) { - var ClientScriptingUtil = rwt.scripting.ClientScriptingUtil; - try { - this._eventType = eventType; - this._source = source; - this._public = ClientScriptingUtil.isPublicObject( source ); - this._targetFunction = targetFunction; - if( this._public ) { - this._eventSource = source; - this._nativeType = eventType; - } else { - this._nativeType = ClientScriptingUtil.getNativeEventType( source, this._eventType ); - this._eventSource = ClientScriptingUtil.getNativeEventSource( source, this._eventType ); - } - this._bind(); - } catch( ex ) { - throw new Error( "Could not create EventBinding " + eventType + ":" + ex.message ); - } -}; +var ClientScriptingUtil = rwt.scripting.ClientScriptingUtil; +var SWT = rwt.scripting.SWT; -rwt.scripting.EventBinding.prototype = { +var wrapperRegistry = {}; - _bind : function() { - if( this._public ) { - this._eventSource.addListener( this._nativeType, this._targetFunction ); - } else { - this._eventSource.addEventListener( this._nativeType, this._processEvent, this ); - } - }, +// TODO : better name? +rwt.scripting.EventBinding = { - _unbind : function() { - if( this._public ) { - this._eventSource.removeListener( this._nativeType, this._targetFunction ); - } else { - this._eventSource.removeEventListener( this._nativeType, this._processEvent, this ); + addListener : function( widget, eventType, targetFunction ) { + var wrapperKey = this._getWrapperKey( widget, eventType, targetFunction ); + if( wrapperRegistry[ wrapperKey ] == null ) { + var nativeType = ClientScriptingUtil.getNativeEventType( widget, eventType ); + var nativeSource = ClientScriptingUtil.getNativeEventSource( widget, eventType ); + var wrappedListener = this._wrapListener( widget, eventType, targetFunction ); + nativeSource.addEventListener( nativeType, wrappedListener, window ); + wrapperRegistry[ wrapperKey ] = wrappedListener; } }, - _processEvent : function( event ) { - try { - var EventProxy = rwt.scripting.EventProxy; - var ClientScriptingUtil = rwt.scripting.ClientScriptingUtil; - var SWT = rwt.scripting.SWT; - var eventProxy = new EventProxy( SWT[ this._eventType ], this._source, event ); - var wrappedEventProxy = ClientScriptingUtil.wrapAsProto( eventProxy ); - this._targetFunction( wrappedEventProxy ); - ClientScriptingUtil.postProcessEvent( eventProxy, wrappedEventProxy, event ); - EventProxy.disposeEventProxy( eventProxy ); - } catch( ex ) { - var msg = "Error in ClientScripting event type "; - throw new Error( msg + this._eventType + ": " + ex.message ? ex.message : ex ); + removeListener : function( widget, eventType, targetFunction ) { + var wrapperKey = this._getWrapperKey( widget, eventType, targetFunction ); + if( wrapperRegistry[ wrapperKey ] != null ) { + var nativeType = ClientScriptingUtil.getNativeEventType( widget, eventType ); + var nativeSource = ClientScriptingUtil.getNativeEventSource( widget, eventType ); + var wrappedListener = wrapperRegistry[ wrapperKey ]; + nativeSource.removeEventListener( nativeType, wrappedListener, window ); + wrapperRegistry[ wrapperKey ] = null; } }, - getType : function() { - return this._eventType; + _wrapListener : function( widget, eventType, targetFunction ) { + return function( nativeEvent ) { + try { + var eventProxy = new rwt.scripting.EventProxy( SWT[ eventType ], widget, nativeEvent ); + var wrappedEventProxy = ClientScriptingUtil.wrapAsProto( eventProxy ); + targetFunction( wrappedEventProxy ); + ClientScriptingUtil.postProcessEvent( eventProxy, wrappedEventProxy, nativeEvent ); + rwt.scripting.EventProxy.disposeEventProxy( eventProxy ); + } catch( ex ) { + var msg = "Error in scripting event type "; + throw new Error( msg + eventType + ": " + ex.message ? ex.message : ex ); + } + }; }, - dispose : function() { - this._unbind(); - this._source = null; - this._targetFunction = null; + _getWrapperKey : function( widget, eventType, targetFunction ) { + var result = [ + rwt.qx.Object.toHashCode( widget ), + eventType, + rwt.qx.Object.toHashCode( targetFunction ) + ]; + return result.join( ":" ); } }; diff --git a/bundles/org.eclipse.rap.clientscripting/js/rwt/scripting/handler/EventBindingHandler.js b/bundles/org.eclipse.rap.clientscripting/js/rwt/scripting/handler/EventBindingHandler.js index 496b42f..c6a214d 100644 --- a/bundles/org.eclipse.rap.clientscripting/js/rwt/scripting/handler/EventBindingHandler.js +++ b/bundles/org.eclipse.rap.clientscripting/js/rwt/scripting/handler/EventBindingHandler.js @@ -11,18 +11,36 @@ (function(){ +var ObjectRegistry = rwt.remote.ObjectRegistry; +var EventBinding = rwt.scripting.EventBinding; + rwt.remote.HandlerRegistry.add( "rwt.scripting.EventBinding", { factory : function( properties ) { - var ObjectRegistry = rwt.remote.ObjectRegistry; - var EventBinding = rwt.scripting.EventBinding; var source = ObjectRegistry.getObject( properties.targetObject ); + var isPublic = rwt.scripting.ClientScriptingUtil.isPublicObject( source ); var eventType = properties.eventType; var targetFunction = ObjectRegistry.getObject( properties.listener ); - return new EventBinding( source, eventType, targetFunction ); + if( isPublic ) { + source.addListener( eventType, targetFunction ); + } else { + EventBinding.addListener( source, eventType, targetFunction ); + } + return { + "isPublic" : isPublic, + "eventType" : eventType, + "source" : source, + "targetFunction" : targetFunction + }; }, - destructor : "dispose" + destructor : function( binding ) { + if( binding.isPublic ) { + binding.source.removeListener( binding.eventType, binding.targetFunction ); + } else { + EventBinding.removeListener( binding.source, binding.eventType, binding.targetFunction ); + } + } } ); diff --git a/bundles/org.eclipse.rap.clientscripting/src/org/eclipse/rap/clientscripting/internal/resources/ClientScriptingResources.java b/bundles/org.eclipse.rap.clientscripting/src/org/eclipse/rap/clientscripting/internal/resources/ClientScriptingResources.java index e989586..c76b0e0 100644 --- a/bundles/org.eclipse.rap.clientscripting/src/org/eclipse/rap/clientscripting/internal/resources/ClientScriptingResources.java +++ b/bundles/org.eclipse.rap.clientscripting/src/org/eclipse/rap/clientscripting/internal/resources/ClientScriptingResources.java @@ -28,8 +28,8 @@ public final class ClientScriptingResources { private static final String[] ALL_RESOURCES = { "SWT.js", "ClientScriptingUtil.js", - "handler/EventBindingHandler.js", "EventBinding.js", + "handler/EventBindingHandler.js", "EventProxy.js", "FunctionFactory.js", "handler/FunctionHandler.js", diff --git a/tests/org.eclipse.rap.clientscripting.jstest/js/org/eclipse/rap/clientscripting/EventBinding_Test.js b/tests/org.eclipse.rap.clientscripting.jstest/js/org/eclipse/rap/clientscripting/EventBinding_Test.js index 7f06b07..134fa84 100644 --- a/tests/org.eclipse.rap.clientscripting.jstest/js/org/eclipse/rap/clientscripting/EventBinding_Test.js +++ b/tests/org.eclipse.rap.clientscripting.jstest/js/org/eclipse/rap/clientscripting/EventBinding_Test.js @@ -15,7 +15,7 @@ var EventBinding = rwt.scripting.EventBinding; var EventProxy = rwt.scripting.EventProxy; var TestUtil = org.eclipse.rwt.test.fixture.TestUtil; var Processor = rwt.remote.MessageProcessor; -var ObjectManager = rwt.remote.ObjectRegistry; +var ObjectRegistry = rwt.remote.ObjectRegistry; var SWT = rwt.scripting.SWT; var EventHandlerUtil = rwt.event.EventHandlerUtil; @@ -28,39 +28,11 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", { members : { - testCreateBindingByProtocol : function() { - var code = "var handleEvent = function(){};"; - Processor.processOperation( { - "target" : "w4", - "action" : "create", - "type" : "rwt.scripting.Function", - "properties" : { - "scriptCode" : code, - "name" : "handleEvent" - } - } ); - - Processor.processOperation( { - "target" : "w5", - "action" : "create", - "type" : "rwt.scripting.EventBinding", - "properties" : { - "eventType" : "KeyDown", - "targetObject" : "w3", - "listener" : "w4" - } - } ); - - var result = ObjectManager.getObject( "w5" ); - assertTrue( result instanceof EventBinding ); - assertIdentical( "KeyDown", result.getType() ); - }, - testBindKeyEvent : function() { TestUtil.flush(); var logger = this._createLogger(); - new EventBinding( text, "KeyDown", logger ); + this._bindByProtocol( text, "KeyDown", logger ); TestUtil.press( text, "A" ); assertEquals( 1, logger.log.length ); @@ -69,19 +41,17 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", { testDisposeBindKeyEvent : function() { var logger = this._createLogger(); - var binding = new EventBinding( text, "KeyDown", logger ); - binding.dispose(); + this._bindByProtocol( text, "KeyDown", logger ); + this._unbindByProtocol(); TestUtil.press( text, "A" ); assertEquals( 0, logger.log.length ); - assertNull( binding._source ); - assertNull( binding._targetFunction ); }, testBindCreatesProxyEvent : function() { var logger = this._createLogger(); - new EventBinding( text, "KeyDown", logger ); + this._bindByProtocol( text, "KeyDown", logger ); TestUtil.press( text, "A" ); var event = logger.log[ 0 ]; @@ -91,7 +61,7 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", { testBindDisposesProxyEvent : function() { var logger = this._createLogger(); - new EventBinding( text, "KeyDown", logger ); + this._bindByProtocol( text, "KeyDown", logger ); TestUtil.press( text, "A" ); var event = logger.log[ 0 ]; @@ -103,7 +73,7 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", { event.doit = false; }; - new EventBinding( text, "KeyDown", listener ); + this._bindByProtocol( text, "KeyDown", listener ); var domEvent = TestUtil.createFakeDomKeyEvent( text.getElement(), "keypress", "a" ); TestUtil.fireFakeDomEvent( domEvent ); @@ -115,7 +85,7 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", { event.doit = false; }; - new EventBinding( text, "MouseDown", listener ); + this._bindByProtocol( text, "MouseDown", listener ); var domEvent = TestUtil.createFakeDomKeyEvent( text.getElement(), "keypress", "a" ); TestUtil.fireFakeDomEvent( domEvent ); @@ -127,7 +97,7 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", { TestUtil.flush(); var logger = this._createLogger(); - var binding = new EventBinding( text, "KeyUp", logger ); + this._bindByProtocol( text, "KeyUp", logger ); TestUtil.keyDown( textEl, "A" ); assertEquals( 0, logger.log.length ); TestUtil.keyUp( textEl, "A" ); @@ -140,7 +110,7 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", { text.blur(); var logger = this._createLogger(); - new EventBinding( text, "FocusIn", logger ); + this._bindByProtocol( text, "FocusIn", logger ); text.focus(); assertEquals( 1, logger.log.length ); @@ -150,7 +120,7 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", { text.focus(); var logger = this._createLogger(); - new EventBinding( text, "FocusOut", logger ); + this._bindByProtocol( text, "FocusOut", logger ); text.blur(); assertEquals( 1, logger.log.length ); @@ -159,7 +129,7 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", { testBindMouseDown : function() { var logger = this._createLogger(); - new EventBinding( text, "MouseDown", logger ); + this._bindByProtocol( text, "MouseDown", logger ); TestUtil.fakeMouseEventDOM( textEl, "mousedown" ); assertEquals( 1, logger.log.length ); @@ -169,7 +139,7 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", { var logger = this._createLogger(); TestUtil.fakeMouseEventDOM( textEl, "mousedown" ); - new EventBinding( text, "MouseUp", logger ); + this._bindByProtocol( text, "MouseUp", logger ); TestUtil.fakeMouseEventDOM( textEl, "mouseup" ); assertEquals( 1, logger.log.length ); @@ -179,7 +149,7 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", { var logger = this._createLogger(); TestUtil.fakeMouseEventDOM( textEl, "mouseover" ); - new EventBinding( text, "MouseMove", logger ); + this._bindByProtocol( text, "MouseMove", logger ); TestUtil.fakeMouseEventDOM( textEl, "mousemove" ); assertEquals( 1, logger.log.length ); @@ -188,7 +158,7 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", { testBindMouseEnter : function() { var logger = this._createLogger(); - new EventBinding( text, "MouseEnter", logger ); + this._bindByProtocol( text, "MouseEnter", logger ); TestUtil.fakeMouseEventDOM( textEl, "mouseover" ); assertEquals( 1, logger.log.length ); @@ -198,7 +168,7 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", { var logger = this._createLogger(); TestUtil.fakeMouseEventDOM( textEl, "mouseover" ); - new EventBinding( text, "MouseExit", logger ); + this._bindByProtocol( text, "MouseExit", logger ); TestUtil.fakeMouseEventDOM( textEl, "mouseout" ); assertEquals( 1, logger.log.length ); @@ -208,7 +178,7 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", { var logger = this._createLogger(); text.setVisibility( false ); - new EventBinding( text, "Show", logger ); + this._bindByProtocol( text, "Show", logger ); text.setVisibility( true ); assertEquals( 1, logger.log.length ); @@ -218,7 +188,7 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", { var logger = this._createLogger(); text.setVisibility( true ); - new EventBinding( text, "Hide", logger ); + this._bindByProtocol( text, "Hide", logger ); text.setVisibility( false ); assertEquals( 1, logger.log.length ); @@ -228,7 +198,7 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", { TestUtil.flush(); var logger = this._createLogger(); - new EventBinding( text, "Verify", logger ); + this._bindByProtocol( text, "Verify", logger ); this._inputText( text, "goo" ); assertEquals( 1, logger.log.length ); @@ -238,8 +208,8 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", { TestUtil.flush(); var logger = this._createLogger(); - var binding = new EventBinding( text, "Verify", logger ); - binding.dispose(); + this._bindByProtocol( text, "Verify", logger ); + this._unbindByProtocol(); this._inputText( text, "goo" ); assertEquals( 0, logger.log.length ); @@ -254,7 +224,7 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", { textValue = event.widget.getText(); }; - new EventBinding( text, "Verify", handler ); + this._bindByProtocol( text, "Verify", handler ); this._inputText( text, "bar" ); assertEquals( "bar", text.getValue() ); @@ -268,7 +238,7 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", { event.doit = false; }; - new EventBinding( text, "Verify", handler ); + this._bindByProtocol( text, "Verify", handler ); this._inputText( text, "bar" ); assertEquals( "foo", text.getValue() ); @@ -282,7 +252,7 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", { event.doit = false; }; - new EventBinding( text, "Verify", handler ); + this._bindByProtocol( text, "Verify", handler ); this._inputText( text, "foobarxxx", [ 3, 3 ] ); assertEquals( 3, text._getSelectionStart() ); @@ -296,7 +266,7 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", { event.type = "boom"; } ; - new EventBinding( text, "Verify", handler ); + this._bindByProtocol( text, "Verify", handler ); this._inputText( text, "bar" ); assertEquals( "bar", text.getValue() ); @@ -309,7 +279,7 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", { event.text = "bar"; }; - new EventBinding( text, "Verify", handler ); + this._bindByProtocol( text, "Verify", handler ); this._inputText( text, "foob", [ 3, 3 ] ); assertEquals( "foobar", text.getValue() ); @@ -322,7 +292,7 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", { event.text = "bar"; } ; - new EventBinding( text, "Verify", handler ); + this._bindByProtocol( text, "Verify", handler ); this._inputText( text, "foxo", [ 2, 2 ] ); assertEquals( "fobaro", text.getValue() ); @@ -337,7 +307,7 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", { event.text = "bar"; } ; - new EventBinding( text, "Verify", handler ); + this._bindByProtocol( text, "Verify", handler ); this._inputText( text, "fxo", [ 1, 2 ] ); assertEquals( "fbaro", text.getValue() ); @@ -354,7 +324,7 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", { selection = event.widget.getSelection(); }; - new EventBinding( text, "Verify", handler ); + this._bindByProtocol( text, "Verify", handler ); this._inputText( text, "foxo", [ 2, 2 ] ); assertEquals( 5, text._getSelectionStart() ); @@ -371,7 +341,7 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", { selection = event.widget.getSelection(); } ; - new EventBinding( text, "Verify", handler ); + this._bindByProtocol( text, "Verify", handler ); text._setSelectionStart( 2 ); text._setSelectionLength( 0 ); TestUtil.press( text, "x" ); @@ -386,7 +356,7 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", { TestUtil.flush(); var logger = this._createLogger(); - new EventBinding( text, "Modify", logger ); + this._bindByProtocol( text, "Modify", logger ); text.setValue( "foo" ); assertEquals( 1, logger.log.length ); @@ -396,8 +366,8 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", { TestUtil.flush(); var logger = this._createLogger(); - new EventBinding( text, "Modify", logger ); - new EventBinding( text, "Verify", logger ); + this._bindByProtocol( text, "Modify", logger ); + this._bindByProtocol( text, "Verify", logger ); this._inputText( text, "foo" ); assertEquals( 2, logger.log.length ); @@ -415,15 +385,14 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", { "parent" : "w2" } } ); - var canvas = ObjectManager.getObject( "w4" ); + var canvas = ObjectRegistry.getObject( "w4" ); var logger = this._createLogger(); TestUtil.flush(); - new EventBinding( canvas, "Paint", logger ); + this._bindByProtocol( canvas, "Paint", logger ); canvas.dispatchSimpleEvent( "paint" ); TestUtil.flush(); - assertEquals( 1, logger.log.length ); canvas.destroy(); }, @@ -439,11 +408,11 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", { "items" : [ "a", "b", "c" ] } } ); - var list = ObjectManager.getObject( "w4" ); + var list = ObjectRegistry.getObject( "w4" ); var logger = this._createLogger(); TestUtil.flush(); - new EventBinding( list, "Selection", logger ); + this._bindByProtocol( list, "Selection", logger ); TestUtil.click( list.getItems()[ 1 ] ); TestUtil.flush(); @@ -461,11 +430,11 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", { "items" : [ "a", "b", "c" ] } } ); - var list = ObjectManager.getObject( "w4" ); + var list = ObjectRegistry.getObject( "w4" ); var logger = this._createLogger(); TestUtil.flush(); - new EventBinding( list, "DefaultSelection", logger ); + this._bindByProtocol( list, "DefaultSelection", logger ); TestUtil.doubleClick( list.getItems()[ 1 ] ); TestUtil.flush(); @@ -476,7 +445,7 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", { var obj = this._createPublicObject( "x1" ); var logger = this._createLogger(); - new EventBinding( obj, "Selection", logger ); + this._bindByProtocol( obj, "Selection", logger ); obj.listenerHolder.dispatchSimpleEvent( "Selection", "myEventObject" ); assertEquals( 1, logger.log.length ); @@ -487,8 +456,8 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", { var obj = this._createPublicObject( "x1" ); var logger = this._createLogger(); - var binding = new EventBinding( obj, "Selection", logger ); - binding.dispose(); + this._bindByProtocol( obj, "Selection", logger ); + this._unbindByProtocol(); obj.listenerHolder.dispatchSimpleEvent( "Selection", "myEventObject" ); assertEquals( 0, logger.log.length ); @@ -518,7 +487,7 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", { } } ); TestUtil.flush(); - text = ObjectManager.getObject( "w3" ); + text = ObjectRegistry.getObject( "w3" ); text.focus(); textEl = text.getElement(); }, @@ -568,8 +537,31 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventBinding_Test", { "properties" : {} } ); return rap.getObject( id ); - } + }, + _bindByProtocol : function( obj, type, targetFunction ) { + if( ObjectRegistry.getId( obj ) == null ) { + ObjectRegistry.add( "w33", obj, { "isPublic" : true } ); + } + ObjectRegistry.add( "w45", targetFunction, {} ); + Processor.processOperation( { + "target" : "w5", + "action" : "create", + "type" : "rwt.scripting.EventBinding", + "properties" : { + "eventType" : type, + "targetObject" : ObjectRegistry.getId( obj ), + "listener" : "w45" + } + } ); + }, + + _unbindByProtocol : function() { + Processor.processOperation( { + "target" : "w5", + "action" : "destroy" + } ); + } } diff --git a/tests/org.eclipse.rap.clientscripting.jstest/js/org/eclipse/rap/clientscripting/EventProxy_Test.js b/tests/org.eclipse.rap.clientscripting.jstest/js/org/eclipse/rap/clientscripting/EventProxy_Test.js index 07b0f55..e63b46b 100644 --- a/tests/org.eclipse.rap.clientscripting.jstest/js/org/eclipse/rap/clientscripting/EventProxy_Test.js +++ b/tests/org.eclipse.rap.clientscripting.jstest/js/org/eclipse/rap/clientscripting/EventProxy_Test.js @@ -14,7 +14,7 @@ var EventProxy = rwt.scripting.EventProxy; var EventBinding = rwt.scripting.EventBinding; var TestUtil = org.eclipse.rwt.test.fixture.TestUtil; var Processor = rwt.remote.MessageProcessor; -var ObjectManager = rwt.remote.ObjectRegistry; +var ObjectRegistry = rwt.remote.ObjectRegistry; var WidgetProxyFactory = rwt.scripting.WidgetProxyFactory; var SWT = rwt.scripting.SWT; @@ -486,11 +486,11 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventProxy_Test", { "parent" : "w2" } } ); - var canvas = ObjectManager.getObject( "w4" ); + var canvas = ObjectRegistry.getObject( "w4" ); TestUtil.flush(); var gc; - new EventBinding( canvas, "Paint", function( ev ) { + this._bindByProtocol( canvas, "Paint", function( ev ) { gc = ev.gc; } ); WidgetProxyFactory.getWidgetProxy( canvas ).redraw(); @@ -510,11 +510,11 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventProxy_Test", { "parent" : "w2" } } ); - var canvas = ObjectManager.getObject( "w4" ); + var canvas = ObjectRegistry.getObject( "w4" ); TestUtil.flush(); var gc = []; - new EventBinding( canvas, "Paint", function( ev ) { + this._bindByProtocol( canvas, "Paint", function( ev ) { gc.push( ev.gc ); } ); WidgetProxyFactory.getWidgetProxy( canvas ).redraw(); @@ -543,12 +543,12 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventProxy_Test", { "parent" : "w4" } } ); - var serverGc = ObjectManager.getObject( "w5" ); - var canvas = ObjectManager.getObject( "w4" ); + var serverGc = ObjectRegistry.getObject( "w5" ); + var canvas = ObjectRegistry.getObject( "w4" ); TestUtil.flush(); var gc; - new EventBinding( canvas, "Paint", function( ev ) { + this._bindByProtocol( canvas, "Paint", function( ev ) { gc = ev.gc; } ); WidgetProxyFactory.getWidgetProxy( canvas ).redraw(); @@ -567,14 +567,14 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventProxy_Test", { "parent" : "w2" } } ); - var canvas = ObjectManager.getObject( "w4" ); + var canvas = ObjectRegistry.getObject( "w4" ); canvas.setBackgroundColor( "#aaaaaa" ); canvas.setTextColor( "#bbbbbb" ); canvas.setFont( rwt.html.Font.fromString( "11px italic Arial") ); TestUtil.flush(); var props; - new EventBinding( canvas, "Paint", function( ev ) { + this._bindByProtocol( canvas, "Paint", function( ev ) { var gc = ev.gc; props = [ gc.strokeStyle, @@ -601,14 +601,14 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventProxy_Test", { "parent" : "w2" } } ); - var canvas = ObjectManager.getObject( "w4" ); + var canvas = ObjectRegistry.getObject( "w4" ); canvas.setBackgroundColor( null ); canvas.setTextColor( null ); canvas.setFont( null ); TestUtil.flush(); var props; - new EventBinding( canvas, "Paint", function( ev ) { + this._bindByProtocol( canvas, "Paint", function( ev ) { var gc = ev.gc; props = [ gc.strokeStyle, gc.fillStyle ]; gc.strokeStyle = "#ff00ff"; @@ -632,7 +632,7 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventProxy_Test", { "parent" : "w2" } } ); - var canvas = ObjectManager.getObject( "w4" ); + var canvas = ObjectRegistry.getObject( "w4" ); Processor.processOperation( { "target" : "w5", "action" : "create", @@ -641,12 +641,12 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventProxy_Test", { "parent" : "w4" } } ); - var serverGc = ObjectManager.getObject( "w5" ); + var serverGc = ObjectRegistry.getObject( "w5" ); TestUtil.flush(); var fontArr = [ [ "Arial" ], 11, false, true ]; var props; - new EventBinding( canvas, "Paint", function( ev ) { + this._bindByProtocol( canvas, "Paint", function( ev ) { var gc = ev.gc; props = [ gc.strokeStyle, @@ -681,7 +681,7 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventProxy_Test", { } } ); TestUtil.flush(); - text = ObjectManager.getObject( "w3" ); + text = ObjectRegistry.getObject( "w3" ); text.focus(); }, @@ -716,6 +716,23 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.EventProxy_Test", { textWidget._inputElement.value = value; textWidget._inValueProperty = false; textWidget._oninputDom( { "propertyName" : "value" } ); + }, + + _bindByProtocol : function( obj, type, targetFunction ) { + if( ObjectRegistry.getId( obj ) == null ) { + ObjectRegistry.add( "w33", obj, { "isPublic" : true } ); + } + ObjectRegistry.add( "w45", targetFunction, {} ); + Processor.processOperation( { + "target" : "w5", + "action" : "create", + "type" : "rwt.scripting.EventBinding", + "properties" : { + "eventType" : type, + "targetObject" : ObjectRegistry.getId( obj ), + "listener" : "w45" + } + } ); } } diff --git a/tests/org.eclipse.rap.clientscripting.jstest/js/org/eclipse/rap/clientscripting/WidgetProxyFactory_Test.js b/tests/org.eclipse.rap.clientscripting.jstest/js/org/eclipse/rap/clientscripting/WidgetProxyFactory_Test.js index d6e457a..aedbb2d 100644 --- a/tests/org.eclipse.rap.clientscripting.jstest/js/org/eclipse/rap/clientscripting/WidgetProxyFactory_Test.js +++ b/tests/org.eclipse.rap.clientscripting.jstest/js/org/eclipse/rap/clientscripting/WidgetProxyFactory_Test.js @@ -26,7 +26,7 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.WidgetProxyFactory_Test", members : { - testCreateTextWidgetProxyFromPublicAPI : function() { + testCreateTextWidgetProxyFromPublicAPI : function() { var widgetProxy = WidgetProxyFactory.getWidgetProxy( text ); var otherProxy = rap.getObject( "w3" ); @@ -270,7 +270,7 @@ rwt.qx.Class.define( "org.eclipse.rap.clientscripting.WidgetProxyFactory_Test", var widgetProxy = WidgetProxyFactory.getWidgetProxy( canvas ); var logger = this._createLogger(); TestUtil.flush(); - new EventBinding( canvas, "Paint", logger ); + EventBinding.addListener( canvas, "Paint", logger ); assertEquals( 0, logger.log.length ); widgetProxy.redraw(); |