List of usage examples for com.vaadin.server Page getCurrent
public static Page getCurrent()
From source file:me.uni.emuseo.view.settings.MyAccountView.java
License:Open Source License
public MyAccountView() { authManager = EMuseoUtil.getAppContext().getBean(AuthManager.class); userService = EMuseoUtil.getAppContext().getBean(UserService.class); final Long userId = authManager.getLoggedUserId(); UserDTO user = userService.getUser(userId); FormWithButtonsLayout<UserDTO> formLayout = new FormWithButtonsLayout<UserDTO>(user) { private static final long serialVersionUID = -1826989504302110056L; @Override//www. j av a 2 s.c om protected void onSave(UserDTO bean) { userService.editUser(bean); } @Override protected FormBuilder<UserDTO> buildForm(UserDTO bean) { return new MyAccountFormLayout(bean); } }; ExpandingPanel myAccountPanel = new ExpandingPanel(); myAccountPanel.setCaption("Moje dane"); myAccountPanel.setContent(formLayout); myAccountPanel.setExpanded(true); Button addButton = new Button("Zmie haso"); addButton.setIcon(FontAwesome.LOCK); addButton.addStyleName("emuseo-button-icon"); addButton.addStyleName("emuseo-button-margin"); addButton.setWidth(100, Unit.PERCENTAGE); addComponent(myAccountPanel); addComponent(addButton); // setComponentAlignment(formLayout, Alignment.MIDDLE_CENTER); addButton.addClickListener(new ClickListener() { private static final long serialVersionUID = -263205007196895260L; @Override public void buttonClick(ClickEvent event) { PasswordPopUpWindow exhibitPopUpWidow = new PasswordPopUpWindow("Zmie haso") { private static final long serialVersionUID = 3776311059670953583L; @Override protected boolean onSave(PasswordDTO bean) throws InvalidBeanException { try { userService.changePassword(userId, bean); return true; } catch (PasswordChangeException e) { new Notification("Bd", e.getReason(), Type.ERROR_MESSAGE, true) .show(Page.getCurrent()); } return false; } }; UI.getCurrent().addWindow(exhibitPopUpWidow); } }); }
From source file:net.sf.gazpachoquest.questionnaires.views.QuestionnaireView.java
License:Open Source License
@Override public void enter(ViewChangeEvent event) { logger.debug("Entering {} view ", QuestionnaireView.NAME); addStyleName(Reindeer.LAYOUT_BLUE);/*from w w w . j a v a 2 s. co m*/ addStyleName("questionnaires"); WebBrowser webBrowser = Page.getCurrent().getWebBrowser(); Integer screenWidth = webBrowser.getScreenWidth(); Integer heightWidth = webBrowser.getScreenHeight(); logger.debug("Browser screen settings {} x {}", screenWidth, heightWidth); if (heightWidth <= 480) { renderingMode = RenderingMode.QUESTION_BY_QUESTION; } // centralLayout.addStyleName("questionnaires"); // new Responsive(centralLayout); RespondentAccount respondent = (RespondentAccount) VaadinServletService.getCurrentServletRequest() .getUserPrincipal(); if (respondent.hasPreferredLanguage()) { preferredLanguage = Language.fromString(respondent.getPreferredLanguage()); } else { preferredLanguage = Language.fromLocale(webBrowser.getLocale()); } questionnaireId = respondent.getGrantedquestionnaireIds().iterator().next(); logger.debug("Trying to fetch questionnair identified with id = {} ", questionnaireId); QuestionnaireDefinitionDTO definition = questionnaireResource.getDefinition(questionnaireId); sectionInfoVisible = definition.isSectionInfoVisible(); QuestionnairePageDTO page = questionnaireResource.getPage(questionnaireId, renderingMode, preferredLanguage, NavigationAction.ENTERING); logger.debug("Displaying page {}/{} with {} questions", page.getMetadata().getNumber(), page.getMetadata().getCount(), page.getQuestions().size()); questionsLayout = new VerticalLayout(); update(page); Label questionnaireTitle = new Label(definition.getLanguageSettings().getTitle()); questionnaireTitle.addStyleName(Reindeer.LABEL_H1); VerticalLayout mainLayout = new VerticalLayout(); mainLayout.setSizeFull(); mainLayout.setMargin(true); mainLayout.addComponent(questionnaireTitle); mainLayout.addComponent(questionsLayout); // Add the responsive capabilities to the components Panel centralLayout = new Panel(); centralLayout.setContent(mainLayout); centralLayout.setSizeFull(); centralLayout.getContent().setSizeUndefined(); Responsive.makeResponsive(questionnaireTitle); setCompositionRoot(centralLayout); setSizeFull(); }
From source file:net.sourceforge.javydreamercsw.validation.manager.web.component.LoginDialog.java
License:Apache License
private void tryToLogIn() { try {//from w w w . j ava2 s . co m //Throws exception if credentials are wrong. VMUserServer user = new VMUserServer(name.getValue(), password.getValue()); if (menu != null) { if (user.getUserStatusId() != null) { switch (user.getUserStatusId().getId()) { case 1: //Everything OK, fall thru case 2: //TODO: Inactive. Right now no special behavior menu.setUser(user); close(); break; case 3: //Locked new Notification( Lookup.getDefault().lookup(InternationalizationProvider.class) .translate("audit.user.account.lock"), Lookup.getDefault().lookup(InternationalizationProvider.class).translate( "menu.connection.error.user"), Notification.Type.ERROR_MESSAGE, true).show(Page.getCurrent()); clear(); break; case 4: //Password Aged new Notification( Lookup.getDefault().lookup(InternationalizationProvider.class) .translate("user.status.aged"), Lookup.getDefault().lookup(InternationalizationProvider.class) .translate("user.status.aged"), Notification.Type.WARNING_MESSAGE, true).show(Page.getCurrent()); menu.setUser(user); //Open the profile page ((VMUI) UI.getCurrent()).showTab("message.admin.userProfile"); close(); break; default: LOG.log(Level.SEVERE, "Unexpected User Status: {0}", user.getUserStatusId().getId()); Notification.show("Unexpected User Status", "Unexpected User Status: " + user.getUserStatusId().getId() + "\n" + TRANSLATOR.translate("message.db.error"), Notification.Type.ERROR_MESSAGE); menu.setUser(null); close(); break; } } else { new Notification( Lookup.getDefault().lookup(InternationalizationProvider.class) .translate("general.login.invalid.title"), Lookup.getDefault().lookup(InternationalizationProvider.class).translate( "general.login.invalid.message"), Notification.Type.ERROR_MESSAGE, true).show(Page.getCurrent()); clear(); } } } catch (VMException ex) { if (menu != null) { menu.setUser(null); } new Notification( Lookup.getDefault().lookup(InternationalizationProvider.class) .translate("general.login.invalid.title"), Lookup.getDefault().lookup(InternationalizationProvider.class) .translate("general.login.invalid.message"), Notification.Type.WARNING_MESSAGE, true).show(Page.getCurrent()); password.setValue(""); } }
From source file:net.sourceforge.javydreamercsw.validation.manager.web.ValidationManagerUI.java
License:Apache License
@Override protected void init(VaadinRequest request) { LOG.log(Level.INFO, "Current working directory: {0}", System.getProperty("user.home")); Page.getCurrent().setTitle("Validation Manager"); updateScreen();// www . j av a 2s. c om //For the code below see: https://vaadin.com/forum#!/thread/1553240/8194235 JavaScript.getCurrent().addFunction("aboutToClose", (JsonArray arguments) -> { try { if (user != null) { int id = SESSIONS.get(VaadinSession.getCurrent().getSession().getId()); VMUserServer u = new VMUserServer(id); LOG.log(Level.FINE, "Clearing session for user: {0}", u.toString()); SESSIONS.remove(VaadinSession.getCurrent().getSession().getId()); } } catch (Exception ex) { LOG.log(Level.SEVERE, null, ex); } }); Page.getCurrent().getJavaScript().execute( "window.onbeforeunload = function (e) { var e = e || window.event; aboutToClose(); return; };"); }
From source file:nz.co.senanque.workflowui.AttachmentsPopup.java
License:Apache License
private void makeStream(final Attachment attachment) { final FileResource stream = new FileResource(new File("")) { private static final long serialVersionUID = 1L; @Override/* w w w .j a v a2s .co m*/ public DownloadStream getStream() { ByteArrayInputStream in = new ByteArrayInputStream(attachment.getBody()); DownloadStream ds = new DownloadStream(in, attachment.getMIMEType(), attachment.getFileName()); // Need a file download POPUP ds.setParameter("Content-Disposition", "attachment; filename=" + attachment.getFileName()); return ds; } }; stream.setCacheTime(0); Page.getCurrent().open(stream, "_blank", true); // panel.requestRepaint(); }
From source file:org.adho.dhconvalidator.ui.ConverterPanel.java
@Override public void enter(ViewChangeEvent event) { VaadinSession.getCurrent().setAttribute(SessionStorageKey.ZIPRESULT.name(), null); cleanUp();//from w w w . j a v a 2 s . c om resultCaption.setValue(Messages.getString("ConverterPanel.previewTitle2")); Page.getCurrent().setTitle(Messages.getString("ConverterPanel.pageTitle")); }
From source file:org.adho.dhconvalidator.ui.DHConvalidatorExample.java
@Override protected void init(VaadinRequest request) { try {//ww w . ja v a 2s .c om Messages.setLocaleProvider(VaadinSessionLocaleProvider.INSTANCE); VerticalLayout content = new VerticalLayout(); content.setMargin(true); content.setSpacing(true); setContent(content); HeaderPanel headerPanel = new HeaderPanel(null); headerPanel.getBackLink().setVisible(false); content.addComponent(headerPanel); // prepare downloader for input file Button btGetInputfile = new Button(Messages.getString("DHConvalidatorExample.btInputCaption")); content.addComponent(btGetInputfile); FileDownloader inputFileDownloader = new FileDownloader(new StreamResource(new StreamSource() { @Override public InputStream getStream() { return Thread.currentThread().getContextClassLoader().getResourceAsStream( "/org/adho/dhconvalidator/conversion/example/1_Digital_Humanities.odt"); } }, "1_Digital_Humanities.odt")); inputFileDownloader.extend(btGetInputfile); // prepare downloader for output file Button btGetOutputfile = new Button( Messages.getString("DHConvalidatorExample.btConversionResultCaption")); content.addComponent(btGetOutputfile); FileDownloader outputFileDownloader = new FileDownloader(new StreamResource(new StreamSource() { @Override public InputStream getStream() { return Thread.currentThread().getContextClassLoader().getResourceAsStream( "/org/adho/dhconvalidator/conversion/example/1_Digital_Humanities.dhc"); } }, "1_Digital_Humanities.dhc")); outputFileDownloader.extend(btGetOutputfile); // setup visual feedback Label preview = new Label("", ContentMode.HTML); preview.addStyleName("tei-preview"); preview.setWidth("800px"); content.addComponent(preview); content.setComponentAlignment(preview, Alignment.MIDDLE_CENTER); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); IOUtils.copy(Thread.currentThread().getContextClassLoader().getResourceAsStream( "/org/adho/dhconvalidator/conversion/example/1_Digital_Humanities.html"), buffer); preview.setValue(buffer.toString("UTF-8")); Page.getCurrent().setTitle(Messages.getString("DHConvalidatorExample.title")); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.adho.dhconvalidator.ui.DHConvalidatorServices.java
@Override protected void init(VaadinRequest request) { Messages.setLocaleProvider(VaadinSessionLocaleProvider.INSTANCE); backgroundService = new UIBackgroundService(false); // are we logged in? if ((VaadinSession.getCurrent().getAttribute(SessionStorageKey.USER.name())) == null) { // no, show login box then setContent(new LoginPanel()); Page.getCurrent().setTitle(Messages.getString("DHConvalidatorServices.loginTitle")); } else {/*from w w w .j a va 2s . co m*/ // add available services and navigation Navigator navigator = new Navigator(this, this); navigator.addView("", new ServiceSelectionPanel()); navigator.addView(ServicesViewName.odt.name(), new PaperSelectionPanel(new OdtInputConverter())); navigator.addView(ServicesViewName.docx.name(), new PaperSelectionPanel(new DocxInputConverter())); navigator.addView(ServicesViewName.converter.name(), new ConverterPanel()); navigator.addView(ServicesViewName.templates.name(), new TemplateGeneratorPanel()); navigator.addView(ServicesViewName.conftoolupload.name(), new ConfToolUploadPanel()); // the visual feedback may reference external resources like images // the ExternalResourceRequestHandler serves those external resources from // the ZipResult of the conversion process try { VaadinSession.getCurrent().addRequestHandler( new ExternalResourceRequestHandler(PropertyKey.tei_image_location.getValue())); } catch (IOException e) { throw new IllegalStateException(Messages.getString("DHConvalidatorServices.errorExampleFiles"), e); } Page.getCurrent().setTitle(Messages.getString("DHConvalidatorServices.servicesTitle")); } }
From source file:org.adho.dhconvalidator.ui.PaperSelectionPanel.java
@Override public void enter(ViewChangeEvent event) { // reload data initData();//from w ww. ja v a 2s .c o m Page.getCurrent().setTitle(Messages.getString("PaperSelectionPanel.title")); }
From source file:org.adho.dhconvalidator.ui.ServiceSelectionPanel.java
@Override public void enter(ViewChangeEvent event) { Page.getCurrent().setTitle(Messages.getString("ServiceSelectionPanel.title")); }