
io.imunity.console.tprofile.MappingResultComponent Maven / Gradle / Ivy
/*
* Copyright (c) 2021 Bixbit - Krzysztof Benedyczak. All rights reserved.
* See LICENCE.txt file for licensing information.
*/
package io.imunity.console.tprofile;
import com.vaadin.flow.component.Html;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import pl.edu.icm.unity.base.message.MessageSource;
import pl.edu.icm.unity.engine.api.translation.in.MappedAttribute;
import pl.edu.icm.unity.engine.api.translation.in.MappedGroup;
import pl.edu.icm.unity.engine.api.translation.in.MappedIdentity;
import pl.edu.icm.unity.engine.api.translation.in.MappingResult;
import java.util.Collections;
import java.util.List;
/**
* Component that displays Mapping Result.
*/
public class MappingResultComponent extends VerticalLayout
{
private VerticalLayout mappingResultWrap;
private VerticalLayout groupsWrap;
private Span groupsTitleLabel;
private VerticalLayout attrsWrap;
private Grid attrsTable;
private Grid groupsTable;
private Span attrsTitleLabel;
private VerticalLayout idsWrap;
private Grid idsTable;
private Span idsTitleLabel;
private HorizontalLayout titleWrap;
private Span noneLabel;
private Html titleLabel;
private final MessageSource msg;
/**
* The constructor should first build the main layout, set the
* composition root and then do any custom initialization.
*
* The constructor will not be automatically regenerated by the
* visual editor.
*/
public MappingResultComponent(MessageSource msg)
{
this.msg = msg;
add(buildMainLayout());
setVisible(false);
initLabels();
initTables();
}
private void initLabels()
{
titleLabel.setHtmlContent("
" + msg.getMessage("MappingResultComponent.title") + "" );
idsTitleLabel.setText(msg.getMessage("MappingResultComponent.idsTitle"));
attrsTitleLabel.setText(msg.getMessage("MappingResultComponent.attrsTitle"));
groupsTitleLabel.setText(msg.getMessage("MappingResultComponent.groupsTitle"));
noneLabel.setText(msg.getMessage("MappingResultComponent.none"));
}
private void initTables()
{
idsTable.addColumn(MappedIdentity::getMode)
.setHeader(msg.getMessage("MappingResultComponent.mode"))
.setAutoWidth(true);
idsTable.addColumn(v -> v.getIdentity().getTypeId())
.setHeader(msg.getMessage("MappingResultComponent.idsTable.type"))
.setAutoWidth(true);
idsTable.addColumn(v -> v.getIdentity().getValue())
.setHeader(msg.getMessage("MappingResultComponent.idsTable.value"))
.setAutoWidth(true);
attrsTable.addColumn(MappedAttribute::getMode)
.setHeader(msg.getMessage("MappingResultComponent.mode"))
.setAutoWidth(true);
attrsTable.addColumn(v -> v.getAttribute().getName())
.setHeader(msg.getMessage("MappingResultComponent.attrsTable.name"))
.setAutoWidth(true);
attrsTable.addColumn(v -> v.getAttribute().getValues())
.setHeader(msg.getMessage("MappingResultComponent.attrsTable.value"))
.setAutoWidth(true);
groupsTable.addColumn(MappedGroup::getCreateIfMissing)
.setHeader(msg.getMessage("MappingResultComponent.mode"))
.setAutoWidth(true);
groupsTable.addColumn(MappedGroup::getGroup)
.setHeader(msg.getMessage("MappingResultComponent.groupsTable.group"))
.setAutoWidth(true);
}
public void displayMappingResult(MappingResult mappingResult)
{
if (mappingResult == null
|| (mappingResult.getIdentities().isEmpty()
&& mappingResult.getAttributes().isEmpty()
&& mappingResult.getGroups().isEmpty()))
{
displayItsTables(Collections.emptyList());
displayAttrsTable(Collections.emptyList());
displayGroups(Collections.emptyList());
noneLabel.setVisible(true);
} else
{
displayItsTables(mappingResult.getIdentities());
displayAttrsTable(mappingResult.getAttributes());
displayGroups(mappingResult.getGroups());
noneLabel.setVisible(false);
}
setVisible(true);
}
public void displayMappingResult(MappingResult mappingResult, String inputTranslationProfile)
{
titleLabel.setHtmlContent("" + msg.getMessage("DryRun.MappingResultComponent.title", inputTranslationProfile) + "");
noneLabel.setText("");
displayMappingResult(mappingResult);
}
private void displayItsTables(List identities)
{
idsTable.setItems(Collections.emptyList());
if (identities.isEmpty())
{
idsWrap.setVisible(false);
}
else
{
idsWrap.setVisible(true);
idsTable.setItems(identities);
idsTable.setAllRowsVisible(true);
}
}
private void displayAttrsTable(List attributes)
{
attrsTable.setItems(Collections.emptyList());
if (attributes.isEmpty())
{
attrsWrap.setVisible(false);
}
else
{
attrsWrap.setVisible(true);
attrsTable.setItems(attributes);
attrsTable.setAllRowsVisible(true);
}
}
private void displayGroups(List groups)
{
groupsTable.setItems(Collections.emptyList());
if (groups.isEmpty())
{
groupsWrap.setVisible(false);
} else
{
groupsWrap.setVisible(true);
groupsTable.setItems(groups);
groupsTable.setAllRowsVisible(true);
}
}
private VerticalLayout buildMainLayout() {
// common part: create layout
VerticalLayout mainLayout = new VerticalLayout();
mainLayout.setSizeFull();
mainLayout.setPadding(false);
// top-level component properties
setSizeFull();
// titleWrap
titleWrap = buildTitleWrap();
mainLayout.add(titleWrap);
// mappingResultWrap
mappingResultWrap = buildMappingResultWrap();
mainLayout.add(mappingResultWrap);
return mainLayout;
}
private HorizontalLayout buildTitleWrap() {
// common part: create layout
titleWrap = new HorizontalLayout();
titleWrap.setPadding(false);
//titleWrap.setSpacing(true);
// titleLabel
titleLabel = new Html("");
titleWrap.add(titleLabel);
// noneLabel
noneLabel = new Span();
noneLabel.setText("Label");
titleWrap.add(noneLabel);
return titleWrap;
}
private VerticalLayout buildMappingResultWrap() {
// common part: create layout
mappingResultWrap = new VerticalLayout();
// idsWrap
idsWrap = buildIdsWrap();
mappingResultWrap.add(idsWrap);
// attrsWrap
attrsWrap = buildAttrsWrap();
mappingResultWrap.add(attrsWrap);
// groupsWrap
groupsWrap = buildGroupsWrap();
mappingResultWrap.add(groupsWrap);
return mappingResultWrap;
}
private VerticalLayout buildIdsWrap() {
// common part: create layout
idsWrap = new VerticalLayout();
idsWrap.setPadding(false);
// idsTitleLabel
idsTitleLabel = new Span();
idsTitleLabel.setText("Label");
idsWrap.add(idsTitleLabel);
// idsTable
idsTable = new Grid<>();
idsTable.setWidthFull();
idsWrap.add(idsTable);
return idsWrap;
}
private VerticalLayout buildAttrsWrap() {
// common part: create layout
attrsWrap = new VerticalLayout();
attrsWrap.setPadding(false);
// attrsTitleLabel
attrsTitleLabel = new Span();
attrsTitleLabel.setText("Label");
attrsWrap.add(attrsTitleLabel);
// attrsTable
attrsTable = new Grid<>();
attrsTable.setWidthFull();
attrsWrap.add(attrsTable);
return attrsWrap;
}
private VerticalLayout buildGroupsWrap() {
// common part: create layout
groupsWrap = new VerticalLayout();
groupsWrap.setPadding(false);
// groupsTitleLabel
groupsTitleLabel = new Span();
groupsTitleLabel.setText("Label");
groupsWrap.add(groupsTitleLabel);
// groupsLabel
groupsTable = new Grid<>();
groupsTable.setWidthFull();
groupsWrap.add(groupsTable);
return groupsWrap;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy