root / src / org / gss_project / gss / admin / client / TwoAdmin.java @ 1205:fbeae20462e6
History | View | Annotate | Download (5 kB)
1 |
package org.gss_project.gss.admin.client; |
---|---|
2 |
|
3 |
import org.gss_project.gss.admin.client.ui.HeaderPanel; |
4 |
import org.gss_project.gss.admin.client.ui.UserPanel; |
5 |
import org.gss_project.gss.admin.client.ui.VisualizationPanel; |
6 |
import org.gss_project.gss.common.dto.SystemStatsDTO; |
7 |
|
8 |
import com.google.gwt.core.client.EntryPoint; |
9 |
import com.google.gwt.core.client.GWT; |
10 |
import com.google.gwt.event.dom.client.ClickEvent; |
11 |
import com.google.gwt.event.dom.client.ClickHandler; |
12 |
import com.google.gwt.event.logical.shared.ResizeEvent; |
13 |
import com.google.gwt.event.logical.shared.ResizeHandler; |
14 |
import com.google.gwt.event.logical.shared.SelectionEvent; |
15 |
import com.google.gwt.event.logical.shared.SelectionHandler; |
16 |
import com.google.gwt.uibinder.client.UiBinder; |
17 |
import com.google.gwt.uibinder.client.UiField; |
18 |
import com.google.gwt.user.client.Command; |
19 |
import com.google.gwt.user.client.DeferredCommand; |
20 |
import com.google.gwt.user.client.Window; |
21 |
import com.google.gwt.user.client.rpc.AsyncCallback; |
22 |
import com.google.gwt.user.client.ui.Button; |
23 |
import com.google.gwt.user.client.ui.DialogBox; |
24 |
import com.google.gwt.user.client.ui.DockLayoutPanel; |
25 |
import com.google.gwt.user.client.ui.Label; |
26 |
import com.google.gwt.user.client.ui.RootLayoutPanel; |
27 |
import com.google.gwt.user.client.ui.TabLayoutPanel; |
28 |
import com.google.gwt.user.client.ui.VerticalPanel; |
29 |
|
30 |
/**
|
31 |
* Entry point classes define <code>onModuleLoad()</code>.
|
32 |
*/
|
33 |
public class TwoAdmin implements EntryPoint { |
34 |
|
35 |
interface Binder extends UiBinder<DockLayoutPanel, TwoAdmin> { |
36 |
} |
37 |
|
38 |
private final AdminServiceAsync adminService = GWT.create(AdminService.class); |
39 |
|
40 |
private static final Binder binder = GWT.create(Binder.class); |
41 |
|
42 |
/**
|
43 |
* The single TwoAdmin instance.
|
44 |
*/
|
45 |
private static TwoAdmin singleton; |
46 |
|
47 |
/**
|
48 |
* Gets the singleton TwoAdmin instance.
|
49 |
*
|
50 |
* @return the TwoAdmin object
|
51 |
*/
|
52 |
public static TwoAdmin get() { |
53 |
if (TwoAdmin.singleton == null) |
54 |
TwoAdmin.singleton = new TwoAdmin();
|
55 |
return TwoAdmin.singleton;
|
56 |
} |
57 |
|
58 |
@UiField(provided = true) |
59 |
HeaderPanel headerPanel = new HeaderPanel();
|
60 |
|
61 |
@UiField UserPanel userPanel;
|
62 |
|
63 |
@UiField
|
64 |
TabLayoutPanel tabPanel; |
65 |
|
66 |
@UiField VisualizationPanel chart2;
|
67 |
|
68 |
final DialogBox loadingBox = new DialogBox(); |
69 |
|
70 |
@Override
|
71 |
public void onModuleLoad() { |
72 |
TwoAdmin.singleton=this;
|
73 |
loadingBox.setHTML("Loading data");
|
74 |
//scroll.setAlwaysShowScrollBars(true);
|
75 |
VerticalPanel vPanel = new VerticalPanel();
|
76 |
loadingBox.setSize("50%", "50%"); |
77 |
loadingBox.setWidget(vPanel); |
78 |
vPanel.add(new Label("Fetching Requested Data")); |
79 |
|
80 |
DockLayoutPanel outer = binder.createAndBindUi(this);
|
81 |
tabPanel.addSelectionHandler(new SelectionHandler<Integer>() { |
82 |
|
83 |
@Override
|
84 |
public void onSelection(SelectionEvent<Integer> event) { |
85 |
switch (event.getSelectedItem()) {
|
86 |
case 0: |
87 |
loadStatistics(); |
88 |
break;
|
89 |
default:
|
90 |
break;
|
91 |
} |
92 |
|
93 |
} |
94 |
}); |
95 |
|
96 |
|
97 |
// Get rid of scrollbars, and clear out the window's built-in margin,
|
98 |
// because we want to take advantage of the entire client area.
|
99 |
//Window.enableScrolling(true);
|
100 |
//Window.setMargin("0px");
|
101 |
Window.addResizeHandler(new ResizeHandler(){ |
102 |
|
103 |
@Override
|
104 |
public void onResize(ResizeEvent event) { |
105 |
int height=event.getHeight();
|
106 |
resize(height); |
107 |
|
108 |
} |
109 |
|
110 |
}); |
111 |
RootLayoutPanel root = RootLayoutPanel.get(); |
112 |
root.add(outer); |
113 |
// RootPanel.get().add(outer);
|
114 |
loadStatistics(); |
115 |
tabPanel.selectTab(0);
|
116 |
|
117 |
resize(Window.getClientHeight());
|
118 |
} |
119 |
|
120 |
private void resize(int height){ |
121 |
|
122 |
int newHeight = height - tabPanel.getAbsoluteTop()-100; |
123 |
if (newHeight < 1) |
124 |
newHeight = 1;
|
125 |
tabPanel.setHeight("" + newHeight);
|
126 |
GWT.log("New Height:"+ newHeight);
|
127 |
} |
128 |
/**
|
129 |
* Retrieve the adminService.
|
130 |
*
|
131 |
* @return the adminService
|
132 |
*/
|
133 |
public AdminServiceAsync getAdminService() {
|
134 |
return adminService;
|
135 |
} |
136 |
|
137 |
public void showErrorBox(String message) { |
138 |
final DialogBox dialogBox = new DialogBox(); |
139 |
dialogBox.setHTML("An error occured");
|
140 |
VerticalPanel vPanel = new VerticalPanel();
|
141 |
dialogBox.setSize("50%", "50%"); |
142 |
ClickHandler cancelHandler = new ClickHandler() {
|
143 |
|
144 |
@Override
|
145 |
public void onClick(ClickEvent event) { |
146 |
dialogBox.hide(); |
147 |
} |
148 |
}; |
149 |
dialogBox.setWidget(vPanel); |
150 |
vPanel.add(new Label(message)); |
151 |
Button close = new Button("Close"); |
152 |
close.addClickHandler(cancelHandler); |
153 |
vPanel.add(close); |
154 |
dialogBox.center(); |
155 |
dialogBox.show(); |
156 |
} |
157 |
|
158 |
|
159 |
|
160 |
public void showLoadingBox() { |
161 |
loadingBox.center(); |
162 |
loadingBox.show(); |
163 |
} |
164 |
|
165 |
public void hideLoadingBox(){ |
166 |
loadingBox.hide(); |
167 |
} |
168 |
|
169 |
|
170 |
public void loadStatistics(){ |
171 |
DeferredCommand.addCommand(new Command() {
|
172 |
|
173 |
@Override
|
174 |
public void execute() { |
175 |
showLoadingBox(); |
176 |
getAdminService().getSystemStatistics(new AsyncCallback<SystemStatsDTO>() {
|
177 |
|
178 |
@Override
|
179 |
public void onFailure(Throwable caught) { |
180 |
hideLoadingBox(); |
181 |
// TODO Auto-generated method stub
|
182 |
|
183 |
} |
184 |
|
185 |
@Override
|
186 |
public void onSuccess(SystemStatsDTO result) { |
187 |
chart2.updateData(result); |
188 |
hideLoadingBox(); |
189 |
}}); |
190 |
|
191 |
} |
192 |
}); |
193 |
} |
194 |
|
195 |
public void searchUsers(String query){ |
196 |
tabPanel.selectTab(1);
|
197 |
userPanel.populateTable(query); |
198 |
} |
199 |
} |