List of usage examples for com.vaadin.ui CssLayout CssLayout
public CssLayout()
From source file:com.esofthead.mycollab.module.project.view.TimeTrackingSummaryViewImpl.java
License:Open Source License
@Override public void display() { projects = ApplicationContextUtil.getSpringBean(ProjectService.class) .getProjectsUserInvolved(AppContext.getUsername(), AppContext.getAccountId()); if (CollectionUtils.isNotEmpty(projects)) { itemTimeLoggingService = ApplicationContextUtil.getSpringBean(ItemTimeLoggingService.class); final CssLayout headerWrapper = new CssLayout(); headerWrapper.setWidth("100%"); headerWrapper.setStyleName("projectfeed-hdr-wrapper"); HorizontalLayout loggingPanel = new HorizontalLayout(); HorizontalLayout controlBtns = new HorizontalLayout(); controlBtns.setMargin(new MarginInfo(true, false, true, false)); final Label layoutHeader = new Label( ProjectAssetsManager.getAsset(ProjectTypeConstants.TIME).getHtml() + " Time Tracking", ContentMode.HTML); layoutHeader.addStyleName("h2"); final MHorizontalLayout header = new MHorizontalLayout().withWidth("100%"); header.with(layoutHeader).withAlign(layoutHeader, Alignment.MIDDLE_LEFT).expand(layoutHeader); final CssLayout contentWrapper = new CssLayout(); contentWrapper.setWidth("100%"); contentWrapper.addStyleName(UIConstants.CONTENT_WRAPPER); headerWrapper.addComponent(header); this.addComponent(headerWrapper); contentWrapper.addComponent(controlBtns); MHorizontalLayout controlsPanel = new MHorizontalLayout().withWidth("100%"); contentWrapper.addComponent(controlsPanel); contentWrapper.addComponent(loggingPanel); this.addComponent(contentWrapper); final Button backBtn = new Button("Back to Workboard"); backBtn.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override/*from w w w . j a v a 2s .c om*/ public void buttonClick(final ClickEvent event) { EventBusFactory.getInstance() .post(new ShellEvent.GotoProjectModule(TimeTrackingSummaryViewImpl.this, null)); } }); backBtn.addStyleName(UIConstants.THEME_GREEN_LINK); backBtn.setIcon(FontAwesome.ARROW_LEFT); controlBtns.addComponent(backBtn); VerticalLayout selectionLayoutWrapper = new VerticalLayout(); selectionLayoutWrapper.setWidth("100%"); selectionLayoutWrapper.addStyleName("time-tracking-summary-search-panel"); controlsPanel.addComponent(selectionLayoutWrapper); final GridLayout selectionLayout = new GridLayout(9, 2); selectionLayout.setSpacing(true); selectionLayout.setDefaultComponentAlignment(Alignment.TOP_RIGHT); selectionLayout.setMargin(true); selectionLayoutWrapper.addComponent(selectionLayout); Label fromLb = new Label("From:"); fromLb.setWidthUndefined(); selectionLayout.addComponent(fromLb, 0, 0); this.fromDateField = new PopupDateFieldExt(); this.fromDateField.setResolution(Resolution.DAY); this.fromDateField.setDateFormat(AppContext.getUserDateFormat()); this.fromDateField.setWidth("100px"); selectionLayout.addComponent(this.fromDateField, 1, 0); Label toLb = new Label("To:"); toLb.setWidthUndefined(); selectionLayout.addComponent(toLb, 2, 0); this.toDateField = new PopupDateFieldExt(); this.toDateField.setResolution(Resolution.DAY); this.toDateField.setDateFormat(AppContext.getUserDateFormat()); this.toDateField.setWidth("100px"); selectionLayout.addComponent(this.toDateField, 3, 0); Label groupLb = new Label("Group:"); groupLb.setWidthUndefined(); selectionLayout.addComponent(groupLb, 0, 1); this.groupField = new ValueComboBox(false, GROUPBY_PROJECT, GROUPBY_DATE, GROUPBY_USER); this.groupField.setWidth("100px"); selectionLayout.addComponent(this.groupField, 1, 1); Label sortLb = new Label("Sort:"); sortLb.setWidthUndefined(); selectionLayout.addComponent(sortLb, 2, 1); this.orderField = new ItemOrderComboBox(); this.orderField.setWidth("100px"); selectionLayout.addComponent(this.orderField, 3, 1); Label projectLb = new Label("Project:"); projectLb.setWidthUndefined(); selectionLayout.addComponent(projectLb, 4, 0); this.projectField = new UserInvolvedProjectsListSelect(); initListSelectStyle(this.projectField); selectionLayout.addComponent(this.projectField, 5, 0, 5, 1); Label userLb = new Label("User:"); userLb.setWidthUndefined(); selectionLayout.addComponent(userLb, 6, 0); this.userField = new UserInvolvedProjectsMemberListSelect(getProjectIds()); initListSelectStyle(this.userField); selectionLayout.addComponent(this.userField, 7, 0, 7, 1); final Button queryBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_SUBMIT), new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { fromDate = fromDateField.getValue(); toDate = toDateField.getValue(); searchCriteria.setRangeDate(new RangeDateSearchField(fromDate, toDate)); searchTimeReporting(); } }); queryBtn.setStyleName(UIConstants.THEME_GREEN_LINK); selectionLayout.addComponent(queryBtn, 8, 0); loggingPanel.setWidth("100%"); loggingPanel.setHeight("80px"); loggingPanel.setSpacing(true); totalHoursLoggingLabel = new Label("Total Hours Logging: 0 Hrs", ContentMode.HTML); totalHoursLoggingLabel.addStyleName(UIConstants.LAYOUT_LOG); totalHoursLoggingLabel.addStyleName(UIConstants.TEXT_LOG_DATE_FULL); loggingPanel.addComponent(totalHoursLoggingLabel); loggingPanel.setExpandRatio(totalHoursLoggingLabel, 1.0f); loggingPanel.setComponentAlignment(totalHoursLoggingLabel, Alignment.MIDDLE_LEFT); Button exportBtn = new Button("Export", new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(ClickEvent event) { exportButtonControl.setPopupVisible(true); } }); exportButtonControl = new SplitButton(exportBtn); exportButtonControl.setWidthUndefined(); exportButtonControl.addStyleName(UIConstants.THEME_GRAY_LINK); exportButtonControl.setIcon(FontAwesome.EXTERNAL_LINK); VerticalLayout popupButtonsControl = new VerticalLayout(); exportButtonControl.setContent(popupButtonsControl); Button exportPdfBtn = new Button("Pdf"); FileDownloader pdfDownloader = new FileDownloader(constructStreamResource(ReportExportType.PDF)); pdfDownloader.extend(exportPdfBtn); exportPdfBtn.setIcon(FontAwesome.FILE_PDF_O); exportPdfBtn.setStyleName("link"); popupButtonsControl.addComponent(exportPdfBtn); Button exportExcelBtn = new Button("Excel"); FileDownloader excelDownloader = new FileDownloader(constructStreamResource(ReportExportType.EXCEL)); excelDownloader.extend(exportExcelBtn); exportExcelBtn.setIcon(FontAwesome.FILE_EXCEL_O); exportExcelBtn.setStyleName("link"); popupButtonsControl.addComponent(exportExcelBtn); controlBtns.addComponent(exportButtonControl); controlBtns.setComponentAlignment(exportButtonControl, Alignment.TOP_RIGHT); controlBtns.setComponentAlignment(backBtn, Alignment.TOP_LEFT); controlBtns.setSizeFull(); this.timeTrackingWrapper = new VerticalLayout(); this.timeTrackingWrapper.setWidth("100%"); contentWrapper.addComponent(this.timeTrackingWrapper); Calendar date = new GregorianCalendar(); date.set(Calendar.DAY_OF_MONTH, 1); fromDate = date.getTime(); date.add(Calendar.DAY_OF_MONTH, date.getActualMaximum(Calendar.DAY_OF_MONTH)); toDate = date.getTime(); fromDateField.setValue(fromDate); toDateField.setValue(toDate); searchCriteria = new ItemTimeLoggingSearchCriteria(); searchCriteria.setRangeDate(new RangeDateSearchField(fromDate, toDate)); } else { final Button backBtn = new Button("Back to Workboard"); backBtn.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { EventBusFactory.getInstance() .post(new ShellEvent.GotoProjectModule(TimeTrackingSummaryViewImpl.this, null)); } }); backBtn.addStyleName(UIConstants.THEME_GREEN_LINK); backBtn.setIcon(FontAwesome.ARROW_LEFT); VerticalLayout contentWrapper = new VerticalLayout(); contentWrapper.setSpacing(true); Label infoLbl = new Label("You are not involved in any project yet to track time working"); infoLbl.setWidthUndefined(); contentWrapper.setMargin(true); contentWrapper.addComponent(infoLbl); contentWrapper.setComponentAlignment(infoLbl, Alignment.MIDDLE_CENTER); contentWrapper.addComponent(backBtn); contentWrapper.setComponentAlignment(backBtn, Alignment.MIDDLE_CENTER); this.addComponent(contentWrapper); this.setComponentAlignment(contentWrapper, Alignment.MIDDLE_CENTER); } }
From source file:com.esofthead.mycollab.module.project.view.user.ProjectActivityStreamPagedList.java
License:Open Source License
@Override public void doSearch() { this.totalCount = this.projectActivityStreamService .getTotalActivityStream(this.searchRequest.getSearchCriteria()); this.totalPage = (this.totalCount - 1) / this.searchRequest.getNumberOfItems() + 1; if (this.searchRequest.getCurrentPage() > this.totalPage) { this.searchRequest.setCurrentPage(this.totalPage); }//from www . j a va2 s.co m if (totalPage > 1) { if (this.controlBarWrapper != null) { this.removeComponent(this.controlBarWrapper); } this.addComponent(this.createPageControls()); } else { if (getComponentCount() == 2) { removeComponent(getComponent(1)); } } final List<ProjectActivityStream> currentListData = this.projectActivityStreamService .getProjectActivityStreams(this.searchRequest); this.listContainer.removeAllComponents(); Date currentDate = new GregorianCalendar(2100, 1, 1).getTime(); CssLayout currentFeedBlock = new CssLayout(); try { for (final ProjectActivityStream activityStream : currentListData) { if (ProjectTypeConstants.PAGE.equals(activityStream.getType())) { ProjectPageService pageService = ApplicationContextUtil.getSpringBean(ProjectPageService.class); Page page = pageService.getPage(activityStream.getTypeid(), AppContext.getUsername()); if (page != null) { activityStream.setNamefield(page.getSubject()); } } final Date itemCreatedDate = activityStream.getCreatedtime(); if (!DateUtils.isSameDay(currentDate, itemCreatedDate)) { currentFeedBlock = new CssLayout(); currentFeedBlock.setStyleName("feed-block"); feedBlocksPut(currentDate, itemCreatedDate, currentFeedBlock); currentDate = itemCreatedDate; } StringBuffer content = new StringBuffer(); String itemType = AppContext .getMessage(ProjectLocalizationTypeMap.getType(activityStream.getType())); String assigneeParam = buildAssigneeValue(activityStream); String itemParam = buildItemValue(activityStream); if (ActivityStreamConstants.ACTION_CREATE.equals(activityStream.getAction())) { content.append( AppContext.getMessage(ProjectCommonI18nEnum.FEED_USER_ACTIVITY_CREATE_ACTION_TITLE, assigneeParam, itemType, itemParam)); } else if (ActivityStreamConstants.ACTION_UPDATE.equals(activityStream.getAction())) { content.append( AppContext.getMessage(ProjectCommonI18nEnum.FEED_USER_ACTIVITY_UPDATE_ACTION_TITLE, assigneeParam, itemType, itemParam)); if (activityStream.getAssoAuditLog() != null) { content.append( ProjectAuditLogStreamGenerator.generatorDetailChangeOfActivity(activityStream)); } } else if (ActivityStreamConstants.ACTION_COMMENT.equals(activityStream.getAction())) { content.append( AppContext.getMessage(ProjectCommonI18nEnum.FEED_USER_ACTIVITY_COMMENT_ACTION_TITLE, assigneeParam, itemType, itemParam)); if (activityStream.getAssoAuditLog() != null) { content.append("<p><ul><li>\"").append(activityStream.getAssoAuditLog().getChangeset()) .append("\"</li></ul></p>"); } } final Label actionLbl = new Label(content.toString(), ContentMode.HTML); final CssLayout streamWrapper = new CssLayout(); streamWrapper.setWidth("100%"); streamWrapper.addStyleName("stream-wrapper"); streamWrapper.addComponent(actionLbl); currentFeedBlock.addComponent(streamWrapper); } } catch (final Exception e) { throw new MyCollabException(e); } }
From source file:com.esofthead.mycollab.module.project.view.user.ProjectActivityStreamPagedList.java
License:Open Source License
@Override protected CssLayout createPageControls() { this.controlBarWrapper = new CssLayout(); this.controlBarWrapper.setWidth("100%"); this.controlBarWrapper.setStyleName("page-controls"); ButtonGroup controlBtns = new ButtonGroup(); controlBtns.setStyleName(UIConstants.THEME_GREEN_LINK); Button prevBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_NAV_NEWER), new Button.ClickListener() { private static final long serialVersionUID = -94021599166105307L; @Override//from w w w. java2 s . c om public void buttonClick(ClickEvent event) { ProjectActivityStreamPagedList.this .pageChange(ProjectActivityStreamPagedList.this.currentPage - 1); } }); if (currentPage == 1) { prevBtn.setEnabled(false); } prevBtn.setStyleName(UIConstants.THEME_GREEN_LINK); prevBtn.setWidth("64px"); Button nextBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_NAV_OLDER), new Button.ClickListener() { private static final long serialVersionUID = 3095522916508256018L; @Override public void buttonClick(ClickEvent event) { ProjectActivityStreamPagedList.this .pageChange(ProjectActivityStreamPagedList.this.currentPage + 1); } }); if (currentPage == totalPage) { nextBtn.setEnabled(false); } nextBtn.setStyleName(UIConstants.THEME_GREEN_LINK); nextBtn.setWidth("64px"); controlBtns.addButton(prevBtn); controlBtns.addButton(nextBtn); this.controlBarWrapper.addComponent(controlBtns); return this.controlBarWrapper; }
From source file:com.esofthead.mycollab.module.project.view.user.ProjectOverdueAssignmentsWidget.java
License:Open Source License
public ProjectOverdueAssignmentsWidget() { super(AppContext.getMessage(ProjectCommonI18nEnum.WIDGET_OVERDUE_ASSIGNMENTS_TITLE, 0), new CssLayout()); this.setWidth("100%"); final CheckBox myItemsSelection = new CheckBox(AppContext.getMessage(GenericI18Enum.OPT_MY_ITEMS)); myItemsSelection.addValueChangeListener(new Property.ValueChangeListener() { @Override// w w w . jav a 2 s. c om public void valueChange(Property.ValueChangeEvent valueChangeEvent) { boolean isMyItemsOption = myItemsSelection.getValue(); if (isMyItemsOption) { searchCriteria.setAssignUser(StringSearchField.and(AppContext.getUsername())); } else { searchCriteria.setAssignUser(null); } updateSearchResult(); } }); taskList = new DefaultBeanPagedList(AppContextUtil.getSpringBean(ProjectGenericTaskService.class), new GenericTaskRowDisplayHandler(), 10) { @Override protected String stringWhenEmptyList() { return AppContext.getMessage(ProjectI18nEnum.OPT_NO_OVERDUE_ASSIGNMENT); } }; this.addHeaderElement(myItemsSelection); bodyContent.addComponent(taskList); }
From source file:com.esofthead.mycollab.module.project.view.user.ProjectSummaryViewImpl.java
License:Open Source License
@Override protected void displayView() { withMargin(new MarginInfo(true, false, false, false)); CssLayout contentWrapper = new CssLayout(); contentWrapper.setStyleName("content-wrapper"); contentWrapper.setWidth("100%"); this.addComponent(contentWrapper); ProjectInformationComponent prjView = new ProjectInformationComponent(); contentWrapper.addComponent(prjView); final MHorizontalLayout layout = new MHorizontalLayout().withWidth("100%"); contentWrapper.addComponent(layout); final VerticalLayout leftPanel = new VerticalLayout(); ProjectActivityStreamComponent activityPanel = new ProjectActivityStreamComponent(); leftPanel.addComponent(activityPanel); layout.addComponent(leftPanel);// w w w . j a va2s.co m final MVerticalLayout rightPanel = new MVerticalLayout() .withMargin(new MarginInfo(false, false, false, true)); layout.addComponent(rightPanel); ProjectMessageListComponent messageWidget = new ProjectMessageListComponent(); ProjectMembersWidget membersWidget = new ProjectMembersWidget(); ProjectAssignmentsWidget taskOverdueWidget = new ProjectAssignmentsWidget(); rightPanel.with(messageWidget, membersWidget, taskOverdueWidget); activityPanel.showProjectFeeds(); prjView.displayProjectInformation(); membersWidget.showInformation(); taskOverdueWidget.showOpenAssignments(); messageWidget.showLatestMessages(); }
From source file:com.esofthead.mycollab.module.project.view.user.ProjectUnresolvedAssignmentWidget.java
License:Open Source License
public ProjectUnresolvedAssignmentWidget() { super("", new CssLayout()); this.setWidth("100%"); final CheckBox myItemsSelection = new CheckBox(AppContext.getMessage(GenericI18Enum.OPT_MY_ITEMS)); myItemsSelection.addValueChangeListener(new Property.ValueChangeListener() { @Override//from ww w. ja v a 2 s .com public void valueChange(Property.ValueChangeEvent valueChangeEvent) { boolean isMyItemsOption = myItemsSelection.getValue(); if (isMyItemsOption) { searchCriteria.setAssignUser(StringSearchField.and(AppContext.getUsername())); } else { searchCriteria.setAssignUser(null); } updateSearchResult(); } }); taskList = new DefaultBeanPagedList(AppContextUtil.getSpringBean(ProjectGenericTaskService.class), new GenericTaskRowDisplayHandler(), 10) { @Override protected String stringWhenEmptyList() { return AppContext.getMessage(ProjectI18nEnum.OPT_NO_ASSIGNMENT); } }; addHeaderElement(myItemsSelection); bodyContent.addComponent(taskList); }
From source file:com.esofthead.mycollab.module.project.view.user.UserUnresolvedAssignmentWidget.java
License:Open Source License
public UserUnresolvedAssignmentWidget() { super("", new CssLayout()); this.setWidth("100%"); final CheckBox myItemsSelection = new CheckBox(AppContext.getMessage(GenericI18Enum.OPT_MY_ITEMS)); myItemsSelection.addValueChangeListener(new Property.ValueChangeListener() { @Override/*from www . j a v a 2 s .c o m*/ public void valueChange(Property.ValueChangeEvent valueChangeEvent) { boolean isMyItemsOption = myItemsSelection.getValue(); if (searchCriteria != null) { if (isMyItemsOption) { searchCriteria.setAssignUser(StringSearchField.and(AppContext.getUsername())); } else { searchCriteria.setAssignUser(null); } updateSearchResult(); } } }); taskList = new DefaultBeanPagedList(AppContextUtil.getSpringBean(ProjectGenericTaskService.class), new GenericTaskRowDisplayHandler(), 10) { @Override protected String stringWhenEmptyList() { return AppContext.getMessage(ProjectI18nEnum.OPT_NO_ASSIGNMENT); } }; this.addHeaderElement(myItemsSelection); this.bodyContent.addComponent(taskList); }
From source file:com.esofthead.mycollab.module.project.view.UserDashboardViewImpl.java
License:Open Source License
@Override protected void displayView() { this.removeAllComponents(); this.withMargin(false).withWidth("100%"); final CssLayout headerWrapper = new CssLayout(); headerWrapper.setWidth("100%"); headerWrapper.setStyleName("projectfeed-hdr-wrapper"); final MHorizontalLayout header = new MHorizontalLayout().withMargin(false).withWidth("100%"); header.addStyleName("projectfeed-hdr"); Button avatar = UserAvatarControlFactory.createUserAvatarEmbeddedButton(AppContext.getUserAvatarId(), 64); avatar.addClickListener(new ClickListener() { private static final long serialVersionUID = 1L; @Override//from www.j ava 2s. c o m public void buttonClick(final ClickEvent event) { String userFullLinkStr = AccountLinkGenerator.generatePreviewFullUserLink(AppContext.getSiteUrl(), AppContext.getUsername()); getUI().getPage().open(userFullLinkStr, null); } }); header.addComponent(avatar); final MVerticalLayout headerContent = new MVerticalLayout() .withMargin(new MarginInfo(false, false, false, true)); headerContent.addStyleName("projectfeed-hdr-content"); final Label headerLabel = new Label(AppContext.getSession().getDisplayName()); headerLabel.setStyleName(Reindeer.LABEL_H1); final MHorizontalLayout headerContentTop = new MHorizontalLayout() .withMargin(new MarginInfo(false, false, true, false)); headerContentTop.with(headerLabel).withAlign(headerLabel, Alignment.TOP_LEFT); if (AppContext.canBeYes(RolePermissionCollections.CREATE_NEW_PROJECT)) { final Button createProjectBtn = new Button( AppContext.getMessage(ProjectCommonI18nEnum.BUTTON_NEW_PROJECT), new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(final Button.ClickEvent event) { final ProjectAddWindow projectNewWindow = new ProjectAddWindow(); UI.getCurrent().addWindow(projectNewWindow); } }); createProjectBtn.setIcon(FontAwesome.PLUS); createProjectBtn.setStyleName(UIConstants.THEME_GREEN_LINK); headerContentTop.addComponent(createProjectBtn); headerContentTop.setComponentAlignment(createProjectBtn, Alignment.MIDDLE_LEFT); } followingTicketsLink = new LabelLink(AppContext.getMessage(FollowerI18nEnum.OPT_MY_FOLLOWING_TICKETS, 0), AppContext.getSiteUrl() + "#project/following"); followingTicketsLink.setIconLink(FontAwesome.EYE); LabelLink timeTrackingLink = new LabelLink(AppContext.getMessage(TimeTrackingI18nEnum.TIME_RECORD_HEADER), AppContext.getSiteUrl() + "#project/timetracking"); timeTrackingLink.setIconLink(ProjectAssetsManager.getAsset(ProjectTypeConstants.TIME)); final MHorizontalLayout headerContentBottom = new MHorizontalLayout().withMargin(false) .with(followingTicketsLink, timeTrackingLink); headerContent.with(headerContentTop, headerContentBottom); header.with(headerContent).expand(headerContent); headerWrapper.addComponent(header); this.addComponent(headerWrapper); final MHorizontalLayout layout = new MHorizontalLayout() .withMargin(new MarginInfo(false, false, true, false)).withWidth("100%"); ActivityStreamComponent activityStreamComponent = new ActivityStreamComponent(); final MVerticalLayout leftPanel = new MVerticalLayout().withSpacing(false) .withMargin(new MarginInfo(false, true, false, false)).withWidth("100%") .with(activityStreamComponent); final MVerticalLayout rightPanel = new MVerticalLayout().withMargin(false).withWidth("565px"); MyProjectListComponent myProjectListComponent = new MyProjectListComponent(); TaskStatusComponent taskStatusComponent = new TaskStatusComponent(); rightPanel.with(myProjectListComponent, taskStatusComponent); layout.with(leftPanel, rightPanel).expand(leftPanel); final CssLayout contentWrapper = new CssLayout(); contentWrapper.setWidth("100%"); contentWrapper.addStyleName("content-wrapper"); this.addComponent(contentWrapper); contentWrapper.addComponent(layout); final ProjectService prjService = ApplicationContextUtil.getSpringBean(ProjectService.class); prjKeys = prjService.getProjectKeysUserInvolved(AppContext.getUsername(), AppContext.getAccountId()); if (CollectionUtils.isNotEmpty(prjKeys)) { activityStreamComponent.showFeeds(prjKeys); myProjectListComponent.displayDefaultProjectsList(); displayFollowingTicketsCount(); } taskStatusComponent.showProjectTasksByStatus(prjKeys); }
From source file:com.esofthead.mycollab.module.user.accountsettings.customize.view.LogoEditWindow.java
License:Open Source License
private void editPhoto(byte[] imageData) { try {//from www . j av a 2s . c om 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 = AppContext.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)); Label lbPreview = new Label( "<p style='margin: 0px;'><strong>To the below is what your logo 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 <strong>Accept</strong> button.</p>", ContentMode.HTML); previewBoxRight.addComponent(lbPreview); MHorizontalLayout controlBtns = new MHorizontalLayout(); controlBtns.setSizeUndefined(); controlBtns.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT); Button cancelBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CANCEL), new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { EventBusFactory.getInstance() .post(new SettingEvent.GotoGeneralSetting(LogoEditWindow.this, null)); } }); cancelBtn.setStyleName(UIConstants.BUTTON_OPTION); controlBtns.with(cancelBtn); 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)); AccountLogoService accountLogoService = AppContextUtil .getSpringBean(AccountLogoService.class); accountLogoService.upload(AppContext.getUsername(), image, AppContext.getAccountId()); Page.getCurrent().getJavaScript().execute("window.location.reload();"); } catch (IOException e) { throw new MyCollabException("Error when saving account logo", e); } } } }); acceptBtn.setStyleName(UIConstants.BUTTON_ACTION); controlBtns.with(acceptBtn); 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(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); content.with(previewBox, ELabel.hr(), cropBox); }
From source file:com.esofthead.mycollab.module.user.accountsettings.profile.view.ProfilePhotoUploadViewImpl.java
License:Open Source License
@SuppressWarnings("serial") @Override//from ww w. j a va2s. co m 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); }