Example usage for com.vaadin.server Page getCurrent

List of usage examples for com.vaadin.server Page getCurrent

Introduction

In this page you can find the example usage for com.vaadin.server Page getCurrent.

Prototype

public static Page getCurrent() 

Source Link

Document

Gets the Page to which the current uI belongs.

Usage

From source file:edu.nps.moves.mmowgli.modules.actionplans.ActionPlanPage2.java

License:Open Source License

@Override
public boolean actionPlanEditBeginEvent(Serializable apId, String msg) {
    if (apId != this.apId)
        return false;

    if (imAuthor) {
        Notification notif = new Notification("", "", Notification.Type.HUMANIZED_MESSAGE);
        notif.setPosition(Position.TOP_LEFT);
        notif.setStyleName("m-actionplan-edit-notification");
        notif.setDelayMsec(3000); // 3 secs to disappear

        notif.setCaption("");
        notif.setDescription(msg);/*  ww  w  .ja v a2  s .c  o m*/
        notif.show(Page.getCurrent());
        return true;
    }
    return false;
}

From source file:edu.nps.moves.mmowgli.modules.actionplans.RfeDialog.java

License:Open Source License

@HibernateSessionThreadLocalConstructor
@SuppressWarnings("serial")
public RfeDialog(Object aplnId) {
    this.apId = aplnId;

    setCaption("Request for Expertise");
    setModal(true);/*from   w w w . j  a  va  2s. c o  m*/
    setSizeUndefined();
    setWidth("500px");
    setHeight("400px");

    VerticalLayout vLay = new VerticalLayout();
    setContent(vLay);
    vLay.setMargin(true);
    vLay.setSpacing(true);
    vLay.setSizeFull();

    IDButton searchButt = new IDButton("Option 1: Search for players with needed expertise", SEARCHCLICK, null);
    searchButt.enableAction(false); // do manually
    searchButt.addClickListener(new SearchListener());
    vLay.addComponent(searchButt);

    VerticalLayout nuts = new VerticalLayout();
    vLay.addComponent(nuts);
    nuts.setSizeFull();
    vLay.setExpandRatio(nuts, 1.0f);
    Label lab;
    /*vLay*/nuts.addComponent(lab = new Label("Option 2: Post help-wanted notice to action plan"));
    lab.addStyleName("m-font-bold11");

    final VerticalLayout helpWantedPan = new VerticalLayout();
    /*vLay*/nuts.addComponent(helpWantedPan);
    helpWantedPan.addStyleName("m-greyborder");
    helpWantedPan.setWidth("99%");
    helpWantedPan.setHeight("99%");
    helpWantedPan.setSpacing(true);
    helpWantedPan.setMargin(true);
    /*vLay*/nuts.setExpandRatio(helpWantedPan, 1.0f);

    helpWantedTA = new TextArea("Current posting");
    helpWantedTA.setWidth("100%");
    helpWantedTA.setHeight("100%");
    helpWantedTA.setNullRepresentation("");
    helpWantedPan.addComponent(helpWantedTA);
    helpWantedPan.setExpandRatio(helpWantedTA, 1.0f);

    HorizontalLayout buttLay = new HorizontalLayout();
    helpWantedPan.addComponent(buttLay);
    buttLay.setSpacing(true);
    buttLay.setWidth("100%");

    buttLay.addComponent(lab = new Label());
    lab.setWidth("10px");

    clearButt = new Button("Clear");
    buttLay.addComponent(clearButt);
    clearButt.addClickListener(clearButtLis = new ClickListener() {
        @Override
        @MmowgliCodeEntry
        @HibernateOpened
        @HibernateClosed
        public void buttonClick(ClickEvent event) {
            HSess.init();
            ActionPlan ap = ActionPlan.getTL(apId);
            helpWantedTA.setValue(null);
            if (null != ap.getHelpWanted()) {
                ap.setHelpWanted(null);
                ActionPlan.updateTL(ap);
                Notification notif = new Notification("Cleared");
                notif.setDelayMsec(3000);
                notif.show(Page.getCurrent());
                GameEventLogger.logHelpWantedTL(ap);
                notifyAuthorsOfChangeTL(ap);
            }
            HSess.close();
        }
    });

    buttLay.addComponent(lab = new Label());
    buttLay.setExpandRatio(lab, 1.0f);

    postButt = new Button("Post");
    buttLay.addComponent(postButt);
    postButt.addClickListener(new ClickListener() {
        @Override
        @MmowgliCodeEntry
        @HibernateOpened
        @HibernateClosed
        public void buttonClick(ClickEvent event) {
            Object val = helpWantedTA.getValue();
            if (val == null || val.toString().length() <= 0) {
                clearButtLis.buttonClick(event);
                return;
            }

            HSess.init();
            String s = val.toString();
            ActionPlan ap = ActionPlan.getTL(apId);
            if (s == null ? ap.getHelpWanted() != null : !s.equals(ap.getHelpWanted())) {
                ap.setHelpWanted(s);
                ActionPlan.updateTL(ap);
                Notification notif = new Notification("Posted");
                notif.setDelayMsec(3000);
                notif.show(Page.getCurrent());
                GameEventLogger.logHelpWantedTL(ap);
                notifyAuthorsOfChangeTL(ap);
            }
            HSess.close();
        }
    });
    buttLay.addComponent(lab = new Label());
    lab.setWidth("10px");

    helpWantedPan.addComponent(lab = new Label());
    lab.setHeight("10px");

    IDButton troubleButt = new IDButton("Option 3: Post Trouble Report", POSTTROUBLECLICK, null);
    troubleButt.enableAction(false); // managed manually
    troubleButt.addClickListener(new TroubleListener());
    vLay.addComponent(troubleButt);

    Button closeButt = new Button("Close");
    vLay.addComponent(closeButt);
    closeButt.addClickListener(new CloseListener());

    vLay.setComponentAlignment(closeButt, Alignment.MIDDLE_RIGHT);

    ActionPlan ap = ActionPlan.getTL(apId);
    String s = ap.getHelpWanted();
    helpWantedTA.setValue(s);
}

From source file:edu.nps.moves.mmowgli.modules.administration.MapGameDesignPanel.java

License:Open Source License

@HibernateSessionThreadLocalConstructor
@SuppressWarnings("serial")
public MapGameDesignPanel(GameDesignGlobals globs) {
    super(false, globs);
    Game g = Game.getTL();/*w  ww .j av  a 2s. c  o m*/
    TextArea titleTA;
    final Serializable uid = Mmowgli2UI.getGlobals().getUserID();

    titleTA = (TextArea) addEditLine("Map Title", "Game.mapTitle", g, g.getId(), "MapTitle").ta;
    titleTA.setValue(g.getMapTitle());
    titleTA.setRows(1);

    latTA = addEditLine("Map Initial Latitude", "Game.mmowgliMapLatitude");
    boolean lastRO = latTA.isReadOnly();
    latTA.setReadOnly(false);
    latTA.setValue("" + g.getMapLatitude());
    latTA.setRows(1);
    latTA.setReadOnly(lastRO);
    latTA.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        @MmowgliCodeEntry
        @HibernateOpened
        @HibernateClosed
        public void valueChange(ValueChangeEvent event) {
            HSess.init();
            try {
                String val = event.getProperty().getValue().toString();
                double lat = Double.parseDouble(val);
                Game g = Game.getTL();
                g.setMapLatitude(lat);
                Game.updateTL();
                GameEventLogger.logGameDesignChangeTL("Map latitude", val, uid);
            } catch (Exception ex) {
                new Notification("Parameter error",
                        "<html>Check for proper decimal format.</br>New value not committed.",
                        Notification.Type.WARNING_MESSAGE, true).show(Page.getCurrent());
            }
            HSess.close();
        }
    });

    lonTA = addEditLine("Map Initial Longitude", "Game.mmowgliMapLongitude");
    lastRO = lonTA.isReadOnly();
    lonTA.setReadOnly(false);
    lonTA.setValue("" + g.getMapLongitude());
    lonTA.setRows(1);
    lonTA.setReadOnly(lastRO);
    lonTA.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        @MmowgliCodeEntry
        @HibernateOpened
        @HibernateClosed
        public void valueChange(ValueChangeEvent event) {
            //System.out.println("lon valueChange");
            HSess.init();
            try {
                String val = event.getProperty().getValue().toString();
                double lon = Double.parseDouble(val);
                Game g = Game.getTL();
                g.setMapLongitude(lon);
                Game.updateTL();
                GameEventLogger.logGameDesignChangeTL("Map longitude", val, uid);
            } catch (Exception ex) {
                new Notification("Parameter error",
                        "<html>Check for proper decimal format.</br>New value not committed.",
                        Notification.Type.WARNING_MESSAGE, true).show(Page.getCurrent());
            }
            HSess.close();
        }
    });

    zoomTA = addEditLine("Map Initial Zoom", "Game.mmowgliMapZoom");
    lastRO = zoomTA.isReadOnly();
    zoomTA.setReadOnly(false);
    zoomTA.setValue("" + g.getMapZoom());
    zoomTA.setRows(1);
    zoomTA.setReadOnly(lastRO);
    zoomTA.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        @MmowgliCodeEntry
        @HibernateOpened
        @HibernateClosed
        public void valueChange(ValueChangeEvent event) {
            HSess.init();
            try {
                String val = event.getProperty().getValue().toString();
                int zoom = Integer.parseInt(val);
                Game g = Game.getTL();
                g.setMapZoom(zoom);
                Game.updateTL();
                GameEventLogger.logGameDesignChangeTL("Map zoom", val, uid);
            } catch (Exception ex) {
                new Notification("Parameter error",
                        "Check for proper integer format.</br>New value not committed.",
                        Notification.Type.WARNING_MESSAGE, true).show(Page.getCurrent());
            }
            HSess.close();
        }
    });
    Button b;
    this.addComponentLine(b = new Button("Set to generic Mmowgli Map Defaults", new MapDefaultSetter()));
    b.setEnabled(!globs.readOnlyCheck(false));
}

From source file:edu.nps.moves.mmowgli.modules.administration.ReportsGameDesignPanel.java

License:Open Source License

@HibernateSessionThreadLocalConstructor
@SuppressWarnings("serial")
public ReportsGameDesignPanel(GameDesignGlobals globs) {
    super(false, globs);
    Game g = Game.getTL();//w  w w .j  a  v a2s  . co m
    long period = g.getReportIntervalMinutes();

    TextArea ta;

    ta = addEditLine("1 Game Reports publishing interval (minutes)", "Game.reportIntervalMinutes");
    boolean lastRO = ta.isReadOnly();
    ta.setReadOnly(false);
    ta.setValue("" + period);
    ta.setRows(1);
    ta.setReadOnly(lastRO);
    ta.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        @MmowgliCodeEntry
        @HibernateOpened
        @HibernateClosed
        public void valueChange(ValueChangeEvent event) {
            //System.out.println("msid valueChange");
            HSess.init();
            try {
                String val = event.getProperty().getValue().toString();
                long lg = Long.parseLong(val);
                if (lg < 0)
                    throw new Exception();

                MmowgliSessionGlobals globs = Mmowgli2UI.getGlobals();
                Game gm = Game.getTL(1L);
                gm.setReportIntervalMinutes(lg);
                Game.updateTL();
                GameEventLogger.logGameDesignChangeTL("Report interval", "" + "" + lg, globs.getUserID());

                // Wake it up
                AppMaster.instance().pokeReportGenerator();
            } catch (Exception ex) {
                new Notification("Parameter error",
                        "<html>Check for proper positive integer format.</br>New value not committed.",
                        Notification.Type.WARNING_MESSAGE, true).show(Page.getCurrent());
            }
            HSess.close();
        }
    });
    addEditBoolean("2 Indicate PDF reports available", "Game.pdfAvailable", g, 1L, "PdfAvailable");
    addEditBoolean("2 Show hidden cards", "Game.reportsShowHiddenCards", g, 1L, "ReportsShowHiddenCards");
}

From source file:edu.nps.moves.mmowgli.modules.registrationlogin.RegistrationPageBase.java

License:Open Source License

private void doCACNotif(String title, String text) {
    Notification notif = new Notification(title, text, Notification.Type.HUMANIZED_MESSAGE);
    notif.setPosition(Position.BOTTOM_CENTER);
    notif.setHtmlContentAllowed(true);//w  w  w  . j  a v  a 2  s  .  co m
    notif.setDelayMsec(2000);
    notif.show(Page.getCurrent());
}

From source file:edu.nps.moves.mmowgli.modules.registrationlogin.RegistrationPageBase.java

License:Open Source License

@Override
@MmowgliCodeEntry//from  ww w.jav a2 s. c  o  m
@HibernateConditionallyOpened
@HibernateConditionallyClosed
@HibernateUpdate
@HibernateUserUpdate
@HibernateUserRead
public void buttonClick(ClickEvent event) {
    MSysOut.println(DEBUG_LOGS, "RegistrationPageBase multi-button handler entered");

    killQuickLoginThread(); // if running

    if (lockedOut)
        return;

    if (event.getButton() == signupButt) {
        //String url = VaadinServletService.getCurrentServletRequest().getRequestURI();
        String url = AppMaster.getUrlString();
        if (url.endsWith("PUSH/")) //todo figure this out
            url = url.substring(0, url.length() - 5);
        if (url.endsWith("PUSH"))
            url = url.substring(0, url.length() - 4);
        if (url.endsWith("/"))
            url = url + "signup";
        else
            url = url + "/signup";

        Mmowgli2UI.getAppUI().getSession().close(); //app.close();
        Mmowgli2UI.getAppUI().getPage().setLocation(url);
        return;
    }
    Object key = HSess.checkInit();
    if (event.getButton() == imNewButt) {
        MSysOut.println(NEWUSER_CREATION_LOGS, "\"I'm new to Mmowgli\" clicked");
        if (!CACManager.canRegisterTL(Mmowgli2UI.getGlobals().getCACInfo())) {
            Notification notif = new Notification("Can't Register", "CAC card required",
                    Notification.Type.ERROR_MESSAGE);
            notif.show(Page.getCurrent());
        } else {
            RegistrationPageAgreementCombo comboPg = new RegistrationPageAgreementCombo(this);
            openPopup(comboPg, comboPg.getUsualWidth());
        }
        HSess.checkClose(key);
        return;
    }

    if (event.getButton() == guestButt) {
        LoginPopup lp = new LoginPopup(this, true);
        if (lp.userID != null) {
            handleLoginReturnTL(lp.userID);
            HSess.checkClose(key);
            return;
        }
        // Here is we clicked guest button, but no guest user in db or guest has been deemed locked out ("accountDisabled");
        Notification.show("Can't login!", "No guest account registered.  Please submit a trouble report.",
                Notification.Type.ERROR_MESSAGE);

        // Continue to allow login with other name
        openPopup(lp, lp.getUsualWidth());
        HSess.checkClose(key);
        return;
    }

    if (currentPopup instanceof RegistrationPageAgreementCombo) {
        closePopup(currentPopup);
        boolean rejected = ((RegistrationPageAgreementCombo) currentPopup).getRejected();
        Game g = Game.getTL();
        if (rejected) {
            // Either let them try again or close and say thank you
            handleLoginReturnTL(null); // back to try again
            //Mmowgli2UI.getAppUI().quitAndGoTo(GameLinks.getTL().getThanksForInterestLink());  // bye bye
            HSess.checkClose(key);
            return;
        }
        if (g.isSecondLoginPermissionPage()) {
            RegistrationPageSecondPermissionPopup p2 = new RegistrationPageSecondPermissionPopup(this);
            openPopup(p2, p2.getUsualWidth());
            HSess.checkClose(key);
            return;
        }
        RegistrationPageSurvey surv = new RegistrationPageSurvey(this);
        openPopup(surv, surv.getUsualWidth());
        HSess.checkClose(key);
        return;
    }
    if (currentPopup instanceof RegistrationPageSecondPermissionPopup) {
        closePopup(currentPopup);
        boolean rejected = ((RegistrationPageSecondPermissionPopup) currentPopup).getRejected();
        if (rejected) {
            // Either let them try again or close and say thankyou
            handleLoginReturnTL(null); // back to try again
            //Mmowgli2UI.getAppUI().quitAndGoTo(GameLinks.getTL().getThanksForInterestLink());  // bye bye
            HSess.checkClose(key);
            return;
        }

        RegistrationPageSurvey surv = new RegistrationPageSurvey(this);
        openPopup(surv, surv.getUsualWidth());
        HSess.checkClose(key);
        return;
    }
    /*    if (currentPopup instanceof RegistrationPageConsent) {
          app.getMainWindow().removeWindow(currentPopup);
          boolean rejected = ((RegistrationPageConsent)currentPopup).getRejected();
          if(rejected) {
            app.getMainWindow().setScrollTop(0);
            return;
          }
          //else
          RegistrationPageAUP aup = new RegistrationPageAUP(app,this);
          openPopup(aup,aup.getUsualWidth());
          return;
        }
        if(currentPopup instanceof RegistrationPageAUP) {
          app.getMainWindow().removeWindow(currentPopup);
          boolean rejected = ((RegistrationPageAUP)currentPopup).getRejected();
          if(rejected) {
            app.getMainWindow().setScrollTop(0);
            return;
          }
          //else
          RegistrationPageSurvey surv = new RegistrationPageSurvey(app,this);
          openPopup(surv,surv.getUsualWidth());
          return;
        }
        */
    if (currentPopup instanceof RegistrationPageSurvey) {
        closePopup(currentPopup);
        if (((RegistrationPageSurvey) currentPopup).wasCancelButtonClicked()) {
            // Either let them try again or close and say thankyou
            handleLoginReturnTL(null); // back to try again
            //Mmowgli2UI.getAppUI().quitAndGoTo(GameLinks.getTL().getThanksForInterestLink());  // bye bye
            HSess.checkClose(key);
            return;
        }
        // don't have to do the survey
        boolean rejected = ((RegistrationPageSurvey) currentPopup).getRejected();
        okSurvey = !rejected;
        if (!rejected)
            MSysOut.println(NEWUSER_CREATION_LOGS, "Accept survey clicked");
        else
            MSysOut.println(NEWUSER_CREATION_LOGS, "Reject survey clicked");

        RegistrationPagePopupFirstA pa = new RegistrationPagePopupFirstA(this);
        openPopup(pa, pa.getUsualWidth());
        HSess.checkClose(key);
        return;
    }

    if (currentPopup instanceof RegistrationPagePopupFirstA) {
        closePopup(currentPopup);
        userId = ((RegistrationPagePopupFirstA) currentPopup).getUserId();
        if (userId == null) { // cancelled
            UI.getCurrent().setScrollTop(0);
            HSess.checkClose(key);
            return;
        }
        RegistrationPagePopupFirstB pb = new RegistrationPagePopupFirstB(this, userId);
        openPopup(pb, pb.getUsualWidth());
        HSess.checkClose(key);
        return;
    }

    if (event.getButton() == imRegisteredButt) {
        if (!CACManager.canLoginTL(Mmowgli2UI.getGlobals().getCACInfo())) {
            Notification notif = new Notification("Can't Login", "CAC card required",
                    Notification.Type.ERROR_MESSAGE);
            notif.show(Page.getCurrent());
        } else {
            LoginPopup lp = new LoginPopup(this);
            openPopup(lp, lp.getUsualWidth());
        }
        HSess.checkClose(key);
        return;
    }
    if (currentPopup instanceof RegistrationPagePopupFirstB) {
        closePopup(currentPopup);
        userId = ((RegistrationPagePopupFirstB) currentPopup).getUserId();
        if (userId == null) { // cancelled
            UI.getCurrent().setScrollTop(0);
            HSess.checkClose(key);
            return;
        }
        // That user is detached from our session right now
        RegistrationPagePopupSecond p2 = new RegistrationPagePopupSecond(this, userId);
        openPopup(p2, p2.getUsualWidth());
        HSess.checkClose(key);
        return;
    }
    if (currentPopup instanceof RegistrationPagePopupSecond) {
        closePopup(currentPopup);
        userId = ((RegistrationPagePopupSecond) currentPopup).getUserId();
        if (userId == null) {
            UI.getCurrent().setScrollTop(0);
            HSess.checkClose(key);
            return;
        }
        RoleSelectionPage rsp = new RoleSelectionPage(this, userId);
        openPopup(rsp, rsp.getUsualWidth());
        HSess.checkClose(key);
        return;
    }
    if (currentPopup instanceof RoleSelectionPage) {
        // check for good stuff
        // put up warning if can't do it
        closePopup(currentPopup);
        userId = ((RoleSelectionPage) currentPopup).getUserId();
        if (userId == null) {
            UI.getCurrent().setScrollTop(0);
            HSess.checkClose(key);
            return;
        }

        User _usr = User.getTL(userId); // into this session
        doOtherUserInit(_usr);
        _usr.setOkSurvey(okSurvey); // saved above
        Game g = Game.getTL();
        _usr.setRegisteredInMove(g.getCurrentMove()); // this is now redundant...done on new User()

        User.updateTL(_usr);

        Mmowgli2UI.getGlobals().getScoreManager().userCreatedTL(_usr); // give him his points if appropriate

        UI.getCurrent().setScrollTop(0);
        wereInTL(_usr);
        HSess.checkClose(key);

        MSysOut.println(NEWUSER_CREATION_LOGS,
                "New user registration successful, userID " + _usr.getUserName());
        return;
    }
    if (currentPopup instanceof LoginPopup) {
        handleLoginReturnTL(((LoginPopup) currentPopup).getUserId());
        HSess.checkClose(key);
        return;
    }
    HSess.checkClose(key);

    System.err.println("Program logic error in RegistrationPageBase.buttonClick()");
}

From source file:edu.nps.moves.mmowgli.signupServer.SignupServer.java

License:Open Source License

private void doRedirNotification(final String url) {
    Notification notif = new Notification("<center>Welcome to MMOWGLI!<center>",
            "<br/><center>We're taking you directly to the game.<center>", Notification.Type.HUMANIZED_MESSAGE);

    notif.setDelayMsec(5000);/*from   w  w w  . ja  v  a 2s.  co  m*/
    notif.setPosition(Position.MIDDLE_CENTER);
    notif.setHtmlContentAllowed(true);
    notif.setStyleName("m-green-notification");
    notif.show(Page.getCurrent());

    Timer timer = new Timer();
    timer.schedule(new TimerTask() {
        @Override
        public void run() {
            UI.getCurrent().access(new Runnable() {
                @Override
                public void run() {
                    quitUIAndGoTo(url);
                }
            });
        }
    }, 4000);
}

From source file:edu.nps.moves.mmowgli.signupServer.SignupWindow.java

License:Open Source License

@HibernateSessionThreadLocalConstructor
public SignupWindow(String title, SignupServer ssui) {
    // super(title);
    this.ui = ssui;
    gameImagesUrl = AppMaster.instance().getGameImagesUrlString();
    if (!gameImagesUrl.endsWith("/"))
        gameImagesUrl = gameImagesUrl + "/";
    appUrl = Page.getCurrent().getLocation().toString();
    appUrl = appUrl.substring(0, appUrl.lastIndexOf("/"));
    addComponent(new Content());
    //  setContent(new Content());
    //  this.setHeightUndefined();
    //    this.addCloseListener(new CloseListener()
    //    {//from  w  ww. ja  v a2  s .c o m
    //      @Override
    //      public void windowClose(CloseEvent e)
    //      {
    //        ui.quitAndGoTo(appUrl);        
    //      }     
    //    });
}

From source file:edu.nps.moves.security.PasswordResetUI.java

License:Open Source License

private void handleChangeTL(User user) {
    this.user = user;
    Game g = Game.getTL();//from  w w  w.j a  v a2 s  . c o  m

    String brand = g.getCurrentMove().getTitle();
    Page.getCurrent().setTitle("Password reset for " + brand + " mmowgli");

    HorizontalLayout hLay = new HorizontalLayout();
    hLay.setMargin(true);
    hLay.setWidth("100%");
    setContent(hLay);

    GameLinks gl = GameLinks.getTL();
    String blog = gl.getBlogLink();
    Label lab;
    hLay.addComponent(lab = new Label());
    hLay.setExpandRatio(lab, 0.5f);

    VerticalLayout vl = new VerticalLayout();
    hLay.addComponent(vl);
    vl.setWidth(bannerWidthPx);

    hLay.addComponent(lab = new Label());
    hLay.setExpandRatio(lab, 0.5f);

    vl.addStyleName("m-greyborder");
    vl.setMargin(true);
    vl.setSpacing(true);

    vl.addComponent(lab = new HtmlLabel(""));
    lab.addStyleName("m-font-21-bold");
    lab.setSizeUndefined();
    vl.setComponentAlignment(lab, Alignment.MIDDLE_CENTER);
    StringBuilder sb = new StringBuilder();
    sb.append(thanksHdr1);
    sb.append(blog);
    sb.append(thanksHdr2);
    sb.append(brand);
    sb.append(thanksHdr3);
    lab.setValue(sb.toString());

    vl.addComponent(lab = new HtmlLabel(""));
    lab.setHeight("15px");
    vl.setComponentAlignment(lab, Alignment.MIDDLE_CENTER);

    FormLayout fLay = new FormLayout();
    fLay.setSizeUndefined();
    fLay.addStyleName("m-login-form"); // to allow styling contents (v-textfield)
    vl.addComponent(fLay);
    vl.setComponentAlignment(fLay, Alignment.MIDDLE_CENTER);

    newPw = new PasswordField("New Password");
    newPw.setWidth("99%");
    fLay.addComponent(newPw);

    newPw2 = new PasswordField("Again, please");
    newPw2.setWidth("99%");
    fLay.addComponent(newPw2);

    HorizontalLayout buttLay = new HorizontalLayout();
    buttLay.setSpacing(true);
    vl.addComponent(buttLay);
    vl.setComponentAlignment(buttLay, Alignment.TOP_CENTER);

    NativeButton cancelButt = new NativeButton();
    cancelButt.setStyleName("m-cancelButton");
    buttLay.addComponent(cancelButt);
    buttLay.setComponentAlignment(cancelButt, Alignment.BOTTOM_RIGHT);

    saveButt = new NativeButton();
    saveButt.setClickShortcut(ShortcutAction.KeyCode.ENTER);
    saveButt.setStyleName("m-continueButton"); //m-saveChangesButton");
    buttLay.addComponent(saveButt);
    buttLay.setComponentAlignment(saveButt, Alignment.BOTTOM_RIGHT);

    cancelButt.addClickListener(this);
    saveButt.addClickListener(this);
}

From source file:edu.vserver.exercises.videoMcq.QuestionForm.java

License:Apache License

/**
 * Sets the listeners to the buttons./*w  w  w . j av a 2s .  c  o m*/
 */
private void setListeners() {
    this.vjs.addVideojsListener(Videojs.VjsListener.ANY_EVENT, new Videojs.VjsListener() {

        private static final long serialVersionUID = 8427274367098667303L;

        @Override
        public void on(String eventName, Videojs source, Double triggerTime) {
            timeLabel.setValue(Time.convertToTimeString(triggerTime));
        }
    });
    this.vjs.addVideojsListener(Videojs.VjsListener.DURATIONCHANGE_EVENT, new Videojs.VjsListener() {

        private static final long serialVersionUID = -7568539997745781255L;

        @Override
        public void on(String eventName, Videojs source, Double triggerTime) {
            double duration = source.getDuration();
            if (duration > 0) {
                durationLabel.setValue(Time.convertToTimeString(duration));
            } else {
                durationLabel.setValue("??:??:??");
            }
        }
    });
    this.newQuestionBtn.addClickListener(new Button.ClickListener() {

        private static final long serialVersionUID = 4746159071748280285L;

        @Override
        public void buttonClick(ClickEvent event) {
            newQuestionBtn.setEnabled(false);
            cancelButton.setEnabled(true);
            saveButton.setEnabled(true);
            toggleQuestionFields(true);
            setFields(new Question());
            operationType = QuestionForm.NEW_QUESTION;
        }
    });
    this.cancelButton.addClickListener(new Button.ClickListener() {

        private static final long serialVersionUID = 3774334826140277183L;

        @Override
        public void buttonClick(ClickEvent event) {
            newQuestionBtn.setEnabled(true);
            cancelButton.setEnabled(false);
            saveButton.setEnabled(false);
            setFields(new Question());
            toggleQuestionFields(false);
        }
    });
    this.saveButton.addClickListener(new Button.ClickListener() {

        private static final long serialVersionUID = -8736827762492077607L;

        @Override
        public void buttonClick(ClickEvent event) {
            Question q = getQuestion();
            if (isValid() && vjs.isPaused()) {
                newQuestionBtn.setEnabled(true);
                cancelButton.setEnabled(false);
                saveButton.setEnabled(false);
                toggleQuestionFields(false);
                if (operationType == QuestionForm.EDIT_QUESTION) {
                    Notification n = new Notification("Question edited",
                            "<strong>Question:</strong> '" + q.getQuestion() + "' was edited succesfully!",
                            Notification.Type.TRAY_NOTIFICATION, true);
                    n.show(Page.getCurrent());
                    eventManager.callListeners(QuestionFormListener.QUESTION_EDITED_EVENT, QuestionForm.this,
                            getQuestion());
                } else {
                    Notification n = new Notification("New question added",
                            "<strong>Question:</strong> '" + q.getQuestion() + "' was added succesfully!",
                            Notification.Type.TRAY_NOTIFICATION, true);
                    n.show(Page.getCurrent());
                    eventManager.callListeners(QuestionFormListener.QUESTION_CREATED_EVENT, QuestionForm.this,
                            getQuestion());
                }
            } else {
                Notification n = new Notification("Saving failed!",
                        "<strong>Question form </strong> contains some errors!",
                        Notification.Type.WARNING_MESSAGE, true);
                n.show(Page.getCurrent());
            }
        }
    });
    this.addIncorrectAnswer.addClickListener(new Button.ClickListener() {

        private static final long serialVersionUID = 4746159071748280285L;

        @Override
        public void buttonClick(ClickEvent event) {
            wrongAnswerHandler.addWrongAnswerRow("");
        }
    });
    this.clearIncorrectAnswers.addClickListener(new Button.ClickListener() {

        private static final long serialVersionUID = 3632221052083079517L;

        @Override
        public void buttonClick(ClickEvent event) {
            wrongAnswerHandler.clear();
        }
    });
}