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:info.magnolia.ui.framework.action.ExportAction.java

License:Open Source License

/**
 * After command execution we push the created XML to the client browser.<br>
 * The created data is put in the temporary file 'fileOutput' linked to 'fileOutputStream' sent to the export command.<br>
 * This temporary file is the used to create a {@code FileInputStream} that ensure that this temporary file is removed once the <br>
 * fileInputStream is closed by Vaadin resource component.
 * Directs the created XML file to the user.
 *///from  w  w  w.  ja va2  s  .c om
@Override
protected void onPostExecute() throws Exception {
    final ExportCommand exportCommand = (ExportCommand) getCommand();
    tempFileStreamResource.setFilename(exportCommand.getFileName());
    tempFileStreamResource.setMIMEType(exportCommand.getMimeExtension());
    // Opens the resource for download
    Page.getCurrent().open(tempFileStreamResource, "", true);
}

From source file:info.magnolia.ui.framework.action.ExportYamlAction.java

License:Open Source License

@Override
protected void onPostExecute() throws Exception {
    final ExportJcrNodeToYamlCommand exportYamlCommand = (ExportJcrNodeToYamlCommand) getCommand();
    tempFileStreamResource.setFilename(exportYamlCommand.getFileName());
    tempFileStreamResource.setMIMEType("application/yaml");
    // Opens the resource for download
    Page.getCurrent().open(tempFileStreamResource, "", true);
}

From source file:info.magnolia.ui.vaadin.magnoliashell.MagnoliaShell.java

License:Open Source License

public void setUriFragment(Fragment fragment) {
    if (fragment.isApp()) {
        getState().currentAppUriFragment = fragment;
    }//from   w w  w .j a  va 2 s  . c  om
    Page current = Page.getCurrent();
    if (current != null) {
        current.setUriFragment(fragment.toFragment(), false);
    }
}

From source file:info.magnolia.ui.vaadin.magnoliashell.MagnoliaShell.java

License:Open Source License

public String getUriFragment() {
    Page current = Page.getCurrent();
    if (current != null) {
        return current.getUriFragment();
    }//from  w w  w  .  j a va 2 s .c  o m
    return null;
}

From source file:io.mateu.ui.vaadin.framework.MyUI.java

License:Apache License

/**
 * por aqu entramos. se llama al inicio, cuando refrescamos la pgina (si no est anotado @preserveonrefresh) o la abrimos en otra pestaa
 * @param request/*from w ww. j  ava  2 s .c  o m*/
 */
@Override
protected void init(VaadinRequest request) {

    /*
    inicializamos la configuracin del tooltip para las ayudas
     */
    TooltipConfiguration ttc = super.getTooltipConfiguration();
    ttc.setOpenDelay(200);
    ttc.setQuickOpenDelay(300);
    ttc.setQuickOpenTimeout(300);

    /*
    si no tenemos la app en la sesin, entonces la buscamos utilizando SPI y la metemos en la sesin
     */
    if (getApp() == null) {
        Iterator<App> apps = ServiceLoader.load(App.class).iterator();

        while (apps.hasNext()) {
            setApp((AbstractApplication) apps.next());
            System.out.println("app " + getApp().getName() + " loaded");
            break;
        }

        String u = "" + Page.getCurrent().getLocation();
        if (u.contains("#"))
            u = u.substring(0, u.indexOf("#"));

        if (getApp() == null) {

            // creamos una app al vuelo para probar la interfaz

            setApp(new AbstractApplication() {
                @Override
                public String getName() {
                    return "Test app";
                }

                @Override
                public List<AbstractArea> buildAreas() {
                    return Lists.newArrayList(new AbstractArea("Area 1") {
                        @Override
                        public List<AbstractModule> buildModules() {
                            return Lists.newArrayList(new AbstractModule() {
                                @Override
                                public String getName() {
                                    return "Mdulo 1";
                                }

                                @Override
                                public List<MenuEntry> buildMenu() {
                                    return Lists.newArrayList(new AbstractAction("Opcin 1") {
                                        @Override
                                        public void run() {
                                            io.mateu.ui.core.client.app.MateuUI.alert("hola!");
                                        }
                                    });
                                }
                            });
                        }
                    });
                }
            });

        }

        getApp().setBaseUrl(u);
    }

    /*
    corregimos el acho de la barra izda para IE9
     */
    if (getPage().getWebBrowser().isIE() && getPage().getWebBrowser().getBrowserMajorVersion() == 9) {
        menu.setWidth("320px");
    }

    /*
    ponemos el ttulo de la pgina
     */
    getPage().setTitle(getApp().getName());

    /*
    fijamos el componente root como contenido de la pgina y lo ajustamos al 100% del ancho de la pgina
     */
    setContent(root);
    root.setWidth("100%");

    /*
    creamos un navigator
     */
    navigator = new Navigator(this, viewDisplay);

    /*
    aadimos el componente men
     */
    root.addMenu(buildMenu(request));
    addStyleName(ValoTheme.UI_WITH_MENU);

    /*
    buscamos view providers utilizando SPI. Los view providers convierten de url a vista vaadin
     */
    ServiceLoader<ViewProvider> sl = ServiceLoader.load(ViewProvider.class);

    for (ViewProvider p : sl)
        navigator.addProvider(new com.vaadin.navigator.ViewProvider() {
            @Override
            public String getViewName(String viewNameAndParameters) {
                return p.getViewName(viewNameAndParameters);
            }

            @Override
            public View getView(String viewName) {
                return getVaadinView(p.getView(viewName));
            }
        });

    /*
    actualizar los settings (datos del usuario en la parte izda)
     */
    refreshSettings();

    /*
    ponemos una vista por defecto
     */
    navigator.setErrorView(HomeView.class);

    /*
    aadimos un listener para cuando cambia la url. Aqu es donde se gestiona la navegacin
     */
    navigator.addViewChangeListener(new ViewChangeListener() {

        @Override
        public boolean beforeViewChange(ViewChangeEvent event) {
            /*
            aqu controlamos si el usuario tiene acceso a esta vista
             */
            boolean ok = true;

            return ok;
        }

        @Override
        public void afterViewChange(ViewChangeEvent event) {

            View v = event.getNewView();
            if (v instanceof ViewLayout) {

                ViewLayout vl = (ViewLayout) v;

                if (!vl.getView().isGranted()) { // esta opcin no est en nuestro men, as que pedimos login
                    openLoginDialog(false);
                } else {

                    vl.getView().addListener(new ViewListener() {
                        @Override
                        public void onClose() {
                            UI.getCurrent().getPage().getJavaScript().execute("history.back()");
                        }
                    });

                    if (vl.getView() instanceof AbstractEditorView) {
                        Object id = null;
                        if (id != null) {
                            ((AbstractEditorView) vl.getView()).setInitialId(id);
                            ((AbstractEditorView) vl.getView()).load();
                        }
                    } else if (vl.getView() instanceof AbstractListView) {
                        AbstractListView lv = (AbstractListView) vl.getView();
                        Data data = null;

                        int page = 0;
                        String s = vl.getView().getParametros();
                        if (!Strings.isNullOrEmpty(s)) {

                            String d = s;
                            if (s.contains("/")) {
                                d = s.split("/")[0];
                                page = Integer.parseInt(s.split("/")[1]);
                            }

                            data = new Data(new String(BaseEncoding.base64().decode(d)));
                        }

                        if (data != null) {
                            lv.setData(data);
                        }

                        if (lv.isSearchOnOpen() || (data != null && data.getPropertyNames().size() > 0)) {
                            lv.set("_data_currentpageindex", page);
                            List<String> errors = lv.getForm().validate();
                            if (errors.size() > 0) {
                                io.mateu.ui.core.client.app.MateuUI.notifyErrors(errors);
                            } else {
                                lv.rpc();
                            }
                        }

                    }

                    getViewDisplay().removeAllComponents();
                    getViewDisplay().addComponent(v.getViewComponent());

                    refreshMenu(((ViewLayout) v).getView().getArea(), ((ViewLayout) v).getView().getMenu());

                    getPage().setTitle(((ViewLayout) v).getView().getTitle());
                }

            }

            for (Iterator<Component> it = menuItemsLayout.iterator(); it.hasNext();) {
                it.next().removeStyleName("selected");
            }
            menu.removeStyleName("valo-menu-visible");

        }
    });

    /*
    si hemos entrado por la raz y no hay contenidos pblicos, entonces pedir el login inmediatamente
     */
    String f = Page.getCurrent().getUriFragment();
    System.out.println("Page.getCurrent().getUriFragment()=" + f);
    if (f == null || f.equals("")) {
        boolean hayPartePublica = false;
        for (AbstractArea a : getApp().getAreas()) {
            hayPartePublica |= a.isPublicAccess();
        }
        if (!hayPartePublica)
            openLoginDialog(true);
    }

}

From source file:io.mateu.ui.vaadin.framework.MyUI.java

License:Apache License

/**
 * construye el menu/*from www .  ja v a2  s. co m*/
 *
 * @param request
 * @return
 */
CssLayout buildMenu(VaadinRequest request) {

    HorizontalLayout top = new HorizontalLayout();
    top.setWidth("100%");
    top.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);
    top.addStyleName(ValoTheme.MENU_TITLE);
    menu.addComponent(top);
    //menu.addComponent(createThemeSelect());

    Button showMenu = new Button("Menu", new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            if (menu.getStyleName().contains("valo-menu-visible")) {
                menu.removeStyleName("valo-menu-visible");
            } else {
                menu.addStyleName("valo-menu-visible");
            }
        }
    });
    showMenu.addStyleName(ValoTheme.BUTTON_PRIMARY);
    showMenu.addStyleName(ValoTheme.BUTTON_SMALL);
    showMenu.addStyleName("valo-menu-toggle");
    showMenu.setIcon(FontAwesome.LIST);
    menu.addComponent(showMenu);

    //Label title = new Label("<h3><strong>" + getApp().getName() + "</strong></h3>", ContentMode.HTML);

    Button title = new Button(getApp().getName(), new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            Page.getCurrent().open("#!",
                    (event.isAltKey() || event.isCtrlKey()) ? "_blank" : Page.getCurrent().getWindowName());
        }
    });
    title.addStyleName(ValoTheme.BUTTON_LINK);
    title.addStyleName("tituloapp");

    title.setSizeUndefined();
    top.addComponent(title);
    top.setExpandRatio(title, 1);

    settings = new MenuBar();
    settings.addStyleName("user-menu");
    settings.addStyleName("mi-user-menu");
    menu.addComponent(settings);

    HorizontalLayout navlinks = new HorizontalLayout();
    navlinks.setSpacing(true);

    {
        Button nav = new Button(VaadinIcons.ARROWS_CROSS, new ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                Page.getCurrent().open("#!nav",
                        (event.isAltKey() || event.isCtrlKey()) ? "_blank" : Page.getCurrent().getWindowName());
            }
        });
        nav.addStyleName(ValoTheme.BUTTON_LINK);
        nav.setDescription("Search inside menu");
        nav.addStyleName("navlink");

        navlinks.addComponent(nav);
    }

    if (MateuUI.getApp().isFavouritesAvailable()) {
        Button nav = new Button(VaadinIcons.USER_STAR, new ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                Page.getCurrent().open("#!favourites",
                        (event.isAltKey() || event.isCtrlKey()) ? "_blank" : Page.getCurrent().getWindowName());
            }
        });
        nav.addStyleName(ValoTheme.BUTTON_LINK);
        nav.addStyleName("navlink");
        nav.setDescription("My favourites");
        nav.setVisible(MateuUI.getApp().getUserData() != null);

        linkFavoritos = nav;

        navlinks.addComponent(nav);
    }

    if (MateuUI.getApp().isLastEditedAvailable()) {
        Button nav = new Button(VaadinIcons.RECORDS, new ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                Page.getCurrent().open("#!lastedited",
                        (event.isAltKey() || event.isCtrlKey()) ? "_blank" : Page.getCurrent().getWindowName());
            }
        });
        nav.addStyleName(ValoTheme.BUTTON_LINK);
        nav.addStyleName("navlink");
        nav.setDescription("Last edited records");
        nav.setVisible(MateuUI.getApp().getUserData() != null);

        linkUltimosRegistros = nav;

        navlinks.addComponent(nav);
    }

    HorizontalLayout aux = new HorizontalLayout(navlinks);
    aux.setSpacing(false);
    aux.addStyleName("contenedoriconosnav");
    menu.addComponent(aux);

    if (MateuUI.getApp().isFavouritesAvailable()) {
        aux = new HorizontalLayout();
        {
            Button nav = new Button(VaadinIcons.STAR, new ClickListener() {
                @Override
                public void buttonClick(ClickEvent event) {
                    System.out.println(Page.getCurrent().getUriFragment());
                    System.out.println(Page.getCurrent().getLocation());
                }
            });
            nav.addStyleName(ValoTheme.BUTTON_LINK);
            nav.addStyleName("navlink");
            nav.setDescription("Add current page to my favourites");
            nav.setVisible(MateuUI.getApp().getUserData() != null);

            linkNuevoFavorito = nav;

            aux.addComponent(nav);
        }
        aux.setSpacing(false);
        aux.addStyleName("contenedoriconosnav");
        menu.addComponent(aux);
    }

    menuItemsLayout.setPrimaryStyleName("valo-menuitems");
    menu.addComponent(menuItemsLayout);

    refreshMenu(null, null);

    return menu;
}

From source file:io.mateu.ui.vaadin.framework.MyUI.java

License:Apache License

/**
 * are el dilogo para autenticarse//  ww  w .jav a2s .c o  m
 */
private void openLoginDialog(boolean gohome) {

    // Create a sub-window and set the content
    Window subWindow = new Window("Login");

    subWindow.setWidth("375px");

    FormLayout f = new FormLayout();
    f.setMargin(true);

    TextField l;
    f.addComponent(l = new TextField("Username"));
    PasswordField p;
    f.addComponent(p = new PasswordField("Password"));
    Label e;
    f.addComponent(e = new Label());

    VerticalLayout v = new VerticalLayout();
    v.addComponent(f);

    HorizontalLayout footer = new HorizontalLayout();
    footer.setWidth("100%");
    footer.setSpacing(true);
    footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);

    Label footerText = new Label("");
    footerText.setSizeUndefined();

    Button forgot = new Button("Forgot password", new ClickListener() {
        @Override
        public void buttonClick(ClickEvent clickEvent) {
            e.setValue("Asking for email...");
            io.mateu.ui.core.client.app.MateuUI.getBaseService().forgotPassword(l.getValue(),
                    new AsyncCallback<Void>() {

                        @Override
                        public void onFailure(Throwable caught) {
                            e.setValue("" + caught.getClass().getName() + ": " + caught.getMessage());
                        }

                        @Override
                        public void onSuccess(Void result) {
                            e.setValue("Email sent. Please check your inbox");
                        }
                    });
        }
    });
    //forgot.addStyleName(ValoTheme.BUTTON_);

    Button ok = new Button("Login", new ClickListener() {
        @Override
        public void buttonClick(ClickEvent clickEvent) {
            e.setValue("Authenticating...");
            io.mateu.ui.core.client.app.MateuUI.getBaseService().authenticate(l.getValue(), p.getValue(),
                    new AsyncCallback<UserData>() {

                        @Override
                        public void onFailure(Throwable caught) {
                            e.setValue("" + caught.getClass().getName() + ": " + caught.getMessage());
                        }

                        @Override
                        public void onSuccess(UserData result) {
                            e.setValue("OK!");
                            getApp().setUserData(result);
                            VaadinSession.getCurrent().setAttribute("usuario", "admin");
                            subWindow.close();

                            if (MateuUI.getApp().isFavouritesAvailable())
                                linkFavoritos.setVisible(true);
                            if (MateuUI.getApp().isLastEditedAvailable())
                                linkUltimosRegistros.setVisible(true);
                            if (MateuUI.getApp().isFavouritesAvailable())
                                linkNuevoFavorito.setVisible(true);

                            refreshSettings();
                            refreshMenu(null, null);
                            System.out.println("STATE:" + navigator.getState());
                            System.out.println("URIFRAGMENT:" + Page.getCurrent().getUriFragment());
                            navigator.navigateTo((gohome) ? "" : navigator.getState());
                        }
                    });
        }
    });
    ok.addStyleName(ValoTheme.BUTTON_PRIMARY);
    ok.setClickShortcut(ShortcutAction.KeyCode.ENTER);

    Button cancel = new Button("Cancel");

    footer.addComponents(footerText, forgot, ok); //, cancel);
    footer.setExpandRatio(footerText, 1);

    v.addComponent(footer);

    subWindow.setContent(v);

    // Center it in the browser window
    subWindow.center();

    subWindow.setModal(true);

    // Open it in the UI
    UI.getCurrent().addWindow(subWindow);

    l.focus();
}

From source file:io.mateu.ui.vaadin.framework.MyUI.java

License:Apache License

/**
 * construye una opcin del men/*from  w  w w . j  av  a2  s.  c o  m*/
 *
 */
private void addMenu(AbstractArea area, MenuEntry e) {

    Button b = null;

    if (e instanceof AbstractMenu) {
        b = new Button(e.getName(), new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {
                setAreaActual(area);
                setMenuActual(e);
                Page.getCurrent().open("#!" + getApp().getAreaId(area) + "/" + getApp().getMenuId(e) + "/menu",
                        (event.isAltKey() || event.isCtrlKey()) ? "_blank" : Page.getCurrent().getWindowName());
            }
        });
        b.setCaption(b.getCaption() + " <span class=\"valo-menu-badge\">"
                + ((AbstractMenu) e).getEntries().size() + "</span>");
    }

    if (e instanceof AbstractAction) {

        b = new Button(e.getName(), new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {
                setAreaActual(area);
                setMenuActual(e);
                ((AbstractAction) e).setModifierPressed(event.isAltKey() || event.isCtrlKey()).run();
            }
        });

    }

    if (b != null) {
        b.setCaptionAsHtml(true);
        b.setPrimaryStyleName(ValoTheme.MENU_ITEM);

        //b.setIcon(testIcon.get());  // sin iconos en el men
        menuItemsLayout.addComponent(b);

        botonesMenu.put(e, b);

    }

}

From source file:life.qbic.utils.qOfferManagerUtils.java

License:Open Source License

/**
 * Displays a vaadin Notification with the respective title, description and type.
 * @param title: title of the displayNotification window
 * @param description: description of the displayNotification Window
 * @param type: one of "error", "success" and "warning". Changes the style and the delay of the displayNotification.
 *//*www. j a v a2 s  . co  m*/
public static void displayNotification(String title, String description, String type) {
    com.vaadin.ui.Notification notify = new com.vaadin.ui.Notification(title, description);
    notify.setPosition(Position.TOP_CENTER);
    switch (type) {
    case "error":
        notify.setDelayMsec(16000);
        notify.setIcon(FontAwesome.FROWN_O);
        notify.setStyleName(ValoTheme.NOTIFICATION_ERROR + " " + ValoTheme.NOTIFICATION_CLOSABLE);
        break;
    case "success":
        notify.setDelayMsec(8000);
        notify.setIcon(FontAwesome.SMILE_O);
        notify.setStyleName(ValoTheme.NOTIFICATION_SUCCESS + " " + ValoTheme.NOTIFICATION_CLOSABLE);
        break;
    case "warning":
        notify.setDelayMsec(16000);
        notify.setIcon(FontAwesome.MEH_O);
        notify.setStyleName(ValoTheme.NOTIFICATION_WARNING + " " + ValoTheme.NOTIFICATION_CLOSABLE);
        break;
    default:
        notify.setDelayMsec(16000);
        notify.setIcon(FontAwesome.MEH_O);
        notify.setStyleName(ValoTheme.NOTIFICATION_TRAY + " " + ValoTheme.NOTIFICATION_CLOSABLE);
        break;
    }
    notify.show(Page.getCurrent());
}

From source file:lifetime.component.custom.LifetimeHomeButton.java

License:Apache License

public LifetimeHomeButton(String language) {
    super(Translator.getTranslation("Home", language), language, FontAwesome.HOME);
    setDescription(Translator.getTranslation("Home", language));
    setId(StyleClassName.HOME_BUTTON.getId());
    addClickListener(new ClickListener() {

        @Override/* ww  w.  j a va  2  s.  co m*/
        public void buttonClick(ClickEvent event) {
            Page.getCurrent().setLocation(Location.HOME.getUri());
        }
    });
}