org.datacleaner.widgets.properties.PropertyWidgetCollection Maven / Gradle / Ivy
/**
* DataCleaner (community edition)
* Copyright (C) 2014 Neopost - Customer Information Management
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.datacleaner.widgets.properties;
import java.util.Collection;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.Map;
import org.datacleaner.descriptors.ConfiguredPropertyDescriptor;
import org.datacleaner.job.builder.ComponentBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Contains the {@link PropertyWidget}s of a particular component
*/
public class PropertyWidgetCollection {
private static final Logger logger = LoggerFactory.getLogger(PropertyWidgetCollection.class);
private final ComponentBuilder _componentBuilder;
private final Map> _widgets;
private final Map _propertyWidgetMappings;
public PropertyWidgetCollection(final ComponentBuilder componentBuilder) {
_componentBuilder = componentBuilder;
_widgets = new HashMap<>();
_propertyWidgetMappings = new IdentityHashMap<>();
logger.debug("id={} - init", System.identityHashCode(this));
}
public Collection> getWidgets() {
return _widgets.values();
}
public PropertyWidget> getWidget(final ConfiguredPropertyDescriptor propertyDescriptor) {
return _widgets.get(propertyDescriptor);
}
public void putMappedPropertyWidget(final ConfiguredPropertyDescriptor mappedProperty,
final PropertyWidgetMapping propertyWidgetMapping) {
_propertyWidgetMappings.put(mappedProperty, propertyWidgetMapping);
}
public PropertyWidget> getMappedPropertyWidget(final ConfiguredPropertyDescriptor propertyDescriptor) {
final PropertyWidgetMapping existingMapping = _propertyWidgetMappings.get(propertyDescriptor);
if (existingMapping != null) {
final PropertyWidget> propertyWidget = existingMapping.getMapping(propertyDescriptor);
if (propertyWidget != null) {
return propertyWidget;
}
}
return null;
}
/**
* Registers a widget in this factory in rare cases when the factory is not
* used to actually instantiate the widget, but it is still needed to
* register the widget for compliancy with eg. the onConfigurationChanged()
* behaviour.
*
* @param propertyDescriptor
* @param widget
*/
public void registerWidget(final ConfiguredPropertyDescriptor propertyDescriptor, final PropertyWidget> widget) {
if (widget == null) {
_widgets.remove(propertyDescriptor);
} else {
_widgets.put(propertyDescriptor, widget);
@SuppressWarnings("unchecked") final PropertyWidget
© 2015 - 2025 Weber Informatics LLC | Privacy Policy