List of usage examples for com.vaadin.ui Button.ClickListener Button.ClickListener
Button.ClickListener
From source file:com.esofthead.mycollab.module.user.accountsettings.profile.view.ProfilePhotoUploadViewImpl.java
License:Open Source License
@SuppressWarnings("serial") @Override//from w w w . j a va 2 s. com public void editPhoto(final byte[] imageData) { this.removeAllComponents(); LOG.debug("Receive avatar upload with size: " + imageData.length); try { 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().withSpacing(true) .withMargin(new MarginInfo(false, true, true, false)).withWidth("100%"); Resource defaultPhoto = UserAvatarControlFactory.createAvatarResource(AppContext.getUserAvatarId(), 100); previewImage = new Embedded(null, defaultPhoto); previewImage.setWidth("100px"); previewBox.addComponent(previewImage); previewBox.setComponentAlignment(previewImage, Alignment.TOP_LEFT); VerticalLayout previewBoxRight = new VerticalLayout(); previewBoxRight.setMargin(new MarginInfo(false, true, false, true)); Label lbPreview = new Label( "<p style='margin: 0px;'><strong>To the left is what your profile photo will look like.</strong></p><p style='margin-top: 0px;'>To make adjustment, you can drag around and resize the selection square below. When you are happy with your photo, click the “Accept“ button.</p>", ContentMode.HTML); previewBoxRight.addComponent(lbPreview); MHorizontalLayout controlBtns = new MHorizontalLayout(); controlBtns.setSizeUndefined(); Button cancelBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CANCEL), new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { EventBusFactory.getInstance() .post(new ProfileEvent.GotoProfileView(ProfilePhotoUploadViewImpl.this, null)); } }); cancelBtn.setStyleName(UIConstants.THEME_GRAY_LINK); Button acceptBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_ACCEPT), new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { if (scaleImageData != null && scaleImageData.length > 0) { try { BufferedImage image = ImageIO.read(new ByteArrayInputStream(scaleImageData)); UserAvatarService userAvatarService = ApplicationContextUtil .getSpringBean(UserAvatarService.class); userAvatarService.uploadAvatar(image, AppContext.getUsername(), AppContext.getUserAvatarId()); Page.getCurrent().getJavaScript().execute("window.location.reload();"); } catch (IOException e) { throw new MyCollabException("Error when saving user avatar", e); } } } }); acceptBtn.setStyleName(UIConstants.THEME_GREEN_LINK); acceptBtn.setIcon(FontAwesome.CHECK); controlBtns.with(acceptBtn, cancelBtn).alignAll(Alignment.MIDDLE_LEFT); previewBoxRight.addComponent(controlBtns); previewBoxRight.setComponentAlignment(controlBtns, Alignment.TOP_LEFT); previewBox.addComponent(previewBoxRight); previewBox.setExpandRatio(previewBoxRight, 1.0f); this.addComponent(previewBox); CssLayout cropBox = new CssLayout(); cropBox.addStyleName(UIConstants.PHOTO_CROPBOX); 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(1.0f); cropField.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { VCropSelection newSelection = (VCropSelection) event.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); this.addComponent(previewBox); this.addComponent(cropBox); this.setExpandRatio(cropBox, 1.0f); }
From source file:com.esofthead.mycollab.module.user.accountsettings.profile.view.ProfileReadViewImpl.java
License:Open Source License
private void displayUserAvatar() { this.userAvatar.removeAllComponents(); final Image cropField = UserAvatarControlFactory .createUserAvatarEmbeddedComponent(AppContext.getUserAvatarId(), 100); userAvatar.addComponent(cropField);// w w w .ja v a2s .c om this.avatarAndPass.removeAllComponents(); avatarAndPass.addComponent(userAvatar); User user = formItem.getUser(); final VerticalLayout basicLayout = new VerticalLayout(); basicLayout.setSpacing(true); final HorizontalLayout userWrapper = new HorizontalLayout(); final Label userName = new Label(AppContext.getSession().getDisplayName()); userName.setStyleName("h1"); userWrapper.addComponent(userName); final Button btnChangeBasicInfo = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_EDIT), new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { UI.getCurrent().addWindow(new BasicInfoChangeWindow(formItem.getUser())); } }); btnChangeBasicInfo.setStyleName("link"); HorizontalLayout btnChangeBasicInfoWrapper = new HorizontalLayout(); btnChangeBasicInfoWrapper.setWidth("40px"); btnChangeBasicInfoWrapper.addComponent(btnChangeBasicInfo); btnChangeBasicInfoWrapper.setComponentAlignment(btnChangeBasicInfo, Alignment.MIDDLE_RIGHT); userWrapper.addComponent(btnChangeBasicInfoWrapper); basicLayout.addComponent(userWrapper); basicLayout.setComponentAlignment(userWrapper, Alignment.MIDDLE_LEFT); basicLayout.addComponent(new Label(AppContext.getMessage(UserI18nEnum.FORM_BIRTHDAY) + ": " + AppContext.formatDate(user.getDateofbirth()))); basicLayout.addComponent( new MHorizontalLayout(new Label(AppContext.getMessage(UserI18nEnum.FORM_EMAIL) + ": "), new LabelLink(user.getEmail(), "mailto:" + user.getEmail()))); basicLayout.addComponent(new Label(AppContext.getMessage(UserI18nEnum.FORM_TIMEZONE) + ": " + TimezoneMapper.getTimezone(user.getTimezone()).getDisplayName())); basicLayout.addComponent(new Label(AppContext.getMessage(UserI18nEnum.FORM_LANGUAGE) + ": " + AppContext.getMessage(LangI18Enum.class, user.getLanguage()))); HorizontalLayout passwordWrapper = new HorizontalLayout(); passwordWrapper .addComponent(new Label(AppContext.getMessage(ShellI18nEnum.FORM_PASSWORD) + ": ***********")); final Button btnChangePassword = new Button("Change", new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { UI.getCurrent().addWindow(new PasswordChangeWindow(formItem.user)); } }); btnChangePassword.setStyleName("link"); HorizontalLayout btnChangePasswordWrapper = new HorizontalLayout(); btnChangePasswordWrapper.setWidth("50px"); btnChangePasswordWrapper.addComponent(btnChangePassword); btnChangePasswordWrapper.setComponentAlignment(btnChangePassword, Alignment.MIDDLE_RIGHT); passwordWrapper.addComponent(btnChangePasswordWrapper); basicLayout.addComponent(passwordWrapper); basicLayout.setComponentAlignment(passwordWrapper, Alignment.MIDDLE_LEFT); avatarAndPass.addComponent(basicLayout); avatarAndPass.setComponentAlignment(basicLayout, Alignment.TOP_LEFT); avatarAndPass.setExpandRatio(basicLayout, 1.0f); final UploadField avatarUploadField = 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("Do not support image format for avatar"); } else { mimeType = "image/png"; } } if (mimeType.equals("image/png")) { EventBusFactory.getInstance() .post(new ProfileEvent.GotoUploadPhoto(ProfileReadViewImpl.this, imageData)); } else { throw new UserInvalidInputException( "Upload file does not have valid image format. The supported formats are jpg/png"); } } }; avatarUploadField.addStyleName("upload-field"); avatarUploadField.setButtonCaption(AppContext.getMessage(UserI18nEnum.BUTTON_CHANGE_AVATAR)); avatarUploadField.setSizeUndefined(); avatarUploadField.setFieldType(FieldType.BYTE_ARRAY); this.userAvatar.addComponent(avatarUploadField); }
From source file:com.esofthead.mycollab.module.user.accountsettings.team.view.NewUserAddedWindow.java
License:Open Source License
public NewUserAddedWindow(final SimpleUser user, String uncryptPassword) { super(AppContext.getMessage(UserI18nEnum.NEW)); this.setModal(true); this.setResizable(false); this.setClosable(false); this.center(); this.setWidth("600px"); MVerticalLayout content = new MVerticalLayout(); this.setContent(content); ELabel infoLbl = new ELabel( FontAwesome.CHECK_CIRCLE.getHtml() + AppContext.getMessage(UserI18nEnum.OPT_NEW_USER_CREATED, user.getDisplayName()), ContentMode.HTML);/* w w w.j a va 2 s . co m*/ content.with(infoLbl); String signinInstruction = AppContext.getMessage(UserI18nEnum.OPT_SIGN_IN_MSG, AppContext.getSiteUrl(), AppContext.getSiteUrl()); content.with(new MVerticalLayout(new Label(signinInstruction, ContentMode.HTML), new ELabel(AppContext.getMessage(ShellI18nEnum.FORM_EMAIL)).withStyleName(UIConstants.META_INFO), new Label(" " + user.getUsername()), new ELabel(AppContext.getMessage(ShellI18nEnum.FORM_PASSWORD)).withStyleName(UIConstants.META_INFO), new Label(" " + (uncryptPassword != null ? uncryptPassword : AppContext.getMessage(UserI18nEnum.OPT_USER_SET_OWN_PASSWORD))))); Button sendEmailBtn = new Button(AppContext.getMessage(GenericI18Enum.ACTION_SEND_EMAIL), new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { ExtMailService mailService = AppContextUtil.getSpringBean(ExtMailService.class); if (!mailService.isMailSetupValid()) { UI.getCurrent().addWindow(new GetStartedInstructionWindow(user)); } else { NotificationUtil.showNotification( AppContext.getMessage(GenericI18Enum.HELP_SPAM_FILTER_PREVENT_TITLE), AppContext.getMessage(GenericI18Enum.HELP_SPAM_FILTER_PREVENT_MESSAGE)); } } }); content.with(new ELabel(AppContext.getMessage(GenericI18Enum.HELP_SPAM_FILTER_PREVENT_MESSAGE)) .withStyleName(UIConstants.META_INFO)); Button createMoreUserBtn = new Button(AppContext.getMessage(UserI18nEnum.OPT_CREATE_ANOTHER_USER), new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { EventBusFactory.getInstance().post(new UserEvent.GotoAdd(this, null)); close(); } }); createMoreUserBtn.addStyleName(UIConstants.BUTTON_LINK); Button doneBtn = new Button(AppContext.getMessage(GenericI18Enum.ACTION_DONE), new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { EventBusFactory.getInstance().post(new UserEvent.GotoList(this, null)); close(); } }); doneBtn.addStyleName(UIConstants.BUTTON_ACTION); MHorizontalLayout buttonControls = new MHorizontalLayout(createMoreUserBtn, doneBtn).withFullWidth() .withAlign(createMoreUserBtn, Alignment.MIDDLE_LEFT).withAlign(doneBtn, Alignment.MIDDLE_RIGHT); content.with(buttonControls); }
From source file:com.esofthead.mycollab.module.user.accountsettings.team.view.RoleSearchPanel.java
License:Open Source License
private HorizontalLayout createSearchTopPanel() { final MHorizontalLayout layout = new MHorizontalLayout().withStyleName(UIConstants.HEADER_VIEW) .withWidth("100%").withSpacing(true).withMargin(new MarginInfo(true, false, true, false)); layout.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT); final Label searchtitle = new Label( FontAwesome.USERS.getHtml() + " " + AppContext.getMessage(RoleI18nEnum.VIEW_LIST_TITLE), ContentMode.HTML);//w w w. j a va 2 s.c om searchtitle.setStyleName(UIConstants.HEADER_TEXT); layout.addComponent(searchtitle); layout.setExpandRatio(searchtitle, 1.0f); final Button createBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CREATE), new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(final Button.ClickEvent event) { EventBusFactory.getInstance().post(new RoleEvent.GotoAdd(this, null)); } }); createBtn.setStyleName(UIConstants.THEME_GREEN_LINK); createBtn.setIcon(FontAwesome.PLUS); createBtn.setEnabled(AppContext.canWrite(RolePermissionCollections.ACCOUNT_ROLE)); layout.with(createBtn).withAlign(createBtn, Alignment.MIDDLE_RIGHT); return layout; }
From source file:com.esofthead.mycollab.module.user.accountsettings.team.view.UserListViewImpl.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/* w w w .ja v a2s. c o m*/ public void setSearchCriteria(UserSearchCriteria searchCriteria) { UserService userService = ApplicationContextUtil.getSpringBean(UserService.class); List<SimpleUser> userAccountList = userService .findPagableListByCriteria(new SearchRequest<>(searchCriteria, 0, Integer.MAX_VALUE)); this.removeAllComponents(); this.setSpacing(true); HorizontalLayout header = new HorizontalLayout(); header.setStyleName(UIConstants.HEADER_VIEW); header.setWidth("100%"); header.setMargin(new MarginInfo(true, false, true, false)); Button createBtn = new Button("Invite user", new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(Button.ClickEvent event) { EventBusFactory.getInstance().post(new UserEvent.GotoAdd(this, null)); } }); createBtn.setEnabled(AppContext.canWrite(RolePermissionCollections.ACCOUNT_USER)); createBtn.setStyleName(UIConstants.THEME_GREEN_LINK); createBtn.setIcon(FontAwesome.PLUS); header.addComponent(createBtn); header.setComponentAlignment(createBtn, Alignment.MIDDLE_RIGHT); this.addComponent(header); CssLayout contentLayout = new CssLayout(); contentLayout.setWidth("100%"); for (SimpleUser userAccount : userAccountList) { contentLayout.addComponent(generateMemberBlock(userAccount)); } this.addComponent(contentLayout); }
From source file:com.esofthead.mycollab.module.user.accountsettings.team.view.UserListViewImpl.java
License:Open Source License
private Component generateMemberBlock(final SimpleUser member) { CssLayout memberBlock = new CssLayout(); memberBlock.addStyleName("member-block"); VerticalLayout blockContent = new VerticalLayout(); HorizontalLayout blockTop = new HorizontalLayout(); blockTop.setSpacing(true);/*from w ww.ja v a2s. c o m*/ Image memberAvatar = UserAvatarControlFactory.createUserAvatarEmbeddedComponent(member.getAvatarid(), 100); blockTop.addComponent(memberAvatar); VerticalLayout memberInfo = new VerticalLayout(); HorizontalLayout layoutButtonDelete = new HorizontalLayout(); layoutButtonDelete.setVisible(AppContext.canWrite(RolePermissionCollections.ACCOUNT_USER)); layoutButtonDelete.setWidth("100%"); Label emptylb = new Label(""); layoutButtonDelete.addComponent(emptylb); layoutButtonDelete.setExpandRatio(emptylb, 1.0f); Button deleteBtn = new Button(); deleteBtn.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(ClickEvent event) { ConfirmDialogExt.show(UI.getCurrent(), AppContext.getMessage(GenericI18Enum.DIALOG_DELETE_TITLE, SiteConfiguration.getSiteName()), AppContext.getMessage(GenericI18Enum.DIALOG_DELETE_SINGLE_ITEM_MESSAGE), AppContext.getMessage(GenericI18Enum.BUTTON_YES), AppContext.getMessage(GenericI18Enum.BUTTON_NO), new ConfirmDialog.Listener() { private static final long serialVersionUID = 1L; @Override public void onClose(ConfirmDialog dialog) { if (dialog.isConfirmed()) { UserService userService = ApplicationContextUtil .getSpringBean(UserService.class); userService.pendingUserAccounts(Arrays.asList(member.getUsername()), AppContext.getAccountId()); EventBusFactory.getInstance() .post(new UserEvent.GotoList(UserListViewImpl.this, null)); } } }); } }); deleteBtn.setIcon(FontAwesome.TRASH_O); deleteBtn.addStyleName(UIConstants.BUTTON_ICON_ONLY); layoutButtonDelete.addComponent(deleteBtn); memberInfo.addComponent(layoutButtonDelete); ButtonLink userAccountLink = new ButtonLink(member.getDisplayName()); userAccountLink.addClickListener(new ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(ClickEvent event) { EventBusFactory.getInstance() .post(new UserEvent.GotoRead(UserListViewImpl.this, member.getUsername())); } }); userAccountLink.setWidth("100%"); userAccountLink.setHeight("100%"); memberInfo.addComponent(userAccountLink); Label memberEmailLabel = new Label( "<a href='mailto:" + member.getUsername() + "'>" + member.getUsername() + "</a>", ContentMode.HTML); memberEmailLabel.addStyleName("member-email"); memberEmailLabel.setWidth("100%"); memberInfo.addComponent(memberEmailLabel); Label memberSinceLabel = new Label("Member since: " + AppContext.formatDate(member.getRegisteredtime())); memberSinceLabel.addStyleName("member-email"); memberSinceLabel.setWidth("100%"); memberInfo.addComponent(memberSinceLabel); if (RegisterStatusConstants.SENT_VERIFICATION_EMAIL.equals(member.getRegisterstatus())) { final VerticalLayout waitingNotLayout = new VerticalLayout(); Label infoStatus = new Label("Waiting for accept invitation"); infoStatus.addStyleName("member-email"); waitingNotLayout.addComponent(infoStatus); ButtonLink resendInvitationLink = new ButtonLink("Resend Invitation", new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(ClickEvent event) { UserService userService = ApplicationContextUtil.getSpringBean(UserService.class); userService.updateUserAccountStatus(member.getUsername(), member.getAccountId(), RegisterStatusConstants.VERIFICATING); waitingNotLayout.removeAllComponents(); Label statusEmail = new Label("Sending invitation email"); statusEmail.addStyleName("member-email"); waitingNotLayout.addComponent(statusEmail); } }); resendInvitationLink.setStyleName("link"); resendInvitationLink.addStyleName("member-email"); waitingNotLayout.addComponent(resendInvitationLink); memberInfo.addComponent(waitingNotLayout); } else if (RegisterStatusConstants.ACTIVE.equals(member.getRegisterstatus())) { Label lastAccessTimeLbl = new Label("Logged in " + DateTimeUtils.getPrettyDateValue(member.getLastaccessedtime(), AppContext.getUserLocale())); lastAccessTimeLbl.addStyleName("member-email"); memberInfo.addComponent(lastAccessTimeLbl); } else if (RegisterStatusConstants.VERIFICATING.equals(member.getRegisterstatus())) { Label infoStatus = new Label("Sending invitation email"); infoStatus.addStyleName("member-email"); memberInfo.addComponent(infoStatus); } blockTop.addComponent(memberInfo); blockTop.setExpandRatio(memberInfo, 1.0f); blockTop.setWidth("100%"); blockContent.addComponent(blockTop); if (member.getRoleid() != null) { String memberRoleLinkPrefix = "<a href=\"" + AccountLinkBuilder.generatePreviewFullRoleLink(member.getRoleid()) + "\""; Label memberRole = new Label(); memberRole.setContentMode(ContentMode.HTML); if (member.getIsAccountOwner() != null && member.getIsAccountOwner()) { memberRole.setValue(memberRoleLinkPrefix + "style=\"color: #B00000;\">" + "Account Owner" + "</a>"); } else { memberRole.setValue(memberRoleLinkPrefix + "style=\"color:gray;font-size:12px;\">" + member.getRoleName() + "</a>"); } memberRole.setSizeUndefined(); blockContent.addComponent(memberRole); blockContent.setComponentAlignment(memberRole, Alignment.MIDDLE_RIGHT); } else if (member.getIsAccountOwner() != null && member.getIsAccountOwner() == Boolean.TRUE) { Label memberRole = new Label(); memberRole.setContentMode(ContentMode.HTML); memberRole.setValue("<a style=\"color: #B00000;\">" + "Account Owner" + "</a>"); memberRole.setSizeUndefined(); blockContent.addComponent(memberRole); blockContent.setComponentAlignment(memberRole, Alignment.MIDDLE_RIGHT); } else { Label lbl = new Label(); lbl.setHeight("10px"); blockContent.addComponent(lbl); } blockContent.setWidth("100%"); memberBlock.addComponent(blockContent); return memberBlock; }
From source file:com.esofthead.mycollab.module.user.accountsettings.team.view.UserSearchPanel.java
License:Open Source License
private HorizontalLayout createSearchTopPanel() { final MHorizontalLayout layout = new MHorizontalLayout().withWidth("100%").withSpacing(true) .withMargin(true);//from w w w . j a va2s . com final Label searchtitle = new Label("Users"); searchtitle.setStyleName(Reindeer.LABEL_H2); layout.addComponent(searchtitle); layout.setComponentAlignment(searchtitle, Alignment.MIDDLE_LEFT); final Button createBtn = new Button("Invite", new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(final Button.ClickEvent event) { EventBusFactory.getInstance().post(new UserEvent.GotoAdd(this, null)); } }); createBtn.setStyleName(UIConstants.THEME_GREEN_LINK); createBtn.setIcon(FontAwesome.PLUS); createBtn.setEnabled(AppContext.canWrite(RolePermissionCollections.ACCOUNT_USER)); layout.with(createBtn).withAlign(createBtn, Alignment.MIDDLE_RIGHT); return layout; }
From source file:com.esofthead.mycollab.module.user.ui.components.ImagePreviewCropWindow.java
License:Open Source License
public ImagePreviewCropWindow(final ImageSelectionCommand imageSelectionCommand, final byte[] imageData) { super("Preview and modify image"); setModal(true);//w w w . j a v a 2 s.com setResizable(false); setWidth("700px"); center(); MVerticalLayout content = new MVerticalLayout(); setContent(content); try { 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().withSpacing(true) .withMargin(new MarginInfo(false, true, true, false)).withFullWidth(); previewPhoto = new VerticalLayout(); previewPhoto.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER); previewPhoto.setWidth("100px"); previewBox.with(previewPhoto).withAlign(previewPhoto, Alignment.TOP_LEFT); VerticalLayout previewBoxTitle = new VerticalLayout(); previewBoxTitle.setMargin(new MarginInfo(false, true, false, true)); Label lbPreview = new Label("<p style='margin: 0px;'><strong>To the bottom is what your profile photo will " + "look like.</strong></p>" + "<p style='margin-top: 0px;'>To make adjustment, you can drag around and resize the selection square below. " + "When you are happy with your photo, click the “Accept“ button.</p>", ContentMode.HTML); previewBoxTitle.addComponent(lbPreview); MHorizontalLayout controlBtns = new MHorizontalLayout(); controlBtns.setSizeUndefined(); Button cancelBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CANCEL), new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { close(); } }); cancelBtn.setStyleName(UIConstants.BUTTON_OPTION); Button acceptBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_ACCEPT), new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (scaleImageData != null && scaleImageData.length > 0) { try { BufferedImage image = ImageIO.read(new ByteArrayInputStream(scaleImageData)); imageSelectionCommand.process(image); close(); } catch (IOException e) { throw new MyCollabException("Error when saving user avatar", e); } } } }); acceptBtn.setStyleName(UIConstants.BUTTON_ACTION); acceptBtn.setIcon(FontAwesome.CHECK); controlBtns.with(acceptBtn, cancelBtn).alignAll(Alignment.MIDDLE_LEFT); previewBoxTitle.addComponent(controlBtns); previewBoxTitle.setComponentAlignment(controlBtns, Alignment.TOP_LEFT); previewBox.with(previewBoxTitle).expand(previewBoxTitle); 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(1.0f); cropField.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { VCropSelection newSelection = (VCropSelection) event.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("520px"); currentPhotoBox.setHeight("470px"); currentPhotoBox.addComponent(cropField); cropBox.addComponent(currentPhotoBox); content.with(previewBox, ELabel.hr(), cropBox); displayPreviewImage(); }
From source file:com.esofthead.mycollab.reporting.CustomizeReportOutputWindow.java
License:Open Source License
public CustomizeReportOutputWindow(final String viewId, final String reportTitle, final Class<B> beanCls, final ISearchableService<S> searchableService, final VariableInjector<S> variableInjector) { super("Export"); this.setModal(true); this.setWidth("1000px"); this.setResizable(false); this.center(); this.viewId = viewId; this.variableInjector = variableInjector; MVerticalLayout contentLayout = new MVerticalLayout(); setContent(contentLayout);/*from www .ja va 2 s. c o m*/ final OptionGroup optionGroup = new OptionGroup(); optionGroup.addStyleName("sortDirection"); optionGroup.addItems(AppContext.getMessage(FileI18nEnum.CSV), AppContext.getMessage(FileI18nEnum.PDF), AppContext.getMessage(FileI18nEnum.EXCEL)); optionGroup.setValue(AppContext.getMessage(FileI18nEnum.CSV)); contentLayout.with( new MHorizontalLayout(ELabel.h3(AppContext.getMessage(GenericI18Enum.ACTION_EXPORT)), optionGroup) .alignAll(Alignment.MIDDLE_LEFT)); contentLayout.with(ELabel.h3(AppContext.getMessage(GenericI18Enum.ACTION_SELECT_COLUMNS))); listBuilder = new ListBuilder(); listBuilder.setImmediate(true); listBuilder.setColumns(0); listBuilder.setLeftColumnCaption(AppContext.getMessage(GenericI18Enum.OPT_AVAILABLE_COLUMNS)); listBuilder.setRightColumnCaption(AppContext.getMessage(GenericI18Enum.OPT_VIEW_COLUMNS)); listBuilder.setWidth(100, Sizeable.Unit.PERCENTAGE); listBuilder.setItemCaptionMode(AbstractSelect.ItemCaptionMode.EXPLICIT); final BeanItemContainer<TableViewField> container = new BeanItemContainer<>(TableViewField.class, this.getAvailableColumns()); listBuilder.setContainerDataSource(container); Iterator<TableViewField> iterator = getAvailableColumns().iterator(); while (iterator.hasNext()) { TableViewField field = iterator.next(); listBuilder.setItemCaption(field, AppContext.getMessage(field.getDescKey())); } final Collection<TableViewField> viewColumnIds = this.getViewColumns(); listBuilder.setValue(viewColumnIds); contentLayout.with(listBuilder).withAlign(listBuilder, Alignment.TOP_CENTER); contentLayout.with(ELabel.h3(AppContext.getMessage(GenericI18Enum.ACTION_PREVIEW))); sampleTableDisplay = new Table(); for (TableViewField field : getAvailableColumns()) { sampleTableDisplay.addContainerProperty(field.getField(), String.class, "", AppContext.getMessage(field.getDescKey()), null, Table.Align.LEFT); sampleTableDisplay.setColumnWidth(field.getField(), field.getDefaultWidth()); } sampleTableDisplay.setWidth("100%"); sampleTableDisplay.addItem(buildSampleData(), 1); sampleTableDisplay.setPageLength(1); contentLayout.with(sampleTableDisplay); filterColumns(); listBuilder.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent valueChangeEvent) { filterColumns(); } }); Button resetBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_RESET), new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { listBuilder.setValue(getDefaultColumns()); filterColumns(); } }); resetBtn.addStyleName(UIConstants.BUTTON_LINK); Button cancelBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CANCEL), new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { close(); } }); cancelBtn.addStyleName(UIConstants.BUTTON_OPTION); final Button exportBtn = new Button(AppContext.getMessage(GenericI18Enum.ACTION_EXPORT)); exportBtn.addStyleName(UIConstants.BUTTON_ACTION); OnDemandFileDownloader pdfFileDownloader = new OnDemandFileDownloader(new LazyStreamSource() { @Override protected StreamResource.StreamSource buildStreamSource() { return new StreamResource.StreamSource() { @Override public InputStream getStream() { Collection<TableViewField> columns = (Collection<TableViewField>) listBuilder.getValue(); // Save custom table view def CustomViewStoreService customViewStoreService = AppContextUtil .getSpringBean(CustomViewStoreService.class); CustomViewStore viewDef = new CustomViewStore(); viewDef.setSaccountid(AppContext.getAccountId()); viewDef.setCreateduser(AppContext.getUsername()); viewDef.setViewid(viewId); viewDef.setViewinfo(FieldDefAnalyzer.toJson(new ArrayList<>(columns))); customViewStoreService.saveOrUpdateViewLayoutDef(viewDef); SimpleReportTemplateExecutor reportTemplateExecutor = new SimpleReportTemplateExecutor.AllItems<>( reportTitle, new RpFieldsBuilder(columns), exportType, beanCls, searchableService); ReportStreamSource streamSource = new ReportStreamSource(reportTemplateExecutor) { @Override protected void initReportParameters(Map<String, Object> parameters) { parameters.put(SimpleReportTemplateExecutor.CRITERIA, variableInjector.eval()); } }; return streamSource.getStream(); } }; } @Override public String getFilename() { String exportTypeVal = (String) optionGroup.getValue(); if (AppContext.getMessage(FileI18nEnum.CSV).equals(exportTypeVal)) { exportType = ReportExportType.CSV; } else if (AppContext.getMessage(FileI18nEnum.EXCEL).equals(exportTypeVal)) { exportType = ReportExportType.EXCEL; } else { exportType = ReportExportType.PDF; } return exportType.getDefaultFileName(); } }); pdfFileDownloader.extend(exportBtn); MHorizontalLayout buttonControls = new MHorizontalLayout(resetBtn, cancelBtn, exportBtn); contentLayout.with(buttonControls).withAlign(buttonControls, Alignment.TOP_RIGHT); }
From source file:com.esofthead.mycollab.shell.view.components.AdRequestWindow.java
License:Open Source License
public AdRequestWindow(final SimpleUser user) { super("Need help!"); this.setModal(true); this.setResizable(false); this.setWidth("600px"); MVerticalLayout content = new MVerticalLayout(); Label message = new Label("Hey <b>" + AppContext.getUser().getDisplayName() + "</b>, you've been " + "using MyCollab for a while now. And we hope you are happy with it. We spent countless hours and money developing this free " + "software for you. If you like it, please write a few words on twitter, blog or our " + "testimonial form. It will help other " + "people find this useful software quickly. <b> Thank you</b>", ContentMode.HTML); MVerticalLayout shareControls = new MVerticalLayout(); Label rateSourceforge = new Label( new Div().appendChild(new Text(FontAwesome.THUMBS_O_UP.getHtml()), DivLessFormatter.EMPTY_SPACE(), new A("http://sourceforge.net/projects/mycollab/reviews/new", "_blank") .appendText("Rate us on Sourceforge")) .setStyle("color:#006dac").write(), ContentMode.HTML);/*from w w w. ja va 2s . co m*/ Label tweetUs = new Label(new Div().appendChild(new Text(FontAwesome.TWITTER.getHtml()), DivLessFormatter.EMPTY_SPACE(), new A("https://twitter.com/intent/tweet?text=Im using MyCollab to manage all project activities, accounts and it works great @mycollabdotcom&source=webclient", "_blank").appendText("Share on Twitter")) .setStyle("color:#006dac").write(), ContentMode.HTML); Label linkedIn = new Label(new Div().appendChild(new Text(FontAwesome.LINKEDIN_SQUARE.getHtml()), DivLessFormatter.EMPTY_SPACE(), new A("https://www.linkedin.com/cws/share?url=https%3A%2F%2Fwww.mycollab.com&original_referer=https%3A%2F%2Fwww.mycollab.com&token=&isFramed=false&lang=en_US", "_blank").appendText("Share on LinkedIn")) .setStyle("color:#006dac").write(), ContentMode.HTML); Button testimonialBtn = new Button("Write a testimonial", new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { AdRequestWindow.this.close(); turnOffAdd(user); UI.getCurrent().addWindow(new TestimonialWindow()); } }); testimonialBtn.setStyleName(UIConstants.BUTTON_LINK); testimonialBtn.setIcon(FontAwesome.KEYBOARD_O); shareControls.with(rateSourceforge, tweetUs, linkedIn, testimonialBtn); MHorizontalLayout btnControls = new MHorizontalLayout(); Button ignoreBtn = new Button("No, thanks", new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { close(); turnOffAdd(user); } }); ignoreBtn.addStyleName(UIConstants.BUTTON_OPTION); Button loveBtn = new Button("I did", new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { AdRequestWindow.this.close(); NotificationUtil.showNotification("We appreciate your kindness action", "Thank you for your time"); turnOffAdd(user); } }); loveBtn.addStyleName(UIConstants.BUTTON_ACTION); loveBtn.setIcon(FontAwesome.HEART); btnControls.with(ignoreBtn, loveBtn); content.with(message, shareControls, btnControls).withAlign(btnControls, Alignment.MIDDLE_RIGHT); this.setContent(content); }