Statistics
| Branch: | Tag: | Revision:

root / src / org / gss_project / gss / admin / client / TwoAdmin.java @ 1205:fbeae20462e6

History | View | Annotate | Download (5 kB)

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