List of usage examples for com.vaadin.server Page getCurrent
public static Page getCurrent()
From source file:com.mcparland.john.vaadin_mvn_arch.samples.authentication.LoginScreen.java
License:Apache License
private void showNotification(Notification notification) { // keep the notification visible a little while after moving the // mouse, or until clicked notification.setDelayMsec(2000);/*www . j av a2 s . com*/ notification.show(Page.getCurrent()); }
From source file:com.mcparland.john.vaadin_mvn_arch.samples.crud.ProductForm.java
License:Apache License
public void editProduct(Product product) { if (product == null) { product = new Product(); }/*from w ww .j av a 2 s .com*/ fieldGroup.setItemDataSource(new BeanItem<Product>(product)); // before the user makes any changes, disable validation error indicator // of the product name field (which may be empty) productName.setValidationVisible(false); // Scroll to the top // As this is not a Panel, using JavaScript String scrollScript = "window.document.getElementById('" + getId() + "').scrollTop = 0;"; Page.getCurrent().getJavaScript().execute(scrollScript); }
From source file:com.mcparland.john.vaadin_mvn_arch.samples.Menu.java
License:Apache License
public Menu(Navigator navigator) { this.navigator = navigator; setPrimaryStyleName(ValoTheme.MENU_ROOT); menuPart = new CssLayout(); menuPart.addStyleName(ValoTheme.MENU_PART); // header of the menu final HorizontalLayout top = new HorizontalLayout(); top.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT); top.addStyleName(ValoTheme.MENU_TITLE); top.setSpacing(true);//from w w w . j av a2s. co m Label title = new Label("My CRUD"); title.addStyleName(ValoTheme.LABEL_H3); title.setSizeUndefined(); Image image = new Image(null, new ThemeResource("img/table-logo.png")); image.setStyleName("logo"); top.addComponent(image); top.addComponent(title); menuPart.addComponent(top); // logout menu item MenuBar logoutMenu = new MenuBar(); logoutMenu.addItem("Logout", FontAwesome.SIGN_OUT, new Command() { /** * The serialVersionUID. */ private static final long serialVersionUID = 1L; @Override public void menuSelected(MenuItem selectedItem) { VaadinSession.getCurrent().getSession().invalidate(); Page.getCurrent().reload(); } }); logoutMenu.addStyleName("user-menu"); menuPart.addComponent(logoutMenu); // button for toggling the visibility of the menu when on a small screen final Button showMenu = new Button("Menu", new ClickListener() { /** * The serialVersionUID. */ private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { if (menuPart.getStyleName().contains(VALO_MENU_VISIBLE)) { menuPart.removeStyleName(VALO_MENU_VISIBLE); } else { menuPart.addStyleName(VALO_MENU_VISIBLE); } } }); showMenu.addStyleName(ValoTheme.BUTTON_PRIMARY); showMenu.addStyleName(ValoTheme.BUTTON_SMALL); showMenu.addStyleName(VALO_MENU_TOGGLE); showMenu.setIcon(FontAwesome.NAVICON); menuPart.addComponent(showMenu); // container for the navigation buttons, which are added by addView() menuItemsLayout = new CssLayout(); menuItemsLayout.setPrimaryStyleName(VALO_MENUITEMS); menuPart.addComponent(menuItemsLayout); addComponent(menuPart); }
From source file:com.mh.ui.HelloUi.java
License:Open Source License
@Override protected void init(VaadinRequest vaadinRequest) { button = new Button("Click me!"); button.addClickListener(new Button.ClickListener() { @Override// www . ja v a 2 s . c o m public void buttonClick(Button.ClickEvent clickEvent) { Notification.show("You are at: " + Page.getCurrent().getLocation()); } }); setContent(button); }
From source file:com.mycollab.community.shell.view.components.AboutWindow.java
License:Open Source License
public AboutWindow() { MHorizontalLayout content = new MHorizontalLayout().withMargin(true).withFullWidth(); this.setContent(content); Image about = new Image("", new ExternalResource(StorageFactory.generateAssetRelativeLink(WebResourceIds._about))); MVerticalLayout rightPanel = new MVerticalLayout(); ELabel versionLbl = ELabel.h2(String.format("MyCollab Community Edition %s", Version.getVersion())); Label javaNameLbl = new Label(String.format("%s, %s", System.getProperty("java.vm.name"), System.getProperty("java.runtime.version"))); Label homeFolderLbl = new Label("Home folder: " + FileUtils.getHomeFolder().getAbsolutePath()); WebBrowser browser = Page.getCurrent().getWebBrowser(); Label osLbl = new Label( String.format("%s, %s", System.getProperty("os.name"), browser.getBrowserApplication())); osLbl.addStyleName(UIConstants.LABEL_WORD_WRAP); Div licenseDiv = new Div().appendChild(new Text("Powered by: ")) .appendChild(new A("https://www.mycollab.com").appendText("MyCollab")) .appendChild(new Text(". Open source under GPL license")); Label licenseLbl = new Label(licenseDiv.write(), ContentMode.HTML); Label copyRightLbl = new Label(String.format("© %s - %s MyCollab Ltd. All rights reserved", "2011", new GregorianCalendar().get(Calendar.YEAR) + ""), ContentMode.HTML); rightPanel.with(versionLbl, javaNameLbl, osLbl, homeFolderLbl, licenseLbl, copyRightLbl) .withAlign(copyRightLbl, Alignment.BOTTOM_LEFT); content.with(about, rightPanel).expand(rightPanel); }
From source file:com.mycollab.mobile.MobileApplication.java
License:Open Source License
@Override protected void init(VaadinRequest request) { OfflineMode offlineMode = new OfflineMode(); offlineMode.extend(this); // Maintain the session when the browser app closes offlineMode.setPersistentSessionCookie(true); // Define the timeout in secs to wait when a server // request is sent before falling back to offline mode offlineMode.setOfflineModeTimeout(15); VaadinSession.getCurrent().setErrorHandler(new DefaultErrorHandler() { private static final long serialVersionUID = 1L; @Override/* ww w. j av a 2 s . co m*/ public void error(com.vaadin.server.ErrorEvent event) { Throwable e = event.getThrowable(); IgnoreException ignoreException = (IgnoreException) getExceptionType(e, IgnoreException.class); if (ignoreException != null) { return; } SessionExpireException sessionExpireException = (SessionExpireException) getExceptionType(e, SessionExpireException.class); if (sessionExpireException != null) { Page.getCurrent().getJavaScript().execute("window.location.reload();"); return; } UserInvalidInputException invalidException = (UserInvalidInputException) getExceptionType(e, UserInvalidInputException.class); if (invalidException != null) { NotificationUtil.showWarningNotification(UserUIContext .getMessage(GenericI18Enum.ERROR_USER_INPUT_MESSAGE, invalidException.getMessage())); } else { UsageExceedBillingPlanException usageBillingException = (UsageExceedBillingPlanException) getExceptionType( e, UsageExceedBillingPlanException.class); if (usageBillingException != null) { if (UserUIContext.isAdmin()) { ConfirmDialog.show(UI.getCurrent(), UserUIContext.getMessage(GenericI18Enum.EXCEED_BILLING_PLAN_MSG_FOR_ADMIN), UserUIContext.getMessage(GenericI18Enum.BUTTON_YES), UserUIContext.getMessage(GenericI18Enum.BUTTON_NO), dialog -> { if (dialog.isConfirmed()) { Collection<Window> windows = UI.getCurrent().getWindows(); for (Window window : windows) { window.close(); } EventBusFactory.getInstance().post(new ShellEvent.GotoUserAccountModule( this, new String[] { "billing" })); } }); } else { NotificationUtil.showErrorNotification( UserUIContext.getMessage(GenericI18Enum.EXCEED_BILLING_PLAN_MSG_FOR_USER)); } } else { LOG.error("Error", e); NotificationUtil.showErrorNotification( UserUIContext.getMessage(GenericI18Enum.ERROR_USER_NOTICE_INFORMATION_MESSAGE)); } } } }); setCurrentFragmentUrl(this.getPage().getUriFragment()); currentContext = new UserUIContext(); postSetupApp(request); final NavigationManager manager = new NavigationManager(); setContent(manager); registerControllers(manager); ThemeManager.loadMobileTheme(MyCollabUI.getAccountId()); getPage().addUriFragmentChangedListener(new UriFragmentChangedListener() { private static final long serialVersionUID = -6410955178515535406L; @Override public void uriFragmentChanged(UriFragmentChangedEvent event) { setCurrentFragmentUrl(event.getUriFragment()); enter(event.getUriFragment()); } }); detectAutoLogin(); }
From source file:com.mycollab.module.user.accountsettings.customize.view.AccountInfoChangeWindow.java
License:Open Source License
AccountInfoChangeWindow() { super(UserUIContext.getMessage(AdminI18nEnum.OPT_CHANGE_ACCOUNT_INFO)); MVerticalLayout content = new MVerticalLayout(); this.withModal(true).withResizable(false).withWidth("700px").withContent(content).withCenter(); billingAccount = BeanUtility.deepClone(MyCollabUI.getBillingAccount()); editForm = new AdvancedEditBeanForm<>(); editForm.setFormLayoutFactory(new AbstractFormLayoutFactory() { private GridFormLayoutHelper gridFormLayoutHelper = GridFormLayoutHelper.defaultFormLayoutHelper(1, 9, "200px"); @Override// ww w . j a va 2 s . com public AbstractComponent getLayout() { return gridFormLayoutHelper.getLayout(); } @Override public Component onAttachField(Object propertyId, Field<?> field) { if (BillingAccount.Field.sitename.equalTo(propertyId)) { return gridFormLayoutHelper.addComponent(field, UserUIContext.getMessage(AdminI18nEnum.FORM_SITE_NAME), 0, 0); } else if (BillingAccount.Field.subdomain.equalTo(propertyId)) { return gridFormLayoutHelper.addComponent(field, UserUIContext.getMessage(AdminI18nEnum.FORM_SITE_ADDRESS), 0, 1); } else if (BillingAccount.Field.defaulttimezone.equalTo(propertyId)) { return gridFormLayoutHelper.addComponent(field, UserUIContext.getMessage(AdminI18nEnum.FORM_DEFAULT_TIMEZONE), 0, 2); } else if (BillingAccount.Field.defaultcurrencyid.equalTo(propertyId)) { return gridFormLayoutHelper.addComponent(field, UserUIContext.getMessage(AdminI18nEnum.FORM_DEFAULT_CURRENCY), 0, 3); } else if (BillingAccount.Field.defaultyymmddformat.equalTo(propertyId)) { return gridFormLayoutHelper.addComponent(field, UserUIContext.getMessage(AdminI18nEnum.FORM_DEFAULT_YYMMDD_FORMAT), UserUIContext.getMessage(GenericI18Enum.FORM_DATE_FORMAT_HELP), 0, 4); } else if (BillingAccount.Field.defaultmmddformat.equalTo(propertyId)) { return gridFormLayoutHelper.addComponent(field, UserUIContext.getMessage(AdminI18nEnum.FORM_DEFAULT_MMDD_FORMAT), UserUIContext.getMessage(GenericI18Enum.FORM_DATE_FORMAT_HELP), 0, 5); } else if (BillingAccount.Field.defaulthumandateformat.equalTo(propertyId)) { return gridFormLayoutHelper.addComponent(field, UserUIContext.getMessage(AdminI18nEnum.FORM_DEFAULT_HUMAN_DATE_FORMAT), UserUIContext.getMessage(GenericI18Enum.FORM_DATE_FORMAT_HELP), 0, 6); } else if (BillingAccount.Field.defaultlanguagetag.equalTo(propertyId)) { return gridFormLayoutHelper.addComponent(field, UserUIContext.getMessage(AdminI18nEnum.FORM_DEFAULT_LANGUAGE), 0, 7); } else if (BillingAccount.Field.displayemailpublicly.equalTo(propertyId)) { return gridFormLayoutHelper.addComponent(field, UserUIContext.getMessage(AdminI18nEnum.FORM_SHOW_EMAIL_PUBLICLY), UserUIContext.getMessage(AdminI18nEnum.FORM_SHOW_EMAIL_PUBLICLY_HELP), 0, 8); } return null; } }); editForm.setBeanFormFieldFactory( new AbstractBeanFieldGroupEditFieldFactory<SimpleBillingAccount>(editForm) { @Override protected Field<?> onCreateField(Object propertyId) { if (BillingAccount.Field.subdomain.equalTo(propertyId)) { return new SubDomainField(); } else if (BillingAccount.Field.defaulttimezone.equalTo(propertyId)) { return new TimeZoneSelectionField(false); } else if (BillingAccount.Field.defaultcurrencyid.equalTo(propertyId)) { return new CurrencyComboBoxField(); } else if (BillingAccount.Field.defaultyymmddformat.equalTo(propertyId)) { return new DateFormatField(billingAccount.getDateFormatInstance()); } else if (BillingAccount.Field.defaultmmddformat.equalTo(propertyId)) { return new DateFormatField(billingAccount.getShortDateFormatInstance()); } else if (BillingAccount.Field.defaulthumandateformat.equalTo(propertyId)) { return new DateFormatField(billingAccount.getLongDateFormatInstance()); } else if (BillingAccount.Field.defaultlanguagetag.equalTo(propertyId)) { return new LanguageSelectionField(); } return null; } }); editForm.setBean(billingAccount); MHorizontalLayout buttonControls = new MHorizontalLayout().withMargin(true); MButton saveBtn = new MButton(UserUIContext.getMessage(GenericI18Enum.BUTTON_SAVE), clickEvent -> { if (editForm.validateForm()) { BillingAccountService billingAccountService = AppContextUtil .getSpringBean(BillingAccountService.class); billingAccountService.updateSelectiveWithSession(billingAccount, UserUIContext.getUsername()); close(); String siteUrl = MyCollabUI.getSiteUrl(); String assignExec = String.format("window.location.assign(\'%s\');", siteUrl); Page.getCurrent().getJavaScript().execute(assignExec); } }).withIcon(FontAwesome.SAVE).withStyleName(WebThemes.BUTTON_ACTION) .withClickShortcut(ShortcutAction.KeyCode.ENTER); MButton cancelBtn = new MButton(UserUIContext.getMessage(GenericI18Enum.BUTTON_CANCEL), clickEvent -> close()).withStyleName(WebThemes.BUTTON_OPTION); buttonControls.with(cancelBtn, saveBtn); content.with(editForm, buttonControls).withAlign(buttonControls, Alignment.MIDDLE_RIGHT); }
From source file:com.mycollab.module.user.accountsettings.customize.view.GeneralSettingViewImpl.java
License:Open Source License
private void buildLogoPanel() { FormContainer formContainer = new FormContainer(); MHorizontalLayout layout = new MHorizontalLayout().withFullWidth().withMargin(true); MVerticalLayout leftPanel = new MVerticalLayout().withMargin(false); Label logoDesc = new Label(UserUIContext.getMessage(AdminI18nEnum.OPT_LOGO_FORMAT_DESCRIPTION)); leftPanel.with(logoDesc).withWidth("250px"); MVerticalLayout rightPanel = new MVerticalLayout().withMargin(false); CustomLayout previewLayout = CustomLayoutExt.createLayout("topNavigation"); previewLayout.setStyleName("example-block"); previewLayout.setHeight("40px"); previewLayout.setWidth("520px"); Button currentLogo = AccountAssetsResolver.createAccountLogoImageComponent(billingAccount.getLogopath(), 150);/* w w w . j av a2 s . co m*/ previewLayout.addComponent(currentLogo, "mainLogo"); final ServiceMenu serviceMenu = new ServiceMenu(); Button.ClickListener clickListener = new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(final Button.ClickEvent event) { for (Component comp : serviceMenu) { if (comp != event.getButton()) { comp.removeStyleName("selected"); } } event.getButton().addStyleName("selected"); } }; serviceMenu.addService(UserUIContext.getMessage(GenericI18Enum.MODULE_CRM), VaadinIcons.MONEY, clickListener); serviceMenu.addService(UserUIContext.getMessage(GenericI18Enum.MODULE_PROJECT), VaadinIcons.TASKS, clickListener); serviceMenu.addService(UserUIContext.getMessage(GenericI18Enum.MODULE_DOCUMENT), VaadinIcons.SUITCASE, clickListener); serviceMenu.selectService(0); previewLayout.addComponent(serviceMenu, "serviceMenu"); MHorizontalLayout buttonControls = new MHorizontalLayout() .withMargin(new MarginInfo(true, false, false, false)); buttonControls.setDefaultComponentAlignment(Alignment.TOP_LEFT); final UploadField logoUploadField = new UploadField() { private static final long serialVersionUID = 1L; @Override protected void updateDisplay() { byte[] imageData = (byte[]) this.getValue(); String mimeType = this.getLastMimeType(); if (mimeType.equals("image/jpeg")) { imageData = ImageUtil.convertJpgToPngFormat(imageData); if (imageData == null) { throw new UserInvalidInputException( UserUIContext.getMessage(FileI18nEnum.ERROR_INVALID_SUPPORTED_IMAGE_FORMAT)); } else { mimeType = "image/png"; } } if (mimeType.equals("image/png")) { UI.getCurrent().addWindow(new LogoEditWindow(imageData)); } else { throw new UserInvalidInputException( UserUIContext.getMessage(FileI18nEnum.ERROR_UPLOAD_INVALID_SUPPORTED_IMAGE_FORMAT)); } } }; logoUploadField.setButtonCaption(UserUIContext.getMessage(GenericI18Enum.ACTION_CHANGE)); logoUploadField.addStyleName("upload-field"); logoUploadField.setSizeUndefined(); logoUploadField.setFieldType(UploadField.FieldType.BYTE_ARRAY); logoUploadField.setVisible(UserUIContext.canBeYes(RolePermissionCollections.ACCOUNT_THEME)); MButton resetButton = new MButton(UserUIContext.getMessage(GenericI18Enum.BUTTON_RESET), clickEvent -> { BillingAccountService billingAccountService = AppContextUtil.getSpringBean(BillingAccountService.class); billingAccount.setLogopath(null); billingAccountService.updateWithSession(billingAccount, UserUIContext.getUsername()); Page.getCurrent().getJavaScript().execute("window.location.reload();"); }).withStyleName(WebThemes.BUTTON_OPTION); resetButton.setVisible(UserUIContext.canBeYes(RolePermissionCollections.ACCOUNT_THEME)); buttonControls.with(resetButton, logoUploadField); rightPanel.with(previewLayout, buttonControls); layout.with(leftPanel, rightPanel).expand(rightPanel); formContainer.addSection("Logo", layout); this.with(formContainer); }
From source file:com.mycollab.module.user.accountsettings.customize.view.GeneralSettingViewImpl.java
License:Open Source License
private void buildShortcutIconPanel() { FormContainer formContainer = new FormContainer(); MHorizontalLayout layout = new MHorizontalLayout().withFullWidth().withMargin(new MarginInfo(true)); MVerticalLayout leftPanel = new MVerticalLayout().withMargin(false); Label logoDesc = new Label(UserUIContext.getMessage(FileI18nEnum.OPT_FAVICON_FORMAT_DESCRIPTION)); leftPanel.with(logoDesc).withWidth("250px"); MVerticalLayout rightPanel = new MVerticalLayout().withMargin(false); final Image favIconRes = new Image("", new ExternalResource( StorageFactory.getFavIconPath(billingAccount.getId(), billingAccount.getFaviconpath()))); MHorizontalLayout buttonControls = new MHorizontalLayout() .withMargin(new MarginInfo(true, false, false, false)); buttonControls.setDefaultComponentAlignment(Alignment.BOTTOM_LEFT); final UploadField favIconUploadField = new UploadField() { private static final long serialVersionUID = 1L; @Override//from w w w. j av a2 s . c o m protected void updateDisplay() { byte[] imageData = (byte[]) this.getValue(); String mimeType = this.getLastMimeType(); if (mimeType.equals("image/jpeg")) { imageData = ImageUtil.convertJpgToPngFormat(imageData); if (imageData == null) { throw new UserInvalidInputException( UserUIContext.getMessage(FileI18nEnum.ERROR_INVALID_SUPPORTED_IMAGE_FORMAT)); } else { mimeType = "image/png"; } } if (mimeType.equals("image/png")) { try { AccountFavIconService favIconService = AppContextUtil .getSpringBean(AccountFavIconService.class); BufferedImage image = ImageIO.read(new ByteArrayInputStream(imageData)); String newFavIconPath = favIconService.upload(UserUIContext.getUsername(), image, MyCollabUI.getAccountId()); favIconRes.setSource(new ExternalResource( StorageFactory.getFavIconPath(billingAccount.getId(), newFavIconPath))); Page.getCurrent().getJavaScript().execute("window.location.reload();"); } catch (IOException e) { throw new MyCollabException(e); } } else { throw new UserInvalidInputException( UserUIContext.getMessage(FileI18nEnum.ERROR_UPLOAD_INVALID_SUPPORTED_IMAGE_FORMAT)); } } }; favIconUploadField.setButtonCaption(UserUIContext.getMessage(GenericI18Enum.ACTION_CHANGE)); favIconUploadField.addStyleName("upload-field"); favIconUploadField.setSizeUndefined(); favIconUploadField.setFieldType(UploadField.FieldType.BYTE_ARRAY); favIconUploadField.setVisible(UserUIContext.canBeYes(RolePermissionCollections.ACCOUNT_THEME)); MButton resetButton = new MButton(UserUIContext.getMessage(GenericI18Enum.BUTTON_RESET), clickEvent -> { BillingAccountService billingAccountService = AppContextUtil.getSpringBean(BillingAccountService.class); billingAccount.setFaviconpath(null); billingAccountService.updateWithSession(billingAccount, UserUIContext.getUsername()); Page.getCurrent().getJavaScript().execute("window.location.reload();"); }).withStyleName(WebThemes.BUTTON_OPTION); resetButton.setVisible(UserUIContext.canBeYes(RolePermissionCollections.ACCOUNT_THEME)); buttonControls.with(resetButton, favIconUploadField); rightPanel.with(favIconRes, buttonControls); layout.with(leftPanel, rightPanel).expand(rightPanel); formContainer.addSection("Favicon", layout); this.with(formContainer); }
From source file:com.mycollab.module.user.accountsettings.customize.view.LogoEditWindow.java
License:Open Source License
private void editPhoto(byte[] imageData) { try {//from w ww.j a va 2 s .co m originalImage = ImageIO.read(new ByteArrayInputStream(imageData)); } catch (IOException e) { throw new UserInvalidInputException("Invalid image type"); } originalImage = ImageUtil.scaleImage(originalImage, 650, 650); MHorizontalLayout previewBox = new MHorizontalLayout().withMargin(new MarginInfo(false, true, true, false)) .withFullWidth(); final String logoPath = MyCollabUI.getBillingAccount().getLogopath(); Resource defaultPhoto = AccountAssetsResolver.createLogoResource(logoPath, 150); previewImage = new Embedded(null, defaultPhoto); previewImage.setWidth("100px"); previewBox.addComponent(previewImage); previewBox.setComponentAlignment(previewImage, Alignment.TOP_LEFT); MVerticalLayout previewBoxRight = new MVerticalLayout().withSpacing(false) .withMargin(new MarginInfo(false, true, false, true)); previewBoxRight .addComponent(ELabel.html(UserUIContext.getMessage(ShellI18nEnum.OPT_IMAGE_EDIT_INSTRUCTION))); MButton cancelBtn = new MButton(UserUIContext.getMessage(GenericI18Enum.BUTTON_CANCEL), clickEvent -> EventBusFactory.getInstance() .post(new SettingEvent.GotoGeneralSetting(LogoEditWindow.this, null))) .withStyleName(WebThemes.BUTTON_OPTION); MButton acceptBtn = new MButton(UserUIContext.getMessage(GenericI18Enum.BUTTON_ACCEPT), clickEvent -> { if (scaleImageData != null && scaleImageData.length > 0) { try { BufferedImage image = ImageIO.read(new ByteArrayInputStream(scaleImageData)); AccountLogoService accountLogoService = AppContextUtil.getSpringBean(AccountLogoService.class); accountLogoService.upload(UserUIContext.getUsername(), image, MyCollabUI.getAccountId()); Page.getCurrent().getJavaScript().execute("window.location.reload();"); } catch (IOException e) { throw new MyCollabException("Error when saving account logo", e); } } }).withStyleName(WebThemes.BUTTON_ACTION).withIcon(FontAwesome.SAVE) .withClickShortcut(ShortcutAction.KeyCode.ENTER); MHorizontalLayout controlBtns = new MHorizontalLayout(acceptBtn, cancelBtn); previewBoxRight.with(controlBtns).withAlign(controlBtns, Alignment.TOP_LEFT); previewBox.with(previewBoxRight).expand(previewBoxRight); content.addComponent(previewBox); CssLayout cropBox = new CssLayout(); cropBox.setWidth("100%"); VerticalLayout currentPhotoBox = new VerticalLayout(); Resource resource = new ByteArrayImageResource(ImageUtil.convertImageToByteArray(originalImage), "image/png"); CropField cropField = new CropField(resource); cropField.setImmediate(true); cropField.setSelectionAspectRatio(150 / 28); cropField.addValueChangeListener(valueChangeEvent -> { VCropSelection newSelection = (VCropSelection) valueChangeEvent.getProperty().getValue(); int x1 = newSelection.getXTopLeft(); int y1 = newSelection.getYTopLeft(); int x2 = newSelection.getXBottomRight(); int y2 = newSelection.getYBottomRight(); if (x2 > x1 && y2 > y1) { BufferedImage subImage = originalImage.getSubimage(x1, y1, (x2 - x1), (y2 - y1)); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); try { ImageIO.write(subImage, "png", outStream); scaleImageData = outStream.toByteArray(); displayPreviewImage(); } catch (IOException e) { LOG.error("Error while scale image: ", e); } } }); currentPhotoBox.setWidth("650px"); currentPhotoBox.setHeight("650px"); currentPhotoBox.addComponent(cropField); cropBox.addComponent(currentPhotoBox); content.with(previewBox, ELabel.hr(), cropBox); }