1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
public class GrblInfoWidget extends Composite {
private RpcCallServiceAsync rpc;
// main widget panel
private VerticalPanel pWidget = new VerticalPanel();
private LoadingWidget loading = new LoadingWidget();
private VerticalPanel pBibleTable = new VerticalPanel();
// table for the bible info
private Grid grid = null;
/**
* constructor - init the composite widget for use
*/
public GrblInfoWidget() {
HorizontalPanel hp = new HorizontalPanel();
hp.add(new HTML("List of users "));
hp.add(loading);
pWidget.add(hp);
pWidget.add(pBibleTable);
// init widget, this can be added into the rootpanel
initWidget(pWidget);
// init the rpc
rpc = RpcInit.initRpc();
}
public void draw() {
// start the process
getBibleInfo();
}
/**
* draw bible info to screen after rpc callback
*
* @param bibleData
*/
private void drawBibleInfo(GrblData[] grblData) {
// if null nothing to do, then exit
// this will prevent errors from showing up
if (grblData == null) {
return;
}
int rows = grblData.length;
// set up the table the bible info will go into.
// I already init the grid var above so I can reference it other methods in this instance.
grid = new Grid(rows+1, 3);
pBibleTable.add(grid);
Label lLname = new Label("Last name");
Label lFname = new Label("First name");
// tool-tip hover
lLname.setTitle("Last name of user");
lFname.setTitle("First name of user");
// label row - Starts with 0 ordinal
grid.setWidget(0, 0, lLname);
grid.setWidget(0, 1, lFname);
// go through the books of the bible
for (int i = 0; i < rows; i++) {
grid.setWidget(i+1, 0, new HTML(grblData[i].UserLastName));
grid.setWidget(i+1, 1, new HTML(grblData[i].UserFirstName));
// row style
boolean even = i % 2 == 0;
String style = "";
if (even == true) {
style = "rs-even";
} else {
style = "rs-odd";
}
grid.getRowFormatter().setStyleName(i+1, style);
}
grid.setStyleName("grblTable");
}
/**
* rpc request to get the bible info.
*
* on return, draw the data to screen
*/
private void getBibleInfo() {
// draw loading
loading.show();
// remote procedure call to the server to get the bible info
rpc.getBibleInfo(new AsyncCallback<GrblData[]>() {
public void onSuccess(GrblData[] bibleData) {
// draw bible info
drawBibleInfo(bibleData);
// hide loading
loading.hide();
}
public void onFailure(Throwable caught) {
RootPanel.get().add(new HTML(caught.toString()));
}
});
}
} |
Partager