this is a small sample of Loading While GWT Application Loads,
perhaps this example can help someone.
package com.javaneses.example.loading.client;
import java.util.List;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.widgetideas.client.ProgressBar;
import com.google.gwt.widgetideas.client.ProgressBar.TextFormatter;
import com.javaneses.example.loading.client.rpc.service.MyService;
import
com.javaneses.example.loading.client.rpc.service.MyServiceAsync;
public class MainTest implements EntryPoint {
private final PopupPanel loading = new PopupPanel();
//ProgressBar gwt incubator
private final ProgressBar bar = new ProgressBar();
private final FlexTable flexTable = new FlexTable();
private Timer timer;
private final MyServiceAsync myServiceAsync = GWT.create
(MyService.class);
private int index;
public void onModuleLoad() {
flexTable.setText(0, 0, "Row");
flexTable.setText(0, 1, "First Name");
flexTable.setText(0, 2, "Last Name");
flexTable.setCellSpacing(5);
flexTable.setVisible(false);
RootPanel.get().add(flexTable);
bar.setTextVisible(false);
loading.add(bar);
loading.center();
AsyncCallback<List<MyBean>> asyncCallback = new
AsyncCallback<List<MyBean>>() {
public void onSuccess(final List<MyBean> result) {
bar.setTextVisible(true);
final int count = result.size();
bar.setMaxProgress(count);
bar.setProgress(0);
TextFormatter formatter = new TextFormatter() {
protected String getText(ProgressBar
bar, double curProgress) {
return "Loading Data ";
}//end getText(ProgressBar bar, double
curProgress)
};
bar.setTextFormatter(formatter);
timer = new Timer() {
public void run() {
if(count == index){
loading.hide();
flexTable.setVisible(true);
timer.cancel();
}else{
MyBean bean =
result.get(index);
flexTable.setText(index
+ 1, 0, ""+index);
flexTable.setText(index
+ 1, 1, bean.getName());
flexTable.setText(index
+ 1, 2, bean.getLastName());
index++;
bar.setProgress(index);
}//end else
}//end run
};//end timer = new Timer()
timer.scheduleRepeating(25);
}//end onSuccess(List<MyBean> result)
public void onFailure(Throwable caught) {
Window.alert(caught.toString());
}//end onFailure(Throwable caught)
};
myServiceAsync.listMyBean(asyncCallback);
}//end onModuleLoad
}//end class
//SERVICE CLASS
package com.javaneses.example.loading.client.rpc.service;
import java.util.List;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
import com.javaneses.example.loading.client.MyBean;
@RemoteServiceRelativePath("/myService")
public interface MyService extends RemoteService{
List<MyBean> listMyBean();
}//end interface
package com.javaneses.example.loading.client.rpc.service;
import java.util.List;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.javaneses.example.loading.client.MyBean;
public interface MyServiceAsync {
void listMyBean(AsyncCallback<List<MyBean>> asyncCallback);
}//end interface
package com.javaneses.example.loading.server.rpc.service;
import java.util.ArrayList;
import java.util.List;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.javaneses.example.loading.client.MyBean;
import com.javaneses.example.loading.client.rpc.service.MyService;
public class MyServiceImpl extends RemoteServiceServlet implements
MyService{
private static final long serialVersionUID = -6260441209521818053L;
@Override
public List<MyBean> listMyBean() {
List<MyBean> list = new ArrayList<MyBean>();
for(int i = 0; i < 1000; i++){
MyBean bean = new MyBean();
bean.setName("Vagner");
bean.setLastName("Araujo");
list.add(bean);
}//end for(int i = 0; i < 1000; i++)
return list;
}//end listMyBean
}//end class
//BEAN
package com.javaneses.example.loading.client;
import java.io.Serializable;
public final class MyBean implements Serializable{
private static final long serialVersionUID = 2264295145291728318L;
private String name;
private String lastName;
public void setName(String name) {
this.name = name;
}//end setName
public String getName() {
return name;
}//end getName
public void setLastName(String lastName) {
this.lastName = lastName;
}//end setLastName
public String getLastName() {
return lastName;
}//end getLastName
}//end class
//MY MODULE
<module>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User' />
<inherits name='com.google.gwt.widgetideas.WidgetIdeas' />
<inherits name='com.google.gwt.libideas.LibIdeas' />
<!-- Inherit the default GWT style sheet. You can change -->
<!-- the theme of your GWT application by uncommenting -->
<!-- any one of the following lines. -->
<inherits name='com.google.gwt.user.theme.standard.Standard' />
<!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
<!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->
<!-- Other module inherits -->
<!-- Specify the app entry point class. -->
<entry-point class='com.javaneses.example.loading.client.MainTest' />
<!-- Specify the application specific style sheet. -->
<stylesheet src='MainTest.css' />
<servlet path="/myService"
class="com.javaneses.example.loading.server.rpc.service.MyServiceImpl" /
>
</module>
//MY CSS
.gwt-ProgressBar-shell {
width: 150px;
height: 15px;
border: double;
}
.gwt-ProgressBar-shell .gwt-ProgressBar-bar {
background: #4188FA;
}
.gwt-ProgressBar-shell .gwt-ProgressBar-text {
font-size: 12px;
}
.gwt-ProgressBar-shell .gwt-ProgressBar-text-firstHalf {
color: green;
}
.gwt-ProgressBar-shell .gwt-ProgressBar-text-secondHalf {
color: black;
}
--
Vagner Araujo
Java + Vagner = Javagner
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---