io.imunity.vaadin.endpoint.common.message_templates.CompatibleTemplatesComboBox Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of unity-server-vaadin-endpoint-common Show documentation
Show all versions of unity-server-vaadin-endpoint-common Show documentation
Common Vaadin endpoint components
The newest version!
/*
* Copyright (c) 2014 ICM Uniwersytet Warszawski All rights reserved.
* See LICENCE.txt file for licensing information.
*/
package io.imunity.vaadin.endpoint.common.message_templates;
import com.vaadin.flow.component.combobox.ComboBox;
import com.vaadin.flow.component.select.Select;
import org.apache.logging.log4j.Logger;
import pl.edu.icm.unity.base.exceptions.EngineException;
import pl.edu.icm.unity.base.msg_template.MessageTemplate;
import pl.edu.icm.unity.base.utils.Log;
import pl.edu.icm.unity.engine.api.MessageTemplateManagement;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
/**
* A {@link ComboBox} showing only the templates which are compatible with a given description.
* @author K. Benedyczak
*/
public class CompatibleTemplatesComboBox extends Select
{
private static final Logger LOG = Log.getLogger(Log.U_SERVER_WEB, CompatibleTemplatesComboBox.class);
private Collection values;
private final MessageTemplateManagement msgTplMan;
public CompatibleTemplatesComboBox(String definitionName, MessageTemplateManagement msgTplMan)
{
this.msgTplMan = msgTplMan;
setDefinitionName(definitionName);
setEmptySelectionAllowed(true);
}
public void setDefinitionName(String definitionName)
{
Map templates = new HashMap<>();
try
{
templates = msgTplMan.getCompatibleTemplates(definitionName);
} catch (EngineException e)
{
LOG.error("Cannot get message templates", e);
}
values = templates.keySet();
setItems(values);
}
@Override
public void setValue(String value)
{
if (values != null && values.contains(value))
super.setValue(value);
}
public void setDefaultValue()
{
if (values != null && !values.isEmpty())
setValue(values.iterator().next());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy