org.ikasan.dashboard.ui.administration.component.SelectGroupDialog Maven / Gradle / Ivy
package org.ikasan.dashboard.ui.administration.component;
import com.vaadin.flow.component.ComponentEventListener;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.grid.HeaderRow;
import com.vaadin.flow.component.grid.ItemDoubleClickEvent;
import com.vaadin.flow.component.html.H3;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import org.ikasan.dashboard.ui.administration.filter.GroupFilter;
import org.ikasan.dashboard.ui.general.component.AbstractCloseableResizableDialog;
import org.ikasan.dashboard.ui.general.component.FilteringGrid;
import org.ikasan.dashboard.ui.util.SystemEventConstants;
import org.ikasan.dashboard.ui.util.SystemEventLogger;
import org.ikasan.security.model.IkasanPrincipal;
import org.ikasan.security.model.IkasanPrincipalLite;
import org.ikasan.security.model.Role;
import org.ikasan.security.service.SecurityService;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
public class SelectGroupDialog extends AbstractCloseableResizableDialog
{
private SecurityService securityService;
private SystemEventLogger systemEventLogger;
private List associatedGroups;
private FilteringGrid ikasanPrincipalLiteFilteringGrid;
public SelectGroupDialog(List associatedGroups, SecurityService securityService
, SystemEventLogger systemEventLogger, FilteringGrid ikasanPrincipalLiteFilteringGrid)
{
this.associatedGroups = associatedGroups;
if(this.associatedGroups == null)
{
throw new IllegalArgumentException("associatedGroups cannot be null!");
}
this.securityService = securityService;
if(this.securityService == null)
{
throw new IllegalArgumentException("securityService cannot be null!");
}
this.systemEventLogger = systemEventLogger;
if(this.systemEventLogger == null)
{
throw new IllegalArgumentException("systemEventLogger cannot be null!");
}
this.ikasanPrincipalLiteFilteringGrid = ikasanPrincipalLiteFilteringGrid;
if(this.ikasanPrincipalLiteFilteringGrid == null)
{
throw new IllegalArgumentException("groupDataProvider cannot be null!");
}
init();
}
private void init()
{
super.title.setText(getTranslation("label.select-group", UI.getCurrent().getLocale()));
H3 selectGroupLabel = new H3(getTranslation("label.select-group", UI.getCurrent().getLocale()));
List principals = this.securityService.getAllPrincipalLites();
principals.removeAll(associatedGroups);
GroupFilter groupFilter = new GroupFilter();
FilteringGrid groupGrid = new FilteringGrid<>(groupFilter);
groupGrid.setSizeFull();
groupGrid.setClassName("my-grid");
groupGrid.setItems(principals.stream()
.filter(principal -> principal.getType() != null && principal.getType().equals("application"))
.collect(Collectors.toList()));
groupGrid.addColumn(IkasanPrincipalLite::getName)
.setHeader(getTranslation("table-header.group-name", UI.getCurrent().getLocale(), null))
.setKey("name")
.setSortable(true)
.setFlexGrow(2);
groupGrid.addColumn(IkasanPrincipalLite::getDescription)
.setHeader(getTranslation("table-header.group-description", UI.getCurrent().getLocale(), null))
.setKey("description")
.setSortable(true)
.setFlexGrow(8);
groupGrid.addItemDoubleClickListener((ComponentEventListener>) ikasanPrincipalLiteItemDoubleClickEvent ->
{
Collection items = this.ikasanPrincipalLiteFilteringGrid.getItems();
items.add(ikasanPrincipalLiteItemDoubleClickEvent.getItem());
this.ikasanPrincipalLiteFilteringGrid.setItems(items);
this.ikasanPrincipalLiteFilteringGrid.getDataProvider().refreshAll();
groupGrid.getItems().remove(ikasanPrincipalLiteItemDoubleClickEvent.getItem());
groupGrid.getDataProvider().refreshAll();
});
HeaderRow hr = groupGrid.appendHeaderRow();
groupGrid.addGridFiltering(hr, groupFilter::setNameFilter, "name");
groupGrid.addGridFiltering(hr, groupFilter::setDescriptionFilter, "description");
groupGrid.setSizeFull();
VerticalLayout layout = new VerticalLayout();
layout.setSizeFull();
layout.add(selectGroupLabel, groupGrid);
this.content.add(layout);
super.setWidth("1200px");
super.setHeight("700px");
}
}