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.mycollab.module.project.view.settings; import com.mycollab.common.TableViewField; import com.mycollab.common.i18n.GenericI18Enum; import com.mycollab.module.project.CurrentProjectVariables; import com.mycollab.module.project.ProjectLinkBuilder; import com.mycollab.module.project.ProjectRolePermissionCollections; import com.mycollab.module.project.domain.ProjectRole; import com.mycollab.module.project.domain.SimpleProjectRole; import com.mycollab.module.project.domain.criteria.ProjectRoleSearchCriteria; import com.mycollab.module.project.service.ProjectRoleService; import com.mycollab.spring.AppContextUtil; import com.mycollab.vaadin.UserUIContext; import com.mycollab.vaadin.events.HasMassItemActionHandler; import com.mycollab.vaadin.events.HasSearchHandlers; import com.mycollab.vaadin.events.HasSelectableItemHandlers; import com.mycollab.vaadin.events.HasSelectionOptionHandlers; import com.mycollab.vaadin.mvp.AbstractVerticalPageView; import com.mycollab.vaadin.mvp.ViewComponent; import com.mycollab.vaadin.ui.DefaultMassItemActionHandlerContainer; import com.mycollab.vaadin.web.ui.*; import com.mycollab.vaadin.web.ui.table.AbstractPagedBeanTable; import com.mycollab.vaadin.web.ui.table.DefaultPagedBeanTable; import com.vaadin.shared.ui.MarginInfo; import com.vaadin.ui.*; import org.vaadin.viritin.layouts.MHorizontalLayout; import java.util.Arrays; /** * @author MyCollab Ltd. * @since 1.0 */ @ViewComponent public class ProjectRoleListViewImpl extends AbstractVerticalPageView implements ProjectRoleListView { private static final long serialVersionUID = 1L; private ProjectRoleSearchPanel searchPanel; private SelectionOptionButton selectOptionButton; private DefaultPagedBeanTable<ProjectRoleService, ProjectRoleSearchCriteria, SimpleProjectRole> tableItem; private VerticalLayout listLayout; private DefaultMassItemActionHandlerContainer tableActionControls; private Label selectedItemsNumberLabel = new Label(); public ProjectRoleListViewImpl() { this.setMargin(new MarginInfo(false, true, true, true)); searchPanel = new ProjectRoleSearchPanel(); listLayout = new VerticalLayout(); with(searchPanel, listLayout); this.generateDisplayTable(); } private void generateDisplayTable() { tableItem = new DefaultPagedBeanTable<>(AppContextUtil.getSpringBean(ProjectRoleService.class), SimpleProjectRole.class, new TableViewField(null, "selected", WebUIConstants.TABLE_CONTROL_WIDTH), Arrays.asList( new TableViewField(GenericI18Enum.FORM_NAME, "rolename", WebUIConstants.TABLE_EX_LABEL_WIDTH), new TableViewField(GenericI18Enum.FORM_DESCRIPTION, "description", WebUIConstants.TABLE_EX_LABEL_WIDTH))); tableItem.addGeneratedColumn("selected", (source, itemId, columnId) -> { final SimpleProjectRole role = tableItem.getBeanByIndex(itemId); CheckBoxDecor cb = new CheckBoxDecor("", role.isSelected()); cb.setImmediate(true); cb.addValueChangeListener(valueChangeEvent -> tableItem.fireSelectItemEvent(role)); role.setExtraData(cb); return cb; }); tableItem.addGeneratedColumn("rolename", (source, itemId, columnId) -> { ProjectRole role = tableItem.getBeanByIndex(itemId); return new LabelLink(role.getRolename(), ProjectLinkBuilder.generateRolePreviewFullLink(role.getProjectid(), role.getId())); }); listLayout.addComponent(this.constructTableActionControls()); listLayout.addComponent(this.tableItem); } @Override public void showNoItemView() { } @Override public HasSearchHandlers<ProjectRoleSearchCriteria> getSearchHandlers() { return this.searchPanel; } private ComponentContainer constructTableActionControls() { CssLayout layoutWrapper = new CssLayout(); layoutWrapper.setWidth("100%"); MHorizontalLayout layout = new MHorizontalLayout(); layoutWrapper.addStyleName(WebThemes.TABLE_ACTION_CONTROLS); layoutWrapper.addComponent(layout); selectOptionButton = new SelectionOptionButton(this.tableItem); layout.addComponent(this.selectOptionButton); tableActionControls = new DefaultMassItemActionHandlerContainer(); if (CurrentProjectVariables.canAccess(ProjectRolePermissionCollections.ROLES)) { tableActionControls.addDeleteActionItem(); } tableActionControls.addDownloadPdfActionItem(); tableActionControls.addDownloadExcelActionItem(); tableActionControls.addDownloadCsvActionItem(); layout.with(this.tableActionControls, this.selectedItemsNumberLabel).withAlign(selectedItemsNumberLabel, Alignment.MIDDLE_LEFT); return layoutWrapper; } @Override public void enableActionControls(int numOfSelectedItems) { tableActionControls.setVisible(true); selectedItemsNumberLabel .setValue(UserUIContext.getMessage(GenericI18Enum.TABLE_SELECTED_ITEM_TITLE, numOfSelectedItems)); } @Override public void disableActionControls() { tableActionControls.setVisible(false); selectOptionButton.setSelectedCheckbox(false); selectedItemsNumberLabel.setValue(""); } @Override public HasSelectionOptionHandlers getOptionSelectionHandlers() { return this.selectOptionButton; } @Override public HasMassItemActionHandler getPopupActionHandlers() { return this.tableActionControls; } @Override public HasSelectableItemHandlers<SimpleProjectRole> getSelectableItemHandlers() { return this.tableItem; } @Override public AbstractPagedBeanTable<ProjectRoleSearchCriteria, SimpleProjectRole> getPagedBeanTable() { return this.tableItem; } }