Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Problem in Custom Widgets
Problem in Custom Widgets [message #671202] Tue, 17 May 2011 06:13 Go to next message
Swap  is currently offline Swap Friend
Messages: 30
Registered: March 2011
Member
I have prepared custom widget as per guidelines.
I have followed steps given at

http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .rap.help/help/html/advanced/custom-widget.html

But I am unable to get UI for it. When I run application, It shows nothing in browser.

Can anybody help me?

Re: Problem in Custom Widgets [message #671223 is a reply to message #671202] Tue, 17 May 2011 07:11 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2426
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi Swap,
without providing some code I can't help you much. Please attach your
server-side custom widget java class, the LCA and the client-side
javascript class.
Best,
Ivan

On 5/17/2011 9:13 AM, Swap wrote:
> I have prepared custom widget as per guidelines.
> I have followed steps given at
>
> http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .rap.help/help/html/advanced/custom-widget.html
>
>
> But I am unable to get UI for it. When I run application, It
> shows nothing in browser.
>
> Can anybody help me?
>
>
Re: Problem in Custom Widgets [message #671238 is a reply to message #671223] Tue, 17 May 2011 08:59 Go to previous messageGo to next message
Swap  is currently offline Swap Friend
Messages: 30
Registered: March 2011
Member
Thanks for your reply.

Here I am attaching code:

Widget java class:

public class GMap extends Composite {

public GMap(Composite parent, int style) {
super(parent, style);
// TODO Auto-generated constructor stub
}

private String address = null;
private String centerLocation;



public void setAddress( String address ) {
if( address == null ) {
this.address = "";
} else {
this.address = address;
}
}

public String getAddress() {
return address;
}

public void setCenterLocation( String location ) {
this.centerLocation = location;
}

public String getCenterLocation() {
return this.centerLocation;
}

public void setLayout (Layout layout) {

}


}

LCA class:

public class GMapLCA extends AbstractWidgetLCA {

private static final String PROP_ADDRESS = "address";
private static final String JS_PROP_ADDRESS = "address";
private static final String PARAM_CENTER = "centerLocation";


public void readData( Widget widget ) {
GMap map = ( GMap )widget;
String location = WidgetLCAUtil.readPropertyValue( map, PARAM_CENTER );
map.setCenterLocation( location );
}


@Override
public void preserveValues( Widget widget ) {
ControlLCAUtil.preserveValues( ( org.eclipse.swt.widgets.Control )widget );
IWidgetAdapter adapter = WidgetUtil.getAdapter( widget );
adapter.preserve( PROP_ADDRESS, ( ( GMap )widget ).getAddress() );

// only needed for custom variants (themeing)
WidgetLCAUtil.preserveCustomVariant( widget );
}


@Override
public void renderInitialization( Widget widget ) throws IOException {
JSWriter writer = JSWriter.getWriterFor( widget );
String id = WidgetUtil.getId( widget );
writer.newWidget( "org.eclipse.rap.gmaps.GMap", new Object[] { id } );
writer.set( "appearance", "composite" );
writer.set( "overflow", "hidden" );
ControlLCAUtil.writeStyleFlags( ( GMap )widget );
}


@Override
public void renderChanges( Widget widget ) throws IOException {
GMap gmap = ( GMap )widget;
ControlLCAUtil.writeChanges( gmap );
JSWriter writer = JSWriter.getWriterFor( widget );
writer.set( PROP_ADDRESS, JS_PROP_ADDRESS, gmap.getAddress() );

// only needed for custom variants (themeing)
WidgetLCAUtil.writeCustomVariant( widget );
}


@Override
public void renderDispose( Widget widget ) throws IOException {
JSWriter writer = JSWriter.getWriterFor( widget );
writer.dispose();
}

}

Client Side JavaScript:

qx.Class.define( "org.eclipse.rap.gmaps.GMap", {
extend: qx.ui.layout.CanvasLayout,

construct: function( id ) {
this.base( arguments );
this.setHtmlAttribute( "id", id );
this._id = id;
this._map = null;
if( GBrowserIsCompatible() ) {
this._geocoder = new GClientGeocoder();
this.addEventListener( "changeHeight", this._doResize, this );
this.addEventListener( "changeWidth", this._doResize, this );
}
}

}, // <-- comma added, see javascript syntax reference

members : {
_doActivate : function() {
var shell = null;
var parent = this.getParent();
while( shell == null && parent != null ) {
if( parent.classname == "org.eclipse.swt.widgets.Shell" ) {
shell = parent;
}
parent = parent.getParent();
}
if( shell != null ) {
shell.setActiveChild( this );
}
},

load : function() {
var current = this.getAddress();
if( GBrowserIsCompatible() && current != null && current != "" ) {
qx.ui.core.Widget.flushGlobalQueues();
if( this._map == null ) {
this._map = new GMap2( document.getElementById( this._id ) );
this._map.addControl( new GSmallMapControl() );
this._map.addControl( new GMapTypeControl() );
GEvent.bind( this._map, "click", this, this._doActivate );
GEvent.bind( this._map, "moveend", this, this._onMapMove );

}
var map = this._map;
map.clearOverlays();
this._geocoder.getLatLng(
current,
function( point ) {
if( !point ) {
alert( "'" + current + "' not found" );
} else {
map.setCenter( point, 13 );
var marker = new GMarker( point );
map.addOverlay( marker );
marker.openInfoWindowHtml( current );
}
}
);
}
},

_onMapMove : function() {
if( !org_eclipse_rap_rwt_EventUtil_suspend ) {
var wm = org.eclipse.swt.WidgetManager.getInstance();
var gmapId = wm.findIdByWidget( this );
var center = this._map.getCenter().toString();
var req = org.eclipse.swt.Request.getInstance();
req.addParameter( gmapId + ".centerLocation", center );
}
},

_doResize : function() {
qx.ui.core.Widget.flushGlobalQueues();
if( this._map != null ) {
this._map.checkResize();
}
}

}
}, // <-- comma added, see javascript syntax reference

properties : {
address : {
init : "",
apply : "load"
}
}

}
});


There are no compilation errors. But nothing is displayed in browser &
it gets hanged.

Please provide me solution...
Re: Problem in Custom Widgets [message #671268 is a reply to message #671238] Tue, 17 May 2011 10:02 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2426
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi Swap,
do you have any client-side javascript errors? Look at JavaScript
console or use Firebug in case of Firefox browser. Remove "writer.set(
"appearance", "composite" );" from the LCA. Does it help?
BTW with RAP 1.4 M4 or later there is an easy way to create a custom
widget by using Browser widget only. Look at this blog post:
http://eclipsesource.com/blogs/2010/12/18/a-new-google-maps- widget-for-swt-and-rap/
HTH,
Ivan

On 5/17/2011 11:59 AM, Swap wrote:
> Thanks for your reply.
>
> Here I am attaching code:
>
> Widget java class:
>
> public class GMap extends Composite {
>
> public GMap(Composite parent, int style) {
> super(parent, style);
> // TODO Auto-generated constructor stub
> }
>
> private String address = null;
> private String centerLocation;
>
>
>
> public void setAddress( String address ) {
> if( address == null ) {
> this.address = "";
> } else {
> this.address = address;
> }
> }
>
> public String getAddress() {
> return address;
> }
>
> public void setCenterLocation( String location ) {
> this.centerLocation = location;
> }
> public String getCenterLocation() {
> return this.centerLocation;
> }
>
> public void setLayout (Layout layout) {
>
> }
> }
>
> LCA class:
>
> public class GMapLCA extends AbstractWidgetLCA {
>
> private static final String PROP_ADDRESS = "address";
> private static final String JS_PROP_ADDRESS = "address";
> private static final String PARAM_CENTER =
> "centerLocation";
>
>
> public void readData( Widget widget ) {
> GMap map = ( GMap )widget;
> String location = WidgetLCAUtil.readPropertyValue( map,
> PARAM_CENTER );
> map.setCenterLocation( location );
> }
>
>
> @Override
> public void preserveValues( Widget widget ) {
> ControlLCAUtil.preserveValues( (
> org.eclipse.swt.widgets.Control )widget );
> IWidgetAdapter adapter = WidgetUtil.getAdapter( widget
> );
> adapter.preserve( PROP_ADDRESS, ( ( GMap )widget
> ).getAddress() );
> // only needed for custom variants (themeing)
> WidgetLCAUtil.preserveCustomVariant( widget );
> }
>
>
> @Override
> public void renderInitialization( Widget widget ) throws
> IOException {
> JSWriter writer = JSWriter.getWriterFor( widget );
> String id = WidgetUtil.getId( widget );
> writer.newWidget( "org.eclipse.rap.gmaps.GMap", new
> Object[] { id } );
> writer.set( "appearance", "composite" );
> writer.set( "overflow", "hidden" );
> ControlLCAUtil.writeStyleFlags( ( GMap )widget );
> }
>
>
> @Override
> public void renderChanges( Widget widget ) throws
> IOException {
> GMap gmap = ( GMap )widget;
> ControlLCAUtil.writeChanges( gmap );
> JSWriter writer = JSWriter.getWriterFor( widget );
> writer.set( PROP_ADDRESS, JS_PROP_ADDRESS,
> gmap.getAddress() );
> // only needed for custom variants (themeing)
> WidgetLCAUtil.writeCustomVariant( widget );
> }
>
>
> @Override
> public void renderDispose( Widget widget ) throws
> IOException {
> JSWriter writer = JSWriter.getWriterFor( widget );
> writer.dispose();
> }
>
> }
>
> Client Side JavaScript:
>
> qx.Class.define( "org.eclipse.rap.gmaps.GMap", {
> extend: qx.ui.layout.CanvasLayout,
>
> construct: function( id ) {
> this.base( arguments );
> this.setHtmlAttribute( "id", id );
> this._id = id;
> this._map = null;
> if( GBrowserIsCompatible() ) {
> this._geocoder = new GClientGeocoder();
> this.addEventListener( "changeHeight",
> this._doResize, this );
> this.addEventListener( "changeWidth",
> this._doResize, this ); }
> }
> }, // <-- comma added, see javascript syntax reference
> members : {
> _doActivate : function() {
> var shell = null;
> var parent = this.getParent();
> while( shell == null && parent != null ) {
> if( parent.classname ==
> "org.eclipse.swt.widgets.Shell" ) {
> shell = parent;
> }
> parent = parent.getParent();
> }
> if( shell != null ) {
> shell.setActiveChild( this );
> }
> },
> load : function() {
> var current = this.getAddress();
> if( GBrowserIsCompatible() && current != null &&
> current != "" ) {
> qx.ui.core.Widget.flushGlobalQueues();
> if( this._map == null ) {
> this._map = new GMap2(
> document.getElementById( this._id ) );
> this._map.addControl( new
> GSmallMapControl() );
> this._map.addControl( new
> GMapTypeControl() );
> GEvent.bind( this._map, "click", this,
> this._doActivate );
> GEvent.bind( this._map, "moveend", this,
> this._onMapMove );
> }
> var map = this._map;
> map.clearOverlays();
> this._geocoder.getLatLng(
> current,
> function( point ) {
> if( !point ) {
> alert( "'" + current + "' not found"
> );
> } else {
> map.setCenter( point, 13 );
> var marker = new GMarker( point );
> map.addOverlay( marker );
> marker.openInfoWindowHtml( current
> );
> }
> }
> );
> }
> },
> _onMapMove : function() {
> if( !org_eclipse_rap_rwt_EventUtil_suspend ) {
> var wm =
> org.eclipse.swt.WidgetManager.getInstance();
> var gmapId = wm.findIdByWidget( this );
> var center =
> this._map.getCenter().toString();
> var req =
> org.eclipse.swt.Request.getInstance();
> req.addParameter( gmapId +
> ".centerLocation", center );
> }
> },
> _doResize : function() {
> qx.ui.core.Widget.flushGlobalQueues();
> if( this._map != null ) {
> this._map.checkResize();
> }
> }
> }
> }, // <-- comma added, see javascript syntax reference
> properties : {
> address : {
> init : "",
> apply : "load"
> }
> }
> }
> });
>
>
> There are no compilation errors. But nothing is displayed in
> browser & it gets hanged.
>
> Please provide me solution...
Re: Problem in Custom Widgets [message #672227 is a reply to message #671268] Fri, 20 May 2011 11:54 Go to previous message
Swap  is currently offline Swap Friend
Messages: 30
Registered: March 2011
Member
Thanks a lot..!
There was problem in Javascript & corrected it.
Now working fine.
Previous Topic:UI Loading Mechanism
Next Topic:Tomcat deployment problem
Goto Forum:
  


Current Time: Thu Apr 25 02:04:15 GMT 2024

Powered by FUDForum. Page generated in 0.03411 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top