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:org.vaadin.tori.ToriUI.java

License:Apache License

/**
 * Send data to Google Analytics about what the user is doing.
 * // ww  w .j  a v a  2 s  .  c o m
 * @param action
 *            the action performed in the path. <code>null</code> to ignore.
 *            E.g. "reply"
 */
public void trackAction(final String action) {
    if (analytics != null) {

        String fragment = Page.getCurrent().getUriFragment();
        StringBuilder sb = new StringBuilder(apiLoader.getDataSource().getPathRoot() + "#");
        sb.append(fragment != null ? fragment : "");
        if (action != null) {
            sb.append("/" + action);
        }
        analytics.trackPageview(sb.toString());
    } else {
        getLogger().debug("Can't track an action - no analytics configured");
    }
}

From source file:org.vaadin.tori.view.thread.PostEditor.java

License:Apache License

private AbstractField<String> buildEditor(final boolean bbcode) {
    if (Page.getCurrent().getWebBrowser().isAndroid()) {
        editor = new TextArea();
    } else {/*from  w  w  w.  ja v  a2 s  .  co  m*/
        editor = new BBCodeWysiwygEditor(false, bbcode);
    }
    editor.setSizeFull();
    return editor;
}

From source file:org.vaadin.tori.view.thread.ReportComponent.java

License:Apache License

private Component newReportLayout() {
    final VerticalLayout layout = new VerticalLayout();
    layout.setWidth("260px");
    layout.setSpacing(true);//from   w  ww.j  av a 2s .  c  om
    layout.setMargin(true);

    layout.addComponent(new Label("What's wrong with this post?"));

    final OptionGroup reason = new OptionGroup();
    reason.addItem(Reason.SPAM);
    reason.setItemCaption(Reason.SPAM, "Spam");
    reason.addItem(Reason.OFFENSIVE);
    reason.setItemCaption(Reason.OFFENSIVE, "Offensive, abusive or hateful.");
    reason.addItem(Reason.WRONG_CATEGORY);
    reason.setItemCaption(Reason.WRONG_CATEGORY, "Doesn't belong in the category.");
    reason.addItem(Reason.MODERATOR_ALERT);
    reason.setItemCaption(Reason.MODERATOR_ALERT, "A moderator should take a look at it.");

    reason.setImmediate(true);
    reason.addValueChangeListener(new OptionGroup.ValueChangeListener() {
        @Override
        public void valueChange(final ValueChangeEvent event) {
            explanationLayout.setVisible(reason.getValue() == Reason.MODERATOR_ALERT);
            reportButton.setEnabled(reason.getValue() != null);
        }
    });

    layout.addComponent(reason);

    explanationLayout = new CssLayout();
    explanationLayout.setStyleName("explanationlayout");
    explanationLayout.addComponent(new Label("Here's why:"));
    final TextArea reasonText = createReasonTextArea();
    explanationLayout.addComponent(reasonText);
    explanationLayout.setVisible(false);
    explanationLayout.setWidth("100%");
    layout.addComponent(explanationLayout);

    final HorizontalLayout footer = new HorizontalLayout();
    footer.setSpacing(true);
    layout.addComponent(footer);
    layout.setComponentAlignment(footer, Alignment.BOTTOM_RIGHT);

    reportButton = new Button("Report Post");
    reportButton.addClickListener(new NativeButton.ClickListener() {
        @Override
        public void buttonClick(final ClickEvent event) {
            final URI l = Page.getCurrent().getLocation();
            final String link = l.getScheme() + "://" + l.getAuthority() + l.getPath() + postPermalink;
            presenter.handlePostReport(post, (Reason) reason.getValue(), reasonText.getValue(), link);
            reportPopup.setPopupVisible(false);
        }
    });
    reportButton.setEnabled(false);
    footer.addComponent(reportButton);

    final Button cancel = ComponentUtil.getSecondaryButton("Cancel", new Button.ClickListener() {
        @Override
        public void buttonClick(final ClickEvent event) {
            reportPopup.setPopupVisible(false);
        }
    });
    footer.addComponent(cancel);

    return layout;
}

From source file:org.vaadin.tori.view.thread.ThreadViewImpl.java

License:Apache License

@Override
public void appendQuote(final String textToAppend) {
    reply.insertIntoMessage(textToAppend + "\n\n ");
    // Scroll to reply component
    UI.getCurrent().scrollIntoView(reply);

    if (Page.getCurrent().getWebBrowser().isIE()) {
        JavaScript.eval(/*from   w w  w.  j  a v a2  s.  com*/
                "window.setTimeout(\"document.getElementById('" + REPLY_ID + "').scrollIntoView(true)\",100)");
    } else {
        JavaScript.eval("EPPZScrollTo.scrollVerticalToElementById('" + REPLY_ID + "', 0);");
    }
}

From source file:org.vaadin.viritin.ui.MNotification.java

License:Apache License

/**
 * Shows this notification on the current {@link Page}
 * ({@link Page#getCurrent()}).//  w  w  w. j  av a  2s  . c o m
 *
 * @return this (for method chaining)
 * @see #show(com.vaadin.server.Page)
 * @see Page#getCurrent()
 */
public MNotification display() {
    return display(Page.getCurrent());
}

From source file:pl.exsio.frameset.vaadin.navigation.FramesetNavigatorImpl.java

License:Open Source License

@Override
public boolean navigateHome() {
    Frame home = this.coreRepositories.getFrameRepository().getHomeFrame();
    if (this.acl.isGranted(home, BasePermission.READ)) {
        this.navigateTo(home, true);
        Page.getCurrent().setUriFragment(this.getPath(home));
        return true;
    } else {//from  ww  w  .  j  a  v a 2s .  co m
        return false;
    }
}

From source file:pl.exsio.frameset.vaadin.navigation.FramesetNavigatorImpl.java

License:Open Source License

@Override
public void afterViewChange(ViewChangeEvent event) {
    String path = this.getCurrentState();
    if (this.navigableFrames.containsKey(path)) {
        Frame frame = this.navigableFrames.get(path);
        Page.getCurrent().setTitle(t(frame.getTitle()));
        this.dispatchFrameChangeEvent(frame, EVENT_AFTER_FRAME_CHANGE);
        this.currentFrame = frame;
        if (event.getNewView() instanceof VaadinModule) {
            ((VaadinModule) event.getNewView()).addStyleName("frameset-module-" + frame.getModuleId());
        }/*from w w w  .jav  a 2 s. c om*/
    } else {
        this.navigateHome();
    }

}

From source file:pl.exsio.frameset.vaadin.navigation.target.TabbedNavigationTarget.java

License:Open Source License

@Autowired
public void setApplicationContext(ApplicationContext applicationContext) {
    this.applicationContext = applicationContext;
    final FramesetNavigator navigator = (FramesetNavigator) this.applicationContext
            .getBean(FramesetNavigator.NAVIGATOR_BEAN_NAME);
    this.addSelectedTabChangeListener(new SelectedTabChangeListener() {

        @Override/*  w ww  .j  a v  a2 s  .  c  o m*/
        public void selectedTabChange(SelectedTabChangeEvent event) {
            if (updateSelection) {
                VaadinModule module = (VaadinModule) event.getTabSheet().getSelectedTab();
                Page currentPage = Page.getCurrent();
                currentPage.setUriFragment(navigator.getPath(module.getFrame()), false);
                currentPage.setTitle(t(module.getFrame().getTitle()));
            }
        }
    });
}

From source file:pl.exsio.frameset.vaadin.ui.support.flexer.AbstractFlexerImpl.java

License:Open Source License

@Override
public void attach() {
    Page.getCurrent().addBrowserWindowResizeListener(this);
}

From source file:pl.exsio.frameset.vaadin.ui.support.flexer.AbstractFlexerImpl.java

License:Open Source License

@Override
public void detach() {
    Page.getCurrent().removeBrowserWindowResizeListener(this);
}