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.AppMaster.java

License:Open Source License

public static String getUrlString() {
    String rets = null;//w  ww  .j  a v a  2  s . c  om
    try {
        URL url = Page.getCurrent().getLocation().toURL();
        if (url.getPort() == 80 || url.getPort() == 443)
            url = new URL(url.getProtocol(), url.getHost(), url.getFile()); //lose any query bit
        else
            url = new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getFile());
        String urlString = url.toString();
        if (urlString.endsWith("/") || urlString.endsWith("\\"))
            urlString = urlString.substring(0, urlString.length() - 1);

        rets = urlString;
    } catch (MalformedURLException ex) {
        System.err.println("Can't form App URL in AppMaster.oneTimeSetAppUrlFromUI()");
    }
    return rets;
}

From source file:edu.nps.moves.mmowgli.AppMaster.java

License:Open Source License

public String getUserImagesUrlString() {
    try {//  w  w w  .  jav a2 s  . c o m
        if (userImagesUrlString.contains(GAME_URL_TOKEN)) {
            URL url = Page.getCurrent().getLocation().toURL();
            url = new URL(url.getProtocol(), url.getHost(), url.getFile());
            String gameUrl = url.toString();
            if (gameUrl.endsWith("/"))
                gameUrl = gameUrl.substring(0, gameUrl.length() - 1);
            userImagesUrlString = userImagesUrlString.replace(GAME_URL_TOKEN, gameUrl);
        }
        userImagesUrl = new URL(userImagesUrlString);
    } catch (MalformedURLException ex) {
        System.err.println("** Error constructing user images url from:" + userImagesUrlString);
    }
    return userImagesUrlString;
}

From source file:edu.nps.moves.mmowgli.components.Header.java

License:Open Source License

@SuppressWarnings("serial")
@Override//from   w w  w  .  j a va  2s .c o  m
public void initGui() {
    setWidth(HEADER_W);
    setHeight(HEADER_H);
    Game g = Game.getTL();
    GameLinks gl = GameLinks.getTL();

    Embedded embedded = new Embedded(null, mediaLoc.getHeaderBackground());
    addComponent(embedded, "top:0px;left:0px");

    if (g.isActionPlansEnabled()) {
        embedded = new Embedded(null, mediaLoc.getImage("scoretext200w50h.png"));
        addComponent(embedded, "top:52px;left:63px");
        addComponent(explorPtsLab, "top:55px;left:260px");
        addComponent(implPtsLab, "top:79px;left:247px");
    } else {
        embedded = new Embedded(null, mediaLoc.getImage("scoretextoneline200w50h.png"));
        addComponent(embedded, "top:52px;left:73px");
        addComponent(explorPtsLab, "top:65px;left:205px");
    }

    Resource res = mediaLoc.getHeaderBanner(g);
    if (res != null) {
        embedded = new Embedded(null, res);
        addComponent(embedded, pos_banner);
    }
    HorizontalLayout buttHL = new HorizontalLayout();
    buttHL.setSpacing(false);
    buttHL.setMargin(false);
    buttHL.setWidth("291px");
    buttHL.setHeight("45px");
    addComponent(buttHL, "top:1px;left:687px");

    Label lab;
    boolean armyHack = gl.getFixesLink().toLowerCase().contains("armyscitech")
            || gl.getGlossaryLink().toLowerCase().contains("armyscitech");
    if (armyHack)
        buttonChars = buttonChars - 3 + 9; // Replace "Map" with "Resources
    buttHL.addComponent(lab = new Label());
    lab.setWidth("1px");
    buttHL.setExpandRatio(lab, 0.5f);
    buttHL.addComponent(leaderBoardButt);
    buttHL.setComponentAlignment(leaderBoardButt, Alignment.MIDDLE_CENTER);
    addDivider(buttHL, buttonChars);

    // Hack
    if (armyHack) { //Hack
        Link resourceLink = makeSmallLink("Resources", "", "http://futures.armyscitech.com/resources/");
        buttHL.addComponent(resourceLink);
        buttHL.setComponentAlignment(resourceLink, Alignment.MIDDLE_CENTER);
    } else {
        buttHL.addComponent(mapButt);
        buttHL.setComponentAlignment(mapButt, Alignment.MIDDLE_CENTER);
    }
    addDivider(buttHL, buttonChars);
    buttHL.addComponent(liveBlogButt);
    buttHL.setComponentAlignment(liveBlogButt, Alignment.MIDDLE_CENTER);
    addDivider(buttHL, buttonChars);
    buttHL.addComponent(learnMoreButt);
    buttHL.setComponentAlignment(learnMoreButt, Alignment.MIDDLE_CENTER);

    buttHL.addComponent(lab = new Label());
    lab.setWidth("1px");
    buttHL.setExpandRatio(lab, 0.5f);

    addComponent(playIdeaButt, pos_playIdeaButt);

    if (g.isActionPlansEnabled()) {
        addComponent(takeActionButt, pos_takeActionButt);
        toggleTakeActionButt(true); // everbody can click it me.isGameMaster());
    } else if (armyHack) {
        embedded = new Embedded(null, mediaLoc.getImage("armylogoxpntbg80w80h.png"));
        addComponent(embedded, "top:54px;left:864px");
    }

    Serializable uid = Mmowgli2UI.getGlobals().getUserID();
    refreshUser(uid, HSess.get()); // assume in vaadin transaction here

    avatar.setWidth(HEADER_AVATAR_W);
    avatar.setHeight(HEADER_AVATAR_H);
    avatar.setDescription(user_profile_tt);
    avatar.addClickListener(new MouseEvents.ClickListener() {
        @Override
        public void click(com.vaadin.event.MouseEvents.ClickEvent event) {
            userNameButt.buttonClick(new ClickEvent(userNameButt));
        }
    });
    userNameButt.setDescription(user_profile_tt);
    addComponent(userNameButt, HEADER_USERNAME_POS);
    addComponent(avatar, "top:13px;left:6px"); //HEADER_AVATAR_POS);

    searchField.setWidth("240px");
    //  searchField.setHeight("18px");    // this causes a text _area_ to be used, giving me two lines, default height is good, style removes borders
    searchField.setInputPrompt("Search");
    searchField.setImmediate(true);
    searchField.setTextChangeEventMode(TextChangeEventMode.LAZY);
    searchField.setTextChangeTimeout(5000); // ms
    searchField.addStyleName("m-header-searchfield");
    searchField.addValueChangeListener(new Property.ValueChangeListener() {
        private static final long serialVersionUID = 1L;

        @Override
        @MmowgliCodeEntry
        @HibernateOpened
        @HibernateClosed
        public void valueChange(ValueChangeEvent event) {
            HSess.init();
            handleSearchClickTL();
            HSess.close();
            /*
            searchButt.focus();  // make the white go away
            String s = event.getProperty().getValue().toString();
            if (s.length() > 0) {
              MmowgliController controller = Mmowgli2UI.getGlobals().getController();
              controller.handleEvent(SEARCHCLICK, s, searchField);
            } */
        }
    });
    searchButt.enableAction(false); // want a local listener
    searchButt.addClickListener(new ClickListener() {
        @Override
        @MmowgliCodeEntry
        @HibernateOpened
        @HibernateClosed
        public void buttonClick(ClickEvent event) {
            HSess.init();
            handleSearchClickTL();
            HSess.close();
        }
    });
    addComponent(searchField, "top:107px;left:74px"); //"top:110px;left:74px");
    addComponent(signOutButt, "top:25px;left:250px"); //"top:18px;left:250px");
    addComponent(searchButt, "top:105px;left:30px"); //"top:100px;left:180px");

    MessageUrl mu = MessageUrl.getLastTL();
    if (mu != null)
        decorateBlogHeadlinesLink(mu);
    addBlogHeadlinesLink("top:147px;left:20px");

    String headline = blogHeadlinesLink.getCaption();
    if (headline != null && headline.length() > 0) {
        // Add Window.Notification relaying the same info as the BlogHeadLinesLink
        Notification note = new Notification("Today's News", "<br/>" + headline,
                Notification.Type.WARNING_MESSAGE, true);
        note.setPosition(Position.TOP_CENTER);
        note.setDelayMsec(5 * 1000);
        // Yellow is more an attention getter
        note.setStyleName("m-blue");
        note.show(Page.getCurrent());
    }

    addComponent(callToActionButt, "top:0px;left:333px");
    /* The css has a height, width and even a background, but stupid IE will only properly size the button if an image is
     * used.  Therefore we use an a transparent png of the proper size */
    MediaLocator medLoc = Mmowgli2UI.getGlobals().getMediaLocator();
    callToActionButt.setIcon(medLoc.getEmpty353w135h());

    Move move = g.getCurrentMove();
    if (g.isShowHeaderBranding()) {
        Media brand = g.getHeaderBranding();
        if (brand != null) {
            Embedded bremb = new Embedded(null, mediaLoc.locate(brand));
            addComponent(bremb, "top:0px;left:333px");
        } else {
            brandingLab.setHeight("30px");
            setBrandingLabelText(move, g);
            addComponent(brandingLab, "top:0px;left:333px"); //HEADER_MOVETITLE_POS);  //"top:151px;left:476px";      
        }
    }
    if (move.isShowMoveBranding()) {
        moveNumLab.setValue(move.getName());
        addComponent(moveNumLab, "top:103px;left:333px");
    }
    /*    if(user != null && (user.isAdministrator() || user.isGameMaster() || user.isDesigner() )) { // has a menu
          //  fouoLink.addStyleName("m-absolutePositioning");
            addComponent(fouoLink,"top:-10px;left:400px");
        }
        else
          addComponent(fouoLink,"top:0px;left:400px");
                
        fouoLink.setVisible(g.isShowFouo());
        */
}

From source file:edu.nps.moves.mmowgli.export.BaseExporter.java

License:Open Source License

protected void showStartNotification(String exportType) {
    Notification notif = new Notification("",
            "Export of " + exportType
                    + " begun.  Results may appear in another browser window (unless popups blocked).",
            Notification.Type.WARNING_MESSAGE); // not warning, but want yellow

    notif.setPosition(Position.MIDDLE_CENTER);
    notif.setDelayMsec(-1);//from  w  ww.j ava2s . c o m
    notif.show(Page.getCurrent());
}

From source file:edu.nps.moves.mmowgli.export.BaseExporter.java

License:Open Source License

protected void showEndNotification(String exportType) {
    Notification notif = new Notification("",
            "Export of " + exportType
                    + " complete.  Results may appear in another browser window (unless popups blocked).",
            Notification.Type.WARNING_MESSAGE);

    notif.setPosition(Position.TOP_CENTER);
    notif.setDelayMsec(5000);//from   w  ww  . j a  va 2s. c o m
    notif.show(Page.getCurrent());
}

From source file:edu.nps.moves.mmowgli.export.GameExporter.java

License:Open Source License

@Override
public void exportToBrowser(String title) {
    AppMaster.instance().pokeReportGenerator();
    //Doesn't show for very long
    Notification notification = new Notification("", "Report publication initiated",
            Notification.Type.WARNING_MESSAGE);
    notification.setPosition(Position.TOP_CENTER);
    notification.setDelayMsec(5000);/*ww  w  .j  a v  a  2  s.co  m*/
    notification.show(Page.getCurrent());

    String url = AppMaster.instance().getAppUrlString(); //.toExternalForm();
    if (!url.endsWith("/"))
        url = url + "/";
    BrowserWindowOpener.open(url + "reports", "_blank");
}

From source file:edu.nps.moves.mmowgli.Mmowgli2CACError.java

License:Open Source License

@Override
protected void init(VaadinRequest request) {
    final VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);/*from w  w w.  j a v  a2s  . c o m*/
    setContent(layout);
    Page.getCurrent().setTitle("Mmowgli Authentication Error");
    layout.addComponent(new Label("A Common Access Card (CAC) is required for entry into this game."));
    layout.addComponent(
            new Label("You may try reloading this page after insertion of a CAC into an attached reader."));

    new Thread(new Runnable() {
        @Override
        public void run() {
            Mmowgli2CACError.this.access(new Runnable() {
                public void run() {
                    System.out.println("No CAC -- killing session");
                    getSession().close();
                }
            });
        }
    }).start();
}

From source file:edu.nps.moves.mmowgli.Mmowgli2UI.java

License:Open Source License

@Override
@MmowgliCodeEntry// w w  w.j a v a 2 s  .  c  o  m
@HibernateOpened
protected void init(VaadinRequest request) {
    MSysOut.println(SYSTEM_LOGS, "Into " + (firstUI ? "Mmowgli2UILogin" : "Mmowgli2UISubsequent") + ".init()");

    BrowserPerformanceLogger.registerCurrentPage();

    AppMaster.instance().oneTimeSetAppUrlFromUI();

    Object sessKey = HSess.checkInit();
    uuid = UUID.randomUUID();

    setWindowTitleTL();
    VerticalLayout layout = new VerticalLayout();
    setContent(layout);

    MmowgliSessionGlobals globs = getSession().getAttribute(MmowgliSessionGlobals.class);
    if (!globs.initted) {
        globs.init(Page.getCurrent().getWebBrowser());
        globs.setController(new DefaultMmowgliController());
        globs.setMediaLocator(new MediaLocator());
        globs.setFirstUI(this);

        MessagingManager2 mm = new MessagingManager2();
        globs.setMessagingManager(mm);
        globs.getMessagingManager().registerSession();

        globs.setGameBooleans(Game.getTL());
    }

    globals = globs;
    setCustomBackgroundTL();

    if (firstUI) {
        setLoginContentTL();
    } else {
        setRunningApplicationFrameworkTL(null);
    }
    controllerHelper = new AbstractMmowgliControllerHelper2(this);

    //This has caused some recent exceptions, break it apart temporarily    
    //globs.getMessagingManager().addMessageListener((AbstractMmowgliController)globs.getController());
    MessagingManager2 mm = globs.getMessagingManager();
    MmowgliController cntlr = globs.getController();
    mm.addMessageListener((AbstractMmowgliController) cntlr);

    HSess.checkClose(sessKey);

    if (!globs.initted)
        globs.initted = true;

    MSysOut.println(SYSTEM_LOGS,
            "Out of " + (firstUI ? "Mmowgli2UILogin" : "Mmowgli2UISubsequent") + ".init()");
}

From source file:edu.nps.moves.mmowgli.Mmowgli2UIError.java

License:Open Source License

@SuppressWarnings("serial")
@Override/*from  w  w w. ja  va  2  s  . c o m*/
protected void init(VaadinRequest request) {
    uuid = UUID.randomUUID();

    final VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    setContent(layout);
    Page.getCurrent().setTitle("Mmowgli Login Error");
    layout.addComponent(new Label(
            "Whoops!  It looks like you are opening a second mmowgli window or tab without completing your log-in in the first."));
    //layout.addComponent(new Label("You appear to have an incomplete log-in session pending in another tab or window."));
    layout.addComponent(new Label("If this is the case, close this tab and continue with your log-in."));
    layout.addComponent(new Label(
            "If that window or tab is no longer available, begin a new Mmowgli session by clicking the following button."));
    //layout.addComponent(new Label("Any previously entered information will be discarded."));

    Button button = new Button("Begin new Mmowgli session");
    button.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            getPage().setLocation(getPage().getLocation());
            getSession().close();
        }
    });
    layout.addComponent(button);
}

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

License:Open Source License

public void initGuiTL() {
    setSizeUndefined();/*from  w w  w . j a  v  a  2  s .  c  o m*/
    setWidth(APPLICATION_SCREEN_WIDTH);
    //    setHeight("855px"); //ACTIONDASHBOARD_H);

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

    HorizontalLayout titleHL = new HorizontalLayout();
    titleHL.setWidth("95%");
    addComponent(titleHL);

    titleHL.addComponent(sp = new Label());
    sp.setWidth("20px");
    Component titleC;
    titleHL.addComponent(titleC = Mmowgli2UI.getGlobals().getMediaLocator().getActionDashboardTitle());
    titleHL.setComponentAlignment(titleC, Alignment.MIDDLE_LEFT);

    titleHL.addComponent(sp = new Label());
    sp.setWidth("1px");
    titleHL.setExpandRatio(sp, 1.0f);

    titleHL.addComponent(howToWinActionButt);
    howToWinActionButt.setDescription(howWinAction_tt);

    AbsoluteLayout absL = new AbsoluteLayout();
    addComponent(absL);

    absL.setWidth(APPLICATION_SCREEN_WIDTH);
    absL.setHeight(ACTIONDASHBOARD_H);

    MediaLocator medLoc = Mmowgli2UI.getGlobals().getMediaLocator();

    AbsoluteLayout mainAbsLay = new AbsoluteLayout(); // offset it from master
    mainAbsLay.setWidth(APPLICATION_SCREEN_WIDTH);
    mainAbsLay.setHeight(ACTIONDASHBOARD_H);
    absL.addComponent(mainAbsLay, ACTIONDASHBOARD_OFFSET_POS);

    // Now the background     
    Embedded backgroundImage = new Embedded(null, medLoc.getActionDashboardPlanBackground());
    backgroundImage.setWidth(ACTIONDASHBOARD_W);
    backgroundImage.setHeight(ACTIONDASHBOARD_H);
    mainAbsLay.addComponent(backgroundImage, "top:0px;left:0px");

    HorizontalLayout tabsHL = new HorizontalLayout();
    tabsHL.setStyleName("m-actionDashboardBlackTabs");
    tabsHL.setSpacing(false);

    tabsHL.addComponent(sp = new Label());
    sp.setWidth("12px");

    TabClickHandler tabHndlr = new TabClickHandler();
    actionPlansTabButt.setStyleName("m-actionDashboardActionPlansTab");
    actionPlansTabButt.addClickListener(tabHndlr);
    actionPlansTabButt.setId(ACTION_DASHBOARD_ACTION_PLANS_TAB);
    tabsHL.addComponent(actionPlansTabButt);

    tabsHL.addComponent(sp = new Label());
    sp.setWidth("1px");

    myPlansTabButt.setStyleName("m-actionDashboardMyPlansTab");
    myPlansTabButt.addClickListener(tabHndlr);
    myPlansTabButt.setId(ACTION_DASHBOARD_MY_ACTION_PLANS_TAB);
    tabsHL.addComponent(myPlansTabButt);
    myPlansTabButt.addStyleName("m-transparent-background"); // initially

    tabsHL.addComponent(sp = new Label());
    sp.setWidth("1px");

    needAuthorsTabButt.setStyleName("m-actionDashboardNeedAuthorsTab");
    needAuthorsTabButt.addClickListener(tabHndlr);
    needAuthorsTabButt.setId(ACTION_DASHBOARD_NEED_AUTHORS_TAB);
    tabsHL.addComponent(needAuthorsTabButt);
    needAuthorsTabButt.addStyleName("m-transparent-background"); // initially

    absL.addComponent(tabsHL, "left:7px;top:8px");

    // stack the pages
    absL.addComponent(actionPlansTab, ACTIONDASHBOARD_TABCONTENT_POS);
    actionPlansTab.initGuiTL();

    absL.addComponent(myPlansTab, ACTIONDASHBOARD_TABCONTENT_POS);
    myPlansTab.initGuiTL();
    myPlansTab.setVisible(false);

    absL.addComponent(needAuthorsTab, ACTIONDASHBOARD_TABCONTENT_POS);
    needAuthorsTab.initGuiTL();
    needAuthorsTab.setVisible(false);

    User me = Mmowgli2UI.getGlobals().getUserTL();
    Set<ActionPlan> invitedSet = me.getActionPlansInvited();
    if (invitedSet != null && (invitedSet.size()) > 0) {
        Notification note = new Notification("<center>You're invited to an Action Plan!</center>",
                "<center> Look for the \"you're invited to join!\" notice.<br/>"
                        + "First, check out the plan.  Then, if you want to join,<br/>"
                        + "click the link to become an author." + "</center>",
                Type.HUMANIZED_MESSAGE, true); // allow html

        note.setPosition(Position.MIDDLE_CENTER);
        note.setDelayMsec(5000);// 5 secs
        note.show(Page.getCurrent());
    }
}