use of org.knime.core.data.property.ShapeHandler in project knime-core by knime.
the class ShapeManagerNodeModel method execute.
/**
* Is invoked during the node's execution to make the shape settings.
*
* @param data the input data array
* @param exec the execution monitor
* @return the same input data table with assigned shapes to one column
* @throws CanceledExecutionException if user canceled execution
*
* @see NodeModel#execute(BufferedDataTable[],ExecutionContext)
*/
@Override
protected PortObject[] execute(final PortObject[] data, final ExecutionContext exec) throws CanceledExecutionException {
BufferedDataTable inData = (BufferedDataTable) data[INPORT];
ShapeHandler shapeHandler = new ShapeHandler(new ShapeModelNominal(m_map));
final DataTableSpec newSpec = appendShapeHandler(inData.getSpec(), m_column, shapeHandler);
BufferedDataTable changedSpecTable = exec.createSpecReplacerTable(inData, newSpec);
DataTableSpec modelSpec = new DataTableSpec(newSpec.getColumnSpec(m_column));
ShapeHandlerPortObject viewPort = new ShapeHandlerPortObject(modelSpec, shapeHandler.toString() + " based on column \"" + m_column + "\"");
return new PortObject[] { changedSpecTable, viewPort };
}
use of org.knime.core.data.property.ShapeHandler in project knime-core by knime.
the class ShapeManagerNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inPorts) throws InvalidSettingsException {
// check null column
if (m_column == null) {
throw new InvalidSettingsException("No column selected.");
}
// check column in spec
DataTableSpec inSpec = (DataTableSpec) inPorts[INPORT];
if (!inSpec.containsName(m_column)) {
throw new InvalidSettingsException("Column " + m_column + " not found.");
}
if (m_map.isEmpty()) {
throw new InvalidSettingsException("No shapes defined to apply.");
}
ShapeHandler shapeHandler = new ShapeHandler(new ShapeModelNominal(m_map));
DataTableSpec outSpec = appendShapeHandler(inSpec, m_column, shapeHandler);
DataTableSpec modelSpec = new DataTableSpec(outSpec.getColumnSpec(m_column));
return new DataTableSpec[] { outSpec, modelSpec };
}
use of org.knime.core.data.property.ShapeHandler in project knime-core by knime.
the class DataColumnSpecCreator method merge.
/**
* Merges the existing {@link DataColumnSpec} with a second
* {@link DataColumnSpec}. If they have equal structure, the domain
* information and properties from both DataColumnSpecs is merged,
* Color, Shape and Size-Handlers are compared (must be equal).
*
* @param cspec2 the second {@link DataColumnSpec}.
*
* @see DataTableSpec#mergeDataTableSpecs(DataTableSpec...)
* @throws IllegalArgumentException if the structure (type and name) does
* not match, if the domain cannot be merged, if the Color-,
* Shape- or SizeHandlers are different or the sub element
* names are not equal.
*/
public void merge(final DataColumnSpec cspec2) {
if (!cspec2.getName().equals(m_name) || !cspec2.getType().equals(m_type)) {
throw new IllegalArgumentException("Structures of DataColumnSpecs" + " do not match.");
}
DataColumnDomain domain2 = cspec2.getDomain();
boolean hasDomainChanged = false;
final Set<DataCell> myValues = m_domain.getValues();
final Set<DataCell> oValues = domain2.getValues();
Set<DataCell> newValues;
if (myValues == null || oValues == null) {
newValues = null;
hasDomainChanged |= myValues != null;
} else if (myValues.equals(oValues)) {
newValues = myValues;
} else {
newValues = new LinkedHashSet<DataCell>(myValues);
newValues.addAll(oValues);
hasDomainChanged = true;
}
DataValueComparator comparator = m_type.getComparator();
final DataCell myLower = m_domain.getLowerBound();
final DataCell oLower = domain2.getLowerBound();
DataCell newLower;
if (myLower == null || oLower == null) {
newLower = null;
hasDomainChanged |= myLower != null;
} else if (myLower.equals(oLower)) {
newLower = myLower;
} else if (comparator.compare(myLower, oLower) > 0) {
newLower = oLower;
hasDomainChanged = true;
} else {
newLower = myLower;
}
final DataCell myUpper = m_domain.getUpperBound();
final DataCell oUpper = domain2.getUpperBound();
DataCell newUpper;
if (myUpper == null || oUpper == null) {
newUpper = null;
hasDomainChanged |= myUpper != null;
} else if (myUpper.equals(oUpper)) {
newUpper = myUpper;
} else if (comparator.compare(myUpper, oUpper) < 0) {
newUpper = oUpper;
hasDomainChanged = true;
} else {
newUpper = myUpper;
}
if (hasDomainChanged) {
setDomain(new DataColumnDomain(newLower, newUpper, newValues));
}
// check for redundant color handler
ColorHandler colorHandler2 = cspec2.getColorHandler();
if (!Objects.equals(m_colorHandler, colorHandler2)) {
LOGGER.warn("Column has already a color handler attached, ignoring new handler.");
}
// check for redundant shape handler
ShapeHandler shapeHandler2 = cspec2.getShapeHandler();
if (!Objects.equals(m_shapeHandler, shapeHandler2)) {
LOGGER.warn("Column has already a shape handler attached, ignoring new handler.");
}
// check for redundant size handler
SizeHandler sizeHandler2 = cspec2.getSizeHandler();
if (!Objects.equals(m_sizeHandler, sizeHandler2)) {
LOGGER.warn("Column has already a size handler attached, ignoring new handler.");
}
// check for redundant filter handler
FilterHandler filterHandler = cspec2.getFilterHandler().orElse(null);
if (!Objects.equals(m_filterHandler, filterHandler)) {
LOGGER.warn("Column has already a filter handler attached, ignoring new handler.");
}
// merge properties, take intersection
DataColumnProperties prop2 = cspec2.getProperties();
Map<String, String> mergedProps = new HashMap<String, String>();
Enumeration<String> e = m_properties.properties();
while (e.hasMoreElements()) {
String key = e.nextElement();
String value = m_properties.getProperty(key);
if (prop2.getProperty(key) != null && prop2.getProperty(key).equals(value)) {
mergedProps.put(key, value);
}
}
if (mergedProps.size() != m_properties.size()) {
setProperties(new DataColumnProperties(mergedProps));
}
List<String> elNames2 = cspec2.getElementNames();
String[] elNames2Array = elNames2.toArray(new String[elNames2.size()]);
String[] elNamesArray = m_elementNames == null ? new String[] { m_name } : m_elementNames;
if (!Arrays.deepEquals(elNamesArray, elNames2Array)) {
throw new IllegalArgumentException("Element names are not equal");
}
}
use of org.knime.core.data.property.ShapeHandler in project knime-core by knime.
the class ShapeAppenderNodeModel method createOutputSpec.
private DataTableSpec createOutputSpec(final DataTableSpec modelSpec, final DataTableSpec dataSpec) throws InvalidSettingsException {
if (modelSpec == null || dataSpec == null) {
throw new InvalidSettingsException("Invalid input.");
}
if (modelSpec.getNumColumns() < 1) {
throw new InvalidSettingsException("No shape information in input");
}
DataColumnSpec col = modelSpec.getColumnSpec(0);
ShapeHandler shapeHandler = col.getShapeHandler();
if (col.getShapeHandler() == null) {
throw new InvalidSettingsException("No shape information in input");
}
String column = m_column.getStringValue();
if (column == null) {
// auto-configuration/guessing
if (dataSpec.containsName(col.getName())) {
column = col.getName();
}
}
if (column == null) {
throw new InvalidSettingsException("Not configured.");
}
if (!dataSpec.containsName(column)) {
throw new InvalidSettingsException("Column \"" + column + "\" not available.");
}
DataTableSpec spec = ShapeManagerNodeModel.appendShapeHandler(dataSpec, column, shapeHandler);
return spec;
}
use of org.knime.core.data.property.ShapeHandler in project knime-core by knime.
the class DataColumnSpec method load.
/**
* Reads name, type, domain, and properties from the given
* <code>ConfigRO</code> and - if available - size, shape, and color
* handler. Returns a new <code>DataColumnSpec</code> object initialized
* with the information read.
*
* @param config to read properties from
* @return a new column spec object
* @throws InvalidSettingsException if one of the non-optional properties is
* not available or can't be initialized
* @throws NullPointerException if the config object is <code>null</code>
*/
public static DataColumnSpec load(final ConfigRO config) throws InvalidSettingsException {
String name = config.getString(CFG_COLUMN_NAME);
String[] elNames = config.getStringArray(CFG_ELEMENT_NAMES, (String[]) null);
if (elNames == null) {
elNames = new String[] { name };
}
DataType type = DataType.load(config.getConfig(CFG_COLUMN_TYPE));
DataColumnDomain domain = DataColumnDomain.load(config.getConfig(CFG_COLUMN_DOMAIN));
DataColumnProperties properties = DataColumnProperties.load(config.getConfig(CFG_COLUMN_PROPS));
ColorHandler color = null;
if (config.containsKey(CFG_COLORS)) {
color = ColorHandler.load(config.getConfig(CFG_COLORS));
}
SizeHandler size = null;
if (config.containsKey(CFG_SIZES)) {
size = SizeHandler.load(config.getConfig(CFG_SIZES));
}
ShapeHandler shape = null;
if (config.containsKey(CFG_SHAPES)) {
shape = ShapeHandler.load(config.getConfig(CFG_SHAPES));
}
FilterHandler filter = null;
if (config.containsKey(CFG_FILTER)) {
filter = FilterHandler.load(config.getConfig(CFG_FILTER));
}
final DataColumnMetaDataManager metaDataManager;
if (config.containsKey(CFG_META_DATA)) {
metaDataManager = DataColumnMetaDataManager.load(config.getConfig(CFG_META_DATA));
} else {
// create an empty meta data object to avoid issues with NPEs
metaDataManager = DataColumnMetaDataManager.EMPTY;
}
return new DataColumnSpec(name, elNames, type, domain, properties, size, color, shape, filter, metaDataManager);
}
Aggregations