Guest User

Untitled

a guest
Jul 20th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.09 KB | None | 0 0
  1. package hd.client;
  2.  
  3.  
  4. import com.extjs.gxt.ui.client.widget.Info;
  5. import com.google.gwt.core.client.EntryPoint;
  6. import com.google.gwt.core.client.GWT;
  7. import com.google.gwt.dom.client.Node;
  8. import com.google.gwt.event.dom.client.ClickEvent;
  9. import com.google.gwt.event.dom.client.ClickHandler;
  10. import com.google.gwt.user.client.Element;
  11. import com.google.gwt.user.client.DOM;
  12. import com.google.gwt.user.client.Event;
  13. import com.google.gwt.user.client.EventListener;
  14. import com.google.gwt.user.client.ui.ClickListener;
  15. import com.google.gwt.user.client.ui.HTML;
  16. import com.google.gwt.user.client.ui.RootPanel;
  17. import com.google.gwt.user.client.ui.Widget;
  18.  
  19.  
  20.  
  21. /**
  22. * Entry point classes define <code>onModuleLoad()</code>.
  23. */
  24. public class HD_MQP implements EntryPoint {
  25. /**
  26. * The message displayed to the user when the server cannot be reached or
  27. * returns an error.
  28. */
  29.  
  30.  
  31.  
  32. private static final String SERVER_ERROR = "An error occurred while "
  33. + "attempting to contact the server. Please check your network "
  34. + "connection and try again.";
  35.  
  36. static String username;
  37. /**
  38. * Create a remote service proxy to talk to the server-side Greeting service.
  39. */
  40. private final LoginServiceAsync loginService = GWT
  41. .create(LoginService.class);
  42.  
  43. private final static LoginForm theLoginForm = new LoginForm();
  44. private final static EmployeeProfileView theEmployeeProfileView = new EmployeeProfileView();
  45.  
  46. /**
  47. * This is the entry point method.
  48. */
  49. public void onModuleLoad() {
  50.  
  51. //TODO determine what page it is and if the user is logged and set the content panel appropriately
  52.  
  53.  
  54.  
  55. RootPanel.get("loginPanel").add(theLoginForm);
  56.  
  57. //TODO make user profile tab the active one with JS
  58. // EmployeeProfileView theEmployeeProfileView = new EmployeeProfileView();
  59. // RootPanel.get("appContentPanel").add(theEmployeeProfileView);
  60. // RootPanel.get("appContentPanel").add(theLoginForm);
  61.  
  62. //TODO make user profile tab the active one with JS
  63. // EmployeeProfileView2 theEmployeeProfileView2 = new EmployeeProfileView2();
  64. // RootPanel.get("appContentPanel").add(theEmployeeProfileView2);
  65.  
  66. //TEMP: display of username from session for demo
  67. //String theUsername =
  68. //final TextBox displayStatus = new TextBox();
  69. //displayStatus.setText("Thank you for logging in " + theUsername);
  70.  
  71.  
  72.  
  73. /* final TextBox displayStatus = new TextBox();
  74. displayStatus.setText("THE STATUS IS:_");
  75.  
  76. RootPanel.get("appContentPanel").add(displayStatus);
  77.  
  78.  
  79.  
  80.  
  81. final Button sendButton = new Button("Send");
  82. final TextBox nameField = new TextBox();
  83. nameField.setText("GWT User");
  84.  
  85. // We can add style names to widgets
  86. sendButton.addStyleName("sendButton");
  87.  
  88. // Add the nameField and sendButton to the RootPanel
  89. // Use RootPanel.get() to get the entire body element
  90. RootPanel.get("nameFieldContainer").add(nameField);
  91. RootPanel.get("sendButtonContainer").add(sendButton);
  92.  
  93. // Focus the cursor on the name field when the app loads
  94. nameField.setFocus(true);
  95. nameField.selectAll();
  96. // Create the popup dialog box
  97. final DialogBox dialogBox = new DialogBox();
  98. dialogBox.setText("Remote Procedure Call");
  99. dialogBox.setAnimationEnabled(true);
  100. final Button closeButton = new Button("Close");
  101. // We can set the id of a widget by accessing its Element
  102. closeButton.getElement().setId("closeButton");
  103. final Label textToServerLabel = new Label();
  104. final HTML serverResponseLabel = new HTML();
  105. VerticalPanel dialogVPanel = new VerticalPanel();
  106. dialogVPanel.addStyleName("dialogVPanel");
  107. dialogVPanel.add(new HTML("<b>Sending name to the server:</b>"));
  108. dialogVPanel.add(textToServerLabel);
  109. dialogVPanel.add(new HTML("<br><b>Server replies:</b>"));
  110. dialogVPanel.add(serverResponseLabel);
  111. dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT);
  112. dialogVPanel.add(closeButton);
  113. dialogBox.setWidget(dialogVPanel);
  114.  
  115. // Add a handler to close the DialogBox
  116. closeButton.addClickHandler(new ClickHandler() {
  117. public void onClick(ClickEvent event) {
  118. dialogBox.hide();
  119. sendButton.setEnabled(true);
  120. sendButton.setFocus(true);
  121. }
  122. });
  123.  
  124. // Create a handler for the sendButton and nameField
  125. class MyHandler implements ClickHandler, KeyUpHandler {
  126. *//**
  127. * Fired when the user clicks on the sendButton.
  128. *//*
  129. public void onClick(ClickEvent event) {
  130. sendNameToServer();
  131. }
  132.  
  133. *//**
  134. * Fired when the user types in the nameField.
  135. *//*
  136. public void onKeyUp(KeyUpEvent event) {
  137. if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
  138. sendNameToServer();
  139. }
  140. }
  141.  
  142. *//**
  143. * Send the name from the nameField to the server and wait for a response.
  144. *//*
  145. private void sendNameToServer() {
  146. sendButton.setEnabled(false);
  147. String textToServer = nameField.getText();
  148. textToServerLabel.setText(textToServer);
  149. serverResponseLabel.setText("");
  150.  
  151. loginService.loginServer(textToServer,
  152. new AsyncCallback<Employee>() {
  153. public void onFailure(Throwable caught) {
  154. // Show the RPC error message to the user
  155. Window.alert("Unable to retrive user from DB");
  156. sendButton.setEnabled(true);
  157. }
  158.  
  159. public void onSuccess(Employee result) {
  160. //standard header
  161. Window.alert("Able to retrive user from DB: \n"+ result.toString());
  162. RootPanel.get().setVisible(false);
  163. //sendButton.setEnabled(true);
  164. RootPanel.get("nameFieldContainer").clear();
  165. RootPanel.get("sendButtonContainer").clear();
  166. RootPanel.get().add(new ApplicationLayout(result));
  167. RootPanel.get().setVisible(true);
  168. }
  169. });
  170. }
  171. }
  172.  
  173. // Add a handler to send the name to the server
  174. MyHandler handler = new MyHandler();
  175. sendButton.addClickHandler(handler);
  176. nameField.addKeyUpHandler(handler);
  177.  
  178. */ }
  179.  
  180. public static void loginUser(){
  181. createTabs("User");
  182. RootPanel.get("loginPanel").remove(theLoginForm);
  183. }
  184.  
  185. /** Creates the tabs on the page
  186. *
  187. * @param type Manager / User
  188. */
  189. public static void createTabs(String type){
  190. String userTabs = "<li id=\"home\" class=\"active\"><a href=\"#\">Home</a></li><li><a href=\"#\">User Profile</a><ul><li class=\"first\"><a id=\"viewuserprofile\" href=\"#\">View</a></li><li id=\"edituserprofile\" class=\"last\"><a href=\"#\">Edit</a></li></ul></li><li><a href=\"#\">Timesheeets</a></li><li><a href=\"#\">Reviews</a></li><li><a href=\"#\">Settings</a></li>";
  191. Element nav = DOM.getElementById("nav");
  192. DOM.setInnerHTML(nav, userTabs);
  193.  
  194.  
  195. Element viewProf = DOM.createElement("li");
  196. viewProf.setInnerText("USER PROFILE VIEW");
  197.  
  198. DOM.setEventListener(viewProf, new EventListener(){
  199.  
  200. @Override
  201. public void onBrowserEvent(Event ONCLICK) {
  202. if (RootPanel.get("loginPanel").getWidgetCount() < 1)
  203. RootPanel.get("loginPanel").add(theEmployeeProfileView);
  204. Info.display("View Login", "Number of wigits: " + RootPanel.get("loginPanel").getWidgetCount());
  205. }
  206. });
  207. nav.appendChild(viewProf);
  208.  
  209. Element edit = DOM.getElementById("edituserprofile");
  210.  
  211. }
  212. }
Add Comment
Please, Sign In to add comment