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.bug.components; import java.util.List; import com.esofthead.mycollab.common.domain.GroupItem; import com.esofthead.mycollab.core.arguments.SearchField; import com.esofthead.mycollab.core.arguments.SetSearchField; import com.esofthead.mycollab.module.project.i18n.BugI18nEnum; import com.esofthead.mycollab.module.project.i18n.OptionI18nEnum; import com.esofthead.mycollab.module.project.i18n.OptionI18nEnum.BugPriority; import com.esofthead.mycollab.module.project.view.bug.IBugReportDisplayContainer; import com.esofthead.mycollab.module.tracker.domain.criteria.BugSearchCriteria; import com.esofthead.mycollab.module.tracker.service.BugService; import com.esofthead.mycollab.spring.ApplicationContextUtil; import com.esofthead.mycollab.vaadin.AppContext; import com.esofthead.mycollab.vaadin.ui.ButtonI18nComp; import com.esofthead.mycollab.vaadin.ui.Depot; import com.esofthead.mycollab.vaadin.ui.ProgressBarIndicator; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.VerticalLayout; /** * * @author MyCollab Ltd. * @since 1.0 */ public class UnresolvedBugsByPriorityWidget extends Depot { private static final long serialVersionUID = 1L; private final IBugReportDisplayContainer componentLayout; private BugSearchCriteria bugSearchCriteria; public UnresolvedBugsByPriorityWidget(final IBugReportDisplayContainer componentLayout) { super(AppContext.getMessage(BugI18nEnum.WIDGET_UNRESOLVED_BY_PRIORITY_TITLE), new VerticalLayout()); this.componentLayout = componentLayout; this.setContentBorder(true); ((VerticalLayout) this.bodyContent).setSpacing(true); ((VerticalLayout) this.bodyContent).setMargin(true); } public void setSearchCriteria(final BugSearchCriteria searchCriteria) { this.bugSearchCriteria = searchCriteria; this.bodyContent.removeAllComponents(); final BugService bugService = ApplicationContextUtil.getSpringBean(BugService.class); final int totalCount = bugService.getTotalCount(searchCriteria); final List<GroupItem> groupItems = bugService.getPrioritySummary(searchCriteria); final BugPriorityClickListener listener = new BugPriorityClickListener(); if (!groupItems.isEmpty()) { for (final BugPriority priority : OptionI18nEnum.bug_priorities) { boolean isFound = false; for (final GroupItem item : groupItems) { if (priority.name().equals(item.getGroupid())) { isFound = true; final HorizontalLayout priorityLayout = new HorizontalLayout(); priorityLayout.setSpacing(true); priorityLayout.setWidth("100%"); final ButtonI18nComp priorityLink = new ButtonI18nComp(priority.name(), priority, listener); priorityLink.setWidth("110px"); priorityLink.setStyleName("link"); priorityLayout.addComponent(priorityLink); final ProgressBarIndicator indicator = new ProgressBarIndicator(totalCount, totalCount - item.getValue(), false); indicator.setWidth("100%"); priorityLayout.addComponent(indicator); priorityLayout.setExpandRatio(indicator, 1.0f); this.bodyContent.addComponent(priorityLayout); continue; } } if (!isFound) { final HorizontalLayout priorityLayout = new HorizontalLayout(); priorityLayout.setSpacing(true); priorityLayout.setWidth("100%"); final ButtonI18nComp priorityLink = new ButtonI18nComp(priority.name(), priority, listener); priorityLink.setWidth("110px"); priorityLink.setStyleName("link"); priorityLayout.addComponent(priorityLink); final ProgressBarIndicator indicator = new ProgressBarIndicator(totalCount, totalCount, false); indicator.setWidth("100%"); priorityLayout.addComponent(indicator); priorityLayout.setExpandRatio(indicator, 1.0f); this.bodyContent.addComponent(priorityLayout); } } } } class BugPriorityClickListener implements Button.ClickListener { private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { final String key = ((ButtonI18nComp) event.getButton()).getKey(); UnresolvedBugsByPriorityWidget.this.bugSearchCriteria .setPriorities(new SetSearchField<String>(SearchField.AND, new String[] { key })); UnresolvedBugsByPriorityWidget.this.componentLayout.displayBugListWidget(key, UnresolvedBugsByPriorityWidget.this.bugSearchCriteria); } } }