Integrate with RAP 2.x JavaScript API
If ClientScripting is present, rap.getObject returns
ClientScripting-enabled WidgetProxies. The Composite methods
add/removeListener and append are still supported.
diff --git a/bundles/org.eclipse.rap.clientscripting/js/org/eclipse/rap/clientscripting/ClientScriptingUtil.js b/bundles/org.eclipse.rap.clientscripting/js/org/eclipse/rap/clientscripting/ClientScriptingUtil.js
index b600045..9c9b532 100644
--- a/bundles/org.eclipse.rap.clientscripting/js/org/eclipse/rap/clientscripting/ClientScriptingUtil.js
+++ b/bundles/org.eclipse.rap.clientscripting/js/org/eclipse/rap/clientscripting/ClientScriptingUtil.js
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 EclipseSource and others.
+ * Copyright (c) 2012, 2013 EclipseSource and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -103,20 +103,25 @@
},
attachSetter : function( proxy, source ) {
- var ObjectManager = rwt.remote.ObjectRegistry;
- var id = ObjectManager.getId( source );
- var properties = ObjectManager.getEntry( id ).handler.properties;
- for( var i = 0; i < properties.length; i++ ) {
- var property = properties[ i ];
- proxy[ "set" + rwt.util.Strings.toFirstUp( property ) ] =
- this._createSetter( id, property );
+ var ObjectRegistry = rwt.remote.ObjectRegistry;
+ var id = ObjectRegistry.getId( source );
+ var handler = id ? ObjectRegistry.getEntry( id ).handler : null;
+ if( handler ) {
+ var properties = handler.properties;
+ for( var i = 0; i < properties.length; i++ ) {
+ var property = properties[ i ];
+ proxy[ "set" + rwt.util.Strings.toFirstUp( property ) ] =
+ this._createSetter( id, property );
+ }
}
},
attachGetter : function( proxy, source ) {
- var getterMap = this._getterMapping[ source.classname ];
- for( var key in getterMap ) {
- proxy[ key ] = getterMap[ key ]( source );
+ if( source.classname ) {
+ var getterMap = this._getterMapping[ source.classname ];
+ for( var key in getterMap ) {
+ proxy[ key ] = getterMap[ key ]( source );
+ }
}
},
diff --git a/bundles/org.eclipse.rap.clientscripting/js/org/eclipse/rap/clientscripting/WidgetProxy.js b/bundles/org.eclipse.rap.clientscripting/js/org/eclipse/rap/clientscripting/WidgetProxy.js
index 18948df..f5338c6 100644
--- a/bundles/org.eclipse.rap.clientscripting/js/org/eclipse/rap/clientscripting/WidgetProxy.js
+++ b/bundles/org.eclipse.rap.clientscripting/js/org/eclipse/rap/clientscripting/WidgetProxy.js
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 EclipseSource and others.
+ * Copyright (c) 2012, 2013 EclipseSource and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -9,6 +9,8 @@
* EclipseSource - initial API and implementation
******************************************************************************/
+(function(){
+
rwt.qx.Class.createNamespace( "org.eclipse.rap.clientscripting", {} );
org.eclipse.rap.clientscripting.WidgetProxy = function( originalWidget ) {
@@ -31,12 +33,18 @@
"org.eclipse.rap.clientscripting.WidgetProxy.GC";
org.eclipse.rap.clientscripting.WidgetProxy.getInstance = function( widget ) {
- var protoInstance = widget.getUserData( this._PROXY_KEY );
- if( protoInstance == null ) {
- protoInstance = new org.eclipse.rap.clientscripting.WidgetProxy( widget );
- widget.setUserData( this._PROXY_KEY, protoInstance );
+ return rap._.getWrapperFor( widget );
+};
+
+var getWrapperFor = rap._.getWrapperFor;
+rap._.getWrapperFor = function( obj ) {
+ var result = getWrapperFor.call( rap._, obj );
+ var PROXY_KEY = org.eclipse.rap.clientscripting.WidgetProxy._PROXY_KEY;
+ if( obj.getUserData( PROXY_KEY ) == null ) {
+ org.eclipse.rap.clientscripting.WidgetProxy.call( result, obj );
+ obj.setUserData( PROXY_KEY, result );
}
- return org.eclipse.rap.clientscripting.ClientScriptingUtil.wrapAsProto( protoInstance );
+ return result;
};
org.eclipse.rap.clientscripting.WidgetProxy.disposeWidgetProxy = function( widget ) {
@@ -45,3 +53,5 @@
org.eclipse.rap.clientscripting.ClientScriptingUtil.disposeObject( protoInstance );
org.eclipse.rap.clientscripting.ClientScriptingUtil.disposeObject( userData );
};
+
+}());
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 d693b66..a43e993 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 EclipseSource and others.
+ * Copyright (c) 2012, 2013 EclipseSource and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -56,7 +56,7 @@
assertEquals( "number", typeof eventProxy.button );
assertEquals( "number", typeof eventProxy.x );
assertEquals( "number", typeof eventProxy.y );
- assertTrue( eventProxy.widget instanceof WidgetProxy );
+ assertTrue( eventProxy.widget === rap.getObject( "w3" ) );
},
testType : function() {
diff --git a/tests/org.eclipse.rap.clientscripting.jstest/js/org/eclipse/rap/clientscripting/WidgetProxy_Test.js b/tests/org.eclipse.rap.clientscripting.jstest/js/org/eclipse/rap/clientscripting/WidgetProxy_Test.js
index 7e88b9d..1a50bc3 100644
--- a/tests/org.eclipse.rap.clientscripting.jstest/js/org/eclipse/rap/clientscripting/WidgetProxy_Test.js
+++ b/tests/org.eclipse.rap.clientscripting.jstest/js/org/eclipse/rap/clientscripting/WidgetProxy_Test.js
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 EclipseSource and others.
+ * Copyright (c) 2012, 2013 EclipseSource and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -26,21 +26,19 @@
members : {
- testCreateTextWidgetProxy : function() {
+ testCreateTextWidgetProxyFromPublicAPI : function() {
var widgetProxy = WidgetProxy.getInstance( text );
- assertTrue( widgetProxy instanceof WidgetProxy );
+ var otherProxy = rap.getObject( "w3" );
+
+ assertIdentical( widgetProxy, otherProxy );
},
testCreateTextWidgetProxyTwice : function() {
var widgetProxy1 = WidgetProxy.getInstance( text );
var widgetProxy2 = WidgetProxy.getInstance( text );
- assertTrue( widgetProxy1 !== widgetProxy2 ); // protect against abuse
- if( widgetProxy1.__proto__ ) { // __proto__ is not an ECMA standard
- assertTrue( widgetProxy1.__proto__ instanceof WidgetProxy );
- assertTrue( widgetProxy1.__proto__ === widgetProxy1.__proto__ );
- }
+ assertTrue( widgetProxy1 === widgetProxy2 );
},
testDisposeWidgetProxy : function() {