Java tutorial
/** * This file is part of mycollab-web. * * mycollab-web is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * mycollab-web is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with mycollab-web. If not, see <http://www.gnu.org/licenses/>. */ package com.esofthead.mycollab.module.project.view.settings; import com.esofthead.mycollab.common.i18n.GenericI18Enum; import com.esofthead.mycollab.common.i18n.OptionI18nEnum.StatusI18nEnum; import com.esofthead.mycollab.configuration.SiteConfiguration; import com.esofthead.mycollab.module.project.CurrentProjectVariables; import com.esofthead.mycollab.module.project.ProjectRolePermissionCollections; import com.esofthead.mycollab.module.project.ProjectTypeConstants; import com.esofthead.mycollab.module.project.i18n.VersionI18nEnum; import com.esofthead.mycollab.module.project.ui.ProjectAssetsManager; import com.esofthead.mycollab.module.project.ui.components.AbstractPreviewItemComp; import com.esofthead.mycollab.module.project.ui.components.DateInfoComp; import com.esofthead.mycollab.module.project.ui.components.ProjectActivityComponent; import com.esofthead.mycollab.module.project.ui.components.TagViewComponent; import com.esofthead.mycollab.module.tracker.domain.Version; import com.esofthead.mycollab.module.tracker.service.VersionService; import com.esofthead.mycollab.spring.AppContextUtil; import com.esofthead.mycollab.vaadin.AppContext; import com.esofthead.mycollab.vaadin.events.HasPreviewFormHandlers; import com.esofthead.mycollab.vaadin.mvp.ViewComponent; import com.esofthead.mycollab.vaadin.web.ui.AdvancedPreviewBeanForm; import com.esofthead.mycollab.vaadin.web.ui.ProjectPreviewFormControlsGenerator; import com.esofthead.mycollab.vaadin.web.ui.UIConstants; import com.vaadin.server.FontAwesome; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.ComponentContainer; import com.vaadin.ui.HorizontalLayout; /** * @author MyCollab Ltd. * @since 1.0 */ @ViewComponent public class VersionReadViewImpl extends AbstractPreviewItemComp<Version> implements VersionReadView { private static final long serialVersionUID = 1L; private Button quickActionStatusBtn; private TagViewComponent tagViewComponent; private ProjectActivityComponent activityComponent; private DateInfoComp dateInfoComp; private VersionTimeLogComp versionTimeLogComp; public VersionReadViewImpl() { super(AppContext.getMessage(VersionI18nEnum.DETAIL), ProjectAssetsManager.getAsset(ProjectTypeConstants.BUG_VERSION)); } @Override public HasPreviewFormHandlers<Version> getPreviewFormHandlers() { return this.previewForm; } @Override protected void initRelatedComponents() { activityComponent = new ProjectActivityComponent(ProjectTypeConstants.BUG_VERSION, CurrentProjectVariables.getProjectId()); dateInfoComp = new DateInfoComp(); if (SiteConfiguration.isCommunityEdition()) { addToSideBar(dateInfoComp); } else { versionTimeLogComp = new VersionTimeLogComp(); addToSideBar(dateInfoComp, versionTimeLogComp); } } @Override protected void onPreviewItem() { activityComponent.loadActivities("" + beanItem.getId()); dateInfoComp.displayEntryDateTime(beanItem); if (tagViewComponent != null) { tagViewComponent.display(ProjectTypeConstants.BUG_VERSION, beanItem.getId()); } if (versionTimeLogComp != null) { versionTimeLogComp.displayTime(beanItem); } if (StatusI18nEnum.Open.name().equals(beanItem.getStatus())) { removeLayoutStyleName(UIConstants.LINK_COMPLETED); quickActionStatusBtn.setCaption(AppContext.getMessage(GenericI18Enum.BUTTON_CLOSE)); quickActionStatusBtn.setIcon(FontAwesome.ARCHIVE); } else { addLayoutStyleName(UIConstants.LINK_COMPLETED); quickActionStatusBtn.setCaption(AppContext.getMessage(GenericI18Enum.BUTTON_REOPEN)); quickActionStatusBtn.setIcon(FontAwesome.CLIPBOARD); } } @Override protected ComponentContainer createExtraControls() { if (SiteConfiguration.isCommunityEdition()) { return null; } else { tagViewComponent = new TagViewComponent(); return tagViewComponent; } } @Override protected String initFormTitle() { return beanItem.getVersionname(); } @Override protected AdvancedPreviewBeanForm<Version> initPreviewForm() { return new VersionPreviewForm(); } @Override protected ComponentContainer createButtonControls() { ProjectPreviewFormControlsGenerator<Version> versionPreviewForm = new ProjectPreviewFormControlsGenerator<>( previewForm); HorizontalLayout topPanel = versionPreviewForm .createButtonControls(ProjectRolePermissionCollections.VERSIONS); quickActionStatusBtn = new Button("", new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(ClickEvent event) { if (StatusI18nEnum.Closed.name().equals(beanItem.getStatus())) { beanItem.setStatus(StatusI18nEnum.Open.name()); VersionReadViewImpl.this.removeLayoutStyleName(UIConstants.LINK_COMPLETED); quickActionStatusBtn.setCaption(AppContext.getMessage(GenericI18Enum.BUTTON_CLOSE)); quickActionStatusBtn.setIcon(FontAwesome.ARCHIVE); } else { beanItem.setStatus(StatusI18nEnum.Closed.name()); VersionReadViewImpl.this.addLayoutStyleName(UIConstants.LINK_COMPLETED); quickActionStatusBtn.setCaption(AppContext.getMessage(GenericI18Enum.BUTTON_REOPEN)); quickActionStatusBtn.setIcon(FontAwesome.CLIPBOARD); } VersionService service = AppContextUtil.getSpringBean(VersionService.class); service.updateSelectiveWithSession(beanItem, AppContext.getUsername()); } }); quickActionStatusBtn.setStyleName(UIConstants.BUTTON_ACTION); versionPreviewForm.insertToControlBlock(quickActionStatusBtn); if (!CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.VERSIONS)) { quickActionStatusBtn.setEnabled(false); } return topPanel; } @Override protected ComponentContainer createBottomPanel() { return activityComponent; } @Override public Version getItem() { return beanItem; } @Override protected String getType() { return ProjectTypeConstants.BUG_VERSION; } }