Subversion Repositories SmartDukaan

Rev

Rev 2427 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package in.shop2020.catalog.dashboard.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Widget;

/**
 * Contains logo, welcome message, about and sign out link.
 */
public class TopPanel extends Composite {

  interface Binder extends UiBinder<Widget, TopPanel> { }
  private static final Binder binder = GWT.create(Binder.class);

  @UiField Anchor signOutLink;
  @UiField Anchor aboutLink;
  @UiField HTML greetingLabel;

  public TopPanel() {
    initWidget(binder.createAndBindUi(this));
  }

  @UiHandler("aboutLink")
  void onAboutClicked(ClickEvent event) {
    final DialogBox dlg = new DialogBox();
    Button ok = new Button("Close");
    ok.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            dlg.hide();               
        }
    });
    dlg.setText("Catalog Dashboard.\nYou can edit the item details here.");
    dlg.setWidget(ok);
    dlg.setAutoHideEnabled(true);
    dlg.setGlassEnabled(true);
    dlg.setPopupPosition(500, 250);
    dlg.show();
    dlg.center();
  }
  
  /**
   * Called from CatalogDashboard.java after login authentication is successful.
   * @param greeting
   */
  public void changeGreeting(String greeting){
          greetingLabel.setText("Welcome "+ greeting);
  }
  
  /**
   * Click listener of sign out link is added in CatalogDashboard.initMainDB(String)
   * @return
   */
  public Anchor getSignOutLink(){
          return signOutLink;
  }
}