Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package hd.client;
- import com.extjs.gxt.ui.client.widget.Info;
- import com.google.gwt.core.client.EntryPoint;
- import com.google.gwt.core.client.GWT;
- import com.google.gwt.dom.client.Node;
- import com.google.gwt.event.dom.client.ClickEvent;
- import com.google.gwt.event.dom.client.ClickHandler;
- import com.google.gwt.user.client.Element;
- import com.google.gwt.user.client.DOM;
- import com.google.gwt.user.client.Event;
- import com.google.gwt.user.client.EventListener;
- import com.google.gwt.user.client.ui.ClickListener;
- import com.google.gwt.user.client.ui.HTML;
- import com.google.gwt.user.client.ui.RootPanel;
- import com.google.gwt.user.client.ui.Widget;
- /**
- * Entry point classes define <code>onModuleLoad()</code>.
- */
- public class HD_MQP implements EntryPoint {
- /**
- * The message displayed to the user when the server cannot be reached or
- * returns an error.
- */
- private static final String SERVER_ERROR = "An error occurred while "
- + "attempting to contact the server. Please check your network "
- + "connection and try again.";
- static String username;
- /**
- * Create a remote service proxy to talk to the server-side Greeting service.
- */
- private final LoginServiceAsync loginService = GWT
- .create(LoginService.class);
- private final static LoginForm theLoginForm = new LoginForm();
- private final static EmployeeProfileView theEmployeeProfileView = new EmployeeProfileView();
- /**
- * This is the entry point method.
- */
- public void onModuleLoad() {
- //TODO determine what page it is and if the user is logged and set the content panel appropriately
- RootPanel.get("loginPanel").add(theLoginForm);
- //TODO make user profile tab the active one with JS
- // EmployeeProfileView theEmployeeProfileView = new EmployeeProfileView();
- // RootPanel.get("appContentPanel").add(theEmployeeProfileView);
- // RootPanel.get("appContentPanel").add(theLoginForm);
- //TODO make user profile tab the active one with JS
- // EmployeeProfileView2 theEmployeeProfileView2 = new EmployeeProfileView2();
- // RootPanel.get("appContentPanel").add(theEmployeeProfileView2);
- //TEMP: display of username from session for demo
- //String theUsername =
- //final TextBox displayStatus = new TextBox();
- //displayStatus.setText("Thank you for logging in " + theUsername);
- /* final TextBox displayStatus = new TextBox();
- displayStatus.setText("THE STATUS IS:_");
- RootPanel.get("appContentPanel").add(displayStatus);
- final Button sendButton = new Button("Send");
- final TextBox nameField = new TextBox();
- nameField.setText("GWT User");
- // We can add style names to widgets
- sendButton.addStyleName("sendButton");
- // Add the nameField and sendButton to the RootPanel
- // Use RootPanel.get() to get the entire body element
- RootPanel.get("nameFieldContainer").add(nameField);
- RootPanel.get("sendButtonContainer").add(sendButton);
- // Focus the cursor on the name field when the app loads
- nameField.setFocus(true);
- nameField.selectAll();
- // Create the popup dialog box
- final DialogBox dialogBox = new DialogBox();
- dialogBox.setText("Remote Procedure Call");
- dialogBox.setAnimationEnabled(true);
- final Button closeButton = new Button("Close");
- // We can set the id of a widget by accessing its Element
- closeButton.getElement().setId("closeButton");
- final Label textToServerLabel = new Label();
- final HTML serverResponseLabel = new HTML();
- VerticalPanel dialogVPanel = new VerticalPanel();
- dialogVPanel.addStyleName("dialogVPanel");
- dialogVPanel.add(new HTML("<b>Sending name to the server:</b>"));
- dialogVPanel.add(textToServerLabel);
- dialogVPanel.add(new HTML("<br><b>Server replies:</b>"));
- dialogVPanel.add(serverResponseLabel);
- dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT);
- dialogVPanel.add(closeButton);
- dialogBox.setWidget(dialogVPanel);
- // Add a handler to close the DialogBox
- closeButton.addClickHandler(new ClickHandler() {
- public void onClick(ClickEvent event) {
- dialogBox.hide();
- sendButton.setEnabled(true);
- sendButton.setFocus(true);
- }
- });
- // Create a handler for the sendButton and nameField
- class MyHandler implements ClickHandler, KeyUpHandler {
- *//**
- * Fired when the user clicks on the sendButton.
- *//*
- public void onClick(ClickEvent event) {
- sendNameToServer();
- }
- *//**
- * Fired when the user types in the nameField.
- *//*
- public void onKeyUp(KeyUpEvent event) {
- if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
- sendNameToServer();
- }
- }
- *//**
- * Send the name from the nameField to the server and wait for a response.
- *//*
- private void sendNameToServer() {
- sendButton.setEnabled(false);
- String textToServer = nameField.getText();
- textToServerLabel.setText(textToServer);
- serverResponseLabel.setText("");
- loginService.loginServer(textToServer,
- new AsyncCallback<Employee>() {
- public void onFailure(Throwable caught) {
- // Show the RPC error message to the user
- Window.alert("Unable to retrive user from DB");
- sendButton.setEnabled(true);
- }
- public void onSuccess(Employee result) {
- //standard header
- Window.alert("Able to retrive user from DB: \n"+ result.toString());
- RootPanel.get().setVisible(false);
- //sendButton.setEnabled(true);
- RootPanel.get("nameFieldContainer").clear();
- RootPanel.get("sendButtonContainer").clear();
- RootPanel.get().add(new ApplicationLayout(result));
- RootPanel.get().setVisible(true);
- }
- });
- }
- }
- // Add a handler to send the name to the server
- MyHandler handler = new MyHandler();
- sendButton.addClickHandler(handler);
- nameField.addKeyUpHandler(handler);
- */ }
- public static void loginUser(){
- createTabs("User");
- RootPanel.get("loginPanel").remove(theLoginForm);
- }
- /** Creates the tabs on the page
- *
- * @param type Manager / User
- */
- public static void createTabs(String type){
- 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>";
- Element nav = DOM.getElementById("nav");
- DOM.setInnerHTML(nav, userTabs);
- Element viewProf = DOM.createElement("li");
- viewProf.setInnerText("USER PROFILE VIEW");
- DOM.setEventListener(viewProf, new EventListener(){
- @Override
- public void onBrowserEvent(Event ONCLICK) {
- if (RootPanel.get("loginPanel").getWidgetCount() < 1)
- RootPanel.get("loginPanel").add(theEmployeeProfileView);
- Info.display("View Login", "Number of wigits: " + RootPanel.get("loginPanel").getWidgetCount());
- }
- });
- nav.appendChild(viewProf);
- Element edit = DOM.getElementById("edituserprofile");
- }
- }
Add Comment
Please, Sign In to add comment