List of usage examples for com.vaadin.ui Button setIcon
@Override public void setIcon(Resource icon)
From source file:com.esofthead.mycollab.module.user.accountsettings.team.view.UserListViewImpl.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*from ww w. j a v a2s. co 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 a 2 s .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 ww w . ja va 2s . c o m*/ 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);//from ww w . ja v a 2s .c o m 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.module.user.ui.components.PreviewFormControlsGenerator.java
License:Open Source License
public HorizontalLayout createButtonControls(int buttonEnableFlags, String permissionItem) { optionBtn = new PopupButton(); optionBtn.addStyleName(UIConstants.BOX); optionBtn.setIcon(FontAwesome.ELLIPSIS_H); if (permissionItem != null) { boolean canWrite = AppContext.canWrite(permissionItem); boolean canAccess = AppContext.canAccess(permissionItem); boolean canRead = AppContext.canRead(permissionItem); if ((buttonEnableFlags & ADD_BTN_PRESENTED) == ADD_BTN_PRESENTED) { Button addBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_ADD), new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { optionBtn.setPopupVisible(false); T item = previewForm.getBean(); previewForm.fireAddForm(item); }/*from ww w .ja v a 2 s. com*/ }); addBtn.setIcon(FontAwesome.PLUS); addBtn.setStyleName(UIConstants.BUTTON_ACTION); addBtn.setEnabled(canWrite); editButtons.addComponent(addBtn); } if ((buttonEnableFlags & EDIT_BTN_PRESENTED) == EDIT_BTN_PRESENTED) { Button editBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_EDIT), new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { optionBtn.setPopupVisible(false); T item = previewForm.getBean(); previewForm.fireEditForm(item); } }); editBtn.setIcon(FontAwesome.EDIT); editBtn.setStyleName(UIConstants.BUTTON_ACTION); editBtn.setEnabled(canWrite); editButtons.addComponent(editBtn); } if ((buttonEnableFlags & DELETE_BTN_PRESENTED) == DELETE_BTN_PRESENTED) { Button deleteBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_DELETE), new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { T item = previewForm.getBean(); previewForm.fireDeleteForm(item); } }); deleteBtn.setIcon(FontAwesome.TRASH_O); deleteBtn.setStyleName(UIConstants.BUTTON_DANGER); deleteBtn.setEnabled(canAccess); editButtons.addComponent(deleteBtn); } layout.with(editButtons); if ((buttonEnableFlags & NAVIGATOR_BTN_PRESENTED) == NAVIGATOR_BTN_PRESENTED) { ButtonGroup navigationBtns = new ButtonGroup(); Button previousItem = new Button(null, new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { T item = previewForm.getBean(); previewForm.fireGotoPrevious(item); } }); previousItem.setIcon(FontAwesome.CHEVRON_LEFT); previousItem.setStyleName(UIConstants.BUTTON_ACTION); previousItem.setDescription(AppContext.getMessage(GenericI18Enum.TOOLTIP_SHOW_PREVIOUS_ITEM)); previousItem.setEnabled(canRead); navigationBtns.addButton(previousItem); Button nextItemBtn = new Button(null, new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { T item = previewForm.getBean(); previewForm.fireGotoNextItem(item); } }); nextItemBtn.setIcon(FontAwesome.CHEVRON_RIGHT); nextItemBtn.setStyleName(UIConstants.BUTTON_ACTION); nextItemBtn.setDescription(AppContext.getMessage(GenericI18Enum.TOOLTIP_SHOW_NEXT_ITEM)); nextItemBtn.setEnabled(canRead); navigationBtns.addButton(nextItemBtn); layout.with(navigationBtns); } if ((buttonEnableFlags & CLONE_BTN_PRESENTED) == CLONE_BTN_PRESENTED) { Button cloneBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CLONE), new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { optionBtn.setPopupVisible(false); T item = previewForm.getBean(); previewForm.fireCloneForm(item); } }); cloneBtn.setIcon(FontAwesome.ROAD); cloneBtn.setEnabled(canWrite); popupButtonsControl.addOption(cloneBtn); } if (popupButtonsControl.getComponentCount() > 0) { optionBtn.setContent(popupButtonsControl); layout.with(optionBtn); } } return layout; }
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);/*ww w . j av a 2 s . c om*/ 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); }
From source file:com.esofthead.mycollab.shell.view.MainView.java
License:Open Source License
private CustomLayout createTopMenu() { final CustomLayout layout = CustomLayoutExt.createLayout("topNavigation"); layout.setStyleName("topNavigation"); layout.setHeight("40px"); layout.setWidth("100%"); Button accountLogo = AccountLogoFactory .createAccountLogoImageComponent(ThemeManager.loadLogoPath(AppContext.getAccountId()), 150); accountLogo.addClickListener(new ClickListener() { private static final long serialVersionUID = 1L; @Override// w ww . j a v a2s . c om public void buttonClick(final ClickEvent event) { final UserPreference pref = AppContext.getUserPreference(); if (pref.getLastmodulevisit() == null || ModuleNameConstants.PRJ.equals(pref.getLastmodulevisit())) { EventBusFactory.getInstance().post(new ShellEvent.GotoProjectModule(this, null)); } else if (ModuleNameConstants.CRM.equals(pref.getLastmodulevisit())) { EventBusFactory.getInstance().post(new ShellEvent.GotoCrmModule(this, null)); } else if (ModuleNameConstants.ACCOUNT.equals(pref.getLastmodulevisit())) { EventBusFactory.getInstance().post(new ShellEvent.GotoUserAccountModule(this, null)); } else if (ModuleNameConstants.FILE.equals(pref.getLastmodulevisit())) { EventBusFactory.getInstance().post(new ShellEvent.GotoFileModule(this, null)); } } }); layout.addComponent(accountLogo, "mainLogo"); serviceMenu = new ServiceMenu(); serviceMenu.addStyleName("topNavPopup"); serviceMenu.addService(AppContext.getMessage(GenericI18Enum.MODULE_CRM), MyCollabResource.newResource(WebResourceIds._16_customer), new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { EventBusFactory.getInstance().post(new ShellEvent.GotoCrmModule(this, null)); } }); serviceMenu.addService(AppContext.getMessage(GenericI18Enum.MODULE_PROJECT), MyCollabResource.newResource(WebResourceIds._16_project), new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { if (!event.isCtrlKey() && !event.isMetaKey()) { EventBusFactory.getInstance().post(new ShellEvent.GotoProjectModule(this, null)); } } }); serviceMenu.addService(AppContext.getMessage(GenericI18Enum.MODULE_DOCUMENT), MyCollabResource.newResource(WebResourceIds._16_document), new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { EventBusFactory.getInstance().post(new ShellEvent.GotoFileModule(this, null)); } }); serviceMenu.addService(AppContext.getMessage(GenericI18Enum.MODULE_PEOPLE), MyCollabResource.newResource(WebResourceIds._16_account), new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { EventBusFactory.getInstance() .post(new ShellEvent.GotoUserAccountModule(this, new String[] { "user", "list" })); } }); layout.addComponent(serviceMenu, "serviceMenu"); final MHorizontalLayout accountLayout = new MHorizontalLayout() .withMargin(new MarginInfo(false, true, false, false)); accountLayout.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT); final Label accountNameLabel = new Label(AppContext.getSubDomain()); accountNameLabel.setStyleName("subdomain"); accountLayout.addComponent(accountNameLabel); // display trial box if user in trial mode SimpleBillingAccount billingAccount = AppContext.getBillingAccount(); if (AccountStatusConstants.TRIAL.equals(billingAccount.getStatus())) { Label informLbl = new Label("", ContentMode.HTML); informLbl.addStyleName("trialEndingNotification"); informLbl.setHeight("100%"); HorizontalLayout informBox = new HorizontalLayout(); informBox.addStyleName("trialInformBox"); informBox.setSizeFull(); informBox.addComponent(informLbl); informBox.setMargin(new MarginInfo(false, true, false, false)); informBox.addLayoutClickListener(new LayoutEvents.LayoutClickListener() { private static final long serialVersionUID = 1L; @Override public void layoutClick(LayoutClickEvent event) { EventBusFactory.getInstance() .post(new ShellEvent.GotoUserAccountModule(this, new String[] { "billing" })); } }); accountLayout.addComponent(informBox); accountLayout.setSpacing(true); accountLayout.setComponentAlignment(informBox, Alignment.MIDDLE_LEFT); Date createdTime = billingAccount.getCreatedtime(); long timeDeviation = System.currentTimeMillis() - createdTime.getTime(); int daysLeft = (int) Math.floor(timeDeviation / (1000 * 60 * 60 * 24)); if (daysLeft > 30) { BillingService billingService = ApplicationContextUtil.getSpringBean(BillingService.class); BillingPlan freeBillingPlan = billingService.getFreeBillingPlan(); billingAccount.setBillingPlan(freeBillingPlan); informLbl.setValue("<div class='informBlock'>TRIAL ENDING<br>" + " 0 DAYS LEFT</div><div class='informBlock'>>></div>"); } else { if (AppContext.isAdmin()) { informLbl.setValue("<div class='informBlock'>TRIAL ENDING<br>" + (30 - daysLeft) + " DAYS LEFT</div><div class='informBlock'>>></div>"); } else { informLbl.setValue("<div class='informBlock'>TRIAL ENDING<br>" + (30 - daysLeft) + " DAYS LEFT</div><div class='informBlock'>>></div>"); } } } NotificationButton notificationButton = new NotificationButton(); accountLayout.addComponent(notificationButton); if (AppContext.getSession().getTimezone() == null) { EventBusFactory.getInstance().post(new ShellEvent.NewNotification(this, new TimezoneNotification())); } if (StringUtils.isBlank(AppContext.getSession().getAvatarid())) { EventBusFactory.getInstance() .post(new ShellEvent.NewNotification(this, new RequestUploadAvatarNotification())); } if (SiteConfiguration.getDeploymentMode() != DeploymentMode.site && AppContext.isAdmin()) { try { Client client = ClientBuilder.newBuilder().build(); WebTarget target = client.target("https://api.mycollab.com/api/checkupdate"); Response response = target.request().get(); String values = response.readEntity(String.class); Gson gson = new Gson(); Properties props = gson.fromJson(values, Properties.class); String version = props.getProperty("version"); if (!MyCollabVersion.getVersion().equals(version)) { EventBusFactory.getInstance() .post(new ShellEvent.NewNotification(this, new NewUpdateNotification(props))); } } catch (Exception e) { LOG.error("Error when call remote api", e); } } UserAvatarComp userAvatar = new UserAvatarComp(); accountLayout.addComponent(userAvatar); accountLayout.setComponentAlignment(userAvatar, Alignment.MIDDLE_LEFT); final PopupButton accountMenu = new PopupButton(AppContext.getSession().getDisplayName()); final VerticalLayout accLayout = new VerticalLayout(); accLayout.setWidth("140px"); final Button myProfileBtn = new Button(AppContext.getMessage(AdminI18nEnum.VIEW_PROFILE), new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { accountMenu.setPopupVisible(false); EventBusFactory.getInstance() .post(new ShellEvent.GotoUserAccountModule(this, new String[] { "preview" })); } }); myProfileBtn.setIcon(SettingAssetsManager.getAsset(SettingUIConstants.PROFILE)); myProfileBtn.setStyleName("link"); accLayout.addComponent(myProfileBtn); final Button myAccountBtn = new Button(AppContext.getMessage(AdminI18nEnum.VIEW_BILLING), new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { accountMenu.setPopupVisible(false); EventBusFactory.getInstance() .post(new ShellEvent.GotoUserAccountModule(this, new String[] { "billing" })); } }); myAccountBtn.setStyleName("link"); myAccountBtn.setIcon(SettingAssetsManager.getAsset(SettingUIConstants.BILLING)); accLayout.addComponent(myAccountBtn); final Button userMgtBtn = new Button(AppContext.getMessage(AdminI18nEnum.VIEW_USERS_AND_ROLES), new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { accountMenu.setPopupVisible(false); EventBusFactory.getInstance() .post(new ShellEvent.GotoUserAccountModule(this, new String[] { "user", "list" })); } }); userMgtBtn.setStyleName("link"); userMgtBtn.setIcon(SettingAssetsManager.getAsset(SettingUIConstants.USERS)); accLayout.addComponent(userMgtBtn); final Button signoutBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_SIGNOUT), new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { AppContext.getInstance().clearSession(); EventBusFactory.getInstance().post(new ShellEvent.LogOut(this, null)); } }); signoutBtn.setStyleName("link"); signoutBtn.setIcon(FontAwesome.SIGN_OUT); accLayout.addComponent(signoutBtn); accountMenu.setContent(accLayout); accountMenu.setStyleName("accountMenu"); accountMenu.addStyleName("topNavPopup"); accountLayout.addComponent(accountMenu); layout.addComponent(accountLayout, "accountMenu"); return layout; }
From source file:com.esofthead.mycollab.shell.view.MainViewImpl.java
License:Open Source License
private MHorizontalLayout buildAccountMenuLayout() { accountLayout.removeAllComponents(); if (SiteConfiguration.isDemandEdition()) { // display trial box if user in trial mode SimpleBillingAccount billingAccount = AppContext.getBillingAccount(); if (AccountStatusConstants.TRIAL.equals(billingAccount.getStatus())) { if ("Free".equals(billingAccount.getBillingPlan().getBillingtype())) { Label informLbl = new Label( "<div class='informBlock'>FREE CHARGE<br>UPGRADE</div><div class='informBlock'>>></div>", ContentMode.HTML); informLbl.addStyleName("trialEndingNotification"); informLbl.setHeight("100%"); HorizontalLayout informBox = new HorizontalLayout(); informBox.addStyleName("trialInformBox"); informBox.setSizeFull(); informBox.addComponent(informLbl); informBox.setMargin(new MarginInfo(false, true, false, false)); informBox.addLayoutClickListener(new LayoutEvents.LayoutClickListener() { private static final long serialVersionUID = 1L; @Override//from ww w. j ava2 s . c om public void layoutClick(LayoutClickEvent event) { EventBusFactory.getInstance() .post(new ShellEvent.GotoUserAccountModule(this, new String[] { "billing" })); } }); accountLayout.with(informBox).withAlign(informBox, Alignment.MIDDLE_LEFT); } else { Label informLbl = new Label("", ContentMode.HTML); informLbl.addStyleName("trialEndingNotification"); informLbl.setHeight("100%"); HorizontalLayout informBox = new HorizontalLayout(); informBox.addStyleName("trialInformBox"); informBox.setSizeFull(); informBox.setMargin(new MarginInfo(false, true, false, false)); informBox.addComponent(informLbl); informBox.addLayoutClickListener(new LayoutEvents.LayoutClickListener() { private static final long serialVersionUID = 1L; @Override public void layoutClick(LayoutClickEvent event) { EventBusFactory.getInstance() .post(new ShellEvent.GotoUserAccountModule(this, new String[] { "billing" })); } }); accountLayout.with(informBox).withAlign(informBox, Alignment.MIDDLE_LEFT); Duration dur = new Duration(new DateTime(billingAccount.getCreatedtime()), new DateTime()); int daysLeft = dur.toStandardDays().getDays(); if (daysLeft > 30) { informLbl.setValue( "<div class='informBlock'>Trial<br></div><div class='informBlock'>>></div>"); // AppContext.getInstance().setIsValidAccount(false); } else { informLbl.setValue(String.format("<div class='informBlock'>Trial ending<br>%d days " + "left</div><div class='informBlock'>>></div>", 30 - daysLeft)); } } } } Label accountNameLabel = new Label(AppContext.getSubDomain()); accountNameLabel.addStyleName("subdomain"); accountLayout.addComponent(accountNameLabel); if (SiteConfiguration.isCommunityEdition()) { Button buyPremiumBtn = new Button("Upgrade to Pro edition", new ClickListener() { @Override public void buttonClick(ClickEvent event) { UI.getCurrent().addWindow(new AdWindow()); } }); buyPremiumBtn.setIcon(FontAwesome.SHOPPING_CART); buyPremiumBtn.addStyleName("ad"); accountLayout.addComponent(buyPremiumBtn); } LicenseResolver licenseResolver = AppContextUtil.getSpringBean(LicenseResolver.class); if (licenseResolver != null) { LicenseInfo licenseInfo = licenseResolver.getLicenseInfo(); if (licenseInfo != null) { if (licenseInfo.isExpired()) { Button buyPremiumBtn = new Button(AppContext.getMessage(LicenseI18nEnum.EXPIRE_NOTIFICATION), new ClickListener() { @Override public void buttonClick(ClickEvent event) { UI.getCurrent().addWindow(new BuyPremiumSoftwareWindow()); } }); buyPremiumBtn.setIcon(FontAwesome.SHOPPING_CART); buyPremiumBtn.addStyleName("ad"); accountLayout.addComponent(buyPremiumBtn); } else if (licenseInfo.isTrial()) { Duration dur = new Duration(new DateTime(), new DateTime(licenseInfo.getExpireDate())); int days = dur.toStandardDays().getDays(); Button buyPremiumBtn = new Button( AppContext.getMessage(LicenseI18nEnum.TRIAL_NOTIFICATION, days), new ClickListener() { @Override public void buttonClick(ClickEvent event) { UI.getCurrent().addWindow(new BuyPremiumSoftwareWindow()); } }); buyPremiumBtn.setIcon(FontAwesome.SHOPPING_CART); buyPremiumBtn.addStyleName("ad"); accountLayout.addComponent(buyPremiumBtn); } } } NotificationComponent notificationComponent = new NotificationComponent(); accountLayout.addComponent(notificationComponent); if (StringUtils.isBlank(AppContext.getUser().getAvatarid())) { EventBusFactory.getInstance() .post(new ShellEvent.NewNotification(this, new RequestUploadAvatarNotification())); } if (!SiteConfiguration.isDemandEdition()) { ExtMailService mailService = AppContextUtil.getSpringBean(ExtMailService.class); if (!mailService.isMailSetupValid()) { EventBusFactory.getInstance() .post(new ShellEvent.NewNotification(this, new SmtpSetupNotification())); } SimpleUser user = AppContext.getUser(); GregorianCalendar tenDaysAgo = new GregorianCalendar(); tenDaysAgo.add(Calendar.DATE, -10); if (Boolean.TRUE.equals(user.getRequestad()) && user.getRegisteredtime().before(tenDaysAgo.getTime())) { UI.getCurrent().addWindow(new AdRequestWindow(user)); } } Resource userAvatarRes = UserAvatarControlFactory.createAvatarResource(AppContext.getUserAvatarId(), 24); final PopupButton accountMenu = new PopupButton(""); accountMenu.setIcon(userAvatarRes); accountMenu.setDescription(AppContext.getUserDisplayName()); OptionPopupContent accountPopupContent = new OptionPopupContent(); Button myProfileBtn = new Button(AppContext.getMessage(AdminI18nEnum.VIEW_PROFILE), new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(ClickEvent event) { accountMenu.setPopupVisible(false); EventBusFactory.getInstance() .post(new ShellEvent.GotoUserAccountModule(this, new String[] { "preview" })); } }); myProfileBtn.setIcon(SettingAssetsManager.getAsset(SettingUIConstants.PROFILE)); accountPopupContent.addOption(myProfileBtn); Button userMgtBtn = new Button(AppContext.getMessage(AdminI18nEnum.VIEW_USERS_AND_ROLES), new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { accountMenu.setPopupVisible(false); EventBusFactory.getInstance() .post(new ShellEvent.GotoUserAccountModule(this, new String[] { "user", "list" })); } }); userMgtBtn.setIcon(SettingAssetsManager.getAsset(SettingUIConstants.USERS)); accountPopupContent.addOption(userMgtBtn); Button generalSettingBtn = new Button(AppContext.getMessage(AdminI18nEnum.VIEW_SETTING), new ClickListener() { @Override public void buttonClick(ClickEvent clickEvent) { accountMenu.setPopupVisible(false); EventBusFactory.getInstance().post( new ShellEvent.GotoUserAccountModule(this, new String[] { "setting", "general" })); } }); generalSettingBtn.setIcon(SettingAssetsManager.getAsset(SettingUIConstants.GENERAL_SETTING)); accountPopupContent.addOption(generalSettingBtn); Button themeCustomizeBtn = new Button(AppContext.getMessage(AdminI18nEnum.VIEW_THEME), new ClickListener() { @Override public void buttonClick(ClickEvent clickEvent) { accountMenu.setPopupVisible(false); EventBusFactory.getInstance() .post(new ShellEvent.GotoUserAccountModule(this, new String[] { "setting", "theme" })); } }); themeCustomizeBtn.setIcon(SettingAssetsManager.getAsset(SettingUIConstants.THEME_CUSTOMIZE)); accountPopupContent.addOption(themeCustomizeBtn); if (!SiteConfiguration.isDemandEdition()) { Button setupBtn = new Button(AppContext.getMessage(AdminI18nEnum.VIEW_SETUP), new ClickListener() { @Override public void buttonClick(ClickEvent clickEvent) { accountMenu.setPopupVisible(false); EventBusFactory.getInstance() .post(new ShellEvent.GotoUserAccountModule(this, new String[] { "setup" })); } }); setupBtn.setIcon(FontAwesome.WRENCH); accountPopupContent.addOption(setupBtn); } accountPopupContent.addSeparator(); Button helpBtn = new Button(AppContext.getMessage(GenericI18Enum.ACTION_HELP)); helpBtn.setIcon(FontAwesome.MORTAR_BOARD); ExternalResource helpRes = new ExternalResource("https://community.mycollab.com/meet-mycollab/"); BrowserWindowOpener helpOpener = new BrowserWindowOpener(helpRes); helpOpener.extend(helpBtn); accountPopupContent.addOption(helpBtn); Button supportBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_SUPPORT)); supportBtn.setIcon(FontAwesome.LIFE_SAVER); ExternalResource supportRes = new ExternalResource("http://support.mycollab.com/"); BrowserWindowOpener supportOpener = new BrowserWindowOpener(supportRes); supportOpener.extend(supportBtn); accountPopupContent.addOption(supportBtn); Button translateBtn = new Button(AppContext.getMessage(GenericI18Enum.ACTION_TRANSLATE)); translateBtn.setIcon(FontAwesome.PENCIL); ExternalResource translateRes = new ExternalResource( "https://community.mycollab.com/docs/developing-mycollab/translating/"); BrowserWindowOpener translateOpener = new BrowserWindowOpener(translateRes); translateOpener.extend(translateBtn); accountPopupContent.addOption(translateBtn); if (!SiteConfiguration.isCommunityEdition()) { Button myAccountBtn = new Button(AppContext.getMessage(AdminI18nEnum.VIEW_BILLING), new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { accountMenu.setPopupVisible(false); EventBusFactory.getInstance() .post(new ShellEvent.GotoUserAccountModule(this, new String[] { "billing" })); } }); myAccountBtn.setIcon(SettingAssetsManager.getAsset(SettingUIConstants.BILLING)); accountPopupContent.addOption(myAccountBtn); } accountPopupContent.addSeparator(); Button aboutBtn = new Button("About MyCollab", new ClickListener() { @Override public void buttonClick(ClickEvent clickEvent) { accountMenu.setPopupVisible(false); Window aboutWindow = ViewManager.getCacheComponent(AbstractAboutWindow.class); UI.getCurrent().addWindow(aboutWindow); } }); aboutBtn.setIcon(FontAwesome.INFO_CIRCLE); accountPopupContent.addOption(aboutBtn); Button releaseNotesBtn = new Button("Release Notes"); ExternalResource releaseNotesRes = new ExternalResource( "https://community.mycollab.com/docs/hosting-mycollab-on-your-own-server/releases/"); BrowserWindowOpener releaseNotesOpener = new BrowserWindowOpener(releaseNotesRes); releaseNotesOpener.extend(releaseNotesBtn); releaseNotesBtn.setIcon(FontAwesome.BULLHORN); accountPopupContent.addOption(releaseNotesBtn); Button signoutBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_SIGNOUT), new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(ClickEvent event) { accountMenu.setPopupVisible(false); EventBusFactory.getInstance().post(new ShellEvent.LogOut(this, null)); } }); signoutBtn.setIcon(FontAwesome.SIGN_OUT); accountPopupContent.addSeparator(); accountPopupContent.addOption(signoutBtn); accountMenu.setContent(accountPopupContent); accountLayout.addComponent(accountMenu); return accountLayout; }
From source file:com.esofthead.mycollab.vaadin.ui.AccountAssetsResolver.java
License:Open Source License
public static Button createAccountLogoImageComponent(String logoId, int size) { Button logo = new Button(); logo.setStyleName(BaseTheme.BUTTON_LINK); logo.setIcon(createLogoResource(logoId, size)); return logo;/*w w w. ja va2 s .c o m*/ }
From source file:com.esofthead.mycollab.vaadin.ui.AccountLogoFactory.java
License:Open Source License
public static Button createAccountLogoImageComponent(String logoId, int size) { Button logo = new Button(); logo.setStyleName(BaseTheme.BUTTON_LINK); logo.setIcon(createLogoResource(logoId, size)); return logo;/*from w w w . j ava2 s . co m*/ }